:root {
  --bg: #0e0f11;
  --surface: #17181c;
  --surface-2: #1f2126;
  --border: #2b2e35;
  --text: #f2f3f5;
  --muted: #9aa0ab;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, .14);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, .14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, .14);
  --amber: #eab308;
  --amber-soft: rgba(234, 179, 8, .14);
  --radius: 16px;
  --radius-sm: 10px;
  --tabbar-h: 64px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg.icon { width: 20px; height: 20px; flex: none; }
[data-icon] { display: inline-flex; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Topbar / navegación ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(14, 15, 17, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
  align-items: center; justify-content: center;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #131417; border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.tabbar a.active { color: var(--accent); }
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .topbar { padding: 14px 28px; }
  .tabbar {
    position: static; display: flex; gap: 6px; height: auto; padding: 0;
    background: none; border: 0;
  }
  .tabbar a { flex-direction: row; gap: 8px; padding: 9px 14px; border-radius: 999px; font-size: 14px; }
  .tabbar a:hover { background: var(--surface-2); color: var(--text); }
  .tabbar a.active { background: var(--accent-soft); }
}

/* ---------- Layout ---------- */
.container { max-width: 860px; margin: 0 auto; padding: 18px 14px 28px; outline: none; }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 2px 16px; }
.page-title h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.page-title p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 8px; }
.card h2 .icon { color: var(--accent); width: 18px; height: 18px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; font-size: 14px; }
.empty .icon { width: 34px; height: 34px; color: var(--border); display: block; margin: 0 auto 8px; }

/* ---------- Formularios ---------- */
.grid { display: grid; gap: 12px; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, select.input {
  width: 100%; min-height: 46px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: #6b717c; }
.input.upper { text-transform: uppercase; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; }
.input-icon .input { padding-left: 40px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-weight: 600; cursor: pointer; transition: transform .08s, background .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1a0d03; }
.btn-primary:hover { background: #fb8a3c; }
.btn-ghost { background: transparent; }
.btn-whatsapp { background: #25d366; border-color: #25d366; color: #062b14; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--red); background: var(--red-soft); }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 13px;
  color: var(--muted); cursor: pointer; min-height: 36px;
}
.seg button.active { background: var(--accent); color: #1a0d03; }
.seg.full { display: flex; } .seg.full button { flex: 1; }

/* ---------- Ítems de cotización ---------- */
.items { display: grid; gap: 10px; }
.item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 10px 12px; animation: pop .2s ease-out; }
.item-top { display: flex; align-items: center; gap: 8px; }
.item-desc { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 6px 6px; font-weight: 600; }
.item-desc:focus { border-color: var(--border); outline: none; background: var(--surface); }
.item-bottom { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.stepper button { width: 36px; height: 38px; border: 0; background: transparent; cursor: pointer; font-size: 18px; color: var(--text); }
.stepper button:active { background: var(--accent-soft); }
.stepper input { width: 44px; height: 38px; text-align: center; border: 0; background: transparent; outline: none; font-weight: 600; }
.price-input { position: relative; flex: 1; min-width: 110px; max-width: 160px; }
.price-input span { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; }
.price-input input { width: 100%; height: 40px; padding: 6px 10px 6px 22px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); outline: none; font-weight: 600; }
.price-input input:focus { border-color: var(--accent); }
.line-total { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; flex: none; }
.tag-servicio { background: rgba(59, 130, 246, .15); color: #60a5fa; }
.tag-repuesto { background: rgba(168, 85, 247, .15); color: #c084fc; }
.tag-libre { background: rgba(148, 163, 184, .15); color: #cbd5e1; }

.free-form { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
@media (min-width: 560px) { .free-form { grid-template-columns: 1fr 150px auto; } }

/* ---------- Totales ---------- */
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals .row span:first-child { color: var(--muted); }
.totals .row.discount span:last-child { color: var(--green); }
.totals .row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; font-size: 20px; font-weight: 800; }
.totals .row.total span:first-child { color: var(--text); }
.totals .row.total span:last-child { color: var(--accent); }
.bump { animation: bump .3s ease-out; }

.action-bar {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 10;
  display: flex; align-items: center; gap: 12px;
  background: rgba(23, 24, 28, .95); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 10px 10px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.action-bar .sum { flex: 1; line-height: 1.2; }
.action-bar .sum small { color: var(--muted); font-size: 12px; display: block; }
.action-bar .sum strong { font-size: 20px; color: var(--accent); font-variant-numeric: tabular-nums; }
@media (min-width: 768px) { .action-bar { bottom: 16px; } }

/* ---------- Sheet (modal inferior) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .6);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 20px 20px 0 0; animation: slideup .25s ease-out;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 768px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 20px; border-bottom: 1px solid var(--border); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-tools { padding: 0 16px 12px; display: grid; gap: 10px; }
.sheet-body { overflow-y: auto; padding: 0 16px 16px; }
.pick-list { display: grid; gap: 8px; }
.pick {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
}
.pick:active { transform: scale(.99); border-color: var(--accent); }
.pick .name { flex: 1; font-weight: 600; }
.pick .price { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.pick .count { background: var(--accent); color: #1a0d03; font-size: 12px; font-weight: 800; border-radius: 999px; padding: 2px 8px; }
.pick .plus { color: var(--muted); }

/* ---------- Historial ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-width: 0; }
.kpi small { display: block; color: var(--muted); font-size: 11px; font-weight: 600; line-height: 1.25; min-height: 28px; }
.kpi strong { display: block; font-size: 19px; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kpi.accent strong { color: var(--accent); }
.kpi .bar { height: 4px; background: var(--surface-2); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.kpi .bar i { display: block; height: 100%; background: var(--green); border-radius: 4px; }
@media (min-width: 560px) { .kpi { padding: 16px; } .kpi strong { font-size: 24px; } .kpi small { font-size: 12px; min-height: 0; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip b { font-weight: 700; margin-left: 4px; opacity: .8; }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.quote-list { display: grid; gap: 10px; }
.quote-card {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  cursor: pointer; transition: border-color .15s;
}
.quote-card:hover { border-color: #3a3e47; }
.quote-card .folio { font-size: 12px; font-weight: 700; color: var(--accent); letter-spacing: .02em; }
.quote-card .folio span { color: var(--muted); font-weight: 500; margin-left: 6px; }
.quote-card .client { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote-card .meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; min-width: 0; }
.quote-card .meta .veh { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote-card .total { font-weight: 800; font-size: 16px; text-align: right; font-variant-numeric: tabular-nums; }
.plate {
  display: inline-block; flex: none; font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; font-weight: 700; font-size: 12px;
  padding: 2px 7px; border-radius: 6px; background: #f2f3f5; color: #111; letter-spacing: .05em;
}

.status {
  display: inline-flex; align-items: center; gap: 6px; justify-self: end;
  border-radius: 999px; padding: 6px 11px; font-size: 12px; font-weight: 700; cursor: pointer;
  border: 1px solid transparent; -webkit-tap-highlight-color: transparent; transition: transform .1s;
}
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status:active { transform: scale(.94); }
.status.pendiente { background: var(--amber-soft); color: var(--amber); border-color: rgba(234, 179, 8, .35); }
.status.aprobada { background: var(--green-soft); color: var(--green); border-color: rgba(34, 197, 94, .35); }
.status.rechazada { background: var(--red-soft); color: var(--red); border-color: rgba(239, 68, 68, .35); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 2px 0; display: flex; align-items: center; gap: 6px; }
.hint .icon { width: 14px; height: 14px; }

/* ---------- Catálogo ---------- */
.cat-list { display: grid; gap: 8px; }
.cat-row { display: flex; align-items: center; gap: 10px; padding: 10px 6px 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.cat-row .name { flex: 1; min-width: 0; font-weight: 600; }
.cat-row .price { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Documento de cotización ---------- */
.doc-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.doc-actions .back { grid-column: span 2; justify-self: start; }
.doc-status { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.doc {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 16px; overflow: hidden;
}
.doc-head { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding-bottom: 16px; border-bottom: 2px solid var(--accent); }
.doc-brand { display: flex; align-items: center; gap: 10px; }
.doc-brand .brand-logo { width: 44px; height: 44px; }
.doc-brand h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.doc-brand p { margin: 0; font-size: 12px; color: var(--muted); }
.doc-meta { text-align: right; margin-left: auto; }
.doc-meta .label { font-size: 11px; font-weight: 700; letter-spacing: .12em; color: var(--muted); }
.doc-meta .folio { font-size: 20px; font-weight: 800; color: var(--accent); }
.doc-meta .date { font-size: 13px; color: var(--muted); }
.doc-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 18px 0 8px; }
.doc-client { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.doc-client div small { display: block; font-size: 11px; color: var(--muted); }
.doc-client div span { font-weight: 600; word-break: break-word; }

.doc-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.doc-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.doc-table td { padding: 10px 6px; border-bottom: 1px solid var(--border); vertical-align: top; font-variant-numeric: tabular-nums; }
.doc-table .num { text-align: right; white-space: nowrap; }
.doc-table .desc-sub { display: none; color: var(--muted); font-size: 12px; margin-top: 2px; }
@media (max-width: 559px) {
  .doc-table .col-qty, .doc-table .col-unit { display: none; }
  .doc-table .desc-sub { display: block; }
}
.doc-totals { margin-left: auto; max-width: 320px; margin-top: 12px; }
.doc-foot { margin-top: 22px; padding-top: 14px; border-top: 1px dashed var(--border); font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- Toast y animación de guardado ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 90px + env(safe-area-inset-bottom)); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #26282e; border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; max-width: 90vw;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--red); color: #fecaca; }
@media (min-width: 768px) { .toast { bottom: 100px; } }

.saved-overlay {
  position: fixed; inset: 0; z-index: 90; display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px);
}
.saved-overlay.show { display: flex; animation: fade .2s; }
.saved-box { text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 26px 34px; animation: pop .3s ease-out; }
.saved-box p { margin: 12px 0 2px; font-weight: 600; }
.saved-box strong { color: var(--accent); font-size: 20px; }
.saved-check { width: 72px; height: 72px; }
.saved-check circle { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 151; stroke-dashoffset: 151; }
.saved-check path { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 36; stroke-dashoffset: 36; }
.saved-overlay.show circle { animation: draw .5s ease-out forwards; }
.saved-overlay.show path { animation: draw .35s .4s ease-out forwards; }

.loading { text-align: center; color: var(--muted); padding: 50px 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }

@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bump { 50% { transform: scale(1.06); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- Impresión / PDF ---------- */
@media print {
  @page { size: A4; margin: 14mm; }
  :root { --text: #111; --muted: #555; --border: #d4d4d8; }
  body { background: #fff; color: #111; padding: 0; font-size: 12px; }
  .no-print, .topbar, .tabbar, #sheet-root, .toast, .saved-overlay { display: none !important; }
  .container { max-width: none; padding: 0; }
  .doc { background: #fff; border: 0; padding: 0; border-radius: 0; }
  .doc-brand .brand-logo { background: #fff3e8; }
  .doc-table .col-qty, .doc-table .col-unit { display: table-cell !important; }
  .doc-table .desc-sub { display: none !important; }
  .doc-table tr { page-break-inside: avoid; }
  .totals .row.total span:last-child, .doc-meta .folio { color: #c2410c; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
