/* Factugas panel — same world as the app: brand teal, Archivo for figures. */
:root {
  --teal: #0A8FA6;
  --teal-deep: #06616F;
  --ok: #1F8A53;
  --pending: #B26A00;
  --error: #C23C2F;
  --bg: #F3F7F8;
  --surface: #FFFFFF;
  --surface-2: #EAF1F3;
  --line: #D9E3E6;
  --text: #12262B;
  --muted: #5B6F74;
  --accent: var(--teal);
  --accent-ink: #FFFFFF;
  --accent-soft: #D8EEF2;
  --shadow: 0 1px 2px rgba(10, 40, 48, .06), 0 4px 16px rgba(10, 40, 48, .05);
  --radius: 14px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: Archivo, var(--font);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C1719;
    --surface: #132225;
    --surface-2: #1A2D31;
    --line: #26393D;
    --text: #E4EEF0;
    --muted: #93A8AD;
    --accent: #34C0D6;
    --accent-ink: #03272D;
    --accent-soft: #123A41;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); letter-spacing: -.01em; margin: 0; }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- Login ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 800; font-size: 22px; letter-spacing: -.02em; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--teal); display: grid; place-items: center; }
.brand-mark svg { width: 22px; height: 22px; }

/* ---- Shell ---- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100dvh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100dvh; overflow-y: auto; }
.side nav { display: grid; gap: 2px; }
.side nav a, .side nav button { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; border: 0; background: none; cursor: pointer; text-align: left; width: 100%; }
.side nav a:hover { background: var(--surface-2); }
.side nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .grupo { font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px 4px; text-transform: uppercase; letter-spacing: .06em; }
.side .pie { margin-top: auto; display: grid; gap: 8px; font-size: 13px; }
.main { padding: 28px 32px 48px; min-width: 0; }
.velo { display: none; }
.top { display: none; }
.cabeza { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 20px; margin-bottom: 22px; }
.cabeza h1 { font-size: 26px; }
.cabeza .acciones { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 272px; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .shell.abierto .side { transform: none; }
  .shell.abierto .velo { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
  .top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
  .main { padding: 18px 16px 40px; }
  .cabeza h1 { font-size: 22px; }
  .cabeza .acciones { margin-left: 0; width: 100%; }
}

/* ---- Controls ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; min-height: 38px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primario { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primario:hover { filter: brightness(1.06); }
.btn.peligro { color: var(--error); }
.btn.chico { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.icono { border: 0; background: none; padding: 6px; border-radius: 8px; cursor: pointer; display: inline-grid; place-items: center; }
.icono:hover { background: var(--surface-2); }
.campo { display: grid; gap: 5px; }
.campo > span { font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-height: 40px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.filtros { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filtros input[type="date"] { width: auto; }
.filtros input[type="search"] { width: min(280px, 100%); }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }

/* ---- Cards, KPIs, charts ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card h2 { font-size: 16px; margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi .valor { font-family: var(--display); font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .etiqueta { color: var(--muted); font-size: 13px; }
.kpi.destacado { background: linear-gradient(135deg, var(--teal), var(--teal-deep)); border: 0; color: #fff; }
.kpi.destacado .etiqueta { color: rgba(255,255,255,.8); }
.rejilla { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.barras { display: grid; gap: 10px; }
.barra { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.barra .riel { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.barra .riel i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.barra .n { font-family: var(--display); font-variant-numeric: tabular-nums; font-weight: 600; }
.serie { display: flex; align-items: end; gap: 6px; height: 160px; padding-top: 8px; }
.serie .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; height: 100%; justify-content: end; }
.serie .col i { width: 100%; max-width: 44px; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.serie .col span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.vacio { text-align: center; padding: 36px 12px; color: var(--muted); }

/* ---- Tables ---- */
.tabla-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clic { cursor: pointer; }
tbody tr.clic:hover { background: var(--surface-2); }
td.der, th.der { text-align: right; }
td.ancho { white-space: normal; min-width: 180px; }
.paginas { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* ---- Badges ---- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.chip.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.chip.pend { background: color-mix(in srgb, var(--pending) 16%, transparent); color: var(--pending); }
.chip.err { background: color-mix(in srgb, var(--error) 14%, transparent); color: var(--error); }
.positivo { color: var(--ok); }
.negativo { color: var(--error); }

/* ---- Dialog ---- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(6, 20, 24, .45); }
dialog form { display: grid; gap: 14px; padding: 22px 22px 18px; max-height: calc(100dvh - 48px); overflow-y: auto; }
dialog .pie { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
dialog .dos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { dialog .dos { grid-template-columns: 1fr; } }
.error { color: var(--error); font-size: 14px; }
.codigo { font-family: var(--display); font-size: 30px; font-weight: 800; letter-spacing: .14em; }
.detalle dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.detalle dt { color: var(--muted); }
.detalle dd { margin: 0; word-break: break-word; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
#toast.visible { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--error); color: #fff; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
