:root {
  --brand: #1F4A40;
  --bg: #F4F6F5;
  --card: #FFFFFF;
  --text: #1E2B28;
  --muted: #5F6B67;
  --line: #DCE2DF;
  --danger: #B42318;
  --ok: #2E7D5B;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 18px; margin: 0; flex: 1; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--brand); }
a { color: inherit; text-decoration: none; }
small { display: block; color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

/* Barra superior y pestañas */
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--brand); color: #fff; }
.bar .status { width: auto; background: #fff; color: var(--text); border: 0; padding: 6px 8px; font-size: 14px; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 20px; min-width: 40px; min-height: 40px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
.card .icon-btn, .grid .icon-btn { color: var(--muted); }
.offline { display: none; font-size: 12px; background: #fff3; padding: 2px 8px; border-radius: 99px; }
.is-offline .offline { display: inline; }
.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--line); }
.tabs a { flex: 1; text-align: center; padding: 12px; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a.on { color: var(--brand); border-color: var(--brand); font-weight: 600; }

.page { max-width: 760px; margin: 0 auto; padding: 12px 12px 120px; }
.search { margin-bottom: 12px; }

/* Lista de presupuestos */
.list { list-style: none; margin: 0; padding: 0; }
.list li a { display: flex; justify-content: space-between; gap: 12px; padding: 14px; margin-bottom: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.list .right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.chip { font-size: 12px; padding: 2px 10px; border-radius: 99px; background: #EEF1F0; color: var(--muted); white-space: nowrap; }
.chip.pending { background: #FFF4DB; color: #8A5A00; }
.chip.accepted { background: #E3F2EA; color: #1D6B47; }
.chip.lost { background: #F6E6E4; color: #8E2B20; }
.chip.done { background: #E4ECF7; color: #284B7A; }
.list .right small { color: var(--muted); font-size: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.chip-btn { font: inherit; font-size: 13px; padding: 6px 12px; min-height: 32px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--muted); cursor: pointer; }
.chip-btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.summary { margin: 8px 2px 10px; color: var(--muted); font-size: 14px; }
.summary strong { color: var(--brand); }
.warn { color: #B54708; font-weight: 600; }
.warn-box { background: #FFF4DB; color: #8A5A00; padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; }
.fab { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); background: var(--brand); color: #fff; border: 0; border-radius: 99px; padding: 14px 22px; font-size: 16px; font-weight: 600; box-shadow: 0 4px 14px #0003; cursor: pointer; }

/* Formularios */
section, details { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
summary { font-weight: 600; color: var(--brand); cursor: pointer; }
details .grid, details .f { margin-top: 10px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.paint { grid-template-columns: minmax(0, 1fr) 90px 40px; align-items: end; margin-bottom: 10px; }
.grid.pay { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 40px; align-items: end; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.grid.item { grid-template-columns: minmax(0, 1fr) 64px 92px 40px; align-items: center; margin-bottom: 8px; }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; width: auto; }
.wide { grid-column: 1 / -1; }
.grow { flex: 1; min-width: 0; }
.f { display: flex; flex-direction: column; gap: 4px; }
.f span { font-size: 12px; color: var(--muted); }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 6px 0; cursor: pointer; }
.chk input { width: 20px; height: 20px; accent-color: var(--brand); }
.row { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; margin-top: 6px; }
.btn { font: inherit; font-size: 15px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; min-height: 44px; }
.btn.small { font-size: 14px; padding: 6px 12px; min-height: 36px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); border-color: #F0C7C2; width: 100%; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.card.free { border-style: dashed; background: #F7FAF8; }
.card-head { display: flex; gap: 4px; align-items: center; margin-bottom: 8px; }
.card-head input { font-weight: 600; }
.out { margin: 8px 0 0; font-weight: 600; color: var(--brand); font-size: 14px; }
.total-bar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px max(16px, calc(50% - 368px)); padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.total-bar strong { font-size: 24px; color: var(--brand); }
.logo-prev { display: flex; align-items: center; gap: 12px; grid-column: 1 / -1; }
.logo-prev img { max-height: 60px; max-width: 160px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #1E2B28; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20; }
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 24px; }
.login h1 { flex: none; font-size: 26px; color: var(--brand); }
.login p { color: var(--muted); margin: 0 0 16px; }
.send textarea { font-size: 14px; margin-bottom: 10px; }

/* Presupuesto para el cliente (A4) */
.doc-wrap { padding: 12px; overflow-x: auto; }
.doc { background: #fff; max-width: 210mm; margin: 0 auto; padding: 14mm 14mm 10mm; border: 1px solid var(--line); font-size: 12.5px; line-height: 1.5; color: #1E2B28; }
.doc-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand img { max-height: 56px; max-width: 140px; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: .06em; color: var(--brand); text-transform: uppercase; }
.doc-meta { text-align: right; }
.doc-meta strong { color: var(--brand); font-size: 15px; white-space: nowrap; }
.doc small { font-size: 11.5px; }
.doc-boxes { display: flex; gap: 24px; margin-top: 20px; padding: 12px 14px; background: #F1F5F3; }
.doc-boxes > div { flex: 1; }
.doc h3 { font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--brand); margin: 18px 0 6px; }
.doc table { width: 100%; border-collapse: collapse; }
.doc td { padding: 6px 0; border-bottom: 1px solid #E3E7E5; vertical-align: top; }
.doc td:first-child { width: 32%; padding-right: 8px; }
.doc .r { text-align: right; white-space: nowrap; width: 16%; }
.doc .muted, .doc-foot { color: #5F6B67; }
.doc p { margin: 0; }
.totals { margin: 10px 0 0 auto; width: 260px; max-width: 100%; }
.totals > div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .disc { color: var(--ok); }
.totals .gst { margin: 6px 0 0; font-size: 11px; text-align: right; }
.totals .sum { font-weight: 700; border-top: 1px solid #E3E7E5; margin-top: 4px; padding-top: 8px; }
.doc .pre { white-space: pre-line; }
.totals .grand { margin-top: 6px; padding: 10px 12px; background: var(--brand); color: #fff; font-size: 15px; font-weight: 700; }
.doc-foot { display: flex; justify-content: center; margin-top: 22px; padding-top: 10px; border-top: 1px solid #E3E7E5; font-size: 11.5px; }

@media (max-width: 420px) {
  .grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .doc { padding: 6mm; }
  .doc-boxes { flex-direction: column; gap: 10px; }
}
@media print {
  /* Margen 0: así el navegador no imprime el título y la dirección de la app en el PDF del cliente.
     El margen real lo da el padding, repetido en cada hoja. */
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .no-print, .bar, .toast { display: none !important; }
  .doc-wrap { padding: 0; }
  .doc { border: 0; padding: 12mm 14mm; max-width: none; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
  tr { break-inside: avoid; }
  .doc-boxes, .totals .grand { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
