/* Portfolio pages — theme tokens per the reference dataviz palette. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --up: #006300;
  --down: #d03b3b;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --up: #0ca30c;
    --down: #e66767;
    --accent: #3987e5;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.num { text-align: right; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface-1);
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 18px; }
.brand { font-weight: 700; }
.topbar nav a { margin-right: 12px; text-decoration: none; color: var(--ink-2); }
.topbar nav a.active { color: var(--ink); font-weight: 600; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface-1); color: var(--ink);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; font: inherit; text-decoration: none;
}
.btn:hover { border-color: var(--baseline); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn[disabled] { opacity: 0.5; cursor: default; }

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 20px; display: grid; gap: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; }
.panel h2 { font-size: 15px; margin: 0; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 820px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px;
}
.tile-label { color: var(--ink-2); font-size: 12px; }
.tile-value { font-size: 26px; font-weight: 700; margin-top: 2px; }
.tile-sub { color: var(--muted); font-size: 12px; min-height: 1em; }
.tile-sub.up { color: var(--up); }
.tile-sub.down { color: var(--down); }

/* ---------- chart ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.range-row { display: flex; gap: 4px; }
.range-btn {
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font: inherit;
}
.range-btn.active { border-color: var(--border); color: var(--ink); font-weight: 600; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px;
  font-size: 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  white-space: nowrap; z-index: 2; display: none;
}
.chart-tip .tip-val { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- alerts + rules ---------- */
.alerts-list, .rules-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.alerts-list li, .rules-list li {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.alerts-list li.unread { border-left: 3px solid var(--accent); }
.alert-time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.rule-form { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.rule-form select, .rule-form input {
  font: inherit; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-1); color: var(--ink);
}
.rule-form input[name="threshold"] { width: 80px; }
.rule-form input[name="window_days"] { width: 64px; }

/* ---------- inventory table ---------- */
.table-scroll { overflow-x: auto; }
.inv-table { width: 100%; border-collapse: collapse; }
.inv-table th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  border-bottom: 1px solid var(--baseline); padding: 6px 8px;
}
.inv-table th.num { text-align: right; }
.inv-table td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.inv-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.inv-thumb { width: 34px; height: 47px; object-fit: cover; border-radius: 3px; display: block; }
.inv-name { font-weight: 600; }
.inv-set { color: var(--ink-2); font-size: 12px; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions .btn { padding: 3px 9px; font-size: 12px; }

/* ---------- auth pages ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 12px; padding: 26px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-sub { margin: 0 0 16px; color: var(--ink-2); }
.auth-card form { display: grid; gap: 12px; }
.auth-card label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.auth-card input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--page); color: var(--ink);
}
.auth-card .hint { color: var(--muted); }
.auth-error {
  background: color-mix(in srgb, var(--down) 12%, transparent);
  border: 1px solid var(--down); border-radius: 6px; padding: 8px 10px; font-size: 13px;
}
.auth-alt { margin: 12px 0 0; font-size: 13px; color: var(--ink-2); }

/* ---------- marketplace grid ---------- */
.market-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px;
}
.market-card {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: var(--surface-1); display: flex; flex-direction: column;
}
.market-card img, .market-card .ph, .mc-img {
  width: 100%; aspect-ratio: 5 / 7; object-fit: cover; background: var(--grid);
}
.mc-body { padding: 10px; display: grid; gap: 4px; }
.mc-price { font-size: 16px; font-weight: 700; }
.mc-body .btn { justify-self: start; margin-top: 4px; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1);
  color: var(--ink); max-width: 460px; padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin-top: 0; font-size: 16px; }
dialog form { display: grid; gap: 10px; }
dialog input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--page); color: var(--ink); width: 100%;
}
.dialog-row { display: flex; gap: 8px; }

/* Advanced settings (per-user eBay keys) */
.hidden { display: none !important; }
.adv-section h3 { margin: 0 0 6px; font-size: 15px; }
.adv-section p { margin: 0 0 10px; max-width: 70ch; }
#ebay-status { margin-bottom: 10px; }
#ebay-keys-form input[name="client_id"],
#ebay-keys-form input[name="client_secret"],
#ebay-keys-form input[name="ru_name"] { min-width: 220px; }
#ebay-connect { margin-top: 10px; align-items: center; }
#ebay-redirect { min-width: 320px; }

/* =====================================================================
   Library / decks / marketplace additions
   ===================================================================== */

/* "Needs a human look". The only red-tinted surface on these pages; do not
   reuse it for decoration (falling prices use --down text, not this). */
:root { --row-flag: #fff5f5; --row-flag-text: #b00020; --ok-bg: #edf7ed; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --row-flag: #2b1717; --row-flag-text: #ff8f8f; --ok-bg: #14261a; }
}

.wrap.wide { max-width: 1320px; }
.hidden { display: none !important; }
.holo { font-weight: 400; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
td.num, th.num, .tile-value, .totals-strip, .mc-price { font-variant-numeric: tabular-nums; }

/* ---------- tabs + controls ---------- */
.tabs { display: flex; gap: 2px; }
.tab {
  border: 1px solid transparent; border-bottom: 2px solid transparent; background: transparent;
  color: var(--ink-2); padding: 5px 12px; cursor: pointer; font: inherit; border-radius: 6px 6px 0 0;
}
.tab.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.tab .count { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.controls-group { display: contents; }
.controls input[type="search"], .controls select, .form-grid input, .form-grid select, dialog textarea, dialog select {
  font: inherit; padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--page); color: var(--ink);
}
.controls input[type="search"] { flex: 1 1 220px; min-width: 160px; }
.controls > .muted { margin-left: auto; font-size: 12px; }
.totals-strip {
  display: flex; gap: 18px; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 8px;
  background: var(--page); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; color: var(--ink-2);
}
.totals-strip strong { color: var(--ink); }

/* ---------- dense tables ---------- */
.table-scroll { max-height: 70vh; overflow: auto; }
.inv-table thead th { position: sticky; top: 0; background: var(--surface-1); z-index: 1; }
.inv-table td { padding: 5px 8px; }
.inv-table th.sel, .inv-table td.sel { width: 28px; text-align: center; }
.inv-table tr.flag { background: var(--row-flag); }
.inv-table tbody tr:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.inv-table tr.flag:hover { background: var(--row-flag); }
.inv-thumb.ph { background: var(--grid); }
.empty { color: var(--muted); padding: 22px 8px !important; text-align: center; }
.price-cell { min-width: 150px; }
td.num > .flag-note { max-width: 320px; margin-left: auto; }
.prov { display: block; font-size: 11px; color: var(--muted); font-weight: 400; white-space: nowrap; }
.flag-note { display: block; font-size: 11px; color: var(--row-flag-text); font-weight: 600; white-space: normal; }
p.flag-note { font-size: 13px; }
.listed { font-size: 12px; color: var(--up); white-space: nowrap; align-self: center; }
.row-actions { flex-wrap: nowrap; white-space: nowrap; }
.pill { font-size: 11px; border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; color: var(--ink-2); }
.pill.ok { color: var(--up); border-color: var(--up); }
.pill.warn { color: var(--row-flag-text); border-color: var(--row-flag-text); background: var(--row-flag); }

/* ---------- dialogs ---------- */
dialog { width: min(460px, 94vw); }
dialog.wide { width: min(620px, 94vw); max-width: none; }
dialog form, dialog { color: var(--ink); }
dialog label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
dialog label.check { display: inline-flex; margin: 8px 0; }
dialog input[type="checkbox"] { width: auto; }
dialog p { margin: 0 0 8px; }
.dialog-row { justify-content: flex-end; margin-top: 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .span-2 { grid-column: 1 / -1; }
dialog textarea { width: 100%; min-height: 220px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }

/* ---------- status line ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--page); padding: 9px 14px; border-radius: 8px; font-size: 13px;
  max-width: min(640px, 92vw); pointer-events: none; transition: opacity 0.15s, transform 0.15s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--row-flag-text); color: #fff; }

/* ---------- marketplace ---------- */
.market-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.market-card.flag { background: var(--row-flag); border-color: var(--row-flag-text); }
.market-card img, .market-card .ph, .mc-img { display: block; }
.mc-body { padding: 8px 10px 10px; gap: 3px; }
.mc-price { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.mc-price .chg { font-size: 12px; font-weight: 400; }
.mc-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 4px; }
.mc-foot .btn { padding: 4px 12px; }

/* ---------- decks ---------- */
.deck-layout { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 980px) { .deck-layout { grid-template-columns: 1fr; } }
.deck-list { list-style: none; margin: 0; padding: 0; }
.deck-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 8px; cursor: pointer;
  border-bottom: 1px solid var(--grid); border-left: 3px solid transparent;
}
.deck-list li:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.deck-list li.active { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.deck-list .dl-name { font-weight: 600; }
.deck-list .dl-have { font-variant-numeric: tabular-nums; text-align: right; }
.deck-list .dl-meta { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.bar { grid-column: 1 / -1; height: 4px; background: var(--grid); border-radius: 2px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin: 10px 0 4px; }
.list-head h3 { margin: 0; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.source-note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.deck-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0; }
@media (max-width: 700px) { .deck-tiles { grid-template-columns: repeat(2, 1fr); } }
.deck-tiles .tile { padding: 8px 12px; }
.deck-tiles .tile-value { font-size: 20px; }
.deck-tiles .tile.flag { background: var(--row-flag); }
.deck-tiles .tile.flag .tile-value { color: var(--row-flag-text); }
.deck-tiles .tile.done { background: var(--ok-bg); }
.deck-table .sec-row td { background: var(--page); font-weight: 600; font-size: 12px; color: var(--ink-2); position: sticky; top: 30px; }
.deck-table .miss { font-weight: 700; }
.deck-table tr.covered td { color: var(--ink-2); }
.get { display: flex; gap: 6px 10px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.get .btn { padding: 2px 9px; font-size: 12px; }
.get a { white-space: nowrap; }
.panel-head select { font: inherit; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--page); color: var(--ink); }
.topbar nav a:hover { color: var(--ink); }
.btn:focus-visible, .tab:focus-visible, .deck-list li:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.market-card .prov, .market-card .flag-note { white-space: normal; max-width: none; margin-left: 0; }
.wrap > *, .deck-layout > *, .two-col > * { min-width: 0; }
.deck-list li { grid-template-columns: minmax(0, 1fr) auto; }
@media (max-width: 700px) { .wrap { padding: 12px; } .form-grid { grid-template-columns: 1fr; } }

/* Account notices (email not confirmed yet) */
.notice { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  border-left: 3px solid var(--accent); }
.totals-strip .btn { padding: 2px 10px; font-size: 12px; }
