/* PrestaFácil V1 — tema "Naturaleza corporativa", legible A PLENO SOL.
   UN vocabulario de componentes, DOS shells (móvil captura / desktop oficina).
   Reglas heredadas de Norem: números 800, de-énfasis con color SÓLIDO (nunca
   opacity), chips con tinta AA calculada en JS, targets 48px (piso 40px),
   inputs 16px (mata el auto-zoom de iOS), guardas de layout móvil. */

:root {
  --verde: #1b3a2b;          /* chrome oscuro */
  --verde-2: #24503a;
  --verde-claro: #2e7d4f;
  --rio: #1b6b8f;
  --oro: #b98a00;
  --barro: #8a5a36;
  --rojo: #a3271e;
  --naranja: #c94f2e;
  --papel: #f2f0ea;          /* lienzo claro */
  --carta: #ffffff;
  --tinta: #1c2420;
  --tinta-2: #5a6660;        /* de-énfasis SÓLIDO */
  --linea: #e3e0d8;
  --tap: 48px;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* el atributo hidden SIEMPRE gana sobre cualquier display de autor */
[hidden] { display: none !important; }
html { background: var(--verde); }   /* pinta el chrome del sistema */
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--papel);
  color: var(--tinta);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;                 /* guarda móvil */
}
/* guardas de layout móvil (bugs reales de Safari) */
.card, .fila, .kpi, .lista > * { min-width: 0; }
.feed-txt, .nota { overflow-wrap: anywhere; }

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: var(--rio); text-decoration: none; }
input, select, textarea {
  font: inherit; font-size: 16px;     /* nunca menos — iOS */
  width: 100%; padding: 12px; border: 1.5px solid var(--linea);
  border-radius: 10px; background: var(--carta); color: var(--tinta);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--verde-claro); border-color: transparent; }
label { display: block; font-size: .82rem; font-weight: 600; color: var(--tinta-2); margin: 12px 0 4px; }
.lbl-req::after { content: " *"; color: var(--rojo); }

h1, h2, h3 { font-weight: 800; }
.eyebrow {
  font-size: .7rem; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--tinta-2); margin: 18px 0 8px;
}
.num { font-variant-numeric: tabular-nums; font-weight: 800; }

/* ── Botones ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px;
  font-weight: 700; font-size: 1rem; text-align: center;
}
.btn-pri  { background: var(--verde); color: #fff; }
.btn-pri:active { background: var(--verde-2); }
.btn-sec  { background: var(--carta); color: var(--tinta); border: 1.5px solid var(--linea); }
.btn-oro  { background: var(--oro); color: #fff; }
.btn-danger { background: var(--rojo); color: #fff; }
.btn-block { width: 100%; }
.btn[disabled] { background: #c9c5bb; color: #fff; }
.btn-ico {
  width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 10px;
  background: var(--papel); color: var(--verde); border: 1.5px solid var(--linea);
}
.btn-ico svg { width: 19px; height: 19px; }

/* ── Chips ───────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  max-width: 100%;
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Cards / listas ──────────────────────────────────────── */
.card {
  background: var(--carta); border-radius: var(--radius);
  border: 1px solid var(--linea); padding: 14px; margin-bottom: 10px;
}
.fila { display: flex; align-items: center; gap: 10px; }
.fila-sp { justify-content: space-between; }
.crece { flex: 1; min-width: 0; }
.nombre { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: .82rem; color: var(--tinta-2); }
.acciones { display: flex; gap: 8px; margin-top: 10px; }

/* ── KPI tiles ───────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi {
  background: var(--carta); border: 1px solid var(--linea);
  border-radius: var(--radius); padding: 12px 14px;
}
.kpi .k-v { font-size: 1.45rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .k-l { font-size: .74rem; font-weight: 600; color: var(--tinta-2); margin-top: 2px; }
.kpi-hero {
  grid-column: 1 / -1; background: var(--verde); color: #fff; border: none;
}
.kpi-hero .k-l { color: #cfe0d5; }
.kpi-dim { background: #eceae2; }    /* de-énfasis sólido, nunca opacity */

/* ── Barras 7 días ──────────────────────────────────────── */
.barras { display: flex; align-items: flex-end; gap: 6px; height: 90px; padding: 10px 2px 0; }
.barra { flex: 1; background: var(--verde-claro); border-radius: 4px 4px 0 0; min-height: 3px; }
.barra-hoy { background: var(--oro); }
.barras-lbl { display: flex; gap: 6px; }
.barras-lbl span { flex: 1; text-align: center; font-size: .62rem; color: var(--tinta-2); }

/* ═══ SHELL MÓVIL ═══════════════════════════════════════════ */
#m-shell { display: block; }
.m-top {
  position: sticky; top: 0; z-index: 20;
  background: var(--verde); color: #fff;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.m-top .brand { font-weight: 800; font-size: 1.05rem; letter-spacing: .3px; flex: 1; }
.m-top .build { font-size: .62rem; color: #9db8a8; font-weight: 600; }
.m-top .off {
  font-size: .68rem; background: var(--oro); color: #fff; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}
#m-view { padding: 14px 14px calc(86px + var(--safe-b)); max-width: 640px; margin: 0 auto; }

/* tab bar + FAB dorado central */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--verde); display: flex;
  padding-bottom: var(--safe-b);
  box-shadow: 0 -4px 16px rgba(0,0,0,.18);
}
#tabbar::after {   /* backstop bajo el teclado de iOS */
  content: ""; position: absolute; top: 100%; left: 0; right: 0; height: 60px; background: var(--verde);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; color: #9db8a8; font-size: .62rem; font-weight: 700;
  min-height: var(--tap);
}
.tab svg { width: 22px; height: 22px; }
.tab.act { color: #fff; }
.tab-fab {
  flex: 1.15; align-items: center; justify-content: flex-start; position: relative;
}
.tab-fab .fab {
  position: absolute; top: -22px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--oro); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
}
.tab-fab .fab svg { width: 26px; height: 26px; }
.tab-fab .t { margin-top: 34px; font-size: .62rem; color: #9db8a8; font-weight: 700; }

/* ═══ SHELL DESKTOP ═════════════════════════════════════════ */
#d-shell { display: none; }

@media (min-width: 1000px) {
  #m-shell { display: none; }
  #d-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

  .rail {
    background: var(--verde); color: #fff; padding: 18px 12px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
  .rail .brand { font-weight: 800; font-size: 1.1rem; padding: 0 10px 14px; }
  .rail-lbl {
    font-size: .64rem; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
    color: #9db8a8; padding: 14px 10px 4px;
  }
  .rail a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 9px; color: #d8e4dc; font-weight: 600; font-size: .92rem;
  }
  .rail a svg { width: 18px; height: 18px; }
  .rail a.act { background: var(--verde-2); color: #fff; }
  .rail a:hover { background: var(--verde-2); }

  .d-main { display: flex; flex-direction: column; min-width: 0; }
  .d-top {
    position: sticky; top: 0; z-index: 20; background: var(--papel);
    border-bottom: 1px solid var(--linea);
    display: flex; align-items: center; gap: 14px; padding: 12px 22px;
  }
  .d-top input { max-width: 340px; }
  #d-view { padding: 22px; max-width: 1100px; }

  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi-hero { grid-column: 1 / -1; }

  /* grid estilo Excel */
  .tbl-wrap { overflow-x: auto; background: var(--carta); border: 1px solid var(--linea); border-radius: var(--radius); }
  table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
  .tbl th {
    position: sticky; top: 0; background: var(--carta); z-index: 2;
    text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .8px;
    color: var(--tinta-2); padding: 10px 12px; border-bottom: 2px solid var(--linea);
    white-space: nowrap; cursor: pointer; user-select: none;
  }
  .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--linea); white-space: nowrap; }
  .tbl td.dinero, .tbl th.dinero { text-align: right; font-variant-numeric: tabular-nums; }
  .tbl tr:hover td { background: #faf9f5; }
  .tbl tr.clic { cursor: pointer; }
  .tbl tfoot td { font-weight: 800; border-top: 2px solid var(--linea); background: var(--carta); }

  /* sheet → modal centrado */
  #sheet-host .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, 92vw); border-radius: var(--radius);
    max-height: 86vh;
  }
  #sheet-host .sheet-handle { display: none; }
}

/* móvil: las tablas de escritorio no existen — las vistas móviles usan cards */
@media (max-width: 999px) {
  .tbl-wrap { display: none; }
}

/* ── Sheet (primitiva única) ─────────────────────────────── */
#sheet-host[hidden] { display: none; }
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 28, 24, .5); z-index: 90;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 91;
  background: var(--carta); border-radius: 18px 18px 0 0;
  max-height: 82vh; overflow-y: auto;
  padding: 10px 18px calc(18px + var(--safe-b));
  animation: sube .18s ease-out;
}
@keyframes sube { from { transform: translateY(30px); opacity: .6; } }
.sheet-handle {
  width: 44px; height: 4px; border-radius: 2px; background: var(--linea);
  margin: 4px auto 10px;
}
.sheet-x {
  position: absolute; top: 12px; right: 12px;
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  color: var(--tinta-2);
}
.sheet-x svg { width: 18px; height: 18px; }
.s-title { font-size: 1.1rem; margin: 4px 0 10px; padding-right: 44px; }
.s-preview {
  background: var(--papel); border-radius: 10px; padding: 12px; font-size: .92rem;
  margin-bottom: 12px;
}
.s-actions { display: flex; gap: 10px; margin-top: 16px; }
.s-actions .btn { flex: 1; }
.s-note { font-size: .74rem; color: var(--tinta-2); text-align: center; margin-top: 10px; }
.s-monto {
  font-size: 2rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums;
  padding: 14px;
}
.rapidos { display: flex; gap: 8px; }
.rapidos .btn { flex: 1; min-height: 40px; }

/* ── Toast ───────────────────────────────────────────────── */
#toast-host {
  position: fixed; left: 0; right: 0; bottom: calc(88px + var(--safe-b)); z-index: 120;
  display: flex; justify-content: center; pointer-events: none;
}
#toast-host[hidden] { display: none; }
.toast {
  background: var(--tinta); color: #fff; font-weight: 600; font-size: .9rem;
  padding: 10px 18px; border-radius: 999px; max-width: 90vw;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.toast-err { background: var(--rojo); }
.toast-oro { background: var(--oro); }
@media (min-width: 1000px) { #toast-host { bottom: 30px; } }

/* ── Login ───────────────────────────────────────────────── */
#login-shell {
  min-height: 100vh; display: grid; place-items: center; background: var(--verde);
  padding: 20px;
}
.login-card {
  background: var(--carta); border-radius: 18px; padding: 28px 24px;
  width: min(380px, 94vw); text-align: center;
}
.login-card .logo { font-size: 1.5rem; font-weight: 800; color: var(--verde); }
.login-card .sub2 { color: var(--tinta-2); font-size: .88rem; margin: 4px 0 18px; }
.pin-input {
  text-align: center; font-size: 1.6rem; letter-spacing: 10px; font-weight: 800;
}
.login-err { color: var(--rojo); font-size: .85rem; font-weight: 600; margin-top: 10px; min-height: 1.2em; }

/* ── Detalle (capa completa en móvil) ────────────────────── */
.det-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.det-head h2 { font-size: 1.2rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs2 { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs2 button {
  flex: 1; min-height: 40px; border-radius: 999px; font-weight: 700; font-size: .84rem;
  background: var(--carta); border: 1.5px solid var(--linea); color: var(--tinta-2);
}
.tabs2 button.act { background: var(--verde); border-color: var(--verde); color: #fff; }

.resumen3 { display: flex; text-align: center; background: var(--papel); border-radius: 10px; padding: 10px 0; margin: 10px 0; }
.resumen3 > div { flex: 1; }
.resumen3 .v { font-weight: 800; font-variant-numeric: tabular-nums; }
.resumen3 .l { font-size: .7rem; color: var(--tinta-2); font-weight: 600; }

.feed { list-style: none; }
.feed li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--linea); font-size: .9rem; }
.feed .f-fecha { color: var(--tinta-2); font-size: .8rem; white-space: nowrap; padding-top: 2px; }
.feed .f-monto { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.feed .rev { color: var(--rojo); }

.vacio { text-align: center; color: var(--tinta-2); padding: 40px 20px; font-size: .95rem; }
.vacio svg { width: 42px; height: 42px; margin-bottom: 10px; color: #b9beb4; }

.buscador { position: relative; margin-bottom: 12px; }
.buscador svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--tinta-2); }
.buscador input { padding-left: 40px; }

.fab-lista {
  position: fixed; right: 16px; bottom: calc(96px + var(--safe-b)); z-index: 25;
  width: 54px; height: 54px; border-radius: 50%; background: var(--verde); color: #fff;
  display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.28);
}
.fab-lista svg { width: 24px; height: 24px; }
@media (min-width: 1000px) { .fab-lista { display: none; } }

@media print {
  .m-top, #tabbar, .rail, .d-top, .fab-lista, #sheet-host, #toast-host { display: none !important; }
  body { background: #fff; }
}
