:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #15181d;
  --muted: #5d6573;
  --border: #dde1e7;
  --accent: #3b6fd8;
  --accent-text: #ffffff;
  --accent-soft: #e6eefc;
  --new: #1f8a4c;
  --new-soft: #e2f4e9;
  --cheaper: #a8670b;
  --cheaper-soft: #fbefd9;
  --danger: #c23b3b;
  --danger-soft: #fbe6e6;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #20262e;
    --text: #e8ebf0;
    --muted: #98a1b0;
    --border: #2b323c;
    --accent: #6b95f0;
    --accent-text: #0d1320;
    --accent-soft: #1c2944;
    --new: #4cc17f;
    --new-soft: #15301f;
    --cheaper: #f0b155;
    --cheaper-soft: #3a2a10;
    --danger: #f07171;
    --danger-soft: #3a1717;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 0.75rem; }
a { color: var(--accent); }
.muted { color: var(--muted); margin: 0.2rem 0 0; }
[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); padding: 0.5rem 0.95rem; font-weight: 550; }
button:disabled { opacity: 0.6; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button.link { border: 0; background: none; padding: 0.25rem 0; color: var(--muted); font-weight: 500; }
button.link:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="text"], input[type="number"], input[type="password"], input[type="search"], select {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 0.5rem 0.65rem; min-width: 0; width: 100%;
}

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.top-inner { max-width: 1180px; margin: 0 auto; padding: 0.6rem 16px; display: flex; align-items: center; gap: 1.25rem; }
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.tabs { display: flex; gap: 0.25rem; flex: 1; }
.tabs a { padding: 0.4rem 0.75rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550; }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.signout { margin: 0; }

.page { max-width: 1180px; margin: 0 auto; padding: 1rem 16px 6rem; }

/* Status */
.statusbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; box-shadow: var(--shadow); }
.status-text { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.9rem; color: var(--muted); font-size: 0.92rem; }
.status-text strong { color: var(--text); font-weight: 600; }
.pill { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--surface-2); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.ok::before { background: var(--new); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.bad::before { background: var(--danger); }
#scan-now { white-space: nowrap; }

.problem { margin-top: 0.75rem; padding: 0.75rem 1rem; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); white-space: pre-wrap; font-size: 0.92rem; }
.problem strong { display: block; margin-bottom: 0.15rem; }

/* Offers */
.view { margin-top: 1.5rem; }
.view-head { display: flex; justify-content: space-between; align-items: end; gap: 1rem; flex-wrap: wrap; }
.notes { color: var(--muted); font-size: 0.9rem; margin: 0.75rem 0 1rem; }
.notes span + span::before { content: " · "; }
.notes .warn { color: var(--cheaper); }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented button { white-space: nowrap; border: 0; background: transparent; padding: 0.35rem 0.8rem; border-radius: 8px; color: var(--muted); font-weight: 550; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button span { color: var(--muted); font-weight: 500; margin-left: 0.15rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: inherit; text-decoration: none; box-shadow: var(--shadow); transition: transform 0.12s ease, border-color 0.12s ease; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.photo { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rank { position: absolute; top: 0.5rem; left: 0.5rem; background: rgb(15 18 22 / 72%); color: #fff; font-weight: 700; font-size: 0.8rem; padding: 0.15rem 0.5rem; border-radius: 999px; }
.badges { position: absolute; top: 0.5rem; right: 0.5rem; display: flex; gap: 0.3rem; }
.badge { font-size: 0.75rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; }
.badge.new { background: var(--new-soft); color: var(--new); }
.badge.cheaper { background: var(--cheaper-soft); color: var(--cheaper); }
.card-body { padding: 0.8rem 0.9rem 0.9rem; display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }
.price { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.price strong { font-size: 1.35rem; letter-spacing: -0.01em; }
.price s { color: var(--muted); font-size: 0.9rem; }
.title { font-weight: 600; line-height: 1.3; }
.specs { color: var(--muted); font-size: 0.86rem; }
.foot { margin-top: auto; padding-top: 0.4rem; display: flex; justify-content: space-between; gap: 0.5rem; color: var(--muted); font-size: 0.8rem; }

.empty { grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* Search form */
#search-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1rem; margin-top: 1rem; }
fieldset { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }
fieldset.wide { grid-column: 1 / -1; }
legend { float: left; width: 100%; padding: 0; margin-bottom: 0.25rem; font-weight: 650; }
legend + * { clear: both; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.75rem; }
.field { display: grid; gap: 0.3rem; margin-top: 0.75rem; }
.field > span { font-size: 0.88rem; font-weight: 550; }
.row { display: flex; gap: 0.5rem; align-items: center; }
.row > * { flex: 1; }
.row > .sep { flex: 0; color: var(--muted); }
.readonly { padding: 0.5rem 0.65rem; background: var(--surface-2); border-radius: 8px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0.7rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.88rem; cursor: pointer; user-select: none; background: var(--surface); }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgb(0 0 0 / 20%); }

.models { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.model { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.25rem 0.3rem 0.25rem 0.7rem; background: var(--accent-soft); color: var(--accent); border-radius: 999px; font-weight: 600; font-size: 0.88rem; }
.model button { border: 0; background: none; padding: 0 0.35rem; color: inherit; font-size: 1.05rem; line-height: 1; }
.suggest { position: relative; }
.suggestions { position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / 15%); max-height: 260px; overflow: auto; padding: 0.25rem; }
.suggestions button { display: flex; justify-content: space-between; width: 100%; border: 0; background: none; text-align: left; padding: 0.45rem 0.6rem; font-weight: 500; }
.suggestions button:hover, .suggestions button:focus-visible { background: var(--surface-2); }
.suggestions small { color: var(--muted); }

.links { margin: 0; padding-left: 1.1rem; font-size: 0.9rem; }
.links li { margin: 0.2rem 0; }

.form-error { grid-column: 1 / -1; }

/* Save bar */
.savebar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgb(0 0 0 / 8%); z-index: 20; }
.savebar-inner { max-width: 1180px; margin: 0 auto; padding: 0.7rem 16px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.savebar-actions { display: flex; gap: 0.5rem; }

.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 10px; font-size: 0.92rem; z-index: 30; max-width: calc(100vw - 32px); }

/* Sign in */
body.login { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2rem 1.5rem; box-shadow: var(--shadow); text-align: center; }
.login-card h1 { margin-top: 0.6rem; }
.login-card form { display: grid; gap: 0.5rem; margin-top: 1.5rem; text-align: left; }
.login-card label { font-weight: 550; font-size: 0.9rem; }
.login-card button { margin-top: 0.5rem; padding: 0.65rem; }
.error { color: var(--danger); margin: 0; font-size: 0.9rem; }

@media (max-width: 640px) {
  .top-inner { gap: 0.75rem; }
  .brand { font-size: 1rem; }
  .statusbar { flex-direction: column; align-items: stretch; }
  #scan-now { width: 100%; }
  .view-head { align-items: stretch; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  #search-form { grid-template-columns: 1fr; }
  .savebar-inner { flex-direction: column; align-items: stretch; }
  .savebar-actions > * { flex: 1; }
}
