:root {
  --ink: #0E1B2C;
  --ink-soft: #2A3F5C;
  --muted: #566274;
  --bg: #F2F4F7;
  --card: #fff;
  --line: #DCE1E8;
  --accent: #F5A524;
  --accent-press: #E0931A;
  --danger: #9A2A1B;
  --radius: 14px;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.4; }
h1, h2, h3, p { margin: 0; }
a { color: var(--ink); }
button { font-family: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: 150px; }
.head { padding: 28px 20px 12px; }
.head h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.head p { margin-top: 4px; font-size: 14px; }
.pad { padding: 0 20px 14px; }
.back { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; font-size: 14px; text-decoration: none; padding: 0 20px; }

#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; max-width: 640px; margin: 0 auto; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
#tabs a { flex: 1; text-align: center; padding: 13px 0 15px; font-size: 12px; font-weight: 700; text-decoration: none; color: var(--muted); border-top: 3px solid transparent; margin-top: -1px; }
#tabs a[aria-current="page"] { color: var(--ink); border-top-color: var(--accent); }

.input, select.input, textarea.input { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid #B9C2CE; background: #fff; font: inherit; font-size: 16px; color: var(--ink); }
textarea.input { min-height: 88px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .mini { font-size: 13px; font-weight: 700; color: var(--muted); }
.field .hint { font-size: 13px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 20px; border-radius: var(--radius); border: 1.5px solid transparent; font-size: 16px; font-weight: 800; text-decoration: none; cursor: pointer; text-align: center; }
.btn-primary { background: var(--accent); color: var(--ink); }
.btn-primary:hover { background: var(--accent-press); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: var(--ink-soft); }
.btn-outline { background: #fff; border-color: var(--ink); color: var(--ink); }
.btn-sm { min-height: 44px; font-size: 14px; padding: 0 14px; border-radius: 12px; }
.btn-block { width: 100%; }
.link-danger { background: none; border: 0; color: var(--danger); font-weight: 700; font-size: 14px; min-height: 44px; cursor: pointer; text-decoration: underline; padding: 0 4px; }
.fab { position: fixed; left: 20px; right: 20px; bottom: calc(66px + env(safe-area-inset-bottom)); max-width: 600px; margin: 0 auto; box-shadow: 0 6px 18px rgba(14, 27, 44, 0.2); z-index: 4; }

.chips { display: flex; gap: 8px; padding: 0 20px 14px; overflow-x: auto; }
.chip { flex-shrink: 0; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: #3A4558; font-size: 13px; font-weight: 700; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

.list { display: flex; flex-direction: column; gap: 10px; padding: 0 20px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
a.card:hover { border-color: var(--ink); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card .meta { font-size: 13px; font-weight: 700; color: var(--muted); }
.card .who { font-size: 16px; font-weight: 700; }
.card .what { font-size: 14px; color: var(--muted); }
.card .amount { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.st { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.st-draft { background: #E6E9EF; color: #3A4558; }
.st-sent { background: #DCE8FB; color: #1E40AF; }
.st-ok { background: #D6F0E3; color: #0B5A3F; }
.st-no { background: #FBE0DC; color: #9A2A1B; }

.empty { margin: 8px 20px; padding: 28px 20px; background: #fff; border: 1.5px dashed #B9C2CE; border-radius: var(--radius); text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }
.banner { display: block; margin: 0 20px 14px; padding: 12px 16px; border-radius: 12px; background: #FFF3D6; color: #5A3B00; font-weight: 700; font-size: 14px; text-decoration: none; }

.section { padding: 0 20px; margin-bottom: 18px; }
.section > h2 { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px; }
.box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 8px; }
.item-nums { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 8px; align-items: end; }
.item-sub { display: flex; flex-direction: column; gap: 2px; text-align: right; }
.item-sub strong { font-variant-numeric: tabular-nums; min-height: 48px; display: flex; align-items: center; justify-content: flex-end; font-size: 15px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dashed { border: 1.5px dashed #8A96A8; background: transparent; color: var(--ink); min-height: 48px; border-radius: 12px; font-weight: 700; font-size: 14px; cursor: pointer; }

.totals { background: #fff; border-top: 1px solid var(--line); padding: 14px 20px 18px; position: sticky; bottom: 0; }
.totals .line { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.totals .big { display: flex; justify-content: space-between; align-items: baseline; font-size: 24px; font-weight: 800; margin: 6px 0 12px; font-variant-numeric: tabular-nums; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 20px; margin-bottom: 14px; }
.actions .wide { grid-column: 1 / -1; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 14px; }

.paper { background: #fff; border: 1px solid var(--line); border-radius: 8px; margin: 0 20px 18px; padding: 22px; box-shadow: 0 6px 20px rgba(14, 27, 44, 0.1); display: flex; flex-direction: column; gap: 16px; font-size: 14px; }
.paper .top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.paper .brand { display: flex; gap: 12px; align-items: center; }
.paper .brand img { max-width: 72px; max-height: 72px; object-fit: contain; }
.paper .brand .bn { font-size: 17px; font-weight: 800; }
.paper .brand .bd { font-size: 13px; color: var(--muted); }
.paper .docno { text-align: right; }
.paper .docno .t { font-size: 20px; font-weight: 800; }
.paper .docno .d { font-size: 13px; color: var(--muted); }
.paper .to { border-top: 1px solid var(--line); padding-top: 12px; font-size: 14px; }
.paper .to .k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.paper table { width: 100%; border-collapse: collapse; font-size: 14px; }
.paper th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; padding: 6px 4px; border-bottom: 2px solid var(--ink); }
.paper td { padding: 9px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.paper .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.paper .sums { margin-left: auto; width: min(100%, 280px); font-variant-numeric: tabular-nums; }
.paper .sums .line { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.paper .sums .tot { display: flex; justify-content: space-between; padding-top: 8px; margin-top: 6px; border-top: 2px solid var(--ink); font-size: 20px; font-weight: 800; color: var(--ink); }
.paper .notes { font-size: 14px; white-space: pre-wrap; }
.paper .foot { font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(92vw, 460px); max-height: 88vh; color: var(--ink); font-family: var(--font); }
dialog::backdrop { background: rgba(14, 27, 44, 0.55); }
.dlg-form { padding: 20px; display: flex; flex-direction: column; }
.dlg-form h2 { font-size: 20px; font-weight: 800; margin-bottom: 14px; }
.dlg-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.pick { display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; font-size: 15px; cursor: pointer; color: var(--ink); }
.pick:hover { border-color: var(--ink); }
.pick small { display: block; color: var(--muted); font-size: 13px; }
.logo-prev { width: 72px; height: 72px; border-radius: 12px; background: #E6E9EF; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; color: var(--muted); overflow: hidden; }
.logo-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }

#toast { position: fixed; left: 50%; bottom: calc(130px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 700; max-width: 90vw; opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 20; }
#toast.on { opacity: 1; }

@page { margin: 14mm; }
@media print {
  body { background: #fff; }
  #tabs, .no-print, #toast, .fab, .back { display: none !important; }
  #app { max-width: none; padding: 0; }
  .paper { margin: 0; border: 0; box-shadow: none; padding: 0; font-size: 12pt; }
  .paper th { font-size: 9pt; }
}

@media (max-width: 440px) {
  .paper { padding: 16px; }
  .paper table, .paper td { font-size: 13px; }
  .paper th { font-size: 11px; padding: 6px 2px; }
  .paper td { padding: 8px 2px; }
  .paper .docno { text-align: left; }
}

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 20px 14px; }
.stats > div { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.stats strong { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.st-exp { background: #FFF3D6; color: #5A3B00; }
@media (max-width: 380px) { .stats strong { font-size: 15px; } }

/* ---------- Computadora y pantallas grandes ---------- */
@media (min-width: 900px) {
  #tabs, #tabs[hidden] { display: flex !important; position: fixed; top: 0; bottom: 0; left: 0; right: auto; width: 232px; max-width: none; margin: 0; flex-direction: column; gap: 4px; padding: 28px 14px; background: var(--ink); border-top: 0; }
  #tabs::before { content: 'Cotizá'; color: #fff; font-size: 24px; font-weight: 800; letter-spacing: -0.5px; padding: 0 14px 22px; }
  #tabs a { flex: none; text-align: left; padding: 13px 16px; margin: 0; font-size: 15px; color: #C9D3E0; border-top: 0; border-radius: 10px; }
  #tabs a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
  #tabs a[aria-current="page"] { background: var(--accent); color: var(--ink); }
  #tabs a:focus-visible { outline-color: #fff; }
  #app { max-width: none; margin: 0 0 0 232px; padding: 12px 40px 120px; }
  #view { max-width: 980px; margin: 0 auto; }
  .head { padding: 28px 0 14px; }
  .head h1 { font-size: 30px; }
  .pad, .chips, .seg, .actions, .section, .stats { padding-left: 0; padding-right: 0; }
  .banner { margin-left: 0; margin-right: 0; }
  .back { padding: 0; }
  .stats { grid-template-columns: repeat(2, minmax(0, 260px)); }
  .list { padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .empty { margin: 8px 0; }
  .fab { left: auto; right: 40px; bottom: 32px; width: auto; min-width: 260px; max-width: none; margin: 0; }
  #toast { bottom: auto; top: 24px; margin-left: 116px; }
  .input { max-width: 100%; }
  .paper { margin: 0 0 18px; padding: 36px 40px; max-width: 760px; font-size: 15px; }
  .actions { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 760px; }
  .actions .wide { grid-column: 1 / -1; }
  .totals { padding: 16px 0 20px; max-width: 760px; }
  .section { max-width: 760px; }
  .item-nums { grid-template-columns: 110px 1fr 1fr; }
  dialog { width: 480px; }
}
@media (min-width: 900px) and (hover: hover) {
  a.card:hover, button.card:hover { border-color: var(--ink); box-shadow: 0 4px 14px rgba(14, 27, 44, 0.08); }
}
@media print {
  #app { margin: 0 !important; padding: 0 !important; }
  #view { max-width: none; }
  .paper { max-width: none; padding: 0; }
}
