:root {
  --azul: #1a73e8;
  --azul-d: #1557b0;
  --fondo: #f1f5f9;
  --card: #ffffff;
  --texto: #0f172a;
  --muted: #64748b;
  --linea: #e2e8f0;
  --verde: #16a34a;
  --rojo: #dc2626;
}
* { box-sizing: border-box; }
/* El atributo hidden debe ganar SIEMPRE: si no, reglas como .gate{display:grid}
   lo anulan y la pantalla de desbloqueo se queda encima de la app. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  -webkit-tap-highlight-color: transparent;
}
.noscript { padding: 1.5rem; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.error { color: var(--rojo); font-weight: 600; margin-top: .5rem; }

/* ── Gate ── */
.gate {
  min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem;
  background: linear-gradient(160deg, #0f172a, #1e293b);
}
.gate-card {
  background: var(--card); border-radius: 18px; padding: 1.75rem 1.5rem;
  width: 100%; max-width: 380px; box-shadow: 0 12px 40px rgba(0,0,0,.35); text-align: center;
}
.gate-logo { width: 72px; height: 72px; border-radius: 16px; }
.gate-card h1 { margin: .75rem 0 .25rem; font-size: 1.4rem; }
.filebtn { display: block; margin: 1.25rem 0 .5rem; }
.filebtn input { display: none; }
.filebtn span {
  display: block; padding: .8rem; border: 2px dashed var(--linea); border-radius: 12px;
  color: var(--azul); font-weight: 600; cursor: pointer;
  overflow-wrap: anywhere; word-break: break-word;  /* nombres largos sin espacios no desbordan */
}
.filebtn span.has-file { border-style: solid; border-color: var(--verde); color: var(--verde); }
.field { text-align: left; margin: 1rem 0 .5rem; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }
.field input, #pass {
  width: 100%; padding: .7rem; border: 1px solid var(--linea); border-radius: 10px; font-size: 1rem;
}
.remember { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); margin: .25rem 0 1rem; }
button.primary {
  width: 100%; padding: .85rem; border: none; border-radius: 12px;
  background: var(--azul); color: #fff; font-size: 1rem; font-weight: 700; cursor: pointer;
}
button.primary:active { background: var(--azul-d); }

/* ── App ── */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: max(.9rem, env(safe-area-inset-top)) 1rem .9rem; background: var(--azul); color: #fff;
}
.empresa { font-weight: 700; font-size: 1.05rem; }
.actions { display: flex; gap: .4rem; align-items: center; }
.ghost { background: rgba(255,255,255,.15); border: none; color: #fff; border-radius: 10px; padding: .45rem .7rem; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.toast {
  position: fixed; left: 50%; bottom: max(1.2rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: .6rem 1rem; border-radius: 10px; font-size: .85rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); z-index: 50; max-width: 90vw;
}
.tabs {
  display: flex; gap: .25rem; overflow-x: auto; padding: .5rem; background: var(--card);
  border-bottom: 1px solid var(--linea); position: sticky; top: 56px; z-index: 4;
}
.tabs button {
  flex: 0 0 auto; padding: .45rem .8rem; border: none; background: transparent; color: var(--muted);
  font-weight: 600; border-radius: 999px; cursor: pointer; font-size: .9rem;
}
.tabs button.active { background: #e8f0fe; color: var(--azul); }
.panel { padding: 1rem; max-width: 720px; margin: 0 auto; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.kpi { background: var(--card); border-radius: 14px; padding: .9rem; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.kpi .lbl { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.kpi .val { font-size: 1.25rem; font-weight: 700; margin-top: .2rem; }
.kpi .val.pos { color: var(--verde); }
.kpi .val.neg { color: var(--rojo); }
.kpi.wide { grid-column: 1 / -1; }

.list { display: flex; flex-direction: column; gap: .5rem; }
.row {
  background: var(--card); border-radius: 12px; padding: .8rem .9rem; box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.row .r-top { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.row .r-title { font-weight: 600; }
.row .r-sub { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.amount.pos { color: var(--verde); }
.amount.neg { color: var(--rojo); }
.badge { display: inline-block; background: #e8f0fe; color: var(--azul); border-radius: 6px; padding: .05rem .4rem; font-size: .72rem; font-weight: 700; }
.apuntes { margin-top: .6rem; border-top: 1px dashed var(--linea); padding-top: .5rem; display: none; }
.row.open .apuntes { display: block; }
.apunte { display: flex; justify-content: space-between; font-size: .82rem; padding: .15rem 0; color: #334155; }
.apunte .ap-cta { color: var(--muted); }

table.bal { width: 100%; border-collapse: collapse; font-size: .82rem; background: var(--card); border-radius: 12px; overflow: hidden; }
table.bal th, table.bal td { padding: .5rem .6rem; text-align: right; border-bottom: 1px solid var(--linea); }
table.bal th:first-child, table.bal td:first-child { text-align: left; }
table.bal th { background: #f8fafc; color: var(--muted); font-size: .72rem; text-transform: uppercase; }

.docbtn { background: var(--azul); color: #fff; border: none; border-radius: 8px; padding: .4rem .8rem; font-size: .82rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.docbtn:active { background: var(--azul-d); }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.foot { text-align: center; padding: 1.5rem 1rem max(1.5rem, env(safe-area-inset-bottom)); }

/* ── Impresión / PDF ── */
#printable { display: none; }
@media print {
  body { background: #fff; }
  .topbar, .tabs, .panel, .foot, .gate { display: none !important; }
  #printable { display: block; padding: 1.5rem; color: #000; font-size: 12px; }
  #printable h1 { font-size: 18px; margin: 0 0 .2rem; }
  #printable h2 { font-size: 13px; margin: 1.1rem 0 .35rem; border-bottom: 1px solid #999; padding-bottom: .15rem; }
  #printable .meta { color: #555; margin-bottom: .5rem; }
  #printable table { width: 100%; border-collapse: collapse; }
  #printable th, #printable td { padding: .2rem .4rem; border-bottom: 1px solid #ddd; text-align: right; }
  #printable th:first-child, #printable td:first-child { text-align: left; }
  #printable th { background: #f1f1f1; }
  #printable .num { font-variant-numeric: tabular-nums; }
}
