/* Francel — panel. Marca rojo/negro sobre la estructura de docs/stitch/DESIGN.md:
   Inter, superficies claras con bordes finos, chips de estado en pastilla. */

@font-face { font-family: Inter; font-weight: 400; font-display: swap; src: url(/static/fonts/inter-400-latin.woff2) format("woff2"); }
@font-face { font-family: Inter; font-weight: 500; font-display: swap; src: url(/static/fonts/inter-500-latin.woff2) format("woff2"); }
@font-face { font-family: Inter; font-weight: 600; font-display: swap; src: url(/static/fonts/inter-600-latin.woff2) format("woff2"); }
@font-face { font-family: Inter; font-weight: 700; font-display: swap; src: url(/static/fonts/inter-700-latin.woff2) format("woff2"); }

:root {
  /* Marca (logo Francel) */
  --rojo: #b3121b;
  --rojo-hover: #8f0e15;
  --rojo-suave: #fde8e8;
  --negro: #141414;
  /* Neutros slate */
  --fondo: #f8fafc;
  --superficie: #ffffff;
  --superficie-2: #f1f5f9;
  --borde: #e2e8f0;
  --borde-fuerte: #cbd5e1;
  --texto: #0f172a;
  --texto-2: #475569;
  --texto-3: #94a3b8;
  /* Semánticos */
  --verde: #059669;       /* WhatsApp, resuelto */
  --verde-suave: #d1fae5;
  --ambar: #b45309;       /* pendiente */
  --ambar-suave: #fef3c7;
  --sombra: 0 4px 12px -2px rgba(15, 23, 42, .06), 0 2px 4px -1px rgba(15, 23, 42, .04);
  --radio: .5rem;
  --radio-lg: .75rem;
  --mono: ui-monospace, "JetBrains Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 .875rem/1.25rem Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--texto);
  background: var(--fondo);
}
h1, h2 { margin: 0; letter-spacing: -.02em; }
h1 { font-size: 1.5rem; line-height: 2rem; font-weight: 700; }
h2 { font-size: 1.125rem; line-height: 1.5rem; font-weight: 600; margin-bottom: 1rem; }
a { color: var(--rojo); }
.mono { font-family: var(--mono); font-size: .75rem; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Botones ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .375rem;
  height: 36px; padding: 0 1rem; border-radius: var(--radio);
  font: 600 .875rem/1 Inter, system-ui, sans-serif; cursor: pointer;
  border: 1px solid var(--borde-fuerte); background: var(--superficie); color: var(--texto);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--superficie-2); }
.btn:focus-visible { outline: 2px solid var(--rojo); outline-offset: 2px; }
.btn-primario { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.btn-primario:hover { background: var(--rojo-hover); border-color: var(--rojo-hover); }
.btn-peligro { color: var(--rojo); border-color: #f3c4c6; }
.btn-peligro:hover { background: var(--rojo-suave); }
.btn-chico { height: 28px; padding: 0 .625rem; font-size: .75rem; }

/* ── Formularios ─────────────────────────────────────────────── */
label { display: grid; gap: .25rem; font-weight: 500; color: var(--texto-2); }
input, select {
  height: 36px; padding: 0 .75rem; width: 100%;
  font: inherit; color: var(--texto); background: var(--superficie);
  border: 1px solid var(--borde-fuerte); border-radius: var(--radio);
}
input:focus, select:focus { outline: none; border-color: var(--rojo); box-shadow: 0 0 0 3px var(--rojo-suave); }
.form-grilla { display: grid; gap: .75rem 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }

/* ── Chips de estado ─────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; height: 22px; padding: 0 .5rem; border-radius: 9999px;
  font-size: .75rem; font-weight: 600; letter-spacing: .02em;
  background: var(--superficie-2); color: var(--texto-2);
}
.chip-rojo { background: var(--rojo-suave); color: var(--rojo-hover); }
.chip-verde { background: var(--verde-suave); color: #065f46; }
.chip-ambar { background: var(--ambar-suave); color: #92400e; }
.chip-gris { background: var(--superficie-2); color: var(--texto-3); }

/* ── Pantallas sin sesión (login, error) ─────────────────────── */
body.auth { min-height: 100dvh; display: flex; padding: 16px; background: linear-gradient(to bottom right, #fff 22%, #ff5a5f 50%, #c00000 78%, #4a0000); }
.auth-card {
  margin: auto; width: 100%; max-width: 380px; padding: 2rem;
  background: var(--superficie); border-radius: var(--radio-lg); box-shadow: var(--sombra);
  display: grid; gap: 1rem; text-align: center;
}
.auth-logo { margin: 0 auto; border-radius: 50%; }
.auth-card form { display: grid; gap: .875rem; text-align: left; }
.auth-card .btn { width: 100%; margin-top: .25rem; }
.auth-nota { margin: 0; color: var(--texto-2); font-size: .8125rem; }
.error-msg { background: var(--rojo-suave); color: var(--rojo-hover); padding: .625rem .75rem; border-radius: var(--radio); font-weight: 500; text-align: left; }

/* ── Panel: barra lateral + contenido ────────────────────────── */
body.panel { display: grid; grid-template-columns: 240px 1fr; min-height: 100dvh; }
.rail {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 1.5rem;
  padding: 1rem .75rem; background: var(--negro); color: #e5e5e5;
}
.marca { display: flex; align-items: center; gap: .625rem; padding: 0 .25rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1rem; }
.marca img { border-radius: 50%; background: #fff; }
.marca small { display: block; font-weight: 500; font-size: .75rem; color: #a3a3a3; }
.rail nav { display: grid; gap: .125rem; }
.rail nav a {
  display: flex; align-items: center; height: 38px; padding: 0 .75rem; border-radius: var(--radio);
  color: #d4d4d4; text-decoration: none; font-weight: 500;
}
.rail nav a:hover { background: #262626; color: #fff; }
.rail nav a.activo { background: var(--rojo); color: #fff; }
.rail-pie { margin-top: auto; display: grid; gap: .5rem; }
.yo { display: flex; align-items: center; gap: .625rem; padding: .5rem; border-radius: var(--radio); background: #1f1f1f; }
.yo b { display: block; color: #fff; font-weight: 600; }
.yo small { color: #a3a3a3; font-size: .75rem; }
.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--rojo); color: #fff; font-weight: 700; }
.salir { color: #a3a3a3; font-size: .8125rem; padding: 0 .5rem; text-decoration: none; }
.salir:hover { color: #fff; }

.contenido { padding: 1.5rem 2rem; display: grid; gap: 1.25rem; align-content: start; min-width: 0; }
.cabecera { display: flex; justify-content: space-between; align-items: end; gap: 1rem; flex-wrap: wrap; }
.bajada { margin: .25rem 0 0; color: var(--texto-2); }
.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio-lg); padding: 1.25rem; }
.tarjeta-tabla { padding: 0; overflow-x: auto; }

/* ── Tablas ──────────────────────────────────────────────────── */
.tabla { width: 100%; border-collapse: collapse; }
.tabla th {
  height: 36px; padding: 0 1rem; text-align: left; white-space: nowrap;
  font-size: .75rem; font-weight: 600; letter-spacing: .025em; text-transform: uppercase;
  color: var(--texto-3); background: var(--superficie-2);
}
.tabla td { padding: .625rem 1rem; border-top: 1px solid var(--superficie-2); vertical-align: middle; }
.tabla tbody tr:hover { background: var(--fondo); }
.tabla .acciones { text-align: right; white-space: nowrap; }
.tabla .acciones .btn + .btn { margin-left: .25rem; }
.tabla .mono { white-space: nowrap; }
.tabla .vacio { text-align: center; color: var(--texto-3); padding: 2rem; }

/* ── Toast y diálogo (dialogo.js) ────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: .625rem 1rem; border-radius: var(--radio); background: var(--negro); color: #fff; box-shadow: var(--sombra);
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--rojo); }
.dialogo { border: none; border-radius: var(--radio-lg); padding: 0; width: min(420px, calc(100vw - 32px)); box-shadow: var(--sombra); }
.dialogo::backdrop { background: rgba(15, 23, 42, .45); }
.dialogo-cuerpo { padding: 1.25rem 1.25rem .5rem; }
.dialogo-titulo { font-weight: 600; font-size: 1rem; margin-bottom: .375rem; }
.dialogo-mensaje { margin: 0; color: var(--texto-2); white-space: pre-line; }
.dialogo-botones { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.25rem; }
.dialogo-btn { height: 36px; padding: 0 1rem; border-radius: var(--radio); font: 600 .875rem Inter, sans-serif; cursor: pointer; border: 1px solid var(--borde-fuerte); background: var(--superficie); }
.dialogo-aceptar { background: var(--negro); border-color: var(--negro); color: #fff; }
.dialogo-aceptar.peligro { background: var(--rojo); border-color: var(--rojo); }

/* ── Clientes y proveedores ──────────────────────────────────── */
.barra { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.barra input[type=search] { width: 280px; max-width: 100%; }
.barra select { width: auto; }
.acciones-form { display: flex; gap: .5rem; align-items: center; }
.celda-notas { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--texto-2); }
.lista-simple { margin: .5rem 0 0; padding-left: 1.25rem; color: var(--texto-2); }

/* ── Bandeja de conversaciones ───────────────────────────────── */
/* Dos tarjetas redondeadas sobre el fondo: lista (búsqueda, filtros, contexto, punto de
   no leído) y chat (globos, indicador "sin responder", compositor en píldora). */
.bandeja { display: grid; grid-template-columns: 380px 1fr; gap: 1.25rem; height: calc(100dvh - 3rem); min-height: 480px; }
.bandeja-lista, .bandeja-chat { background: var(--superficie); border-radius: 1.5rem; box-shadow: var(--sombra); min-height: 0; min-width: 0; overflow: hidden; }
.bandeja-lista { display: flex; flex-direction: column; }
.bandeja-cab { padding: 1.25rem 1.25rem .75rem; display: grid; gap: .875rem; }
.bandeja-cab h1 { font-size: 1.5rem; }
.bandeja-sub { margin: -.5rem 0 0; color: var(--texto-3); }
.buscador input { height: 42px; border-radius: 9999px; border-color: transparent; background: var(--superficie-2); padding: 0 1rem; }
.filtros { display: flex; gap: .375rem; flex-wrap: wrap; }
.filtro {
  height: 30px; padding: 0 .875rem; border-radius: 9999px; cursor: pointer; border: 0;
  font: 500 .8125rem Inter, system-ui, sans-serif; background: var(--superficie-2); color: var(--texto-2);
}
.filtro.activo { background: var(--negro); color: #fff; }
.lista-conv { list-style: none; margin: 0; padding: 0 .75rem .75rem; overflow-y: auto; flex: 1; }
.lista-conv .vacio { padding: 2rem 1rem; text-align: center; color: var(--texto-3); }
.conv {
  display: flex; gap: .75rem; width: 100%; padding: .75rem; text-align: left; cursor: pointer; align-items: center;
  background: none; border: 0; border-radius: 1rem; border-bottom: 1px solid transparent; font: inherit; color: inherit;
  position: relative;
}
.conv + .conv, li + li > .conv { margin-top: .125rem; }
.conv:hover { background: var(--fondo); }
.conv.activa { background: var(--rojo-suave); }
.conv.activa::before { content: ""; position: absolute; left: 0; top: 18%; bottom: 18%; width: 3px; border-radius: 3px; background: var(--rojo); }
.avatar-conv { width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--negro); color: #fff; font-weight: 600; }
.avatar-conv.lead { background: var(--superficie-2); color: var(--texto-2); }
.avatar-conv.urgente { background: var(--rojo); }
.conv-cuerpo { display: grid; gap: .125rem; min-width: 0; flex: 1; }
.conv-fila { display: flex; align-items: center; gap: .5rem; justify-content: space-between; }
.conv-fila b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.conv-fila time { color: var(--texto-3); flex: none; font-size: .75rem; }
.conv-ctx { color: var(--rojo); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-ctx .urg { font-weight: 700; }
.conv-prev { color: var(--texto); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.leida .conv-prev { color: var(--texto-2); }
.punto { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--rojo); }
.punto-ph { width: 9px; flex: none; }

.bandeja-chat { display: flex; flex-direction: column; }
.chat-vacio { margin: auto; color: var(--texto-3); }
.chat-activo { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.chat-cab { display: flex; align-items: center; gap: .875rem; padding: 1.125rem 1.5rem; border-bottom: 1px solid var(--superficie-2); }
.chat-quien { min-width: 0; flex: 1; }
.chat-quien h2 { margin: 0; font-size: 1.0625rem; line-height: 1.375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-quien small { color: var(--texto-2); }
.chat-acciones { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.btn-icono { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--superficie-2); color: var(--texto); text-decoration: none; font-size: 1.125rem; }
.btn-icono:hover { background: var(--borde); }
.volver { display: none; }
.mensajes { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: .75rem; }
.nota-sistema { align-self: center; padding: .25rem .875rem; border-radius: 9999px; background: var(--superficie-2); color: var(--texto-2); font-size: .75rem; }
.nota-sistema.rojo { background: var(--rojo-suave); color: var(--rojo-hover); font-weight: 600; }
.msg-fila { display: grid; gap: .25rem; max-width: min(540px, 82%); }
.msg-fila.entra { align-self: flex-start; }
.msg-fila.sale { align-self: flex-end; justify-items: end; }
.msg { padding: .75rem 1rem; border-radius: 1.25rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.entra .msg { background: var(--superficie-2); border-bottom-left-radius: .375rem; }
.sale .msg { background: var(--rojo); color: #fff; border-bottom-right-radius: .375rem; }
.sale.admin .msg { background: var(--negro); }
.msg-pie { color: var(--texto-3); font-size: .75rem; padding: 0 .5rem; }
.sin-responder { color: var(--texto-3); font-size: .75rem; padding: 0 .5rem; }
.compositor { padding: .75rem 1.5rem 1rem; display: grid; gap: .5rem; }
.redactar { display: flex; gap: .5rem; align-items: center; padding: .375rem .375rem .375rem 1.25rem; border: 1px solid var(--borde); border-radius: 9999px; }
.redactar:focus-within { border-color: var(--rojo); box-shadow: 0 0 0 3px var(--rojo-suave); }
.redactar textarea { flex: 1; height: 24px; min-height: 24px; max-height: 120px; padding: 0; resize: none; border: 0; outline: none; background: none; font: inherit; color: var(--texto); }
.btn-enviar { width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; cursor: pointer; background: var(--rojo); color: #fff; font-size: 1.125rem; }
.btn-enviar:hover { background: var(--rojo-hover); }
.btn-enviar:disabled { opacity: .5; cursor: default; }
.compositor small { color: var(--texto-3); padding: 0 .75rem; }

@media (max-width: 900px) { .bandeja { grid-template-columns: 320px 1fr; } }
@media (max-width: 767px) {
  .bandeja { grid-template-columns: 1fr; height: calc(100dvh - 8rem); }
  .bandeja-chat { display: none; }
  .bandeja.con-chat .bandeja-lista { display: none; }
  .bandeja.con-chat .bandeja-chat { display: flex; }
  .volver { display: inline-flex; }
  .chat-cab { flex-wrap: wrap; padding: 1rem; }
  .chat-quien { flex: 1 1 0; }
  .chat-acciones { flex: 1 1 100%; justify-content: flex-start; }
  .mensajes { padding: 1rem; }
  .compositor { padding: .5rem 1rem 1rem; }
}

/* ── Derivaciones: ficha (columna derecha de la bandeja y pantalla Derivaciones) ─────── */
.nota-derivacion { align-self: center; display: flex; align-items: center; gap: .5rem; padding: .375rem .5rem .375rem .875rem; border-radius: 9999px; background: var(--ambar-suave); color: #92400e; font-size: .8125rem; font-weight: 600; }
.bandeja-ficha { display: none; background: var(--superficie); border-radius: 1.5rem; box-shadow: var(--sombra); min-height: 0; min-width: 0; overflow-y: auto; padding: 1.25rem; }
.ficha-titulo { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: 1rem; }
.ficha-titulo h2 { margin: 0; }
.ficha-card { display: grid; gap: .875rem; padding: 1rem; border: 1px solid var(--borde); border-radius: var(--radio-lg); background: var(--superficie); }
.ficha-card + .ficha-card { margin-top: .875rem; }
.ficha-cab { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.ficha-quien { margin: -.25rem 0 0; color: var(--texto-2); }
.pasos { list-style: none; margin: 0; padding: 0; display: grid; gap: .625rem; }
.pasos li { display: flex; gap: .625rem; align-items: flex-start; color: var(--texto-3); }
.pasos li b { display: block; font-weight: 600; }
.pasos li small { display: block; color: var(--texto-3); overflow-wrap: anywhere; }
.paso-n { width: 24px; height: 24px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 700; background: var(--superficie-2); color: var(--texto-3); }
.pasos li.hecho { color: var(--texto); }
.pasos li.hecho .paso-n { background: var(--verde); color: #fff; }
.pasos li.hecho small { color: var(--texto-2); }
.pasos li.actual { color: var(--texto); }
.pasos li.actual .paso-n { background: var(--rojo); color: #fff; }
.ficha-datos { margin: 0; display: grid; gap: .125rem; padding: .75rem; border-radius: var(--radio); background: var(--fondo); }
.ficha-datos dt { color: var(--texto-3); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .025em; }
.ficha-datos dd { margin: 0 0 .5rem; overflow-wrap: anywhere; }
.ficha-datos dd:last-child { margin-bottom: 0; }
.ficha-acc { display: grid; gap: .5rem; }
.ficha-acc .btn { height: 44px; }
.ficha-acc .btn-chico { height: 44px; font-size: .8125rem; }
.ficha-acc select { height: 44px; }
.ficha-acc .btn:disabled { opacity: .5; cursor: default; }
.deriv-lista { display: grid; gap: .875rem; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
.deriv-lista .vacio { grid-column: 1 / -1; text-align: center; color: var(--texto-3); padding: 2rem; }

@media (min-width: 1280px) {
  .bandeja.con-derivacion { grid-template-columns: 340px 1fr 360px; }
  .bandeja.con-derivacion .bandeja-ficha { display: block; }
  .solo-angosto { display: none; }
  /* Con la ficha al lado el chat queda angosto: las acciones bajan a su propia fila. */
  .bandeja.con-derivacion .chat-cab { flex-wrap: wrap; }
  .bandeja.con-derivacion .chat-quien { flex: 1 1 0; }
  .bandeja.con-derivacion .chat-acciones { flex: 1 1 100%; justify-content: flex-start; }
}
@media (max-width: 1279px) {
  .bandeja.ver-ficha .bandeja-chat { display: none; }
  .bandeja.ver-ficha .bandeja-ficha { display: block; }
}

/* ── Celular: la barra lateral pasa arriba ───────────────────── */
@media (max-width: 767px) {
  /* minmax(0, …): sin esto la columna crece hasta el ancho de los links y se agranda toda la página. */
  body.panel { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .75rem; }
  .rail nav { display: flex; overflow-x: auto; flex: 1 1 100%; order: 3; }
  .rail-pie { margin: 0 0 0 auto; display: flex; align-items: center; }
  .yo { background: none; padding: 0; }
  .yo span:last-child { display: none; }
  .contenido { padding: 1rem; }
  /* iOS hace zoom al enfocar un campo de menos de 16px. */
  input, select, textarea { font-size: 16px; }
}
