:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #15181e;
  --muted: #667085;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --steal: #0f8a5f;
  --steal-bg: #e3f6ee;
  --good: #2f5bea;
  --good-bg: #e8eefe;
  --fair: #667085;
  --fair-bg: #eef0f3;
  --over: #b42318;
  --over-bg: #fdeceb;
  --warn-bg: #fff4e0;
  --warn: #9a5b00;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e8eaee;
    --muted: #98a1b3;
    --accent: #6f8dff;
    --accent-ink: #0b0d12;
    --steal: #3ccf9a;
    --steal-bg: #12332a;
    --good: #7c9bff;
    --good-bg: #1c2747;
    --fair: #98a1b3;
    --fair-bg: #232834;
    --over: #ff8b81;
    --over-bg: #3a1c1a;
    --warn-bg: #3a2c10;
    --warn: #f5b942;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-weight: 500; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.on { color: #b7791f; }
.input, .select, .textarea {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; }
.select { width: auto; padding-right: 26px; }
label.field { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
label.field > .input, label.field > .select, label.field > .textarea { margin-top: 4px; color: var(--text); font-weight: 400; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: -.01em; margin-right: 4px; }
.spacer { flex: 1; }
.grow { min-width: 0; }
.small { font-size: 12px; }
.note { margin: 0; font-size: 12.5px; }
.select.block { width: 100%; }
.grid2.auto-right { grid-template-columns: 1fr auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.empty.slim { padding: 14px; }

/* Layout */
main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 64px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.banner ul { margin: 4px 0 0; padding-left: 18px; }

/* Tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--muted); font-weight: 500; white-space: nowrap;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface); border-color: var(--border); color: var(--text); box-shadow: var(--shadow); }
.tab .count { font-size: 12px; padding: 0 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .search { flex: 1; min-width: 220px; }

/* Deal list */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.deal { border-bottom: 1px solid var(--border); }
.deal:last-child { border-bottom: 0; }
.deal-main {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 12px 16px; cursor: pointer; background: transparent; border: 0; width: 100%; text-align: left;
}
.deal-main:hover { background: var(--surface-2); }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.thumb.ph { display: grid; place-items: center; color: var(--muted); font-size: 11px; font-weight: 600; }
.deal-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.price-col { text-align: right; }
.price { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.saving { font-size: 12.5px; font-weight: 600; }
.saving.pos { color: var(--steal); }
.saving.neg { color: var(--muted); font-weight: 500; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.STEAL { background: var(--steal-bg); color: var(--steal); }
.badge.GOOD_DEAL { background: var(--good-bg); color: var(--good); }
.badge.FAIR { background: var(--fair-bg); color: var(--fair); }
.badge.OFFER { background: var(--good-bg); color: var(--good); }
.badge.SUSPECT { background: var(--over-bg); color: var(--over); }
.badge.OVERPRICED { background: var(--over-bg); color: var(--over); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 11.5px; background: var(--surface-2); color: var(--muted); }
.tag.drop { background: var(--over-bg); color: var(--over); }

.deal-detail { padding: 4px 16px 16px 86px; display: grid; gap: 12px; }
.parts { width: 100%; max-width: 560px; border-collapse: collapse; font-size: 13px; }
.parts td { padding: 5px 0; border-bottom: 1px solid var(--border); }
.parts td:last-child { text-align: right; color: var(--muted); }
.desc { margin: 0; font-size: 13px; color: var(--muted); max-width: 720px; overflow-wrap: anywhere; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 12px; }

/* Dialogs */
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(720px, calc(100vw - 24px)); max-height: 88vh; }
dialog::backdrop { background: rgba(10, 12, 16, .55); }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 10px; }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.dlg-body { padding: 4px 18px 18px; display: grid; gap: 12px; overflow: auto; max-height: calc(88vh - 70px); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; }
.result { padding: 12px; border-radius: 10px; background: var(--surface-2); display: grid; gap: 6px; }
.result .row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
table.catalog { width: 100%; border-collapse: collapse; font-size: 13px; }
table.catalog th { text-align: left; font-size: 12px; color: var(--muted); padding: 6px 6px; position: sticky; top: 0; background: var(--surface); }
table.catalog td { padding: 4px 6px; border-top: 1px solid var(--border); }
table.catalog input { width: 78px; height: 28px; }
.secret-note { font-size: 12px; color: var(--muted); margin-top: 4px; }
code.token { display: block; padding: 8px; border-radius: 8px; background: var(--surface-2); font-size: 12px; overflow-wrap: anywhere; }

/* Toast */
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 60; max-width: 360px; padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 13px; }

@media (max-width: 640px) {
  .deal-main { grid-template-columns: 48px minmax(0, 1fr); }
  .thumb { width: 48px; height: 48px; }
  .price-col { grid-column: 2; text-align: left; display: flex; gap: 10px; align-items: baseline; }
  .deal-detail { padding-left: 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .topbar-inner .search-top { order: 5; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.progress { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--border); display: grid; gap: 8px; font-size: 13px; }
.progress .bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress .bar > span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.progress .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.healthy { background: var(--steal); }
.dot.degraded { background: #e0a100; }
.dot.down { background: var(--over); }
.health-card { padding: 12px; border: 1px solid var(--border); border-radius: 10px; display: grid; gap: 6px; }
.health-card h3 { margin: 0; font-size: 14px; display: flex; align-items: center; gap: 8px; text-transform: capitalize; }
.health-card ul { margin: 0; padding-left: 18px; font-size: 13px; }
.health-recent { font-size: 12px; color: var(--muted); display: grid; gap: 2px; }

/* Login (hosted deployments) */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; box-sizing: border-box; }
.login-card { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.login-card .brand { font-size: 1.1rem; margin-bottom: 6px; }
