/* purchase-advice — vanilla CSS. No framework. Custom props + nesting + color-mix. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b2230;
  --muted: #5b6675;
  --border: #e2e6ec;
  --accent: #2b5fd7;
  --accent-weak: color-mix(in srgb, var(--accent) 12%, transparent);
  --bad: #c0392b;
  --good: #1f8a4c;
  --warn: #b7791f;
  --bad-weak: color-mix(in srgb, var(--bad) 12%, transparent);
  --good-weak: color-mix(in srgb, var(--good) 12%, transparent);
  --warn-weak: color-mix(in srgb, var(--warn) 14%, transparent);
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 28, 40, 0.06), 0 4px 16px rgba(20, 28, 40, 0.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

[data-theme="dark"] {
  --bg: #0f131a;
  --surface: #171c25;
  --surface-2: #1e2430;
  --text: #e6eaf2;
  --muted: #9aa4b2;
  --border: #2a313d;
  --accent: #6f9bff;
  --accent-weak: color-mix(in srgb, var(--accent) 18%, transparent);
  --bad: #ff6b5e;
  --good: #4ade80;
  --warn: #e0bd6e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
}

/* reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; font-size: .9em; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--surface); padding: .5rem .8rem; border: 1px solid var(--border);
}
.skip-link:focus { left: .5rem; top: .5rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* layout */
main { max-width: 1180px; margin: 0 auto; padding: 1.2rem 1.2rem 4rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: .6rem; }
.brand h1 { font-size: 1.1rem; margin: 0; }
.brand-sub { color: var(--muted); font-size: .8rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.btn {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); padding: .35rem .7rem; border-radius: var(--radius);
  cursor: pointer; white-space: nowrap;
  &:hover { background: var(--surface-2); }
}

/* dropzones */
.dropzone-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .dropzone-row { grid-template-columns: 1fr; } }
.dropzone {
  display: block; background: var(--surface); border: 2px dashed var(--border);
  border-radius: var(--radius); padding: 1.6rem 1.2rem; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  &.drag { border-color: var(--accent); background: var(--accent-weak); }
  &.has-file { border-style: solid; border-color: var(--good); background: var(--good-weak); }
}
.dropzone .zone-title { font-weight: 600; }
.dropzone .zone-hint { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.dropzone .zone-filename { margin-top: .5rem; min-height: 1.1em; font-size: .85rem; word-break: break-all; }

.status { margin: 1rem 0; color: var(--muted); }
.toast {
  opacity: 0; transition: opacity .2s; background: var(--surface); border: 1px solid var(--border);
  padding: .5rem .8rem; border-radius: var(--radius); box-shadow: var(--shadow); max-width: 32rem;
  &.show { opacity: 1; }
  &.error { border-color: var(--bad); }
  &.swap { border-color: var(--warn); }
}
.changed {
  background: var(--warn-weak); border: 1px solid var(--warn); color: var(--text);
  padding: .5rem .8rem; border-radius: var(--radius); margin: .6rem 0; max-width: 32rem;
}

/* summary */
.summary { margin: .8rem 0; }
.data-as-of { color: var(--muted); margin-bottom: .6rem; font-size: .95rem; }
.badge {
  font-size: .72rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px;
  vertical-align: middle; margin-left: .4rem; text-transform: uppercase; letter-spacing: .03em;
}
.badge-stale { background: var(--bad-weak); color: var(--bad); }
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .7rem .8rem; box-shadow: var(--shadow);
  &.kpi-bad { border-left: 3px solid var(--bad); }
  &.kpi-good { border-left: 3px solid var(--good); }
  &.kpi-warn { border-left: 3px solid var(--warn); }
}
.kpi-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-label { color: var(--muted); font-size: .78rem; }

/* warnings */
.warnings { margin: .8rem 0; }
.warn-banner {
  background: var(--warn-weak); border: 1px solid var(--warn); border-radius: var(--radius);
  padding: .6rem .8rem; margin-bottom: .8rem;
  &.inline { background: var(--surface-2); }
}
.warn-head { display: flex; justify-content: space-between; align-items: center; }
.warn-close {
  background: none; border: none; font-size: 1.2rem; line-height: 1; cursor: pointer; color: var(--muted);
}
.warn-list { margin: .4rem 0 0; padding-left: 1.2rem; }
.warn-list li { margin: .15rem 0; }
.warn-check { font-family: ui-monospace, monospace; font-size: .82rem; color: var(--warn); margin-right: .3rem; }
.warn-item { font-weight: 600; margin-right: .3rem; }
.warn-detail { color: var(--text); }

/* tabs */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab {
  font: inherit; background: none; border: none; padding: .55rem .9rem; cursor: pointer;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
  &[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
  &:hover { color: var(--text); }
}
.panel { padding-top: 1rem; }

/* tables */
.table-toolbar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem;
}
.table-title { font-weight: 600; }
.table-count { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.table-toolbar input[type="search"] {
  margin-left: auto; font: inherit; padding: .3rem .5rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text); min-width: 12rem;
}
.table-scroll { overflow: auto; max-height: 68vh; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .88rem; }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left;
  padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
thead th[aria-sort="ascending"]::after { content: " ▲"; color: var(--accent); font-size: .7em; }
thead th[aria-sort="descending"]::after { content: " ▼"; color: var(--accent); font-size: .7em; }
tbody td { padding: .4rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
tbody tr:hover td { background: var(--accent-weak); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.empty-row { color: var(--muted); text-align: center; white-space: normal; }

/* how */
.how { max-width: 60ch; }
.how h3 { margin-top: 1.2rem; }
.how ol, .how ul { padding-left: 1.3rem; }
.how li { margin: .3rem 0; }

/* print */
@media print {
  .topbar, .dropzone-row, .status, .toast, .changed, .table-toolbar, .skip-link { display: none !important; }
  main { max-width: none; padding: 0; }
  .panel { page-break-inside: avoid; }
  .table-scroll { overflow: visible; max-height: none; border: none; }
  thead th { position: static; }
  table { font-size: .72rem; }
  thead th, tbody td { padding: .25rem .35rem; }
  .diff-controls, .history { display: none !important; }
  @page { size: landscape; margin: 1cm; }
}

/* diff view */
.small { font-size: .82rem; }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; font-size: .85rem; }
.diff-controls { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.diff-controls .arrow { color: var(--muted); font-size: 1.1rem; }
.diff-sel { display: flex; flex-direction: column; gap: .15rem; }
.diff-sel select {
  font: inherit; padding: .3rem .4rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); min-width: 18rem;
}
.diff-bucket {
  margin: .8rem 0; padding: .6rem .8rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.diff-bucket h3 { font-size: .95rem; margin: 0 0 .3rem; }
.diff-help { margin: 0 0 .4rem; }
.diff-list { margin: .2rem 0 0; padding-left: 1.1rem; }
.diff-list li { margin: .2rem 0; }
.tag {
  font-size: .68rem; font-weight: 600; padding: .05rem .4rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.tag-buy { background: var(--bad-weak); color: var(--bad); }
.tag-covered { background: var(--good-weak); color: var(--good); }
.tag-none { background: var(--surface-2); color: var(--muted); }
.delta-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  font-size: .78rem; font-weight: 600; padding: .2rem .55rem; border-radius: 999px;
  background: var(--surface-2); font-variant-numeric: tabular-nums;
}
.chip.up, .num.up { color: var(--bad); font-weight: 600; }
.chip.up { background: var(--bad-weak); }
.chip.down, .num.down { color: var(--good); font-weight: 600; }
.chip.down { background: var(--good-weak); }
