:root {
  /* Paleta corporativa EC Lawyers */
  --primary:   #0B1F3F;  /* navy del isotipo y del texto principal */
  --accent:    #9ACA3C;  /* verde lima de la flecha y de "EC" */
  --accent-dark:#7AA82B; /* verde más oscuro para contrastes */
  --gray:      #7E7E7E;  /* gris de "Lawyers" */
  --bg:        #F7F8F5;
  --bubble-agent:  #FFFFFF;
  --bubble-client: #0B1F3F;
  --bubble-system: #F2F8E2;
  --text-muted:    #5C5C5C;
  --border:        #DEE2D8;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: #1a1a1a;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--primary);
  color: white;
  padding: 12px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  border-bottom: 3px solid var(--accent);
}
.topbar .brand { display: flex; align-items: center; gap: 14px; }
.topbar .brand img { height: 38px; width: auto; display: block; background: white; padding: 4px 8px; border-radius: 4px; }
.topbar .brand .tagline { display: block; font-size: 12px; opacity: 0.85; margin-top: 2px; }
.ghost-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.ghost-btn:hover { background: rgba(255,255,255,0.1); }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px max(20px, calc((100% - 760px) / 2));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.45;
  font-size: 15px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.bubble.agent {
  background: var(--bubble-agent);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}
.bubble.client {
  background: var(--bubble-client);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}
.bubble.system {
  background: var(--bubble-system);
  border-left: 4px solid var(--accent);
  align-self: stretch;
  font-size: 14px;
  color: #2F4A18;
}
.bubble .meta {
  display: block;
  font-size: 11px;
  opacity: 0.6;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.doc-card {
  background: white;
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 14px 18px;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.doc-card .info { flex: 1; }
.doc-card h3 { margin: 0 0 4px 0; color: var(--primary); font-size: 16px; }
.doc-card p { margin: 0; font-size: 13px; color: var(--text-muted); }
.doc-card a {
  display: inline-block;
  background: var(--primary);
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 14px;
  margin-left: 12px;
}

.doc-card.escrito-card {
  border-color: var(--primary);
  border-left-width: 6px;
  background: #F4FAEE;
}
.doc-card.escrito-card a {
  background: var(--accent);
  color: var(--primary);
  font-weight: 600;
}
.doc-card.escrito-card small { color: var(--text-muted); font-size: 11px; }

.escalada-card {
  background: #FFF0E8;
  border-left: 6px solid #C75A2C;
  border-radius: 8px;
  padding: 14px 18px;
  align-self: stretch;
}
.escalada-card h3 { margin: 0 0 6px 0; color: #6E2F12; font-size: 15px; }
.escalada-card p { margin: 0; font-size: 14px; color: #4A2510; }
.finalizacion-card { background: #F0EEEA; border-left-color: #6B6657; }
.finalizacion-card h3 { color: #2E2A1F; }
.finalizacion-card p { color: #3D372A; }
.finalizacion-card p + p { margin-top: 8px; font-size: 13px; }

.composer {
  display: flex;
  gap: 8px;
  padding: 12px max(20px, calc((100% - 760px) / 2));
  background: white;
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #FCFBF8;
}
.composer textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.composer button {
  background: var(--primary);
  color: white;
  border: 0;
  padding: 0 22px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}
.composer button:disabled { opacity: 0.5; cursor: wait; }

.footnote {
  background: #ECEAE2;
  color: var(--text-muted);
  font-size: 12px;
  padding: 10px max(20px, calc((100% - 760px) / 2));
  border-top: 1px solid var(--border);
  line-height: 1.4;
}

.typing {
  align-self: flex-start;
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 6px;
  font-style: italic;
}

/* === Adjuntos y voz ====================================================== */
.icon-btn {
  background: white;
  color: var(--primary);
  border: 1px solid var(--border);
  width: 42px;
  height: 42px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.icon-btn:hover { background: var(--bubble-system); }
.icon-btn.grabando {
  background: #C75A2C;
  color: white;
  border-color: #6E2F12;
  animation: pulse 1.1s ease-in-out infinite;
}
.icon-btn.deshabilitado {
  opacity: 0.4;
  cursor: not-allowed;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(199, 90, 44, 0.45); }
  50%      { box-shadow: 0 0 0 8px rgba(199, 90, 44, 0); }
}

.adjuntos-wrap {
  background: #F2F8E2;
  border-top: 1px solid var(--border);
  padding: 10px max(20px, calc((100% - 760px) / 2));
  font-size: 13px;
  color: #2E3B12;
}
.adjuntos-wrap.hidden { display: none; }
.adjuntos-titulo {
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.link-btn {
  background: transparent;
  border: 0;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
  padding: 0;
}
.adjuntos-lista {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.adjunto-item {
  display: grid;
  grid-template-columns: 22px 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  background: white;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.adjunto-item .icono { font-size: 16px; text-align: center; }
.adjunto-item .nombre {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.adjunto-item .tamano { font-size: 11px; color: var(--text-muted); }
.adjunto-item .sensible { font-size: 12px; display: inline-flex; gap: 4px; align-items: center; }
.adjunto-item .quitar {
  background: transparent;
  border: 0;
  color: #C75A2C;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
}
.adjuntos-disclaimer {
  margin: 8px 0 0 0;
  font-size: 11px;
  color: var(--text-muted);
}

.bubble-adjuntos {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.bubble-adjunto {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  font-size: 11px;
  padding: 2px 6px;
}
.bubble.agent .bubble-adjunto { background: var(--bubble-system); border-color: var(--border); }

body.dragging .chat { outline: 3px dashed var(--accent-dark); outline-offset: -10px; }

/* ---------- Checkout overlay (pago previo) ---------- */
.checkout-overlay {
  position: fixed; inset: 0;
  background: rgba(11, 31, 63, 0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.checkout-overlay.hidden { display: none; }
.checkout-card {
  background: white;
  border-top: 4px solid var(--accent);
  border-radius: 8px;
  max-width: 520px;
  width: 100%;
  padding: 28px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.checkout-card h2 {
  margin: 0 0 6px 0;
  color: var(--primary);
  font-size: 22px;
}
.checkout-precio {
  font-size: 16px;
  color: var(--text-muted);
  margin: 4px 0 16px 0;
}
.precio-monto {
  font-size: 28px;
  color: var(--primary);
  font-weight: 700;
}
.checkout-detalle {
  font-size: 14px;
  line-height: 1.5;
  color: #333;
  margin: 0 0 14px 0;
}
.checkout-ambiente {
  font-size: 12px;
  color: #B45309;
  background: #FEF3C7;
  border-radius: 4px;
  padding: 8px 10px;
  margin: 0 0 14px 0;
}
.checkout-ambiente:empty { display: none; }
.primary-btn {
  background: var(--accent);
  color: var(--primary);
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 24px;
  cursor: pointer;
  width: 100%;
  transition: background 120ms;
}
.primary-btn:hover { background: var(--accent-dark); color: white; }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.checkout-estado {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 14px;
  text-align: center;
}
.checkout-estado.hidden { display: none; }
.checkout-estado.info     { background: #EFF6FF; color: #1E40AF; }
.checkout-estado.ok       { background: #ECFDF5; color: #047857; }
.checkout-estado.error    { background: #FEF2F2; color: #B91C1C; }
.checkout-disclaimer {
  font-size: 11px;
  color: var(--text-muted);
  margin: 16px 0 0 0;
  line-height: 1.4;
}

/* ---------- Formulario de datos del cliente (antes del chat) ---------- */
.form-overlay {
  position: fixed; inset: 0;
  background: rgba(11, 31, 63, 0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
  padding: 20px;
  overflow-y: auto;
}
.form-overlay.hidden { display: none; }
.form-card {
  background: white;
  border-top: 4px solid var(--accent);
  border-radius: 8px;
  max-width: 560px;
  width: 100%;
  padding: 28px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  margin: auto;
}
.form-card h2 {
  margin: 0 0 6px 0; color: var(--primary); font-size: 22px;
}
.form-intro {
  font-size: 14px; line-height: 1.5; color: #333; margin: 4px 0 18px 0;
}
.form-card fieldset.tipo-persona {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
  margin: 0 0 14px 0;
}
.form-card fieldset.tipo-persona legend {
  padding: 0 6px; font-size: 12px; color: var(--text-muted);
}
.form-card fieldset.tipo-persona label {
  display: inline-block; margin-right: 18px; font-size: 14px;
}
.form-row { margin-bottom: 12px; }
.form-row.hidden { display: none; }
.form-row label {
  display: block; font-size: 12px; color: var(--text-muted);
  margin-bottom: 4px;
}
.form-row input, .form-row select {
  width: 100%; padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 4px;
  background: white; color: #1a1a1a;
}
.form-row input:focus, .form-row select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.form-row-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.form-acepto {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  margin: 14px 0 10px 0;
}
.form-acepto label {
  font-size: 13px; line-height: 1.4; color: #333; display: block;
}
.form-acepto a { color: var(--primary); text-decoration: underline; }
.form-error {
  background: #FEF2F2; color: #B91C1C;
  border-radius: 4px; padding: 8px 12px;
  font-size: 13px; margin: 0 0 12px 0;
}
.form-error.hidden { display: none; }
.form-disclaimer {
  font-size: 11px; color: var(--text-muted);
  margin: 14px 0 0 0; line-height: 1.4;
}

/* ---------- Tarjeta de instrucciones de radicación ---------- */
.doc-card.radicacion-card {
  border-left: 4px solid #B45309;
  background: #FFFBF0;
}
.doc-card.radicacion-card .radicacion-caveat {
  font-size: 12px;
  color: #B45309;
  background: #FEF3C7;
  padding: 6px 8px;
  border-radius: 4px;
  margin: 6px 0 0 0;
  display: inline-block;
}

/* ---------- Tarjeta de pago inline (en chat) ---------- */
.doc-card.checkout-inline {
  border-left: 4px solid var(--accent);
  background: #FFFEF9;
}
.doc-card.checkout-inline .pagar-btn {
  width: auto;
  padding: 10px 18px;
  font-size: 14px;
}
.doc-card.checkout-inline .estado-pago {
  font-size: 13px;
  color: var(--text-muted);
  margin: 8px 0 0 0;
  min-height: 18px;
}
.amb-badge {
  display: inline-block;
  background: #FEF3C7;
  color: #B45309;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  vertical-align: middle;
}


/* ---------- Tarjeta de Orientación jurídica preliminar (en chat) ---------- */
.msg.orientacion-chat {
  background: #FFFFFF;
  border: 1px solid var(--border, #E5E7EB);
  border-left: 4px solid var(--accent, #C5A572);
  border-radius: 6px;
  padding: 20px 24px;
  margin: 12px 0;
  max-width: 100%;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text, #1A1A1A);
}
.msg.orientacion-chat .orientacion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #EEE;
  padding-bottom: 10px;
  margin-bottom: 16px;
}
.msg.orientacion-chat .orientacion-badge {
  background: var(--brand, #0B2545);
  color: #FFF;
  font-size: 11px;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 3px;
  text-transform: uppercase;
  font-weight: 600;
}
.msg.orientacion-chat .orientacion-id {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: var(--text-muted, #6C757D);
}
.msg.orientacion-chat .markdown h2 {
  font-size: 16px;
  color: var(--brand, #0B2545);
  margin: 20px 0 8px 0;
}
.msg.orientacion-chat .markdown h3 {
  font-size: 14px;
  color: var(--brand, #0B2545);
  margin: 16px 0 6px 0;
}
.msg.orientacion-chat .markdown h4 {
  font-size: 13px;
  color: var(--text, #1A1A1A);
  margin: 12px 0 4px 0;
}
.msg.orientacion-chat .markdown p { margin: 6px 0; }
.msg.orientacion-chat .markdown ul,
.msg.orientacion-chat .markdown ol { padding-left: 22px; margin: 6px 0; }
.msg.orientacion-chat .markdown li { margin: 4px 0; }
.msg.orientacion-chat .markdown hr {
  border: 0;
  border-top: 1px solid #DDD;
  margin: 18px 0 12px 0;
}
.msg.orientacion-chat .markdown strong { color: var(--brand, #0B2545); }

/* ============================================================
   Modal "Nueva consulta" (Fase B bloque 2 — fuera_de_asunto)
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 63, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: modal-fade-in 0.18s ease-out;
}
@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal-card {
  position: relative;
  background: #FFFFFF;
  color: var(--primary);
  border-radius: 12px;
  padding: 28px 26px 22px 26px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(11, 31, 63, 0.35);
  animation: modal-slide-in 0.22s ease-out;
}
@keyframes modal-slide-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
.modal-card h3 {
  margin: 0 0 12px 0;
  font-size: 1.15rem;
  color: var(--primary);
  padding-right: 24px;
}
.modal-card p {
  margin: 0 0 20px 0;
  color: var(--text-muted);
  line-height: 1.5;
}
.modal-cerrar {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--gray);
  opacity: 0.55;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: opacity 0.15s, background 0.15s;
}
.modal-cerrar:hover { opacity: 1; background: rgba(11, 31, 63, 0.06); }
.modal-acciones {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.modal-acciones .ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--primary);
}
.modal-acciones .ghost-btn:hover { background: rgba(11, 31, 63, 0.05); }
.modal-acciones .primary-btn { text-decoration: none; }
