:root {
  --bg: #f7f7f5; --surface: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --border: #e3e2dc;
  --accent: #1f6feb; --good-bg: #e3f4e8; --good-text: #1d6b35; --warn-bg: #fdf1dc; --warn-text: #8a5a0b;
  --light-bg: #e8effd; --light-text: #1f4fa8; --full-bg: #fbe9e4; --full-text: #9a3412;
  --row-hover: #f1f1ec;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --surface: #1f1f1d; --text: #ececea; --muted: #a09f99; --border: #34332f;
    --accent: #6ea8ff; --good-bg: #173a24; --good-text: #8fe0a8; --warn-bg: #3d2e10; --warn-text: #f2c46d;
    --light-bg: #1c2a47; --light-text: #a9c5ff; --full-bg: #3f2219; --full-text: #ffb49a;
    --row-hover: #292926;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
header { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap;
         padding: 20px 24px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
.sub, .count, .legend { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
nav { display: flex; gap: 4px; }
.tab { font: inherit; background: none; border: 1px solid transparent; border-radius: 6px; padding: 5px 12px;
       color: var(--muted); cursor: pointer; }
.tab.active { border-color: var(--border); color: var(--text); background: var(--bg); }
main { padding: 16px 24px 40px; }

#filters { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end; margin-bottom: 8px; }
#filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
#filters label.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 7px; font-size: 13px; }
#filters .inline { display: flex; align-items: center; gap: 6px; }
input, select { font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
                border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; }
input[type=search] { width: 220px; }
input[type=number] { width: 72px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-weight: 600; font-size: 12px; color: var(--muted); position: sticky; top: 0; background: var(--surface); }
#bikes th[data-key] { cursor: pointer; user-select: none; }
#bikes th.sorted::after { content: " ▲"; font-size: 9px; }
#bikes th.sorted.desc::after { content: " ▼"; }
#bikes tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.model { font-weight: 500; }
.muted { color: var(--muted); }
.estimate { font-style: italic; color: var(--warn-text); }

/* Price: pinned to the right edge so it stays reachable while the wide table scrolls sideways. */
#bikes th:last-child, #bikes td:last-child { position: sticky; right: 0; background: var(--surface);
                                             border-left: 1px solid var(--border); }
#bikes th:last-child { z-index: 2; }
#bikes tbody tr:hover td:last-child { background: var(--row-hover); }

/* Price: a link out to a Google Shopping search, styled as a small button. */
.pricebtn { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 6px; text-decoration: none;
            border: 1px solid var(--border); background: var(--bg); color: var(--accent); white-space: nowrap; }
.pricebtn:hover { border-color: var(--accent); }
dialog .pricebtn { font-size: 13px; padding: 4px 12px; }

.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 500; }
.badge.light { background: var(--light-bg); color: var(--light-text); }
.badge.full_power { background: var(--full-bg); color: var(--full-text); }
.badge.target { background: var(--good-bg); color: var(--good-text); }
.badge.retailer { background: var(--warn-bg); color: var(--warn-text); }
.badge.ok { background: var(--good-bg); color: var(--good-text); }
.badge.partial, .badge.running { background: var(--warn-bg); color: var(--warn-text); }
.badge.failed { background: var(--full-bg); color: var(--full-text); }

dialog { width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 1px solid var(--border);
         border-radius: 10px; padding: 20px 24px; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog .close { position: sticky; top: 0; float: right; }
dialog .close button { font: inherit; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
dialog h2 { font-size: 18px; margin: 0 0 2px; }
dialog h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 0 8px; }
dialog a { color: var(--accent); }
.specs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 20px; margin: 0; }
.specs div { border-bottom: 1px solid var(--border); padding: 4px 0; }
.specs dt { font-size: 11px; color: var(--muted); }
.specs dd { margin: 0; }
.specs dd.derived::after { content: " *"; color: var(--warn-text); }
.notes { margin: 0; padding-left: 18px; font-size: 13px; }
.notes code { font-size: 12px; color: var(--muted); }
dialog td { white-space: normal; vertical-align: top; }

@media (max-width: 640px) {
  header, main { padding-left: 16px; padding-right: 16px; }
  input[type=search] { width: 100%; }
  #filters label:first-child { flex-basis: 100%; }
}

/* Radar charts - bike profile (accent, filled) vs. your minimums (muted ink, dashed:
   identity never rests on colour alone). */
.radar { display: block; overflow: visible; max-width: 100%; height: auto; }
.radar-grid { fill: none; stroke: var(--border); stroke-width: 1; }
.radar-axis { stroke: var(--border); stroke-width: 1; }
.radar-label { fill: var(--muted); font-size: 12px; }
.radar-bike { fill: color-mix(in srgb, var(--accent) 18%, transparent); stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.radar-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.radar-hit { fill: transparent; }
.radar-target { fill: color-mix(in srgb, var(--muted) 10%, transparent); stroke: var(--text); stroke-width: 1.5; stroke-dasharray: 5 4; pointer-events: none; }
.radar-handle { fill: var(--surface); stroke: var(--text); stroke-width: 2; cursor: grab; touch-action: none; }
.radar-handle:hover, .radar-handle:focus { fill: var(--accent); outline: none; }

.match-top { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 24px; align-items: start; }
.match-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.match-card { font: inherit; text-align: left; color: var(--text); background: var(--surface); border: 1px solid var(--border);
              border-radius: 8px; padding: 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.match-card:hover, .match-card:focus-visible { border-color: var(--accent); }
.match-card .muted { font-size: 12px; }
.match-name { font-weight: 500; font-size: 13px; text-align: center; }
.detail-radar { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.swatch { display: inline-block; width: 18px; height: 0; vertical-align: middle; border-top: 2px solid var(--accent); }
.swatch.target { border-top: 2px dashed var(--text); }

@media (max-width: 760px) {
  .match-top { grid-template-columns: 1fr; }
  .match-target { position: static; }
}
.radar-editable { cursor: crosshair; touch-action: none; }
.pager { display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 0 40px 10px 0; }
.pager .pricebtn { cursor: pointer; font: inherit; font-size: 13px; }
.pager .pricebtn:disabled { opacity: .4; cursor: default; }
.match-grid > p { grid-column: 1 / -1; margin: 0; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { display: block; flex: none; border-radius: 9px; }

/* Left panel of "Find my bike": the envelope editor. */
.match-target { position: sticky; top: 12px; background: var(--surface); border: 1px solid var(--border);
                border-radius: 12px; padding: 18px 18px 14px; box-shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .04);
                display: flex; flex-direction: column; gap: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel-head h2 { font-size: 16px; font-weight: 600; margin: 0; }
.panel-stat { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; }
.panel-stat strong { font-size: 20px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.panel-lead { margin: 0; font-size: 13px; line-height: 1.45; color: var(--muted); }
.panel-radar { display: flex; justify-content: center; margin: 2px -6px; }
.panel-section { border-top: 1px solid var(--border); padding-top: 12px; }
.panel-section h3 { margin: 0 0 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.limit-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.limit-list li { display: grid; grid-template-columns: 1fr auto 22px; align-items: center; gap: 8px;
                 padding: 5px 8px; border-radius: 6px; font-size: 13px; }
.limit-list li.is-set { background: var(--light-bg); }
.limit-name { color: var(--text); }
.limit-value { font-variant-numeric: tabular-nums; color: var(--muted); }
.limit-list li.is-set .limit-value { color: var(--light-text); font-weight: 600; }
.limit-clear { width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: var(--light-text);
               font-size: 16px; line-height: 1; cursor: pointer; }
.limit-clear:hover, .limit-clear:focus-visible { background: var(--surface); outline: none; }

.panel-options { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.btn-secondary { font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 6px; cursor: pointer;
                 color: var(--text); background: var(--bg); border: 1px solid var(--border); }
.btn-secondary:hover, .btn-secondary:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }

.panel-help { font-size: 12px; color: var(--muted); }
.panel-help summary { cursor: pointer; width: fit-content; }
.panel-help summary:hover { color: var(--text); }
.panel-help p { margin: 6px 0 0; line-height: 1.5; }

/* Filter bar: every text field and select the same 34px height (selects and inputs otherwise
   size differently per browser), and the checkbox rows centred on that same height. */
#filters input:not([type=checkbox]), #filters select { height: 34px; padding-top: 0; padding-bottom: 0; line-height: 32px; }
#filters select { padding-right: 28px; }
#filters label.check { height: 34px; padding-bottom: 0; }
#filters label.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* Status page header: latest scrape per brand. */
.status-head { display: grid; gap: 14px; margin-bottom: 22px; }
.status-summary { display: flex; flex-wrap: wrap; gap: 12px 40px; padding: 16px 18px; background: var(--surface);
                  border: 1px solid var(--border); border-radius: 12px; font-size: 13px; }
.status-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.status-big { font-size: 22px; font-weight: 600; line-height: 1.3; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.status-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
               display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.status-card.seed { background: var(--bg); border-style: dashed; }
.status-card-head { display: flex; align-items: center; gap: 8px; font-size: 15px; margin-bottom: 4px; }
.status-when { font-size: 18px; font-weight: 600; }
.status-nums { display: grid; grid-template-columns: repeat(5, auto); gap: 4px 12px; margin: 10px 0 0; justify-content: start; }
.status-nums dt { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.status-nums dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 500; }
.status-nums .has-errors dd { color: var(--full-text); }
.section-title { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.status-nums dt { white-space: nowrap; }
