/* Malibu Price Watch */
@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url("fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url("fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url("fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-display: swap; src: url("fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; font-display: swap; src: url("fonts/barlow-condensed-latin-700-normal.woff2") format("woff2"); }

:root {
  --navy: #16294A;
  --navy-press: #0F1E38;
  --paper: #F4F7FB;
  --surface: #FFFFFF;
  --rule: #D9E0EA;
  --ink: #14213A;
  --muted: #5B6B82;
  --hit: #1E8E5A;
  --hit-bg: #E2F4EA;
  --pre: #A15C00;
  --pre-bg: #FFF1DD;
  --err: #B42318;
  --err-bg: #FDECEA;
  --focus: #5B9BFF;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --cond: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  --tabs-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.45 var(--body);
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.num { font-family: var(--cond); font-variant-numeric: tabular-nums lining-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  background: var(--navy); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 12px;
}
.brand { font: 600 21px/1 var(--cond); letter-spacing: .01em; margin: 0; flex: 1; }
.brand small { display: block; font: 500 13px/1.3 var(--body); opacity: .72; margin-top: 3px; letter-spacing: 0; }
.bar .btn { border-color: rgba(255,255,255,.55); color: #fff; background: transparent; }
.bar .btn:active { background: rgba(255,255,255,.12); }

/* ---------- layout ---------- */
main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); }
h2 { font: 700 26px/1.1 var(--cond); margin: 0; }
h3 { font: 600 17px/1.3 var(--body); margin: 0 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack > * + * { margin-top: 16px; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 8px;
  border: 1.5px solid var(--navy); background: var(--surface); color: var(--navy);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:active { background: var(--navy-press); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 15px; }
.btn.danger { border-color: transparent; color: var(--err); background: transparent; padding: 0 8px; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
label.field { display: block; }
label.field > span { display: block; font-weight: 500; font-size: 15px; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number] {
  width: 100%; min-height: 46px; padding: 0 12px; border: 1.5px solid var(--rule); border-radius: 8px; background: var(--surface);
}
input:focus { border-color: var(--navy); outline: none; box-shadow: 0 0 0 3px rgba(91,155,255,.35); }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--navy); }
.error { color: var(--err); background: var(--err-bg); padding: 10px 12px; border-radius: 8px; }

.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } }

/* ---------- sign in ---------- */
.signin { max-width: 400px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 48px) 20px 40px; }
.signin .mark { width: 64px; height: 64px; border-radius: 14px; display: block; margin-bottom: 20px; }
.signin h1 { font: 700 33px/1.05 var(--cond); margin: 0 0 8px; color: var(--navy); }

/* ---------- watch list ---------- */
.summary { font: 600 17px/1.35 var(--body); margin: 4px 0 2px; }
.summary.good { color: var(--hit); }
.product { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 16px 16px 4px; }
.product.deal { border-color: var(--hit); box-shadow: inset 4px 0 0 var(--hit); }
.product-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.target { white-space: nowrap; font-size: 15px; color: var(--muted); }
.target b { font: 700 19px/1 var(--cond); color: var(--ink); font-variant-numeric: tabular-nums; }

/* the price rail: target tick + one dot per store */
.rail { position: relative; height: 46px; margin: 10px 4px 2px; }
.rail .line { position: absolute; left: 0; right: 0; top: 24px; height: 2px; background: var(--rule); border-radius: 1px; }
.rail .under { position: absolute; left: 0; top: 23px; height: 4px; background: var(--hit-bg); border-radius: 2px; }
.rail .tick { position: absolute; top: 14px; width: 2px; height: 22px; background: var(--navy); transform: translateX(-1px); }
.rail .tick-label { position: absolute; top: 0; transform: translateX(-50%); font: 600 13px/1 var(--cond); color: var(--navy); white-space: nowrap; }
.rail .dot { position: absolute; top: 19px; width: 12px; height: 12px; border-radius: 50%; transform: translateX(-6px); background: var(--muted); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--muted); }
.rail .dot.hit { background: var(--hit); box-shadow: 0 0 0 1px var(--hit); }
.rail .dot.away { background: var(--surface); box-shadow: 0 0 0 1.5px var(--muted); }
.rail .end { position: absolute; top: 32px; font: 600 12px/1 var(--cond); color: var(--muted); }

.stores { list-style: none; margin: 4px 0 0; padding: 0; }
.store { border-top: 1px solid var(--rule); }
.store a, .store .wrap { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 11px 0; text-decoration: none; }
.store .name { font-weight: 500; }
.store .price { font: 700 23px/1.1 var(--cond); font-variant-numeric: tabular-nums; text-align: right; grid-row: span 2; align-self: center; }
.store .price.hit { color: var(--hit); }
.store .price.none { color: var(--muted); font-weight: 600; font-size: 17px; }
.store .line2 { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 13px; font-weight: 600; background: #EEF2F7; color: var(--muted); }
.chip.hit { background: var(--hit-bg); color: var(--hit); }
.chip.pre { background: var(--pre-bg); color: var(--pre); }
.chip.err { background: var(--err-bg); color: var(--err); }

/* ---------- alerts ---------- */
.alerts { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; }
.alerts li + li { border-top: 1px solid var(--rule); }
.alerts a, .alerts .wrap { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 16px; text-decoration: none; }
.alerts .when { font-size: 13px; color: var(--muted); }
.alerts .price { font: 700 23px/1.1 var(--cond); color: var(--hit); grid-row: span 2; align-self: center; font-variant-numeric: tabular-nums; }

/* ---------- manage ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 16px; }
.panel.paused { background: #F8FAFC; }
.panel .upc { font-size: 13px; color: var(--muted); margin: 2px 0 12px; }
.src-list { list-style: none; padding: 0; margin: 12px 0 0; border-top: 1px solid var(--rule); }
.src-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--rule); min-height: 52px; }
.src-list .src-name { flex: 1; min-width: 0; }
.src-list .src-name span { display: block; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.add > summary { cursor: pointer; font-weight: 600; color: var(--navy); min-height: 44px; display: flex; align-items: center; list-style: none; }
details.add > summary::-webkit-details-marker { display: none; }
details.add > summary::before { content: "+"; font: 700 21px/1 var(--cond); width: 22px; }
details.add[open] > summary::before { content: "\2212"; }

/* ---------- settings ---------- */
.setting { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 16px; }
.setting h3 { margin-bottom: 4px; }
.status-line { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.status-dot { flex: none; width: 10px; height: 10px; margin-top: 7px; border-radius: 50%; background: var(--muted); }
.status-dot.on { background: var(--hit); }
.status-dot.off { background: var(--err); }
.results { list-style: none; padding: 0; margin: 12px 0 0; font-size: 15px; }
.results li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--rule); }

/* ---------- empty state ---------- */
.empty { text-align: left; padding: 24px 16px; background: var(--surface); border: 1px dashed var(--rule); border-radius: 12px; }

/* ---------- bottom tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabs-h); text-decoration: none; color: var(--muted); font-size: 13px; font-weight: 500;
  border-top: 3px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--navy); border-top-color: var(--navy); font-weight: 600; }
.tabs svg { width: 24px; height: 24px; }
.tabs .count { position: relative; }
.tabs .badge { position: absolute; top: -4px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--hit); color: #fff; font: 700 12px/18px var(--cond); text-align: center; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); z-index: 10;
  max-width: 528px; margin: 0 auto; background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px;
  font-weight: 500;
}
#toast.bad { background: var(--err); }

/* ---------- store tests & finding stores ---------- */
.src-list li { flex-wrap: wrap; }
.test-result { flex-basis: 100%; font-size: 15px; padding: 2px 0 10px 32px; }
.test-result.ok { color: var(--hit); font-weight: 600; }
.test-result.warn { color: var(--pre); }
.test-result.bad { color: var(--err); }
.test-result.muted { color: var(--muted); }
.test-result > span { display: block; }
.test-result details { margin-top: 6px; color: var(--muted); }
.test-result pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; background: #F1F4F8; padding: 8px; border-radius: 8px; max-height: 240px; overflow: auto; }
.find-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }

/* ---------- v4: health banner, shipping, settings, history ---------- */
.banner { margin: 0; padding: 12px 14px; border-radius: 10px; font-size: 15px; }
.banner.bad { background: var(--err-bg); color: var(--err); }
.banner.warn { background: var(--pre-bg); color: var(--pre); }
select {
  width: 100%; min-height: 46px; padding: 0 12px; border: 1.5px solid var(--rule); border-radius: 8px;
  background: var(--surface); font: inherit; color: inherit;
}
select:focus { border-color: var(--navy); outline: none; box-shadow: 0 0 0 3px rgba(91,155,255,.35); }
.row.inline { align-items: center; margin: 2px 0 6px 32px; }
.row.inline > span { flex: none; }
.row.inline select { max-width: 160px; }
details.ship { flex-basis: 100%; padding: 0 0 6px 32px; font-size: 15px; }
details.ship > summary { cursor: pointer; color: var(--muted); min-height: 32px; display: flex; align-items: center; }
.ship-form { padding: 6px 0 4px; }
.ship-form .row { margin: 8px 0; }
.alerts .price.quiet { color: var(--muted); }
.alerts .alert-msg { grid-column: 1 / -1; white-space: pre-line; font-size: 13px; color: var(--muted); margin-top: 4px; }
.alerts .when .chip { vertical-align: 1px; }

details.history { border-top: 1px solid var(--rule); margin-top: 2px; }
details.history > p { margin: 0 0 8px; }
.seg { display: inline-flex; border: 1.5px solid var(--rule); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.seg-btn { min-height: 36px; padding: 0 12px; border: 0; background: var(--surface); color: var(--muted); font-weight: 600; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1.5px solid var(--rule); }
.seg-btn[aria-pressed="true"] { background: var(--navy); color: #fff; }
.hist-body { padding-bottom: 10px; }
.hist-best { margin: 0 0 6px; }
.hist-best b { font: 700 17px/1 var(--cond); font-variant-numeric: tabular-nums; }
.hist-wrap { position: relative; touch-action: pan-y; }
.hist-svg { display: block; width: 100%; height: auto; overflow: visible; }
.hist-svg:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.hist-grid { stroke: #E7ECF2; stroke-width: 1; }
.hist-axis { fill: var(--muted); font: 500 11px var(--body); font-variant-numeric: tabular-nums; }
.hist-target { stroke: var(--hit); stroke-width: 1.5; }
.hist-line { fill: none; stroke: var(--navy); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.hist-dot { fill: var(--navy); stroke: var(--surface); stroke-width: 2; }
.hist-dot.hit { fill: var(--hit); }
.hist-cross { stroke: var(--muted); stroke-width: 1; }
.hist-tip { margin: 6px 0 2px; min-height: 20px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.hist-table { margin-top: 8px; font-size: 14px; }
.hist-table > summary { cursor: pointer; color: var(--navy); font-weight: 600; min-height: 36px; display: flex; align-items: center; }
.hist-table table { width: 100%; border-collapse: collapse; }
.hist-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; padding: 4px 6px 4px 0; border-bottom: 1px solid var(--rule); }
.hist-table td { padding: 5px 6px 5px 0; border-bottom: 1px solid var(--rule); }
.hist-key { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 4px; }
.hist-key .key-line { display: inline-block; width: 18px; height: 0; border-top: 1.5px solid var(--hit); }
.hist-key .key-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--hit); margin-left: 10px; }
.setup-link { font-size: 13px; word-break: break-all; background: #F1F4F8; padding: 8px 10px; border-radius: 8px; }
