/* Panel XFLOWD TAX — línea gráfica del CRM XFLOWD (Mati 12-11): tokens de static/facturacion.css y el menú lateral
   de templates/_sidebar.html del CRM. Inter servida por el propio panel (la CSP no deja cargar fuentes de afuera).
   Estados SIEMPRE con ícono + texto (nunca solo color). */
@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("/fuentes/Inter-Regular.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("/fuentes/Inter-Medium.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("/fuentes/Inter-SemiBold.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-weight: 700; font-display: swap; src: url("/fuentes/Inter-Bold.ttf") format("truetype"); }

:root {
  --navy: #0F2138;
  --teal: #06697E; --teal-dark: #054F5F; --teal-light: #E6F0F2;
  --bg: #F3F4F6; --white: #fff; --border: #E5E7EB; --muted: #64748B; --text: #0F2138;
  --success: #10B981; --success-bg: #ECFDF5; --success-border: #A7F3D0; --success-fg: #047857;
  --warning: #F59E0B; --warning-bg: #FFFBEB; --warning-border: #FDE68A; --warning-fg: #92400E;
  --danger: #EF4444;  --danger-bg: #FEF2F2;  --danger-border: #FECACA;  --danger-fg: #B91C1C;
  --info: #3B82F6;    --info-bg: #EFF6FF;    --info-border: #BFDBFE;    --info-fg: #1D4ED8;
  --sidebar-w: 220px;
  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 12px; --radius-full: 9999px;
  --font: "Inter", -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--text); }
a { color: var(--teal); font-weight: 500; }
a:hover { color: var(--teal-dark); }
h1 { font-size: 20px; line-height: 28px; font-weight: 700; color: var(--navy); margin: 0 0 1.1rem;
     display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .5rem; overflow-wrap: anywhere; }
h1 .tenue { font-size: 14px; font-weight: 500; }
h2 { font-size: 15px; line-height: 22px; font-weight: 700; color: var(--navy); margin: 0 0 .8rem; }
h3 { font-size: 13px; font-weight: 700; margin: 1rem 0 .5rem; color: var(--navy); }
p { margin: 0 0 .8rem; }
.tenue { color: var(--muted); font-weight: 400; }
.oculto { position: absolute; left: -9999px; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--teal-light); padding: 1px 6px;
       border-radius: var(--radius-sm); overflow-wrap: anywhere; }

/* ── Estructura: menú lateral + área principal ─────────────────────────────────────────── */
.principal { min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
body.con-menu .principal { margin-left: var(--sidebar-w); }
.contenido { width: 100%; max-width: 1280px; padding: 24px 28px 60px; }
body.sin-menu .contenido { margin: 0 auto; }

/* top/bottom 0 en vez de 100vh: en el iPhone, 100vh incluye la barra del navegador y taparía «Cerrar sesión» */
.sidebar { width: var(--sidebar-w); background: var(--white); border-right: 1px solid var(--border); bottom: 0;
           overflow-y: auto; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; z-index: 150; }
.sidebar-logo { padding: 18px 18px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column;
                align-items: flex-start; gap: 8px; text-decoration: none; }
.sidebar-logo img { width: 100%; max-width: 184px; height: auto; display: block; }
.sidebar-logo .tag { background: var(--teal-light); color: var(--teal); font-size: 11px; padding: 2px 10px; }
.sidebar-centro { padding: 14px 20px 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; overflow-wrap: anywhere; }
.sidebar-centro .sidebar-label { padding: 0; }
.sidebar-centro .tenue { font-size: 12px; }
.sidebar-section { padding: 18px 12px 4px; }
.sidebar-label { display: block; font-size: 10px; font-weight: 700; color: #94A3B8; letter-spacing: 1px;
                 text-transform: uppercase; padding: 0 8px; margin: 0 0 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; font-size: 13px;
            font-weight: 500; color: #475569; margin-bottom: 2px; border-left: 3px solid transparent;
            text-decoration: none; transition: background .15s, color .15s; }
.nav-item:hover { background: #F1F5F9; color: var(--navy); }
.nav-item.activo { background: var(--teal-light); color: var(--teal); border-left-color: var(--teal); font-weight: 600; }
.nav-icono { font-size: 15px; flex-shrink: 0; opacity: .5; }
.nav-item.activo .nav-icono { opacity: 1; }
details.grupo { padding-top: 12px; }
details.grupo > summary { display: flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; border-radius: 6px;
                          padding-top: 3px; padding-bottom: 3px; }
details.grupo > summary::-webkit-details-marker { display: none; }
details.grupo > summary > span:first-child { flex: 1; }
details.grupo > summary:hover { background: rgba(15, 33, 56, .05); }
.sb-caret { font-size: 13px; line-height: 1; color: #94A3B8; transition: transform .18s ease; }
details.grupo:not([open]) .sb-caret { transform: rotate(-90deg); }
.nav-item.pronto-item { cursor: default; opacity: .6; padding-left: 13px; }
.nav-item.pronto-item:hover { background: none; color: #475569; }
.pronto { margin-left: auto; background: var(--border); color: var(--muted); font-size: 9px; font-weight: 700;
          padding: 2px 6px; border-radius: 6px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.elegir { padding: 16px 12px 0; margin: 0; }
.elegir select { margin: 0; font-size: 13px; padding: .5rem .6rem; }
.sidebar-footer { margin-top: auto; padding: 14px 12px; border-top: 1px solid var(--border); display: flex;
                  flex-direction: column; gap: 8px; }
.sidebar-footer form { margin: 0; }
.user-pill { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px; background: #F8FAFC;
             border: 1px solid var(--border); min-width: 0; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--teal); color: #fff; font-size: 11px;
               font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.user-datos { display: flex; flex-direction: column; min-width: 0; font-size: 12px; line-height: 1.3; }
.user-datos strong, .user-datos .tenue { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-datos .tenue { font-size: 11px; }
button.boton-salir { width: 100%; justify-content: center; background: #EEF2F6; border-color: #EEF2F6; color: var(--muted);
                     font-size: 12px; padding: 8px 12px; border-radius: 8px; }
button.boton-salir:hover { background: var(--danger-bg); border-color: var(--danger-border); color: #DC2626; }

/* barra con ☰, velo y ✕: solo en celular */
.barra-movil, .velo, .cerrar-menu { display: none; }

/* ── Franjas de arriba ─────────────────────────────────────────────────────────────────── */
.ambiente { background: var(--warning-bg); color: var(--warning-fg); border-bottom: 1px solid var(--warning-border);
            text-align: center; padding: .45rem 1rem; font-weight: 600; font-size: 12px; }
.franja-staff { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: .5rem 1rem;
                align-items: center; justify-content: center; padding: .55rem 1rem; font-size: 13px;
                background: var(--navy); color: #fff; }
.franja-staff form { margin: 0; }
button.boton-franja { background: #fff; color: var(--navy); border-color: #fff; padding: 6px 14px; font-size: 12px; }
button.boton-franja:hover { background: var(--teal-light); color: var(--navy); }

/* ── Tarjetas (como el CRM: borde, sin sombra) ─────────────────────────────────────────── */
.tarjeta { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg);
           padding: 18px 20px; margin-bottom: 16px; min-width: 0; }
.tarjeta > h2:first-child { margin-top: 0; }
.tarjeta.angosta { max-width: 400px; margin: 4rem auto; padding: 28px; border-radius: 16px;
                   box-shadow: 0 4px 24px rgba(27, 42, 74, .1), 0 1px 4px rgba(27, 42, 74, .06); }
.tarjeta.angosta .logo-login { height: 30px; margin-bottom: .8rem; display: block; }
.grilla2, .grilla3 { display: grid; gap: 16px; margin-bottom: 16px; }
.grilla2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grilla3 { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.grilla2 > .tarjeta, .grilla3 > .tarjeta, .grilla2 > div > .tarjeta:last-child { margin-bottom: 0; }
.titulo-fila { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.titulo-fila h1, .titulo-fila h2 { margin: 0; }

/* ── Formularios ───────────────────────────────────────────────────────────────────────── */
label { display: block; font-size: 12px; font-weight: 600; color: var(--navy); margin-bottom: .85rem; }
label.check { display: flex; gap: .5rem; align-items: center; font-size: 14px; font-weight: 400; }
input, select, textarea { display: block; width: 100%; max-width: 100%; margin-top: .35rem; padding: 9px 12px; font: inherit;
                          font-size: 14px; color: var(--text); background: var(--white); border: 1.5px solid var(--border);
                          border-radius: var(--radius-md); }
input::placeholder { color: #94A3B8; }
input[type=checkbox], input[type=radio] { width: auto; display: inline-block; margin: 0; accent-color: var(--teal); }
input[type=file] { padding: 7px 10px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-light); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-md); padding: .8rem 1rem; margin: 0 0 .9rem; min-width: 0; }
legend { font-size: 12px; font-weight: 700; color: var(--navy); padding: 0 .3rem; }
/* en una grilla, un campo nunca empuja su columna más allá de la tarjeta (los date/select tienen ancho propio) */
.campos2 > *, .campos3 > *, .campos-filtro > *, .opciones > * { min-width: 0; }
input, select { min-width: 0; }
.campos2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 0 .9rem; }
.campos3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 0 .9rem; }

/* ── Botones (píldora, como el CRM) ────────────────────────────────────────────────────── */
button, .boton { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-family: var(--font);
                 font-weight: 600; font-size: 13px; line-height: 1.2; padding: 9px 18px; border-radius: var(--radius-full);
                 border: 1.5px solid var(--border); background: transparent; color: var(--navy); cursor: pointer;
                 text-decoration: none; transition: background .15s, border-color .15s, color .15s; }
button:hover, .boton:hover { border-color: var(--teal); color: var(--teal); }
.primario, a.primario { background: var(--teal); color: #fff; border-color: var(--teal); }
.primario:hover, a.primario:hover { background: var(--teal-dark); border-color: var(--teal-dark); color: #fff; }
.peligro { background: var(--danger); color: #fff; border-color: var(--danger); }
.peligro:hover { background: #DC2626; border-color: #DC2626; color: #fff; }
.grande { padding: 11px 24px; font-size: 14px; }
button[disabled], button[disabled]:hover { background: #E2E8F0; color: #475569; border-color: #CBD5E1; cursor: wait; }
button.enlace { border: 0; background: none; color: var(--teal); padding: .25rem .4rem; font-weight: 600; }
button.enlace:hover { color: var(--teal-dark); text-decoration: underline; }
.acciones { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .8rem; }
.acciones form { margin: 0; }
form.en-linea { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
form.en-linea label { margin: 0; }

/* ── Tablas ────────────────────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid #F1F5F9; vertical-align: middle; }
thead th { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px;
           background: #FAFBFC; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover td { background: #FAFBFC; }
tbody tr:last-child td { border-bottom: none; }
.tarjeta > table:first-child, .tarjeta > .tabla-scroll:first-child { margin-top: -6px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table:not(.apilable):not(#items) td:first-child { white-space: nowrap; }
table.compacta td { padding: .45rem .4rem; }
table.compacta th { background: none; }
table#items input, table#items select { margin: 0; }
/* una tabla ancha se corre de lado DENTRO de su caja, nunca la página (panel.js envuelve cada tabla) */
.tabla-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.tabla-scroll > table { min-width: 100%; }

/* ── Estados: fondo claro + texto fuerte + borde, SIEMPRE con ícono y texto ───────────── */
.estado { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; line-height: 1.5;
          padding: 3px 10px; border-radius: var(--radius-full); white-space: nowrap; background: #F1F5F9;
          color: var(--muted); border: 1px solid var(--border); }
.estado-aceptado { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-border); }
.estado-rechazado, .estado-no_enviado { background: var(--danger-bg); color: var(--danger-fg); border: 1.5px solid var(--danger-border); }
.estado-reparos, .estado-incierto { background: var(--warning-bg); color: var(--warning-fg); border: 1.5px solid var(--warning-border); }
.estado-enviando, .estado-enviado, .estado-en_proceso { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-border); }
.tag { display: inline-flex; align-items: center; border-radius: var(--radius-full); padding: 3px 10px; font-size: 11px; font-weight: 600; }

/* ── Avisos (borde izquierdo por tipo, como los toasts del CRM) ────────────────────────── */
.aviso { padding: 12px 16px; border-radius: var(--radius-md); background: var(--white); border: 1px solid var(--border);
         border-left: 4px solid var(--teal); margin-bottom: 16px; font-size: 13px; overflow-wrap: anywhere; }
.aviso-error { border-color: var(--danger-border); border-left-color: var(--danger); background: var(--danger-bg); color: var(--danger-fg); }
.aviso-ok { border-color: var(--success-border); border-left-color: var(--success); background: var(--success-bg); color: var(--success-fg); }

/* ── Emitir ────────────────────────────────────────────────────────────────────────────── */
.opciones { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); gap: .5rem; }
.opcion { display: flex; gap: .55rem; align-items: center; font-size: 13px; font-weight: 500; border: 1.5px solid var(--border);
          border-radius: var(--radius-md); padding: .65rem .8rem; margin: 0; cursor: pointer; background: var(--white); }
.opcion:has(input:checked) { border-color: var(--teal); background: var(--teal-light); }
.opcion.sin-folios { opacity: .65; }
.total { text-align: right; margin: 1rem 0 0; font-size: 14px; }
.total strong { color: var(--navy); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.historial { padding-left: 1.2rem; font-size: 13px; }
.logo-muestra { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-md); padding: .7rem; margin: .4rem 0 .9rem; }
.logo-muestra img { display: block; max-width: 100%; max-height: 70px; }

body.es-boleta .solo-factura, body.es-boleta .solo-factura-i, body:not(.es-boleta) .solo-boleta,
body:not(.es-boleta) .solo-boleta-i, body:not(.es-nota) .solo-nota { display: none; }

/* ── Portal ────────────────────────────────────────────────────────────────────────────── */
.filtros .campos-filtro { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 0 .8rem; }
.nota { font-size: 12px; margin-top: 1rem; }
.enlace-largo { display: block; word-break: break-all; padding: .6rem .8rem; font-size: 12px; }

/* ── Responsive (mismas reglas que static/responsive.css del CRM) ─────────────────────── */
@media (max-width: 1000px) {
  .filtros .campos-filtro { grid-template-columns: 1fr 1fr; }
  .filtros .ancho2 { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .contenido { padding: 20px 18px 48px; }
}
@media (max-width: 720px) {
  body.con-menu .principal { margin-left: 0; }
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; visibility: hidden; }
  body.menu-abierto .sidebar { transform: translateX(0); visibility: visible; box-shadow: 4px 0 24px rgba(0, 0, 0, .2); }
  .velo { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 140; opacity: 0;
          pointer-events: none; transition: opacity .25s; }
  body.menu-abierto .velo { opacity: 1; pointer-events: auto; }
  body.menu-abierto { overflow: hidden; }
  /* barra de arriba (en el flujo: nunca tapa contenido) con ☰, logo y a quién corresponde */
  .barra-movil { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--white);
                 border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 120; }
  .barra-movil img { height: 20px; display: block; flex-shrink: 0; }
  .barra-movil-titulo { font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; white-space: nowrap;
                        overflow: hidden; text-overflow: ellipsis; }
  button.hamburguesa { width: 42px; height: 42px; padding: 0; border: 1px solid #D7DBE0; border-radius: 10px;
                       background: var(--white); color: var(--navy); font-size: 19px; flex-shrink: 0; }
  button.cerrar-menu { display: inline-flex; position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; padding: 0;
                       border-radius: 10px; font-size: 16px; color: var(--muted); }
  .sidebar { width: min(280px, 86vw); }
  .sidebar-logo { padding-right: 56px; }
  .franja-staff { position: static; }
  .contenido { padding: 18px 14px 40px; }
  h1 { font-size: 18px; line-height: 25px; }
  .tarjeta { padding: 16px 14px; }
  .tarjeta.angosta { margin: 1.5rem auto; padding: 22px 18px; }
  /* 16 px: el iPhone no hace zoom al escribir */
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; }
  .acciones > *, .acciones form, .acciones button, .acciones .boton { flex: 1 1 auto; }
  .filtros .campos-filtro { grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
  .filtros input[type=date] { padding-left: 8px; padding-right: 6px; font-size: 15px; }
  .total { text-align: left; }
  /* listados como tarjetas: una fila = un bloque, cada dato con el nombre de su columna */
  table.apilable thead { display: none; }
  table.apilable, table.apilable tbody, table.apilable tr, table.apilable td { display: block; width: 100%; }
  table.apilable tr { padding: 10px 2px; border-bottom: 1px solid var(--border); }
  table.apilable tbody tr:last-child { border-bottom: none; }
  table.apilable tbody tr:hover td { background: none; }
  table.apilable td { padding: 4px 0; border: 0; text-align: right; white-space: normal; overflow-wrap: anywhere; }
  table.apilable td::after { content: ""; display: block; clear: both; }
  table.apilable td::before { content: attr(data-label); float: left; margin-right: 14px; font-size: 11px; font-weight: 700;
                              color: var(--muted); text-transform: uppercase; letter-spacing: .4px; text-align: left;
                              line-height: 20px; }
  table.apilable td[data-label=""]::before, table.apilable td:not([data-label])::before { content: none; }
  table.apilable td:empty { display: none; }
  table.apilable td > form, table.apilable td > .acciones { justify-content: flex-end; margin: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .velo { transition: none; }
}
