:root {
  --bg: #f6f5fb;
  --card: #ffffff;
  --text: #1c1830;
  --muted: #6b6880;
  --line: #e6e3f0;
  --accent: #7c3aed;
  --accent-soft: #efe7ff;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(20, 10, 50, .06), 0 4px 14px rgba(20, 10, 50, .06);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12101c;
    --card: #1d1a2b;
    --text: #f1eefb;
    --muted: #a39fb8;
    --line: #2f2b42;
    --accent: #a78bfa;
    --accent-soft: #2e2550;
    --accent-text: #160f2e;
    --ok: #4ade80;
    --ok-soft: #133222;
    --warn: #fbbf24;
    --warn-soft: #3a2c0b;
    --danger: #f87171;
    --danger-soft: #3b1515;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #12101c;
    --card: #1d1a2b;
    --text: #f1eefb;
    --muted: #a39fb8;
    --line: #2f2b42;
    --accent: #a78bfa;
    --accent-soft: #2e2550;
    --accent-text: #160f2e;
    --ok: #4ade80;
    --ok-soft: #133222;
    --warn: #fbbf24;
    --warn-soft: #3a2c0b;
    --danger: #f87171;
    --danger-soft: #3b1515;
    --shadow: none;
  color-scheme: dark;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { border: 0; background: none; font-size: 26px; line-height: 1; padding: 4px 8px 4px 2px; cursor: pointer; color: var(--accent); }

main { max-width: 640px; margin: 0 auto; padding: 14px 14px calc(110px + var(--safe-b)); }
body.no-tabs main { padding-bottom: calc(40px + var(--safe-b)); }

/* Barra inferior */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-b));
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); text-decoration: none; padding: 4px 0; border-radius: 10px;
}
.tabbar a span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.active span { filter: none; opacity: 1; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.topbar .btn { min-height: 38px; padding: 6px 14px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 140px; }
.icon-btn { border: 0; background: none; font-size: 20px; padding: 6px; cursor: pointer; border-radius: 10px; color: var(--muted); }

.fab {
  position: fixed; z-index: 25; right: max(18px, calc(50vw - 302px)); bottom: calc(82px + var(--safe-b));
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-text); font-size: 34px; line-height: 1;
  box-shadow: 0 6px 20px rgba(124, 58, 237, .45); cursor: pointer;
}
body.no-tabs .fab { bottom: calc(24px + var(--safe-b)); }

/* Tarjetas */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); }
a.card { display: block; color: inherit; text-decoration: none; }
a.card.row { display: flex; }
.card.done { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok-soft) 45%, var(--card)); }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.title { font-weight: 700; font-size: 17px; }
.num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; flex: none; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 4px 8px; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .big { font-size: 46px; margin-bottom: 6px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 13px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag.x { background: var(--danger-soft); color: var(--danger); }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.pill.pendiente { background: var(--warn-soft); color: var(--warn); }
.pill.en_compra { background: var(--accent-soft); color: var(--accent); }
.pill.completado { background: var(--ok-soft); color: var(--ok); }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s; }
.progress.full > div { background: var(--ok); }

/* Selectores tipo chip */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; font-size: 15px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.x.on { background: var(--danger); border-color: var(--danger); color: #fff; }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 2px; white-space: nowrap; border-radius: 9px; font-weight: 600; font-size: 13.5px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* Formularios */
label.field { display: block; margin-bottom: 14px; }
label.field > span, .field-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--card); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 0; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.error { color: var(--danger); font-size: 14px; margin: 8px 0; }

/* Contador comprado */
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-size: 22px; cursor: pointer; }
.stepper b { min-width: 52px; text-align: center; font-size: 17px; }
.buy-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }

/* Hoja inferior */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(10, 5, 25, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 16px calc(18px + var(--safe-b));
  animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { margin: 0 0 14px; font-size: 20px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.wa-preview { white-space: pre-wrap; font: 14px/1.45 ui-monospace, Menlo, monospace; background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 12px; margin: 0; max-height: 260px; overflow: auto; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 8px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 15px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; text-align: center;
}

/* Login */
.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { text-align: center; margin-bottom: 24px; }
.login .logo img { width: 72px; height: 72px; }
.login .logo h1 { margin: 10px 0 2px; font-size: 24px; }

.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list { padding: 0; overflow: hidden; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:disabled + span { opacity: .5; cursor: default; }
.summary-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-weight: 700; margin-bottom: 12px; }

/* Buscador de modelos */
.model-list { max-height: 210px; overflow-y: auto; margin: 8px 0 16px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); }
.model-opt { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 8px; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; font-weight: 600; }
.model-opt:last-child { border-bottom: 0; }
.model-opt.on { background: var(--accent-soft); color: var(--accent); }
.model-opt.other { color: var(--accent); font-weight: 500; }
