:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1a2539;
  --ink: #e7edf6;
  --muted: #8ba0bb;
  --brand: #0f2744;
  --accent: #ff6a2b;
  --accent-soft: rgba(255, 106, 43, .16);
  --line: #24334b;
  --good: #22b573;
  --radius: 14px;
  --shadow: 0 6px 18px rgba(0, 0, 0, .35);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--brand);
  color: #fff;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.header-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 999px;
  padding: 2px 14px;
  min-width: 0;
}
.header-search svg { width: 18px; height: 18px; color: #cfe0f2; flex: none; }
.header-search input {
  flex: 1;
  min-width: 0;
  border: none; outline: none; background: transparent;
  font-size: .96rem; padding: 9px 0; color: #fff;
}
.header-search input::placeholder { color: #cfe0f2; }
.header-search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.icon-btn {
  position: relative;
  flex: none;
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn svg { width: 21px; height: 21px; }
.filter-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  border: 1.5px solid var(--brand);
}
.fab-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px;
  background: #e11d48; color: #fff;
  font-size: .74rem; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--brand);
}

/* ---------- Carrito flotante ---------- */
.cart-fab {
  position: fixed;
  right: 16px;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 40;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, #ff7a3d, #f55312);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(255, 106, 43, .45);
}
.cart-fab:active { transform: scale(.94); }
.cart-fab svg { width: 27px; height: 27px; }

/* ---------- Layout ---------- */
#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(76px + var(--safe-bottom));
}

.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
@keyframes pop { from { transform: scale(.92); opacity: .5; } }

.product-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: transform .15s ease;
}
.card:active { transform: scale(.97); }
.card .thumb { aspect-ratio: 4 / 3; width: 100%; display: grid; place-items: center; background: #0e1726; }
.card .thumb svg { width: 100%; height: 100%; display: block; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card .cat-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); font-weight: 700; }
.card h3 { margin: 0; font-size: .92rem; line-height: 1.3; min-height: 2.4em; }
.card .compat { font-size: .75rem; color: var(--muted); }
.card .price { font-weight: 800; font-size: 1.05rem; color: var(--accent); margin-top: 2px; }
.card .add-btn {
  margin-top: 8px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  padding: 8px;
  border-radius: 9px;
  cursor: pointer;
  font-size: .9rem;
}
.card .add-btn:active { background: var(--accent); color: #fff; }
.card .add-btn[data-added] { background: var(--good); border-color: var(--good); color: #fff; }

.detail { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
.detail .thumb { display: grid; place-items: center; background: #0e1726; }
.detail .thumb svg { width: 100%; display: block; }
.detail .body { padding: 18px; }
.detail h2 { margin: 0 0 6px; }
.detail .price { font-size: 1.5rem; font-weight: 800; color: var(--accent); margin: 8px 0; }
.detail .meta { color: var(--muted); font-size: .9rem; margin: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: .78rem; color: var(--muted); }

/* ---------- Result count ---------- */

/* ---------- Cart ---------- */
.cart-item {
  display: flex;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  animation: pop .2s ease;
}
.cart-item .thumb { width: 64px; height: 64px; flex: none; border-radius: 10px; overflow: hidden; display: grid; place-items: center; background: #0e1726; }
.cart-item .thumb svg { width: 64px; height: 64px; display: block; }
.cart-item .info { flex: 1; min-width: 0; }
.cart-item h4 { margin: 0 0 2px; font-size: .95rem; }
.cart-item .cprice { color: var(--muted); font-size: .8rem; margin-bottom: 6px; }
.qty { display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px; background: var(--surface-2); }
.qty button { width: 26px; height: 26px; border: none; border-radius: 50%; background: var(--surface); font-size: 1rem; font-weight: 700; cursor: pointer; color: var(--ink); }
.qty button:active { background: var(--accent); color: #fff; }
.qty .n { min-width: 18px; text-align: center; font-weight: 700; }
.remove-btn { align-self: flex-start; border: none; background: transparent; color: var(--muted); font-size: 1.3rem; cursor: pointer; padding: 2px 8px; }

.cart-summary {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.cart-totals { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.cart-totals span { color: var(--muted); }
.cart-totals strong { font-size: 1.4rem; color: var(--accent); }

/* ---------- Buttons ---------- */
.primary-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff7a3d, #f55312);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  padding: 14px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(255, 106, 43, .4);
}
.primary-btn:active { transform: scale(.98); }
.back-btn {
  border: none; background: transparent;
  color: var(--muted); font-size: .9rem;
  padding: 8px 0 12px; cursor: pointer; display: block;
}

.result-count { font-size: .85rem; color: var(--muted); margin: 4px 2px 12px; }

/* ---------- Forms ---------- */
form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
form label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 14px; }
form input[type=text], form input[type=tel], form input:not([type]) {
  width: 100%; margin-top: 6px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font-size: 1rem; background: var(--surface-2); color: var(--ink);
  outline: none;
}
form input:focus { border-color: var(--accent); background: var(--surface); }
form fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 16px; padding: 10px 14px; }
form legend { font-weight: 700; font-size: .9rem; padding: 0 6px; }
.radio { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: .95rem; margin: 10px 0; }
.radio input { width: auto; margin: 0; accent-color: var(--accent); }

/* ---------- Success / empty ---------- */
.success-box { text-align: center; padding-top: 26px; }
.success-box svg { width: 88px; height: 88px; }
.success-box h2 { margin: 14px 0 4px; }
.success-box p { color: var(--muted); margin: 6px 0 18px; line-height: 1.5; }
#order-number { font-weight: 700; color: var(--accent); font-size: 1.05rem; }

.empty-state {
  text-align: center;
  padding: 34px 16px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.empty-state strong { color: var(--ink); font-size: 1.05rem; }
.empty-state .primary-btn { max-width: 220px; margin-top: 10px; }

/* ---------- Orders ---------- */
.order-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.order-card .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.order-card .oid { font-weight: 800; color: var(--accent); }
.order-card .odate { font-size: .78rem; color: var(--muted); }
.order-card ul { margin: 0; padding: 0; list-style: none; font-size: .88rem; }
.order-card li { display: flex; justify-content: space-between; padding: 3px 0; color: var(--ink); }
.order-card .total { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; font-weight: 800; color: var(--accent); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  z-index: 30;
}
.nav-item {
  flex: 1;
  border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px;
  font-size: .72rem;
  color: var(--muted);
  cursor: pointer;
}
.nav-item svg { width: 23px; height: 23px; }
.nav-item.active { color: var(--accent); font-weight: 700; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(4, 8, 15, .6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .2s ease;
}
.modal-sheet {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--line);
  border-bottom: none;
  padding: 8px 10px calc(14px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .5);
  animation: sheetUp .25s ease;
}
@keyframes sheetUp { from { transform: translateY(60%); } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 12px;
}
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-close {
  border: none; background: transparent;
  color: var(--muted); font-size: 1.15rem;
  width: 34px; height: 34px; border-radius: 50%;
  cursor: pointer;
}
.modal-close:active { background: var(--surface-2); }
.modal-list { display: flex; flex-direction: column; max-height: 62vh; overflow-y: auto; }
.modal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  padding: 13px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.modal-item:last-child { border-bottom: none; }
.modal-item:active { background: var(--surface-2); }
.modal-item .check { color: var(--accent); font-weight: 800; }
.modal-item .cat-dot { width: 12px; height: 12px; border-radius: 3px; flex: none; }

/* ---------- Modal fullscreen (carrito) ---------- */
.modal-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  animation: fade .2s ease;
}
.fs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.fs-head h3 { margin: 0; font-size: 1.1rem; }
.fs-body { flex: 1; overflow-y: auto; padding: 14px; }
.fs-foot {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 14px calc(12px + var(--safe-bottom));
  box-shadow: 0 -6px 18px rgba(0, 0, 0, .3);
}
.fs-foot .cart-totals { margin-bottom: 10px; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .9rem;
  box-shadow: var(--shadow);
  z-index: 50;
  animation: pop .25s ease;
}

@media (min-width: 560px) {
  .bottom-nav { border-radius: 18px 18px 0 0; box-shadow: 0 -6px 18px rgba(0, 0, 0, .4); }
}