:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --text: #0e1b2e;
  --muted: #5a6478;
  --line: #e1e4ec;
  --primary: #3730a3;
  --primary-hover: #2e2889;
  --primary-ink: #ffffff;
  --primary-soft: #e6e5fa;
  --ink: #0e1b2e;           /* barra superior y toasts */
  --ink-text: #f2f4fa;
  --danger: #a8281c;
  --danger-soft: #fbe9e6;
  --warn: #8f5a00;
  --warn-soft: #fcf0d8;
  --ok: #14663f;
  --ok-soft: #e0f2e8;
  --info: #243f8f;
  --info-soft: #e5ebfa;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(14, 27, 46, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #090f1b;
    --surface: #111a2c;
    --surface-2: #17223a;
    --text: #e6ebf5;
    --muted: #96a3bd;
    --line: #22304a;
    --primary: #959cf7;
    --primary-hover: #aab0fa;
    --primary-ink: #0b1030;
    --primary-soft: #232a5c;
    --ink: #0d1626;
    --ink-text: #e6ebf5;
    --danger: #ff9a8b;
    --danger-soft: #3a1d1b;
    --warn: #f3c46f;
    --warn-soft: #382c12;
    --ok: #72dca2;
    --ok-soft: #12301f;
    --info: #9ab6f7;
    --info-soft: #15244a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.8em; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

.boot { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; background: #0e1b2e; color: #e6ebf5; }
.boot .muted { color: #96a3bd; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { gap: 22px; }
.boot-text { margin: 0; font-size: 0.9rem; letter-spacing: 0.01em; }
/* Logo animado de carga: el maletín flota, el asa se levanta y el check se dibuja en bucle */
.logo-loader { position: relative; width: 88px; height: 88px; display: grid; place-items: center; }
.logo-loader svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 10px 26px rgba(120, 112, 255, 0.35)); animation: ll-float 2.6s ease-in-out infinite; }
.logo-loader .ll-handle { transform-box: fill-box; transform-origin: 50% 100%; animation: ll-handle 2.6s ease-in-out infinite; }
.logo-loader .ll-badge { transform-box: fill-box; transform-origin: 50% 50%; animation: ll-badge 2.6s cubic-bezier(.3,1.5,.5,1) infinite; }
.logo-loader .ll-check { stroke-dasharray: 1; stroke-dashoffset: 1; animation: ll-check 2.6s ease-in-out infinite; }
.logo-loader .ll-ring { position: absolute; inset: -14px; border-radius: 34px; border: 2px solid #959cf7; opacity: 0; animation: ll-ring 2.6s ease-out infinite; }
@keyframes ll-float { 0%, 100% { transform: translateY(2px) scale(0.98); } 50% { transform: translateY(-5px) scale(1); } }
@keyframes ll-handle { 0%, 20%, 100% { transform: translateY(0); } 40%, 60% { transform: translateY(-14px); } }
@keyframes ll-badge { 0%, 30% { transform: scale(0); } 50%, 85% { transform: scale(1); } 100% { transform: scale(0); } }
@keyframes ll-check { 0%, 42% { stroke-dashoffset: 1; } 62%, 85% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: 1; } }
@keyframes ll-ring { 0%, 35% { transform: scale(0.85); opacity: 0; } 50% { opacity: 0.35; } 100% { transform: scale(1.25); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .logo-loader svg { animation: ll-soft 2s ease-in-out infinite !important; }
  .logo-loader .ll-check { stroke-dashoffset: 0; } .logo-loader .ll-badge { transform: none; }
}
@keyframes ll-soft { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- Layout ---------- */
.shell { max-width: 960px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar .brand { font-weight: 700; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .brand img { width: 28px; height: 28px; border-radius: 7px; }
.topbar .org { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
main { flex: 1; padding: 16px; padding-bottom: 96px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface);
  border-top: 1px solid var(--line); display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs .inner { display: flex; width: 100%; max-width: 960px; }
.tabs button {
  flex: 1; background: none; border: 0; padding: 10px 4px 8px; display: grid; gap: 2px; justify-items: center;
  color: var(--muted); font-size: 0.75rem; cursor: pointer; min-height: 56px;
}
.tabs button .ico { font-size: 1.25rem; line-height: 1; }
.tabs button[aria-current="page"] { color: var(--primary); font-weight: 600; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 12px; }
.card.click { cursor: pointer; }
.card.click:hover { border-color: var(--primary); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.kpi .v { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 0.75rem; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 10px; padding: 9px 14px; cursor: pointer; min-height: 42px; font-weight: 600;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; min-height: 34px; font-size: 0.9rem; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.fab {
  position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 15; width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink); border: 0; font-size: 1.8rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); cursor: pointer;
}

label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input:not([type]), input[type="text"], input[type="tel"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-height: 44px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tabs button:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; }
textarea { min-height: 76px; resize: vertical; }
.hint { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.err { color: var(--danger); font-size: 0.9rem; margin: 6px 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.draft, .badge.none { background: var(--surface-2); color: var(--muted); }
.badge.submitted { background: var(--info-soft); color: var(--info); }
.badge.approved { background: var(--ok-soft); color: var(--ok); }
.badge.returned { background: var(--warn-soft); color: var(--warn); }
.badge.closed { background: var(--primary-soft); color: var(--primary); }
.badge.role { background: var(--primary-soft); color: var(--primary); }

.banner { border-radius: 12px; padding: 10px 14px; font-size: 0.92rem; margin-bottom: 12px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.sync.synced .dot { background: #22a55b; }
.sync.pending .dot { background: #e0a100; }
.sync.offline .dot { background: #7a8794; }
.sync.syncing .dot { background: #2f7de1; animation: pulse 1s infinite; }
.sync.error .dot, .sync.auth .dot { background: #d64533; }
@keyframes pulse { 50% { opacity: 0.3; } }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
table.list td.num, table.list th.num { text-align: right; }
.scroll-x { overflow-x: auto; }

.exp { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.exp:last-child { border-bottom: 0; }
.exp .amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.exp .sub { color: var(--muted); font-size: 0.85rem; grid-column: 1 / -1; }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty .big { font-size: 2.2rem; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(8, 16, 22, 0.55); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 18px calc(84px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .overlay { align-items: center; } .modal { border-radius: 18px; } }
.modal h2 { margin-bottom: 12px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 80; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: #14202b; color: #fff; padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font-size: 0.92rem; }
.toast.err { background: #8f1d12; }

.auth { max-width: 420px; margin: 0 auto; padding: 32px 16px; }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 12px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Impresión (PDF) ---------- */
#printArea { display: none; }
@media print {
  body.printing > *:not(#printArea) { display: none !important; }
  body.printing #printArea { display: block !important; color: #000; background: #fff; font-family: Arial, sans-serif; font-size: 12px; padding: 8mm; }
  #printArea h1 { font-size: 20px; margin: 0 0 2px; }
  #printArea table { width: 100%; border-collapse: collapse; margin: 10px 0; }
  #printArea th, #printArea td { border: 1px solid #999; padding: 5px 7px; text-align: left; }
  #printArea table.kv th { background: #eee; width: 14%; }
  #printArea .num { text-align: right; }
  #printArea tfoot td { font-weight: 600; background: #f5f5f5; }
  #printArea .signs { display: flex; gap: 40px; margin-top: 60px; }
  #printArea .signs div { flex: 1; border-top: 1px solid #000; padding-top: 4px; text-align: center; }
}

/* Espejo de la APK: insignias de validación, tarjetas de saldo y lista de soportes */
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.kpi.ok { background: var(--ok-soft); }
.kpi.warn { background: var(--warn-soft); }
.kpi .num { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.files { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.files li { background: var(--surface-2); border-radius: 10px; padding: 6px 10px; }
.stack { display: grid; gap: 10px; }

/* Lectura de facturas */
.hint.warn { color: var(--warn); }
.field.revisa input, .field.revisa select { border-color: var(--warn); background: var(--warn-soft); }
.field.revisa > label::after { content: " · Revisa"; color: var(--warn); font-weight: 600; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 0.85rem; cursor: pointer; }
.chip:hover { background: var(--primary-soft); }
#form-busy { color: var(--info); font-weight: 600; }

/* Formulario de causación: secciones claras */
.fsec { background: var(--surface-2); border-radius: 14px; padding: 12px 14px 4px; margin-bottom: 14px; }
.fsec h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 68px; padding: 8px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; font: inherit; font-size: 0.9rem; color: var(--text); cursor: pointer; }
.tile .ico { font-size: 1.4rem; line-height: 1; }
.tile.main { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.more { margin: 4px 0 12px; }
.more summary { cursor: pointer; color: var(--primary); font-size: 0.92rem; padding: 6px 0; }
.check { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; cursor: pointer; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.check small { color: var(--muted); }

/* Barra inferior con la política de privacidad, bajo la barra de secciones.
   En *.netlify.app (plan gratis) Netlify pone su cartel «Powered by Netlify» abajo a la derecha:
   la barra se hace más alta para que ese cartel no tape botones. */
:root { --legal-h: 30px; }
html.netlify-host { --legal-h: 64px; }
.legalbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; display: flex; align-items: center; padding: 0 16px env(safe-area-inset-bottom);
  height: calc(var(--legal-h) + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.legalbar a { color: var(--muted); font-size: 0.78rem; text-decoration: underline; }
.tabs { bottom: calc(var(--legal-h) + env(safe-area-inset-bottom)); padding-bottom: 0; }
main { padding-bottom: calc(96px + var(--legal-h)); }
.fab { bottom: calc(72px + var(--legal-h) + env(safe-area-inset-bottom)); }
#toasts { bottom: calc(80px + var(--legal-h) + env(safe-area-inset-bottom)); }
.modal { padding-bottom: calc(84px + var(--legal-h) + env(safe-area-inset-bottom)); }

/* Tarjeta de causación: icono a la izquierda, datos en una columna ordenada */
.expcard { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; }
.expcard .ec-ico { flex: none; width: 40px; height: 40px; border-radius: 12px; background: var(--bg, rgba(127,127,127,.12)); display: grid; place-items: center; font-size: 1.35rem; }
.expcard .ec-main { flex: 1; min-width: 0; }
.expcard .ec-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.expcard .ec-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expcard .ec-amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.expcard .ec-date { color: var(--muted); font-size: 0.82rem; margin-top: 1px; }
.expcard .ec-sub { color: var(--muted); font-size: 0.82rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expcard .ec-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.expcard .ec-chips:empty { display: none; }
.expcard .ec-chips .badge { font-size: 0.72rem; padding: 2px 8px; }
.stack > .expcard + .expcard { margin-top: 10px; }


/* =====================================================================
   Rediseño ejecutivo: papel frío, tinta azul marino, índigo de marca.
   Tipografía del sistema con cifras tabulares; el estado de cuenta de
   la misión es la pieza protagonista, el resto se mantiene sobrio.
   ===================================================================== */
body { letter-spacing: 0.005em; -webkit-font-smoothing: antialiased; }
h1 { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; font-weight: 650; letter-spacing: -0.01em; margin-top: 1.2em; }
h3 { font-weight: 650; }
.num, .kpi .num, .ec-amt, .kpi .v { font-variant-numeric: tabular-nums lining-nums; }

/* Barra superior en tinta */
.topbar { background: var(--ink); color: var(--ink-text); border-bottom: 0; padding-top: calc(12px + env(safe-area-inset-top)); padding-bottom: 12px; }
.topbar .brand { font-weight: 650; letter-spacing: -0.01em; }
.topbar .brand img { border-radius: 8px; }
.topbar .org { color: color-mix(in srgb, var(--ink-text) 68%, transparent); }
.topbar .sync { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.16); color: var(--ink-text); }

/* Barra de secciones: indicador superior en la pestaña activa */
.tabs button { position: relative; font-weight: 500; letter-spacing: 0.01em; }
.tabs button[aria-current="page"] { font-weight: 650; }
.tabs button[aria-current="page"]::before { content: ""; position: absolute; top: -1px; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
.tabs button:not([aria-current="page"]) .ico { filter: saturate(0.55); opacity: 0.85; }

/* Tarjetas: planas, con filete fino */
.card { border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.card.click { transition: border-color 0.15s, background 0.15s; }
.card.click:hover { border-color: color-mix(in srgb, var(--primary) 55%, var(--line)); }
.card.click:active { background: var(--surface-2); }

/* Estado de cuenta de la misión: una sola pieza dividida por filetes */
.kpis { gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 14px 0 10px; box-shadow: var(--shadow); }
.kpi { background: transparent; border-radius: 0; padding: 12px 14px 12px; border-left: 1px solid var(--line); }
.kpi:first-child { border-left: 0; }
.kpi .l, .kpi .muted { font-size: 0.74rem; color: var(--muted); line-height: 1.25; }
.kpi .num { font-size: 1.08rem; font-weight: 650; margin-top: 4px; }
.kpi:last-child { border-bottom: 0; background: var(--surface-2); box-shadow: inset 0 -3px 0 var(--muted); }
.kpi:last-child .num { font-size: 1.2rem; font-weight: 750; }
.kpi.ok { background: var(--ok-soft); box-shadow: inset 0 -3px 0 var(--ok); }
.kpi.ok .num { color: var(--ok); }
.kpi.warn { background: var(--warn-soft); box-shadow: inset 0 -3px 0 var(--warn); }
.kpi.warn .num { color: var(--warn); }

/* Botones */
.btn { border-radius: 10px; font-weight: 600; letter-spacing: 0.005em; transition: background 0.15s, border-color 0.15s; }
.btn:hover { border-color: color-mix(in srgb, var(--primary) 60%, var(--line)); background: color-mix(in srgb, var(--primary) 5%, var(--surface)); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.sm { border-radius: 9px; }
.fab { border-radius: 18px; width: 58px; height: 58px; font-size: 1.7rem; box-shadow: 0 8px 22px rgba(14, 27, 46, 0.28); }
.fab:active { transform: scale(0.96); }

/* Formularios */
input:not([type]), input[type="text"], input[type="tel"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  border-radius: 10px; border-color: color-mix(in srgb, var(--muted) 35%, var(--line)); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
label { font-weight: 600; font-size: 0.82rem; color: color-mix(in srgb, var(--text) 82%, var(--muted)); }
.fsec { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); border: 1px solid var(--line); border-radius: 12px; }
.fsec h3 { font-size: 0.92rem; text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 650; }
.tile { border-radius: 10px; }
.tile.main { background: var(--primary); border-color: var(--primary); }
.seg { border-radius: 10px; background: var(--surface-2); }
.seg button { border-radius: 8px; }
.seg button[aria-pressed="true"] { box-shadow: 0 1px 2px rgba(14, 27, 46, 0.12); }

/* Etiquetas */
.badge { font-weight: 600; letter-spacing: 0.01em; padding: 2px 9px; }
.banner { border-radius: 10px; }

/* Lista de causaciones: un solo libro con filas separadas por filetes */
.stack:has(> .expcard) { gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.stack > .expcard, .stack > .expcard + .expcard { margin-top: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; padding: 13px 14px; }
.stack > .expcard:first-child { border-top: 0; }
.expcard.click:hover { background: var(--surface-2); border-color: var(--line); }
.expcard .ec-ico { background: var(--surface-2); border-radius: 11px; width: 42px; height: 42px; }
.expcard .ec-name { font-weight: 600; }
.expcard .ec-amt { font-weight: 700; font-size: 1.02rem; }

/* Tarjeta de misión con avance del anticipo */
.meter { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.meter > i { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.meter.over > i { background: var(--warn); }

/* Barra inferior y avisos */
.legalbar { background: var(--surface); }
.toast { background: var(--ink); color: var(--ink-text); border-radius: 10px; }
.toast.err { background: #8f1d12; }

/* Acceso */
.auth { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin: 28px auto; padding: 28px 22px; max-width: 440px; box-shadow: var(--shadow); }
@media (max-width: 480px) { .auth { margin: 0; border: 0; border-radius: 0; min-height: 100vh; box-shadow: none; } }
.auth h1 { margin-bottom: 6px; }
.auth .logo { border-radius: 14px; }

/* Movimiento mínimo y respetuoso */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.kpi .num { text-align: left; }


/* =====================================================================
   Pases de misión. La misión se presenta como un pase de abordar: el
   cuerpo con la ruta de fechas y, tras la perforación, el talón con la
   cifra que importa. Todo lo demás se mantiene sobrio y rápido.
   ===================================================================== */
:root { --font: "Manrope Variable", "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow-2: 0 1px 2px rgba(14, 27, 46, 0.04), 0 4px 14px rgba(14, 27, 46, 0.05); --sidebar: 232px; }
@media (prefers-color-scheme: dark) { :root { --shadow-2: none; } }
body { font-family: var(--font); }
h1 { font-size: clamp(1.5rem, 1.25rem + 1vw, 1.9rem); font-weight: 750; letter-spacing: -0.025em; }
.num, b.num, .ec-amt, dd.num { font-variant-numeric: tabular-nums lining-nums; }

.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin: 4px 0 16px; }
.pagehead h1 { margin: 0; }
.pagehead p { margin: 2px 0 0; font-size: 0.92rem; max-width: 60ch; }
.sectionhead { display: flex; justify-content: space-between; align-items: baseline; margin: 24px 0 10px; }
.sectionhead h2 { margin: 0; }
.crumbs { display: flex; justify-content: space-between; align-items: center; margin: -4px 0 6px; }
.crumbs .btn.ghost { padding-left: 0; }
.only-wide { display: none !important; }

/* Pase */
.tickets { display: grid; gap: 14px; }
@media (min-width: 760px) { .tickets { grid-template-columns: 1fr 1fr; } }
.ticket { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-2); }
.ticket.click { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.ticket.click:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--line)); }
.ticket.click:active { transform: scale(0.99); }
.ticket .t-main { padding: 16px 16px 14px; min-width: 0; }
.t-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.t-top h3 { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.route { display: flex; align-items: center; gap: 10px; margin: 12px 0 6px; font-weight: 750; font-size: 1.1rem; letter-spacing: -0.01em; white-space: nowrap; }
.route .path { flex: 1; min-width: 28px; position: relative; height: 2px; background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--muted) 55%, transparent) 0 5px, transparent 5px 10px); }
.route .path i { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -54%); font-style: normal; font-size: 0.95rem; line-height: 1; padding: 0 5px; background: var(--surface); }
.route.big { font-size: clamp(1.35rem, 1.1rem + 1.2vw, 1.75rem); margin: 14px 0 6px; }
.route.big .path i { font-size: 1.15rem; }
.t-meta { color: var(--muted); font-size: 0.84rem; }
.t-desc { color: var(--muted); font-size: 0.92rem; margin: 8px 0 0; }

.t-stub { position: relative; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 132px; padding: 14px 16px;
  border-left: 2px dashed var(--line); border-radius: 0 16px 16px 0; background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.t-stub::before, .t-stub::after { content: ""; position: absolute; left: -12px; width: 22px; height: 22px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); }
.t-stub::before { top: -12px; clip-path: inset(50% -2px -2px -2px); }
.t-stub::after { bottom: -12px; clip-path: inset(-2px -2px 50% -2px); }
.t-stub .l { font-size: 0.74rem; color: var(--muted); line-height: 1.25; }
.t-stub b { font-size: 1.05rem; font-weight: 750; }
.t-stub .meter { margin-top: 8px; }
.t-stub.ok { background: var(--ok-soft); } .t-stub.ok b { color: var(--ok); }
.t-stub.warn { background: var(--warn-soft); } .t-stub.warn b { color: var(--warn); }
.ticket.is-closed .t-main > *:not(.t-top) { opacity: 0.72; }

/* Pase grande en la misión: talón abajo en el celular, a la derecha en pantallas anchas */
.ticket.hero { grid-template-columns: 1fr; margin: 6px 0 14px; }
.ticket.hero .t-main { padding: 20px 20px 18px; }
.ticket.hero h1 { margin: 0; padding-right: 84px; overflow-wrap: anywhere; }
.ticket.hero .t-stub { flex-direction: row; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; padding: 16px 20px 18px;
  border-left: 0; border-top: 2px dashed var(--line); border-radius: 0 0 16px 16px; }
.ticket.hero .t-stub::before { left: -12px; top: -12px; clip-path: inset(-2px -2px -2px 50%); }
.ticket.hero .t-stub::after { left: auto; right: -12px; bottom: auto; top: -12px; clip-path: inset(-2px 50% -2px -2px); }
.ticket.hero .t-stub .l { font-size: 0.86rem; font-weight: 600; }
.ticket.hero .t-stub .big { font-size: clamp(1.6rem, 1.25rem + 1.6vw, 2.25rem); font-weight: 800; letter-spacing: -0.03em; }
.ticket.hero .t-stub.even .big { color: var(--text); }
@media (min-width: 760px) {
  .ticket.hero { grid-template-columns: minmax(0, 1fr) 280px; }
  .ticket.hero .t-stub { flex-direction: column; align-items: flex-start; justify-content: center; border-top: 0; border-left: 2px dashed var(--line); border-radius: 0 16px 16px 0; padding: 20px 24px; }
  .ticket.hero .t-stub::before { left: -12px; top: -12px; right: auto; clip-path: inset(50% -2px -2px -2px); }
  .ticket.hero .t-stub::after { left: -12px; right: auto; top: auto; bottom: -12px; clip-path: inset(-2px -2px 50% -2px); }
}
.figs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }
.figs dt { font-size: 0.78rem; color: var(--muted); }
.figs dd { margin: 2px 0 0; font-size: 1.12rem; font-weight: 700; }
.stamp { position: absolute; top: 18px; right: 16px; transform: rotate(-9deg); border: 2px solid currentColor; color: color-mix(in srgb, var(--muted) 80%, transparent);
  border-radius: 6px; padding: 1px 9px; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; pointer-events: none; }

/* Acciones de la misión */
.actionbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 4px; }
.actionbar .btn.primary { flex: 1 1 150px; }
.btn.icon { width: 44px; padding: 0; font-size: 1.35rem; line-height: 1; }

/* Extracto por día */
.ledger { display: grid; gap: 18px; }
.day-h { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 0 4px 7px; font-size: 0.84rem; font-weight: 600; color: var(--muted); }
.day-h .num { color: var(--text); font-weight: 700; }
.expcard .ec-top + .ec-top { margin-top: 2px; }
.expcard .ec-sub { flex: 1; min-width: 0; margin-top: 0; }
.ec-state { flex: none; font-size: 0.76rem; font-weight: 650; }
.ec-state.ok { color: var(--ok); } .ec-state.warn { color: var(--warn); }
.ec-state.ok::before { content: "✓ "; }
.expcard .ec-chips { margin-top: 7px; }

/* Filtros */
.seg.filters { overflow-x: auto; scrollbar-width: none; margin-bottom: 16px; }
.seg.filters::-webkit-scrollbar { display: none; }
.seg.filters button { white-space: nowrap; padding: 8px 12px; }
.seg .n { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 2px; border-radius: 999px; font-size: 0.72rem; line-height: 18px; background: var(--warn-soft); color: var(--warn); }

/* Conceptos como fichas */
.ctiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ctile { display: flex; flex-direction: column; gap: 4px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; cursor: pointer; box-shadow: var(--shadow-2); transition: border-color 0.15s; }
.ctile:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--line)); }
.ctile .ico { width: 54px; height: 54px; display: grid; place-items: center; font-size: 1.9rem; background: var(--surface-2); border-radius: 15px; margin-bottom: 8px; }
.ctile b { font-weight: 700; overflow-wrap: anywhere; }
.ctile .cap { font-size: 0.8rem; color: var(--muted); }
.ctile .cap.has { color: var(--primary); font-weight: 600; }

/* Menú de opciones */
.menu { display: grid; gap: 8px; }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.menu-item:hover { background: var(--surface-2); }
.menu-item > span:first-child { font-size: 1.35rem; }
.menu-item b { display: block; font-weight: 650; }
.menu-item small { color: var(--muted); }
.menu-item.danger b { color: var(--danger); }

/* Ventanas: hoja que sube (responde a la acción) */
.overlay { animation: v-fade 0.18s ease-out; backdrop-filter: blur(2px); }
.modal { animation: v-sheet 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
.modal::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: -6px auto 14px; }
@media (min-width: 640px) { .modal::before { display: none; } }
@keyframes v-fade { from { opacity: 0; } }
@keyframes v-sheet { from { transform: translateY(28px); opacity: 0.4; } }

.empty { padding: 48px 16px; }
.empty .big { font-size: 2.6rem; margin-bottom: 6px; }

/* Escritorio: barra lateral */
@media (min-width: 1024px) {
  .only-wide { display: inline-flex !important; }
  .shell { max-width: none; }
  .topbar { height: 64px; padding: 0 24px; }
  .tabs { top: 64px; bottom: 0; right: auto; width: var(--sidebar); padding: 18px 12px 80px; border-top: 0; border-right: 1px solid var(--line); justify-content: flex-start; align-items: stretch; }
  .tabs .inner { flex-direction: column; gap: 4px; }
  .tabs button { flex: none; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 14px; border-radius: 10px; font-size: 0.95rem; }
  .tabs button:hover { background: var(--surface-2); }
  .tabs button[aria-current="page"] { background: var(--primary-soft); }
  .tabs button[aria-current="page"]::before { top: 10px; bottom: 10px; left: 0; right: auto; width: 3px; height: auto; border-radius: 0 3px 3px 0; }
  .legalbar { right: auto; width: var(--sidebar); height: auto; padding: 16px 26px 20px; border-top: 0; background: transparent; }
  main { margin-left: var(--sidebar); padding: 28px 40px 120px; }
  main > * { max-width: 1000px; }
  .fab { display: none; }
  #toasts { bottom: 28px; }
}

.t-stub .num, .figs .num, .day-h .num { text-align: left; }

/* Lista de soportes: el nombre se corta con «…» y el botón no se sale de la pantalla */
.files li { display: flex; align-items: center; gap: 10px; }
.files .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .new { font-size: 0.72rem; font-weight: 650; color: var(--primary); margin-left: 4px; }
.files .btn { flex: none; }

/* Al enfocar un campo dentro de una ventana, que no quede detrás de la barra inferior ni del cartel de Netlify */
.modal { scroll-padding-bottom: calc(var(--legal-h) + 96px); }

/* Interruptor del vale virtual */
.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 0 0 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; font-size: 0.95rem; font-weight: 400; color: var(--text); }
.switch-row > span { flex: 1; min-width: 0; }
.switch-row b { display: block; font-weight: 650; }
.switch-row small { color: var(--muted); font-size: 0.8rem; }
.switch-row input { appearance: none; -webkit-appearance: none; flex: none; width: 46px; height: 28px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 35%, var(--line)); position: relative; cursor: pointer; transition: background 0.15s; margin: 0; }
.switch-row input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
.switch-row input:checked { background: var(--primary); }
.switch-row input:checked::after { transform: translateX(18px); }
.switch-row input:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }
.sign-btn { width: 100%; margin: 0 0 12px; min-height: 48px; }
.sign-btn[hidden] { display: none; }

/* Ficha del vale: queda marcada mientras el modo vale está activo */
.tile.vale-tile[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 650; }
.vale-box { border: 1px dashed color-mix(in srgb, var(--primary) 45%, var(--line)); border-radius: 12px; padding: 10px 12px; margin: 4px 0 10px; }
.vale-box[hidden] { display: none; }
.linkbtn { background: none; border: 0; padding: 8px 2px; color: var(--primary); font: inherit; font-size: 0.88rem; font-weight: 600; cursor: pointer; }
.files { grid-template-columns: minmax(0, 1fr); }
.files li { min-width: 0; }

/* Firma del vale: ocupa casi toda la pantalla, con el resumen arriba */
.modal.sig-modal { display: flex; flex-direction: column; height: min(94dvh, 780px); max-height: none; max-width: 760px; overflow: hidden;
  padding-bottom: calc(14px + var(--legal-h) + env(safe-area-inset-bottom)); }
.sig-head { flex: none; }
.sig-sum { font-size: 1.12rem; line-height: 1.35; margin: 0 0 4px; }
.sig-sum b { font-weight: 750; }
.sig-head .small { margin: 0; }
.sig-area { position: relative; flex: 1; min-height: 220px; margin: 12px 0 8px; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.sig-area canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.sig-line { position: absolute; left: 8%; right: 8%; bottom: 20%; padding-top: 6px; border-top: 1.5px solid #c3c9d4; color: #8a93a6; font-size: 0.78rem; text-align: center; pointer-events: none; }
.sig-actions { flex: none; display: grid; grid-template-columns: auto auto 1fr; gap: 8px; }
@media (min-width: 640px) { .modal.sig-modal { padding-bottom: 18px; } }
