:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e0e4ea;
  --control: #8a93a2;
  --text: #14171c;
  --muted: #566070;
  --accent: #1a5bd0;
  --accent-hover: #154aab;
  --accent-soft: #e8effc;
  --accent-ink: #ffffff;
  --good: #0d6936;
  --good-bg: #e2f3e8;
  --good-line: #9fd3b4;
  --attn: #874600;
  --attn-bg: #fdf0dc;
  --attn-line: #efc58c;
  --bad: #b3261e;
  --bad-bg: #fdeceb;
  --gratis: #8b2c8f;
  --rossmann: #c4161c;
  --watsons: #00818a;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(20 23 28 / 5%);
  --tap: 40px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --line: #2c313b;
    --control: #697285;
    --text: #e8eaee;
    --muted: #a3abb8;
    --accent: #84aaff;
    --accent-hover: #a5c0ff;
    --accent-soft: #1c2944;
    --accent-ink: #0b1220;
    --good: #74d49f;
    --good-bg: #14301f;
    --good-line: #2c6a45;
    --attn: #f3b765;
    --attn-bg: #37281a;
    --attn-line: #7a5526;
    --bad: #ff9e96;
    --bad-bg: #3b1d1c;
    --gratis: #d68ad9;
    --rossmann: #ff7b7f;
    --watsons: #4fd0d8;
    --shadow: none;
    color-scheme: dark;
  }
}

@media (pointer: coarse) {
  :root { --tap: 44px; }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.125rem; line-height: 1.3; margin: 28px 0 12px; }
h3 { font-size: 1rem; line-height: 1.35; margin: 0; }
p { margin: 4px 0; }
h1:focus { outline: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 30;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.skip:focus { top: 8px; color: var(--accent-ink); }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Top bar; on phones its nav becomes a bottom tab bar within thumb reach. */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  gap: 24px;
  align-items: center;
  padding: 0 16px;
  min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.topbar nav { display: flex; gap: 4px; flex: 1; align-self: stretch; }
.topbar nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.topbar nav a:hover { color: var(--text); }
.topbar nav a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.whoami { display: flex; align-items: center; gap: 12px; font-size: 0.875rem; color: var(--muted); white-space: nowrap; }

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

@media (max-width: 719px) {
  .topbar { position: static; }
  .topbar-inner { min-height: 48px; }
  .whoami { display: none; }
  .topbar nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .topbar nav a {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 58px;
    font-size: 0.75rem;
    border-bottom: 0;
    border-top: 3px solid transparent;
    margin: 0;
  }
  .topbar nav a[aria-current="page"] { border-top-color: var(--accent); border-bottom: 0; }
  .topbar nav .icon { width: 24px; height: 24px; }
  main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
}

/* Building blocks */

.page-head { display: flex; gap: 12px 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.stack > * + * { margin-top: 12px; }
.stack-sm > * + * { margin-top: 4px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.row { display: flex; gap: 8px 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.narrow { width: 80px; }
.empty { color: var(--muted); text-align: center; padding: 28px 16px; }

.price { font-variant-numeric: tabular-nums; font-weight: 700; }
.big { font-size: 1.375rem; letter-spacing: -0.01em; }
.strike { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.per { color: var(--muted); font-size: 0.875rem; font-weight: 400; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.4;
  background: var(--surface-2);
  color: var(--muted);
  max-width: 100%;
}
.badge.deal, .badge.ok { background: var(--good-bg); color: var(--good); }
.badge.cheaper { background: transparent; color: var(--good); border-color: var(--good-line); }
.badge.warn { background: var(--attn-bg); color: var(--attn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.new { background: var(--accent-soft); color: var(--accent); }
.badge.deal::before, .badge.cheaper::before { content: "↓"; }
.badge.warn::before, .badge.bad::before { content: "!"; font-weight: 800; }

.retailer { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); white-space: nowrap; }
.retailer::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--muted); flex: none; }
.retailer.gratis::before { background: var(--gratis); }
.retailer.rossmann::before { background: var(--rossmann); }
.retailer.watsons::before { background: var(--watsons); }

button, .button {
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 6px 14px;
  border: 1px solid var(--control);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); color: var(--text); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.danger:hover { background: var(--bad-bg); }
button:disabled { opacity: 0.55; cursor: default; }
button.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 4px 0;
  min-height: 0;
  font-weight: 500;
  font-size: inherit;
}
button.link:hover { background: none; text-decoration: underline; }
button.link.danger { color: var(--bad); }
button.link.small { font-size: 0.875rem; }
.wide { width: 100%; }

input, select {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--control);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: var(--tap);
  min-width: 0;
  width: 100%;
}
input::placeholder { color: var(--muted); opacity: 0.8; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; margin: 0; flex: none; accent-color: var(--accent); }
input[type="checkbox"]:focus, input[type="radio"]:focus { box-shadow: none; }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.875rem; font-weight: 500; color: var(--text); }
label.field .hint { font-weight: 400; color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.money { position: relative; }
.money::before { content: "₺"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.money input { padding-left: 28px; font-variant-numeric: tabular-nums; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 10px; }

.search { display: flex; gap: 8px; }
.search .field-wrap { position: relative; flex: 1; }
.search .field-wrap .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; width: 22px; height: 22px; }
.search input { font-size: 1.125rem; min-height: 52px; padding-left: 46px; }
.search button { min-height: 52px; padding: 0 22px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8125rem; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.banner { padding: 12px 14px; border-radius: 10px; background: var(--attn-bg); color: var(--attn); border: 1px solid var(--attn-line); }
.banner.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.banner.ok { background: var(--good-bg); color: var(--good); border-color: transparent; }
.banner.info { background: var(--accent-soft); color: var(--text); border-color: transparent; }
.banner a { color: inherit; font-weight: 600; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 10px;
  max-width: calc(100% - 32px);
  z-index: 20;
  box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
}
@media (max-width: 719px) {
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* Login */

.login { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; }
.login .brand { justify-content: center; font-size: 1.25rem; margin-bottom: 20px; }
.login .brand img { width: 36px; height: 36px; }
.login button { width: 100%; }

/* Dashboard */

.todo { border-color: var(--attn-line); }
.todo h2 { margin: 0 0 8px; color: var(--attn); font-size: 1rem; }
.todo ul { margin: 0; padding: 0; list-style: none; }
.todo li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 10px 0; border-top: 1px solid var(--line); }
.todo li:first-child { border-top: 0; padding-top: 4px; }
.todo li > div { flex: 1 1 260px; }

.deals { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); }
.deal-card { padding: 0; overflow: hidden; }
.deal-head { padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
.deal-head a { color: var(--text); text-decoration: none; }
.deal-head a:hover { text-decoration: underline; }
.offers { margin: 0; padding: 0; list-style: none; }
.offer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  align-items: center;
  padding: 12px 16px;
}
.offer + .offer { border-top: 1px solid var(--line); }
.offer.best { background: color-mix(in srgb, var(--good-bg) 45%, transparent); }
.offer-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.offer-line .retailer { min-width: 92px; }
.offer .button { grid-row: span 2; }
.offer .detail { grid-column: 1; }

table.products td:first-child a { color: var(--text); font-weight: 600; text-decoration: none; }
table.products td:first-child a:hover { text-decoration: underline; }
.cell-link { display: block; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

@media (max-width: 719px) {
  .deals { grid-template-columns: 1fr; }
  .offer-line .retailer { min-width: 0; width: 100%; }
  .offer .quote { display: none; }
  table.products thead { display: none; }
  table.products tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.products tr:last-child { border-bottom: 0; }
  table.products td { display: block; border: 0; padding: 2px 0; text-align: left; }
  table.products td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 0.875rem; }
  table.products td.chips-cell { padding-top: 8px; }
  .cell-link { display: inline-flex; align-items: center; min-height: var(--tap); margin: 0 0 0 8px; }
}

/* Lookup */

.retailer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.retailer-head h2 { margin: 0; display: flex; align-items: baseline; gap: 8px; }
.retailer-head .count { color: var(--muted); font-weight: 500; font-size: 0.9375rem; }

.candidate {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.candidate:hover { border-color: var(--control); }
.candidate input[type="radio"] { margin-top: 2px; }
.candidate.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.candidate.none { padding: 8px 12px; align-items: center; color: var(--muted); }
.candidate.taken { cursor: default; background: var(--surface-2); border-style: dashed; }
.candidate img, .thumb { width: 60px; height: 60px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.candidate .name { font-weight: 600; overflow-wrap: anywhere; }
.pack { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding-top: 8px; border-top: 1px dashed var(--control); }
.pack input { width: 72px; }

.form-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
@media (max-width: 719px) {
  .form-actions button { width: 100%; }
}

/* Product */

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.fact { background: var(--surface); padding: 12px 16px; }
.fact .label { font-size: 0.8125rem; color: var(--muted); }
.fact .value { font-weight: 700; font-size: 1.125rem; font-variant-numeric: tabular-nums; }

.attn-card { border-color: var(--attn-line); }
.attn-card > h2:first-child { color: var(--attn); }

.depot-field { display: flex; flex-direction: column; gap: 6px; }
.depot-field > label { font-size: 0.875rem; font-weight: 500; }
.depot-field .hint { font-weight: 400; color: var(--muted); }
.depot-input { display: flex; gap: 8px; max-width: 420px; }
.depot-input .money { flex: 1; }
.depot-input input { font-size: 1.25rem; font-weight: 600; min-height: 52px; }
.depot-input button { min-height: 52px; padding: 0 22px; }
input[aria-invalid="true"] { border-color: var(--bad); }
.field-error { margin: 0; color: var(--bad); font-size: 0.875rem; font-weight: 600; }
.field-warn { margin: 0; color: var(--attn); }
.field-error:empty, .field-warn:empty { display: none; }
.calc > summary { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); color: var(--accent); font-size: 0.875rem; font-weight: 500; }
.calc > summary::-webkit-details-marker { display: none; }
.calc > summary::before { content: "▸"; }
.calc[open] > summary::before { content: "▾"; }
.calc-body { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); max-width: 640px; }
.calc-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.calc legend { margin-bottom: 0; font-weight: 500; }
.calc output { display: block; font-variant-numeric: tabular-nums; }

.spark { width: 100%; height: 48px; display: block; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark line { stroke: var(--muted); stroke-dasharray: 4 3; stroke-width: 1; }

details.section > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; min-height: var(--tap); }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: "▸"; color: var(--muted); }
details.section[open] > summary::before { content: "▾"; }
details.section > summary h2 { margin: 0; }
details > summary { cursor: pointer; }

@media (prefers-reduced-motion: no-preference) {
  .candidate, button, .button, input { transition: border-color 0.12s, background-color 0.12s, box-shadow 0.12s; }
}

main:focus { outline: none; }
.end { align-items: flex-end; }
.card > h2:first-child, .card > fieldset:first-child legend { margin-top: 0; }
select.auto { width: auto; }
.settings-list { margin: 0; padding: 0; list-style: none; }
.setting-row { padding: 10px 0; border-top: 1px solid var(--line); }
.setting-row:first-child { border-top: 0; padding-top: 0; }
@media (max-width: 719px) {
  .hide-sm { display: none; }
  .facts .fact:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* Layout stability: the scrollbar's room is kept whether or not the page scrolls, a pending page shows a bar
   instead of collapsing, and late text gets its room up front. */

html { scrollbar-gutter: stable; }

body.loading::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 40;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
}
@media (prefers-reduced-motion: no-preference) {
  body.loading::before { animation: progress 1.1s ease-in-out infinite; }
}
@keyframes progress { from { background-position: -40% 0; } to { background-position: 140% 0; } }
body.loading main[aria-busy="true"] { opacity: 0.6; transition: opacity 0.2s 0.15s; }

.thumb { display: block; background: var(--surface-2); }
.clef-note { min-height: 3em; }
