:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1b1b1f;
  --muted: #6b6f76;
  --line: #e2e4e8;
  --accent: #0f6cbd;
  --good: #0e8a4f;
  --warn: #b35c00;
  --bad: #c42b1c;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --card: #222428;
    --text: #ececef;
    --muted: #9a9ea6;
    --line: #34373d;
    --accent: #4aa3f0;
    --good: #3cc47c;
    --warn: #f0a04a;
    --bad: #ff6b5e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  overflow-x: hidden;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px calc(10px) 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.top nav { display: flex; flex-wrap: wrap; gap: 4px; }
.tab { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.tab.active { background: var(--bg); color: var(--text); font-weight: 600; }

@media (max-width: 400px) {
  .top { padding-left: 10px; padding-right: 10px; gap: 6px; }
  .brand { font-size: 16px; }
  .tab { padding: 5px 7px; font-size: 14px; }
  .card { grid-template-columns: 92px 1fr; }
  .thumb { width: 92px; height: 84px; }
}

main { max-width: 860px; margin: 0 auto; padding: 12px 12px 40px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.panel h2 { font-size: 16px; margin: 0 0 8px; }
summary { cursor: pointer; font-weight: 600; }
fieldset { border: 0; padding: 0; margin: 10px 0; }
legend { font-weight: 600; margin-bottom: 6px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.row, .checks label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.wide { margin: 8px 0; }

input, select, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

input[type="checkbox"] { width: 18px; height: 18px; padding: 0; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
button, .button { cursor: pointer; background: var(--card); }
.button { display: inline-block; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; text-decoration: none; color: var(--text); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: .55; cursor: default; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 8px 0; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 8px 0; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; }
.chip input { display: none; }
.chip span { padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; color: var(--text); }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }

.locations { display: flex; flex-wrap: wrap; gap: 6px; }
.loc { display: contents; }
.quarters {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 6px 14px;
  padding: 8px;
  border-left: 3px solid var(--accent);
  background: var(--bg);
  border-radius: 0 8px 8px 0;
}
.quarters[hidden] { display: none; }
.quarters .chip.all span { font-weight: 600; }
.chip .count { opacity: .7; font-size: 11px; }
.match-info { font-weight: 600; margin: 10px 0 0; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); }

.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  color: inherit;
  text-decoration: none;
  position: relative;
}

.card.inactive { opacity: .6; }
.thumb { width: 112px; height: 96px; border-radius: 8px; object-fit: cover; background: var(--bg); }
.card-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-price { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-top: 2px; }
.price { font-weight: 700; }
.deal { font-size: 13px; font-weight: 600; }
.deal.good { color: var(--good); }
.deal.bad { color: var(--bad); }

.score {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  background: var(--muted);
  border: 2px solid var(--card);
}

.score.s-high { background: var(--good); }
.score.s-mid { background: var(--accent); }
.score.s-low { background: var(--warn); }

.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.badge.new { background: var(--accent); color: #fff; }
.badge.drop { background: var(--good); color: #fff; }
.badge.fav { background: #d4a106; color: #fff; }

.more { width: 100%; margin-top: 12px; }

.detail-hero { width: 100%; max-height: 300px; object-fit: cover; border-radius: var(--radius); background: var(--card); }
.detail h1 { font-size: 20px; margin: 10px 0 4px; }
.detail .big { font-size: 24px; font-weight: 700; }
.detail ul { margin: 6px 0; padding-left: 20px; }
.detail .good li { color: var(--good); }
.detail .bad li { color: var(--bad); }
.detail .warn li { color: var(--warn); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.back { margin-bottom: 8px; }
.description { white-space: pre-wrap; font-size: 14px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.table td, .table th { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 10px;
  max-width: 92vw;
  z-index: 20;
}

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login-box h1 { margin: 0; font-size: 22px; }
