:root {
  --brand: #F5A623;
  --brand-ink: #1a1a1a;
  --brand-deep: #113A7A;
  --brand-deep-2: #0B2A5A;
  --accent-soft: #FFF4DC;
  --bg: #FAFAF8;
  --surface: #FFFFFF;
  --surface-2: #F4F4F1;
  --line: #E6E4DE;
  --line-strong: #C9C6BE;
  --ink: #111111;
  --ink-2: #3A3A37;
  --muted: #7A7872;
  --danger: #C0392B;
  --ok: #2F7D3E;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(17,17,17,.04), 0 1px 0 rgba(17,17,17,.02);
  --shadow-md: 0 8px 24px rgba(17,17,17,.08), 0 2px 6px rgba(17,17,17,.04);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --row-h: 40px;
}
[data-density="compact"] {
  --row-h: 32px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: #0E0E0D;
  color: #EDECE6;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 6px 10px; border-bottom: 1px solid #26231E;
}
.sidebar-brand img {
  height: 34px; width: 34px; object-fit: contain;
  background: #fff; border-radius: 8px; padding: 3px;
}
.sidebar-brand .t { display: flex; flex-direction: column; line-height: 1; }
.sidebar-brand .t b { font-weight: 800; letter-spacing: .02em; font-size: 14px; color: #fff; }
.sidebar-brand .t span { font-size: 10.5px; color: #A8A59B; letter-spacing: .08em; text-transform: uppercase; margin-top: 3px; }

.nav-section-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em;
  color: #7A776E; padding: 0 10px; margin: 8px 0 4px;
}
.nav a, .nav button {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; color: #D9D7CF;
  text-decoration: none; cursor: pointer; background: transparent;
  border: 0; width: 100%; text-align: left; font-size: 13.5px;
}
.nav a.active, .nav button.active {
  background: rgba(245,166,35,.14); color: #fff;
  box-shadow: inset 2px 0 0 var(--brand);
}
.nav a:hover, .nav button:hover { background: #1C1A16; color: #fff; }
.nav svg { flex-shrink: 0; opacity: .85; }

.sidebar-footer {
  margin-top: auto; padding: 10px; font-size: 11px;
  color: #6A6760; border-top: 1px solid #26231E;
}

.main {
  min-width: 0;
  display: flex; flex-direction: column;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 {
  margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em;
}
.topbar .crumb {
  font-size: 11.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .1em; margin-bottom: 2px;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.content { padding: 28px; }
.content.narrow { max-width: 1180px; margin: 0 auto; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .12s ease;
}
.btn:hover { background: var(--surface-2); border-color: #8A877D; }
.btn.primary {
  background: var(--brand); color: var(--brand-ink); border-color: var(--brand);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.dark {
  background: var(--brand-deep); color: #fff; border-color: var(--brand-deep);
}
.btn.dark:hover { background: var(--brand-deep-2); }
.btn.danger {
  color: var(--danger); border-color: transparent; background: transparent;
}
.btn.danger:hover { background: #fbe9e6; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.icon { padding: 7px; }

/* ---------- Cards & tables ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-head {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.005em; }
.card-head .hint { font-size: 12px; color: var(--muted); }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }

table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data th {
  text-align: left; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--surface-2);
  position: sticky; top: 0;
}
table.data td {
  padding: 0 14px; border-bottom: 1px solid var(--line);
  height: var(--row-h); vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: #fdfcf7; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.mono { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
table.data input, table.data select {
  width: 100%; border: 1px solid transparent; background: transparent;
  padding: 6px 8px; border-radius: 6px; font-size: 13px;
}
table.data input:focus, table.data select:focus {
  outline: none; border-color: var(--brand); background: #fffbf2;
}
table.data input.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(245,166,35,.15);
}
.field textarea { min-height: 80px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge.brand { background: var(--accent-soft); color: #8a5a00; border-color: #f2d89a; }
.badge.deep { background: rgba(17,58,122,.08); color: var(--brand-deep); border-color: rgba(17,58,122,.2); }
.badge.ok { background: #e6f4ea; color: var(--ok); border-color: #bddfc4; }
.badge.dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}

/* ---------- Dashboard ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px;
}
.kpi .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); font-weight: 600;
}
.kpi .value {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  margin-top: 6px; font-variant-numeric: tabular-nums;
}
.kpi .delta { font-size: 12px; color: var(--ok); margin-top: 4px; font-weight: 500; }
.kpi .delta.down { color: var(--danger); }
.kpi.accent { background: linear-gradient(135deg, var(--brand) 0%, #ffc765 100%); border-color: var(--brand); }
.kpi.accent .label { color: rgba(26,26,26,.7); }
.kpi.accent .value { color: #1a1a1a; }

/* ---------- Quote layout ---------- */
.quote-layout {
  display: grid; grid-template-columns: 1fr 320px; gap: 20px;
}
.totals-panel {
  position: sticky; top: 88px; align-self: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.totals-panel .row {
  display: flex; justify-content: space-between; padding: 11px 18px;
  font-size: 13px; border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.totals-panel .row.strong { font-weight: 600; color: var(--brand-deep); }
.totals-panel .row.total {
  background: var(--brand-deep); color: #fff; font-weight: 700; font-size: 16px;
  padding: 16px 18px;
}
.totals-panel .row.total .accent { color: var(--brand); }

/* ---------- Section header ---------- */
.section-title {
  display: flex; align-items: baseline; gap: 10px;
  margin: 22px 0 12px;
}
.section-title .n {
  font-family: var(--mono); font-size: 11px; color: var(--brand);
  font-weight: 600;
}
.section-title h3 {
  margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
}
.section-title .hint { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ---------- Import modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12,12,10,.55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-md);
  width: 100%; max-width: 820px; max-height: 90vh; overflow: auto;
}
.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { padding: 22px; }

/* ---------- Tweaks panel ---------- */
.tweaks {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  width: 300px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 12px;
  box-shadow: var(--shadow-md); overflow: hidden;
  font-size: 13px;
}
.tweaks header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: #0E0E0D; color: #fff;
}
.tweaks header b { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.tweaks header .x {
  background: transparent; border: 0; color: #aaa; cursor: pointer; font-size: 18px;
}
.tweaks .body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.tweaks .swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.tweaks .sw {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer;
}
.tweaks .sw.active { box-shadow: 0 0 0 2px var(--brand-deep); }
.tweaks .toggle {
  display: flex; justify-content: space-between; align-items: center;
}
.tweaks .toggle label { font-weight: 500; }
.switch {
  width: 36px; height: 20px; background: #d6d4cc; border-radius: 999px;
  position: relative; cursor: pointer; transition: background .15s;
  border: 0;
}
.switch.on { background: var(--brand); }
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  transition: transform .15s;
}
.switch.on::after { transform: translateX(16px); }
.tweaks .variant-row { display: flex; gap: 6px; }
.tweaks .variant-row button {
  flex: 1; padding: 7px; border: 1px solid var(--line-strong); background: #fff;
  border-radius: 6px; font-size: 11.5px; cursor: pointer;
}
.tweaks .variant-row button.active { background: var(--brand-deep); color: #fff; border-color: var(--brand-deep); }

/* ---------- Print selector ---------- */
.print-shell {
  display: grid; grid-template-columns: 320px 1fr; gap: 20px;
  padding: 28px;
}
.print-options {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; position: sticky; top: 88px; align-self: start;
}
.print-options h3 { margin: 0 0 14px; font-size: 14px; }
.print-options .opt {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 8px; cursor: pointer; font-size: 13px;
}
.print-options .opt:hover { background: var(--surface-2); }
.print-options .opt.active { background: var(--accent-soft); font-weight: 600; }
.print-options .opt input { accent-color: var(--brand-deep); }
.print-preview {
  background: #e9e7df; padding: 30px; border-radius: var(--radius);
  min-height: 80vh;
  display: flex; flex-direction: column; gap: 16px; align-items: center;
}

/* ---------- Printable pages ---------- */
.page {
  width: 210mm; min-height: 297mm; background: #fff;
  padding: 22mm 18mm 20mm; box-shadow: 0 8px 28px rgba(0,0,0,.15);
  font-size: 11px; color: #222; line-height: 1.4;
  display: flex; flex-direction: column;
  position: relative;
}
.page .ph-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding-bottom: 14px; border-bottom: 2px solid var(--brand-deep);
  margin-bottom: 18px;
}
.page .ph-head .logo { height: 48px; }
.page .ph-head .meta {
  text-align: right; font-size: 10.5px; color: #555;
}
.page .ph-head .meta .num {
  font-family: var(--mono); font-size: 18px; font-weight: 700;
  color: var(--brand-deep); letter-spacing: .04em;
}
.page h1.p-title {
  font-size: 22px; letter-spacing: -0.01em; margin: 10px 0 18px;
  color: var(--brand-deep);
}
.page .p-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--brand); font-weight: 700;
  border-bottom: 1px solid #ddd; padding-bottom: 4px; margin: 18px 0 10px;
}
.page .info-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px;
  font-size: 10.5px;
}
.page .info-grid .k { color: #777; text-transform: uppercase; letter-spacing: .06em; font-size: 9.5px; }
.page .info-grid .v { font-weight: 600; color: #222; }

.page table.pt {
  width: 100%; border-collapse: collapse; font-size: 10px;
  margin-top: 6px;
}
.page table.pt th {
  text-align: left; font-size: 9px; text-transform: uppercase; letter-spacing: .08em;
  color: #555; padding: 6px 6px; border-bottom: 1.5px solid var(--brand-deep);
  background: #f6f6f3;
}
.page table.pt td {
  padding: 6px; border-bottom: 1px solid #eee; vertical-align: top;
  font-variant-numeric: tabular-nums;
}
.page table.pt td.num, .page table.pt th.num { text-align: right; }
.page table.pt td.c, .page table.pt th.c { text-align: center; }
.page table.pt tr.subtotal td {
  background: #f6f6f3; font-weight: 700;
  border-top: 1.5px solid var(--brand-deep); border-bottom: 0;
}

.page .totals-box {
  margin-top: 20px; display: flex; justify-content: flex-end;
}
.page .totals-box table {
  border-collapse: collapse; min-width: 320px;
}
.page .totals-box td { padding: 7px 12px; font-size: 11px; font-variant-numeric: tabular-nums; }
.page .totals-box td.k { color: #555; }
.page .totals-box tr.total td {
  background: var(--brand-deep); color: #fff; font-size: 13px; font-weight: 700;
}
.page .totals-box tr.total td.v { border-left: 4px solid var(--brand); }

.page .footer {
  margin-top: auto; padding-top: 14px; border-top: 1px solid #ddd;
  display: flex; justify-content: space-between; font-size: 9px; color: #888;
}

/* Portada variante grande */
.page.cover h1.p-title {
  font-size: 32px; margin: 30px 0 8px;
}
.page.cover .cover-amount {
  margin: 36px 0; padding: 28px 34px;
  background: linear-gradient(135deg, var(--brand-deep) 0%, var(--brand-deep-2) 100%);
  color: #fff; border-radius: 10px;
  border-left: 8px solid var(--brand);
}
.page.cover .cover-amount .k {
  font-size: 10px; text-transform: uppercase; letter-spacing: .14em; opacity: .8;
}
.page.cover .cover-amount .v {
  font-size: 38px; font-weight: 800; letter-spacing: -0.02em; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.page.cover .cover-amount .sub { font-size: 11px; opacity: .8; margin-top: 4px; }

.page.cover .summary-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin: 18px 0;
}
.page.cover .summary-grid .box {
  border: 1px solid #ddd; border-radius: 8px; padding: 14px;
}
.page.cover .summary-grid .k { font-size: 9.5px; color: #777; text-transform: uppercase; letter-spacing: .08em; }
.page.cover .summary-grid .v { font-size: 18px; font-weight: 700; margin-top: 6px; color: var(--brand-deep); font-variant-numeric: tabular-nums; }

/* ---------- Variants ---------- */
body[data-variant="v2"] {
  --brand: #FFC400;
  --brand-deep: #0A0A0A;
  --brand-deep-2: #1E1E1E;
  --accent-soft: #FFF8DC;
}
body[data-variant="v2"] .sidebar {
  background: #FFC400; color: #111;
}
body[data-variant="v2"] .sidebar-brand { border-bottom-color: rgba(0,0,0,.2); }
body[data-variant="v2"] .sidebar-brand .t b { color: #111; }
body[data-variant="v2"] .sidebar-brand .t span { color: #4a3900; }
body[data-variant="v2"] .nav-section-title { color: #6a5300; }
body[data-variant="v2"] .nav a, body[data-variant="v2"] .nav button { color: #222; }
body[data-variant="v2"] .nav a:hover, body[data-variant="v2"] .nav button:hover { background: rgba(0,0,0,.08); color: #000; }
body[data-variant="v2"] .nav a.active, body[data-variant="v2"] .nav button.active {
  background: #111; color: #FFC400; box-shadow: inset 2px 0 0 #FFC400;
}
body[data-variant="v2"] .sidebar-footer { border-top-color: rgba(0,0,0,.15); color: #4a3900; }

body[data-variant="v3"] .sidebar {
  background: var(--brand-deep); color: #F1F4FA;
}
body[data-variant="v3"] .sidebar-brand { border-bottom-color: rgba(255,255,255,.12); }
body[data-variant="v3"] .nav a.active, body[data-variant="v3"] .nav button.active {
  background: rgba(245,166,35,.18); color: #fff;
}
body[data-variant="v3"] .nav a:hover, body[data-variant="v3"] .nav button:hover {
  background: rgba(255,255,255,.06); color: #fff;
}
body[data-variant="v3"] .kpi.accent {
  background: linear-gradient(135deg, var(--brand-deep) 0%, var(--brand-deep-2) 100%);
}
body[data-variant="v3"] .kpi.accent .label { color: rgba(255,255,255,.7); }
body[data-variant="v3"] .kpi.accent .value { color: #fff; }
body[data-variant="v3"] .kpi.accent .delta { color: var(--brand); }

/* ---------- Empty & utility ---------- */
.empty {
  padding: 60px 20px; text-align: center; color: var(--muted);
}
.empty .ico { font-size: 28px; margin-bottom: 10px; opacity: .5; }

.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* Print */
@media print {
  .no-print, .sidebar, .topbar, .tweaks, .print-options { display: none !important; }
  body { background: #fff; }
  .print-shell { display: block; padding: 0; }
  .print-preview { background: #fff; padding: 0; }
  .page {
    box-shadow: none; page-break-after: always;
    width: auto; min-height: auto;
  }
  .page:last-child { page-break-after: auto; }
}

/* ---------- Login screen ---------- */
.login-shell {
  min-height: 100vh; min-height: 100svh;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg); position: relative; overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(800px 500px at 80% -10%, rgba(245,166,35,.18), transparent 60%),
    radial-gradient(700px 500px at 0% 100%, rgba(17,58,122,.14), transparent 60%),
    linear-gradient(180deg, #FAFAF8 0%, #F0EFEA 100%);
}
.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 440px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow-md);
  padding: 32px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.login-brand img { height: 44px; width: 44px; object-fit: contain; background: #fff; border-radius: 10px; padding: 3px; border: 1px solid var(--line); }
.login-brand .b { font-weight: 800; letter-spacing: -0.01em; font-size: 16px; }
.login-brand .s { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin-top: 2px; }
.login-err {
  padding: 10px 12px; background: #fdecea; border: 1px solid #f5c6c3;
  color: var(--danger); border-radius: 8px; font-size: 13px;
}
.login-foot {
  position: absolute; bottom: 16px; left: 0; right: 0; z-index: 1;
  text-align: center; font-size: 11px; color: var(--muted);
}

/* ---------- Mobile shell ---------- */
.mobile-topbar {
  display: none;
}
.mobile-nav {
  display: none;
}
.mobile-drawer {
  display: none;
}

@media (max-width: 900px) {
  html, body { -webkit-text-size-adjust: 100%; }
  .app { grid-template-columns: 1fr; display: block; }
  .sidebar { display: none; }
  .quote-layout { grid-template-columns: 1fr; }
  .print-shell { grid-template-columns: 1fr; padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .kpi { padding: 14px 16px; }
  .kpi .value { font-size: 22px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; gap: 12px; }

  .topbar { display: none; }
  .main { padding-bottom: 72px; }
  .content { padding: 16px; }
  .card-head { padding: 14px 16px; flex-wrap: wrap; }
  .card-body { padding: 16px; }

  /* Mobile topbar with hamburger */
  .mobile-topbar {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    background: var(--surface); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 10;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .mobile-topbar .burger {
    width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line-strong);
    background: var(--surface); display: grid; place-items: center; cursor: pointer;
  }
  .mobile-topbar .title { flex: 1; min-width: 0; }
  .mobile-topbar .title .crumb { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
  .mobile-topbar .title h1 { margin: 2px 0 0; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-topbar .m-actions { display: flex; gap: 6px; }
  .mobile-topbar .m-actions .btn { padding: 8px 10px; font-size: 12.5px; min-height: 40px; }

  /* Bottom nav tabs */
  .mobile-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 2px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 14px rgba(0,0,0,.05);
  }
  .mobile-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    background: transparent; border: 0; padding: 6px 2px;
    color: var(--muted); font-size: 10.5px; font-weight: 500;
    border-radius: 8px; cursor: pointer; min-height: 52px;
  }
  .mobile-nav button.active { color: var(--brand-deep); }
  .mobile-nav button.active svg { color: var(--brand); }
  .mobile-nav button svg { width: 22px; height: 22px; }

  /* Drawer */
  .mobile-drawer.open { display: block; }
  .mobile-drawer {
    position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4);
  }
  .mobile-drawer .panel {
    position: absolute; left: 0; top: 0; bottom: 0; width: 82%; max-width: 320px;
    background: #0E0E0D; color: #EDECE6; padding: 20px 16px;
    display: flex; flex-direction: column; gap: 14px;
    padding-top: calc(20px + env(safe-area-inset-top));
    overflow-y: auto;
  }
  .mobile-drawer .panel .nav button {
    min-height: 46px; font-size: 14px;
  }

  /* Inputs & buttons: bigger touch targets */
  .btn { min-height: 40px; padding: 9px 14px; }
  .btn.sm { min-height: 34px; }
  .btn.icon { min-height: 40px; min-width: 40px; }
  .field input, .field select, .field textarea { padding: 11px 12px; font-size: 16px; } /* prevent iOS zoom */
  input, select, textarea { font-size: 16px; }

  /* Tables become horizontally scrollable */
  .card-body.flush { -webkit-overflow-scrolling: touch; }
  table.data { min-width: 720px; }
  table.data td { height: 44px; }
  table.data input, table.data select { font-size: 15px; padding: 8px 8px; }

  /* Totals panel becomes a static summary above the editor on mobile */
  .totals-panel { position: static; margin-bottom: 16px; }

  /* Printable preview scales to fit */
  .page {
    width: 100%; min-height: auto; padding: 18px 16px;
    font-size: 10px;
  }
  .page.cover h1.p-title { font-size: 22px; }
  .page.cover .cover-amount .v { font-size: 28px; }
  .page.cover .summary-grid { grid-template-columns: 1fr; }

  /* Modals fit screen */
  .modal { max-width: 100%; border-radius: 12px 12px 0 0; max-height: 94vh; }
  .modal-backdrop { align-items: flex-end; padding: 0; }

  /* Tweaks panel covers full width at bottom, above nav */
  .tweaks { right: 10px; left: 10px; bottom: 76px; width: auto; }

  /* Login */
  .login-card { padding: 22px; border-radius: 14px; }
  .login-foot { position: static; margin-top: 20px; }

  /* Print options become a top sheet */
  .print-options { position: static; }
  .print-preview { padding: 12px; }
}

/* Tiny phones */
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .mobile-nav button { font-size: 10px; }
  .mobile-nav button svg { width: 20px; height: 20px; }
}

/* ---------- Picker row (search modal) ---------- */
.picker-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.picker-row:hover { background: var(--surface-2); }
.picker-row:last-child { border-bottom: 0; }

/* Modal sizing on mobile so it never clips below the bottom nav */
@media (max-width: 900px) {
  .modal-backdrop { padding: 8px; align-items: flex-start; padding-top: 16px; padding-bottom: 80px; }
  .modal { max-height: calc(100dvh - 100px); display: flex; flex-direction: column; }
  .modal-body { overflow-y: auto; }
  .modal-foot { position: sticky; bottom: 0; background: var(--surface); }
  /* Pickers full-width on mobile */
  .picker-row { padding: 12px; }
  .picker-row .num { font-size: 13px !important; }
}

/* iOS / Android safe areas */
@supports (padding: env(safe-area-inset-top)) {
  .sidebar { padding-top: calc(22px + env(safe-area-inset-top)); }
}
