/* Cotizador. Todos los valores salen de tokens.css (sistema de diseño de usados).
   Celular primero; barra lateral desde 1024 px. Sin estilos en línea (CSP). */

/* Base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: var(--fs-body); line-height: 1.5; }
h1, h2, h3, h4, p, dl, dd { margin: 0; }
h1 { font-size: var(--fs-title); line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; text-wrap: balance; }
h2 { font-size: var(--fs-section); line-height: 1.25; font-weight: 600; text-wrap: balance; }
h3 { font-size: var(--fs-body); line-height: 1.3; font-weight: 600; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
img { display: block; max-width: 100%; }
button, input, select, textarea { font-family: inherit; color: inherit; }
button, a, select, label { touch-action: manipulation; }
:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }
.skip-link { position: fixed; left: var(--s-4); top: -60px; z-index: 60; background: var(--ink); color: #fff; padding: var(--s-2) var(--s-4); border-radius: var(--r-control); }
.skip-link:focus { top: var(--s-2); color: #fff; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Botones: neutros; el principal (uno por pantalla) en rojo */
.btn, .tabbar button, .nav-link, .sheet > button, .link-button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  border: 1px solid var(--border); border-radius: var(--r-control); background: var(--surface); color: var(--ink);
  font-size: var(--fs-control); font-weight: 600; cursor: pointer; transition: background-color .15s, border-color .15s, color .15s;
}
.btn { min-height: var(--control-h); padding: 0 var(--s-4); }
.btn:hover { background: var(--line-soft); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { min-height: var(--primary-h); border-color: var(--accent); background: var(--accent); color: #fff; font-size: var(--fs-body); }
.btn.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.link-button { min-height: 0; padding: 0; border: 0; background: none; color: var(--accent); font-weight: 500; text-decoration: underline; }
.link-button:hover { color: var(--accent-hover); }

/* Campos */
.field { display: grid; gap: 6px; font-size: var(--fs-small); min-width: 0; }
.field > span { color: var(--muted); font-weight: 500; }
:where(input:not([type="checkbox"]):not([type="radio"]), select) {
  width: 100%; min-height: var(--primary-h); padding: 0 14px; border: 1px solid var(--border); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink); font-size: var(--fs-body);
}
input:disabled, select:disabled { background: var(--line-soft); color: var(--muted); }
.field.invalid input { border: 2px solid var(--accent); }

/* Avisos */
.notice { padding: var(--s-3) var(--s-4); border-radius: var(--r-control); background: var(--surface); color: var(--text-2); border: 1px solid var(--line); font-size: var(--fs-control); }
.notice.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.notice.error { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.error { color: var(--accent); font-size: var(--fs-control); font-weight: 500; }
.hint, .usage, .source, .empty { color: var(--muted); font-size: var(--fs-small); }

/* Estructura: barra superior + inferior en el celular, lateral en escritorio */
.brand { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.brand img { border-radius: var(--r-control); flex: 0 0 auto; }
.brand span { display: grid; line-height: 1.2; min-width: 0; }
.brand strong { font-size: var(--fs-body); }
.brand small { color: var(--muted); font-size: var(--fs-small); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { flex: 0 0 auto; width: 36px; height: 36px; border-radius: var(--r-pill); background: var(--ink); color: #fff; display: inline-grid; place-items: center; font-weight: 600; font-size: var(--fs-small); }

.side { display: none; }
.topbar { position: sticky; top: 0; z-index: 20; height: 60px; padding: 0 var(--s-4); background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; padding: 6px var(--s-2) calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.tabbar button { flex-direction: column; gap: 2px; min-height: 52px; padding: 0 4px; border: 0; background: none; color: var(--muted); font-size: var(--fs-small); }
.tabbar button:hover { background: var(--line-soft); }
.tabbar button.on { color: var(--accent); }
.tabbar .icon { width: 22px; height: 22px; }
.sheet-back { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-end; overscroll-behavior: contain; }
.sheet { width: 100%; background: var(--surface); border-radius: var(--r-card) var(--r-card) 0 0; padding: var(--s-4) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom)); display: grid; gap: 4px; }
.sheet > a, .sheet > button { justify-content: flex-start; min-height: 52px; padding: 0 var(--s-3); border: 0; border-radius: var(--r-control); background: none; color: var(--ink); font-size: var(--fs-body); font-weight: 500; text-decoration: none; display: flex; align-items: center; }
.sheet > a:hover, .sheet > button:hover { background: var(--line-soft); color: var(--ink); }
.sheet .exit { color: var(--accent); }
.sheet-who { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3) var(--s-4); border-bottom: 1px solid var(--line-soft); margin-bottom: var(--s-2); }
.sheet-who > span:last-child { display: grid; line-height: 1.3; }
.sheet-who small { color: var(--muted); font-size: var(--fs-small); }

.app { max-width: var(--content-max); margin: 0 auto; padding: var(--s-6) var(--s-4) 104px; display: grid; gap: var(--s-4); min-width: 0; }
.app:focus { outline: none; }
.view { display: grid; gap: var(--s-4); min-width: 0; }

.nav-group { margin: 0; padding: var(--s-4) var(--s-3) var(--s-1); font-size: var(--fs-small); font-weight: 600; color: var(--muted); }
.nav-link { width: 100%; justify-content: flex-start; gap: var(--s-3); min-height: 40px; padding: 0 var(--s-3); border: 0; background: none; color: var(--text-2); font-weight: 500; text-decoration: none; }
.nav-link:hover { background: var(--line-soft); color: var(--ink); }
.nav-link.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-user { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3); border-top: 1px solid var(--line-soft); }
.side-user-text { display: grid; min-width: 0; line-height: 1.3; }
.side-user-text strong, .side-user-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-text small { color: var(--muted); font-size: var(--fs-small); }
.side-user-links { display: flex; gap: var(--s-3); margin-top: 2px; }
.side-user-links a, .side-user-links .link-button { color: var(--muted); font-size: var(--fs-small); font-weight: 500; text-decoration: underline; }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s-4); min-width: 0; }
.card > h2 { margin-bottom: var(--s-4); }
.card h3 { margin: var(--s-6) 0 var(--s-3); }

/* Cotizador */
.layout { display: grid; gap: var(--s-4); align-items: start; min-width: 0; }
.picker { display: grid; gap: var(--s-4); }
.picker > h2 { margin-bottom: 0; }
.divider { display: flex; align-items: center; gap: var(--s-2); color: var(--muted); font-size: var(--fs-small); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--r-control); max-height: 420px; overflow: auto; overscroll-behavior: contain; }
.list li + li { border-top: 1px solid var(--line-soft); }
.list button { display: block; width: 100%; min-height: var(--control-h); padding: var(--s-2) var(--s-3); border: 0; background: var(--surface); color: var(--ink); text-align: left; font-size: var(--fs-control); font-weight: 500; cursor: pointer; }
.list button:hover { background: var(--line-soft); }
.list button:disabled { color: var(--muted); cursor: default; background: var(--surface); }
.list button.on { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.list small { display: block; color: var(--muted); font-size: var(--fs-small); font-weight: 400; margin-top: 2px; }

.quote-empty { color: var(--muted); text-align: center; padding: var(--s-12) var(--s-4); }
.quote-head { display: grid; gap: var(--s-4); }
.quote-head img { width: 100%; aspect-ratio: 4 / 3; border-radius: var(--r-control); object-fit: cover; background: var(--photo); }
.quote-head .ttl { min-width: 0; display: grid; gap: var(--s-1); }
.brand-line, .codia { color: var(--muted); font-size: var(--fs-small); font-weight: 500; }

.figures { display: grid; gap: var(--s-3); margin-top: var(--s-6); }
.figure { border: 1px solid var(--line); border-radius: var(--r-control); padding: var(--s-3) var(--s-4); display: grid; gap: 2px; }
.figure .lbl { color: var(--muted); font-size: var(--fs-small); font-weight: 500; }
.figure .val { font-size: var(--fs-section); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.figure .sub { color: var(--muted); font-size: var(--fs-small); }
.figure.main { grid-column: 1 / -1; background: var(--bg); border-color: var(--line); }
.figure.main .val { font-size: var(--fs-title); }

.adjust { display: grid; gap: var(--s-3); }
.adjust + .hint { margin-top: var(--s-2); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: var(--fs-control); }
th { color: var(--muted); font-size: var(--fs-small); font-weight: 600; text-align: left; }
th, td { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line-soft); text-align: left; }
th.num, td.num { text-align: right; }
table.prices tbody tr { cursor: pointer; }
table.prices tbody tr:hover { background: var(--line-soft); }
table.prices tbody tr.on { background: var(--accent-soft); font-weight: 600; }
table.prices tbody tr:focus-visible { box-shadow: inset var(--focus); }
table.prices + .hint { margin-top: var(--s-2); }

.actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-6); }
.actions .btn { flex: 1 1 auto; }
#quote-error { margin-top: var(--s-3); }

.features { columns: 2 260px; column-gap: var(--s-6); }
.features section { break-inside: avoid; margin-bottom: var(--s-4); }
.features h4 { font-size: var(--fs-control); font-weight: 600; margin-bottom: var(--s-1); }
.features dl { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s-3); font-size: var(--fs-small); }
.features dt { color: var(--muted); }
.features dd { text-align: right; }
.source { margin-top: var(--s-6); }

/* Consumo */
.scroll-x { overflow-x: auto; }
.usage-table td:first-child { font-weight: 600; }
.empty { padding: var(--s-6) 0 var(--s-2); text-align: center; }
#upstream-stats { margin-bottom: var(--s-3); }

/* Ingreso (igual a la red de usados) */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--s-4); background: var(--bg); }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s-8) var(--s-6); display: grid; gap: var(--s-4); }
.login-card > img { width: 56px; height: 56px; border-radius: var(--r-control); }
.login-card > p { color: var(--muted); }
.login-card form { display: grid; gap: var(--s-4); }
.login-card .btn.primary { width: 100%; }
.login-card small { color: var(--muted); font-size: var(--fs-small); }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 56px; }
.password-field button { position: absolute; right: 4px; top: 4px; width: 40px; height: 40px; min-height: 0; padding: 0; border: 0; background: none; color: var(--muted); }
.password-field button:hover { background: var(--line-soft); color: var(--ink); }

@media (min-width: 720px) {
  .app { padding: var(--s-8) var(--s-8) 104px; }
  .card { padding: var(--s-6); }
  .quote-head { grid-template-columns: 200px minmax(0, 1fr); align-items: start; }
  .figures { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .adjust { grid-template-columns: 140px 1fr 1fr; }
  .actions .btn { flex: 0 0 auto; }
}

@media (min-width: 1024px) {
  .side { display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 20; background: var(--surface); border-right: 1px solid var(--line); padding: 0 var(--s-3) var(--s-3); overflow-y: auto; }
  .side .brand { height: 72px; padding: 0 var(--s-3); }
  .side-nav { display: grid; gap: 2px; flex: 1 1 auto; align-content: start; }
  .topbar, .tabbar, .sheet-back { display: none; }
  .app { margin-left: 248px; max-width: none; padding: var(--s-8) 40px var(--s-12); }
  .layout { grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); }
  .figure.main .val { font-size: var(--fs-display); }
}

/* En pantallas muy anchas el contenido no se estira de más. */
@media (min-width: 1800px) {
  .app > * { max-width: 1440px; }
}

@media (max-width: 719px) {
  .hide-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .side, .topbar, .tabbar, .sheet-back, .skip-link, .no-print, .picker, .page-title, #demo-banner { display: none !important; }
  body { background: #fff; }
  .app { margin: 0; padding: 0; max-width: none; }
  .layout { display: block; }
  .card { border: 0; padding: 0; }
  .quote-head { grid-template-columns: 160px minmax(0, 1fr); }
  .figure.main { background: #fff; }
  table.prices tbody tr { cursor: auto; }
}
