:root {
  --bg: #f6f4ef; --surface: #ffffff; --surface-2: #f0ede6; --text: #1e2422; --muted: #6a716e;
  --line: #e3dfd6; --brand: #2f5d57; --brand-ink: #ffffff; --brand-soft: #e3eeeb;
  --good: #2e7d4f; --good-bg: #e2f2e8; --warn: #9a6400; --warn-bg: #fbefd6; --bad: #b3261e; --bad-bg: #fbe3e1;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615; --surface: #1b201f; --surface-2: #232928; --text: #e8ecea; --muted: #9aa39f;
    --line: #2d3432; --brand: #7fb8ae; --brand-ink: #0f1514; --brand-soft: #22322f;
    --good: #7fd19b; --good-bg: #1c3326; --warn: #f0c060; --warn-bg: #3a2f17; --bad: #ff8a80; --bad-bg: #3b1d1b;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .r { text-align: right; } .grow { flex: 1; min-width: 0; }
.neg { color: var(--bad); } .strike { text-decoration: line-through; color: var(--muted); }

/* layout */
.app { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
main { max-width: 1040px; margin: 0 auto; padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar select, .toolbar input { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.toolbar input.grow { min-width: 140px; }

.tabs-top { display: none; gap: 2px; }
.tabs-top button { border: 0; background: none; padding: 8px 12px; border-radius: 10px; color: var(--muted); cursor: pointer; }
.tabs-top button.on { background: var(--brand-soft); color: var(--text); font-weight: 600; }
.tabs-bottom { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs-bottom button { border: 0; background: none; padding: 8px 2px 10px; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabs-bottom button span { font-size: 18px; line-height: 1.2; }
.tabs-bottom button.on { color: var(--brand); font-weight: 600; }
@media (min-width: 860px) {
  .tabs-top { display: flex; } .tabs-bottom { display: none; } .app { padding-bottom: 24px; }
}

/* piezas */
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; letter-spacing: .5px; font-size: 20px; }
.logo.sm { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-title { padding: 12px 16px 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.neg .kpi-value { color: var(--bad); } .kpi.pos .kpi-value { color: var(--good); } .kpi.warn .kpi-value { color: var(--warn); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-top: 1px solid var(--line); min-width: 0; }
.card:not(.flush) .list li { padding-left: 0; padding-right: 0; }
.list li:first-child { border-top: 0; }
.list.click li { cursor: pointer; } .list.click li:hover { background: var(--surface-2); }
.list strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docbtn { border: 0; background: none; text-align: left; padding: 0; cursor: pointer; display: flex; flex-direction: column; min-width: 0; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 7px 4px; border-top: 1px solid var(--line); font-size: 14px; }
.tbl th { font-weight: 500; color: var(--muted); font-size: 12px; border-top: 0; text-align: left; }
.tbl th.r { text-align: right; }
.totals { display: flex; gap: 10px; flex-wrap: wrap; }
.totals > div { flex: 1; min-width: 100px; background: var(--surface-2); border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; }
.totals span { font-size: 12px; color: var(--muted); } .totals strong { font-variant-numeric: tabular-nums; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.good { background: var(--good-bg); color: var(--good); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--bad-bg); color: var(--bad); }
.empty { padding: 22px 16px; text-align: center; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: var(--surface); border-color: var(--line); }
.btn.danger { background: none; color: var(--bad); border-color: var(--bad-bg); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { border: 0; background: none; color: var(--brand); cursor: pointer; padding: 4px 0; font-weight: 550; }
.icon-btn { border: 0; background: none; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; color: var(--muted); font-size: 16px; flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.sync { border: 0; border-radius: 99px; padding: 5px 11px; font-size: 12px; cursor: pointer; white-space: nowrap; max-width: 44vw; overflow: hidden; text-overflow: ellipsis; }
.sync.good { background: var(--good-bg); color: var(--good); } .sync.warn { background: var(--warn-bg); color: var(--warn); }
.sync.bad { background: var(--bad-bg); color: var(--bad); } .sync.neutral { background: var(--surface-2); color: var(--muted); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.pin { border: 1px solid var(--line); background: none; border-radius: 99px; font-size: 12px; padding: 3px 9px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.pin.on { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.check { width: 30px; height: 30px; flex: none; border-radius: 50%; border: 1.5px solid var(--line); background: none; cursor: pointer; color: var(--muted); }
.check:hover { background: var(--good-bg); color: var(--good); border-color: var(--good); }

.folders { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .folders { grid-template-columns: repeat(4, 1fr); } }
.folder { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; box-shadow: var(--shadow); align-items: flex-start; }
.folder:hover { border-color: var(--brand); }
.folder-ico { font-size: 20px; color: var(--brand); }

/* formularios */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 620px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field span { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.field input:focus, .field select:focus, .field textarea:focus, .toolbar input:focus, .toolbar select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.field input[readonly] { color: var(--muted); }
.wide { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.filepick { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.msg { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: 10px; margin: 0; font-size: 14px; }

.login, .splash { min-height: 100vh; display: grid; place-items: center; padding: 16px; text-align: center; }
.login .card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; padding: 28px 22px; align-items: stretch; text-align: left; }
.login .logo { margin: 0 auto 4px; } .login h1, .login > .card > p.muted { text-align: center; }
.splash { align-content: center; gap: 12px; }
@media (max-width: 340px) { .form { grid-template-columns: 1fr; } .brand .muted { display: none; } }

/* ajustes móvil */
html, body { overflow-x: hidden; }
.brand strong, .brand .muted { white-space: nowrap; }
.list li > div:first-child:not(.r) { flex: 1; min-width: 0; }
.list li .badge, .list li .r { flex: none; }
.list li .r { max-width: 45%; }
