@import url('https://fonts.googleapis.com/css2?family=Saira+Condensed:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  /* base */
  --paper: #F6F7F5;
  --paper-soft: #FBFBF9;
  --ink: #16201C;
  --pine: #D8202A;
  --pine-soft: #FBE9EA;
  --line: #DCE0DC;
  --line-strong: #C5C9C5;
  --muted: #6B736E;
  --white: #fff;

  /* estados anclados al sistema */
  --success: #1E5C3F;
  --success-soft: #E3F0E9;
  --warn: #B26B0C;
  --warn-soft: #FAEDD7;
  --info: #1F5C6E;
  --info-soft: #DDEDF1;
  --danger: #D8202A;
  --danger-soft: #FBE9EA;

  /* type roles */
  --t-code: 'JetBrains Mono', ui-monospace, monospace;
  --t-display: 'Saira Condensed', sans-serif;
  --t-body: Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--t-body);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 80px;
}
input, select, button, textarea { font-family: inherit; }

/* ============ HEADER ============ */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  background: var(--white); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.logo-n { height: 24px; width: auto; display: block; }
.logo-roots { height: 16px; width: auto; display: block; margin-left: 6px; padding-left: 8px; border-left: 1px solid var(--line); }
.word { font-family: var(--t-display); font-weight: 700; letter-spacing: .06em; font-size: 22px; }
.word2 { font-family: var(--t-display); font-weight: 500; letter-spacing: .18em; font-size: 12px; color: var(--muted); text-transform: uppercase; }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.tc { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.tc input {
  width: 84px; padding: 6px 9px;
  border: 1px solid var(--line); border-radius: 8px;
  font-family: var(--t-code); font-size: 13px; color: var(--ink); background: var(--white);
}
.tc input:disabled { background: var(--paper); color: var(--muted); }

.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px;
}
.user-chip button {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); padding: 5px 11px;
  border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 12px;
}
.user-chip button:hover { border-color: var(--pine); color: var(--pine); }

/* (roles deprecado — vivía cuando no había login. Se mantiene la clase
   por si app.js todavía la renderiza, sin destacarla.) */
.roles { display: none; }

/* ============ TABS top (≥900px) y BOTTOM NAV (<900px) ============ */
.tabs {
  display: flex; align-items: center; gap: 6px;
  padding: 0 16px; background: var(--white);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.tabs button {
  border: 0; background: transparent;
  padding: 13px 4px; margin-right: 18px;
  font-size: 14px; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs button.on { color: var(--ink); border-bottom-color: var(--pine); }
.rolehint { margin-left: auto; font-size: 12px; color: var(--warn); font-weight: 500; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--white); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom)) 0;
  z-index: 30;
}
.bottom-nav button {
  flex: 1; min-height: 54px;
  background: transparent; border: 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--muted); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .04em;
  cursor: pointer;
}
.bottom-nav button.on { color: var(--ink); }
.bottom-nav button.on::after { content: ''; width: 28px; height: 2px; background: var(--pine); margin-top: -2px; }
.bottom-nav .ic { font-family: var(--t-display); font-weight: 700; font-size: 17px; line-height: 1; }

@media (min-width: 900px) {
  .bottom-nav { display: none; }
  body { padding-bottom: 16px; }
}
@media (max-width: 899px) {
  .tabs { display: none; }
}

main { max-width: 1120px; margin: 0 auto; padding: 18px 16px 24px; }

/* ============ KPIs (scroll-snap en mobile, grid en desktop) ============ */
.kpis {
  display: flex; gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 18px;
  padding-bottom: 4px;
}
.kpis::-webkit-scrollbar { display: none; }
.kpi {
  flex: 0 0 auto; min-width: 96px;
  background: var(--white); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
  scroll-snap-align: start;
}
.kpi-n { font-family: var(--t-display); font-weight: 700; font-size: 30px; line-height: 1; }
.kpi-l { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 500; }

@media (min-width: 720px) {
  .kpis {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
    overflow: visible;
  }
  .kpi { min-width: 0; }
}

/* ============ Toolbar (filtros) ============ */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search {
  flex: 1; min-width: 200px;
  padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; background: var(--white); color: var(--ink);
}
.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  background: var(--white); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px;
}
.segmented.sm { margin-bottom: 16px; }
.segmented button {
  border: 0; background: transparent;
  padding: 8px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--muted);
  cursor: pointer; white-space: nowrap;
}
.segmented button.on { background: var(--pine-soft); color: var(--pine); }

/* ============ Categoría ============ */
.cat { margin-bottom: 26px; }
.cat-h {
  display: flex; align-items: baseline; gap: 12px;
  font-family: var(--t-display); font-weight: 600; font-size: 14px;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.cat-h span {
  font-family: var(--t-code); font-size: 12px; font-weight: 500;
  color: var(--ink); background: transparent;
  letter-spacing: 0; padding: 0;
}

/* ============ CARDS de producto (jerarquía invertida) ============ */
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .grid { grid-template-columns: 1fr 1fr 1fr; } }

.card {
  background: var(--white); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  border-left-width: 1px; /* override del border-left-color inline */
}
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.code {
  font-family: var(--t-code); font-weight: 500; font-size: 16px;
  color: var(--ink); letter-spacing: -0.01em;
}
.card-model {
  margin: 0;
  font-family: var(--t-display); font-weight: 600; font-size: 18px;
  line-height: 1.18; color: var(--ink);
}
.usada { color: var(--muted); font-weight: 500; font-style: italic; }
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-family: var(--t-code); font-size: 11px;
  background: var(--paper); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 8px;
}
.chip.ing { background: var(--info-soft); color: var(--info); border-color: transparent; }

/* Badge de estado universal (chip con dot) */
.badge {
  font-family: var(--t-body); font-size: 11px; font-weight: 500;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.prices {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 8px 0;
  border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line);
  align-items: flex-end;
}
.prices > div { display: flex; flex-direction: column; gap: 2px; }
.prices b {
  font-family: var(--t-display); font-weight: 700; font-size: 22px;
  line-height: 1; color: var(--ink); display: block;
}
.prices i {
  font-style: normal; font-size: 12px; color: var(--muted);
  font-family: var(--t-code); margin-top: 4px;
}
.plabel {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); margin-bottom: 2px; font-weight: 500;
}
.dealer b { color: var(--muted); }

.stockrow {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.stock { font-size: 13px; color: var(--muted); }
.stock b { font-family: var(--t-display); font-weight: 700; color: var(--ink); font-size: 18px; }
.reservadas-chip {
  color: var(--warn); font-style: normal;
  font-family: var(--t-code); font-size: 12px; margin-left: 6px;
}

/* Row de acciones de la card */
.row-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.primary-mini {
  background: var(--pine); color: #fff; border: 0;
  padding: 0 14px; min-height: 38px; border-radius: 8px;
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.ghost-mini {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); padding: 0 14px; min-height: 38px;
  border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.steppers { display: none; } /* deprecado por + Unidades */

/* ============ Headrow + botones generales ============ */
.headrow {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.headrow h2 { font-family: var(--t-display); font-size: 24px; font-weight: 700; margin: 0; }
.count {
  font-family: var(--t-code); font-size: 12px;
  background: transparent; color: var(--muted);
  padding: 0; margin-left: 8px; letter-spacing: 0;
}
.primary {
  background: var(--pine); color: #fff; border: 0;
  padding: 11px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  min-height: 44px;
}
.primary:disabled { opacity: .45; cursor: not-allowed; }
.empty {
  color: var(--muted); background: var(--white);
  border: 1px dashed var(--line); border-radius: 12px;
  padding: 28px; text-align: center;
}

/* ============ Panel + form ============ */
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 20px; }
.form { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 14px; }
@media (min-width: 720px) { .form { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); } }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.form input, .form select {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 16px; background: var(--white); color: var(--ink);
}
.note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }

/* ============ Ventas (rows) ============ */
.list { display: flex; flex-direction: column; gap: 11px; }
.row {
  background: var(--white); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.row-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-title b { font-size: 15px; }
.estado { font-size: 12px; font-weight: 600; text-transform: capitalize; }
.row-sub { font-size: 13px; color: var(--muted); margin: 3px 0 7px; }
.row-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.row-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-total { font-family: var(--t-display); font-size: 20px; font-weight: 700; }
.row-saldo { font-size: 12px; color: var(--danger); font-weight: 600; }
.row-ok { font-size: 12px; color: var(--success); font-weight: 600; }
.row-acts select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
  background: var(--white); color: var(--ink); min-height: 38px;
}
.del {
  border: 1px solid var(--line); background: var(--white); color: var(--danger);
  border-radius: 8px; padding: 6px 12px; font-size: 12px; cursor: pointer; min-height: 38px;
}

/* ============ Cobranzas ============ */
.totalcob { text-align: right; }
.totalcob span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.totalcob b { font-family: var(--t-display); font-size: 24px; font-weight: 700; }
.totalcob i { font-style: normal; font-size: 12px; color: var(--muted); font-family: var(--t-code); margin-left: 8px; }

.cuenta { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.cuenta-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.cuenta-head b { font-size: 15px; }
.cuenta-rule {
  font-size: 11px; color: var(--pine); background: var(--pine-soft);
  padding: 3px 10px; border-radius: 999px; height: fit-content; font-weight: 500;
}
.bar { height: 7px; background: var(--paper); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--pine); border-radius: 999px; transition: width .3s; }
.bar-legend { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); margin: 7px 0 12px; flex-wrap: wrap; }
.cuenta-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; border-top: 1px solid var(--line); padding-top: 12px; flex-wrap: wrap; }
.saldo span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.saldo b { font-family: var(--t-display); font-size: 24px; font-weight: 700; }
.saldo i { font-style: normal; font-size: 12px; color: var(--muted); font-family: var(--t-code); margin-left: 8px; }
.pay { display: flex; gap: 7px; }
.pay input { width: 130px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 16px; background: var(--white); color: var(--ink); }
.foot-acts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.wa {
  display: inline-flex; align-items: center; gap: 6px;
  background: #25D366; color: #08361c; text-decoration: none;
  font-weight: 600; font-size: 13px; padding: 9px 14px; border-radius: 9px; min-height: 38px;
}
.wa:hover { filter: brightness(.95); }
.venc { font-weight: 600; }

/* ============ LOGIN (light unificado) ============ */
#login[hidden] { display: none; }
#login {
  min-height: 100vh; display: grid; place-items: center;
  background: var(--paper);
  padding: 24px;
}
.login-card {
  background: var(--white); padding: 32px; border-radius: 16px;
  display: grid; gap: 14px; width: 100%; max-width: 340px;
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(22,32,28,.06);
}
.login-card h1 {
  margin: 0; font-family: var(--t-display); font-weight: 700;
  font-size: 22px; color: var(--ink); text-align: center; letter-spacing: .04em;
}
.login-logo { width: 64px; margin: 0 auto 8px; display: block; }
.login-card label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.login-card input {
  background: var(--paper-soft); border: 1px solid var(--line); color: var(--ink);
  padding: 12px 14px; border-radius: 9px; font-size: 16px;
}
.login-card input:focus { outline: 2px solid var(--pine); outline-offset: -2px; border-color: var(--pine); }
.login-card button {
  background: var(--pine); color: #fff; border: 0;
  padding: 13px; border-radius: 9px; font-weight: 600; font-size: 14px;
  cursor: pointer; min-height: 48px;
}
.login-card button:hover { filter: brightness(.94); }
.login-error { color: var(--danger); font-size: 13px; margin: 0; text-align: center; }

/* ============ Modales (LIGHT unificado, fullscreen mobile) ============ */
.modal {
  background: var(--white); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 24px; max-width: 560px; width: 100%;
  box-shadow: 0 12px 32px rgba(22,32,28,.08);
}
.modal::backdrop { background: rgba(22,32,28,.4); }
.modal h3 {
  margin: 0 0 6px;
  font-family: var(--t-display); font-weight: 700; font-size: 18px;
  color: var(--ink);
}
.modal .muted { color: var(--muted); font-size: 13px; margin: 4px 0 14px; }
.modal textarea, .modal input[type="text"] {
  width: 100%;
  background: var(--paper-soft); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px;
  font: 14px/1.5 var(--t-code);
}
.modal textarea { min-height: 140px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-actions button {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); padding: 10px 16px;
  border-radius: 9px; cursor: pointer; font-size: 14px; font-weight: 500;
  min-height: 42px;
}
.modal-actions .primary { background: var(--pine); color: #fff; border: 0; }

@media (max-width: 720px) {
  .modal {
    max-width: 100%; width: 100%;
    border-radius: 16px 16px 0 0;
    margin: auto 0 0 0;
    border-bottom: 0;
  }
}

/* ============ Tabla de unidades dentro de modal ============ */
.units-table {
  width: 100%; border-collapse: collapse;
  margin-top: 8px; font-size: 13px;
}
.units-table th, .units-table td {
  padding: 8px 8px; border-bottom: 1px solid var(--line);
  text-align: left;
}
.units-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.units-table code {
  background: var(--paper); padding: 2px 6px; border-radius: 4px;
  font-family: var(--t-code); color: var(--ink);
}

/* Badges de estado de unidad — ancladas al sistema */
.badge-en_stock  { background: var(--success-soft); color: var(--success); padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-reservada { background: var(--warn-soft);    color: var(--warn);    padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-vendida   { background: var(--info-soft);    color: var(--info);    padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-baja      { background: var(--danger-soft);  color: var(--danger);  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }

/* TC dual en header */
.tcs { display: flex; gap: 12px; align-items: center; }
.tc-blue {
  font-family: var(--t-code); font-size: 12px; color: var(--muted);
  background: var(--paper-soft); padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line);
}
.tc-badge {
  font-family: var(--t-code); font-size: 11px; color: var(--muted); margin-left: 6px;
}
