/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7873;
  --grid: #e1e0d9;
  --axis: #c3c2b7;

  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(42, 120, 214, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;

  --good: #0ca30c;
  --good-ink: #006300;
  --good-soft: rgba(12, 163, 12, 0.10);
  --warning: #fab219;
  --warning-ink: #8a5a00;
  --warning-soft: rgba(250, 178, 25, 0.16);
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b32626;
  --critical-soft: rgba(208, 59, 59, 0.10);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #97958e;
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --good-ink: #3ecf3e;
    --good-soft: rgba(12, 163, 12, 0.16);
    --warning-ink: #fab219;
    --warning-soft: rgba(250, 178, 25, 0.14);
    --critical-ink: #ef7272;
    --critical-soft: rgba(208, 59, 59, 0.18);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #97958e;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --good-ink: #3ecf3e;
  --good-soft: rgba(12, 163, 12, 0.16);
  --warning-ink: #fab219;
  --warning-soft: rgba(250, 178, 25, 0.14);
  --critical-ink: #ef7272;
  --critical-soft: rgba(208, 59, 59, 0.18);
  --shadow: none;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.container { width: 100%; max-width: 1320px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 8px;
  background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 8px; z-index: 10;
}
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Header / layout
   ========================================================================== */
.app-header {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--page) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: #fff;
}
.brand h1 { font-size: 17px; font-weight: 650; }
.tagline { font-size: 13px; color: var(--muted); }

.layout {
  display: grid; gap: 20px; padding-top: 20px; padding-bottom: 20px;
  grid-template-columns: 360px minmax(0, 1fr); align-items: start;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
.app-footer { padding-bottom: 32px; font-size: 13px; }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; min-width: 0;
}
.card-title { font-size: 15px; font-weight: 650; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .card-title { margin: 0; }
.card-sub { font-size: 13px; color: var(--muted); }

/* ==========================================================================
   Form
   ========================================================================== */
.form-card { position: sticky; top: 84px; }
@media (max-width: 960px) { .form-card { position: static; } }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) 130px; gap: 10px; }
.field-row .field { margin-bottom: 14px; }
.unit { color: var(--muted); font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%; height: 40px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid="true"] { border-color: var(--critical); }
input::placeholder { color: var(--muted); }
.input-group { display: flex; }
.input-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-addon {
  border: 1px solid var(--border-strong); border-left: 0; background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 0 12px; cursor: pointer; font-size: 13px;
}
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); font-weight: 500 !important; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; color: var(--critical-ink); min-height: 0; }
.field-error:empty { display: none; }
.field-check { font-size: 12px; margin: 0; }
.field-check:empty { display: none; }
.field-check.check-ok { color: var(--good-ink); }
.field-check.check-warn { color: var(--warning-ink); }
.field-check.check-error, .field-check.check-empty { color: var(--critical-ink); }

.advanced-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.advanced-grid .field { margin-bottom: 12px; }

/* Settings summary under the main form */
.settings-summary {
  display: grid; gap: 6px; margin: 2px 0 16px; padding: 10px 12px;
  background: var(--surface-2); border-radius: var(--radius-sm); font-size: 12.5px;
}
.summary-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.summary-costs { color: var(--text-2); }
.status { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status.ok { color: var(--good-ink); }
.status.ok .status-dot { background: var(--good); }
.status.warn { color: var(--warning-ink); }
.status.warn .status-dot { background: var(--warning); }
.status.muted-status { color: var(--muted); font-weight: 500; }
.status.muted-status .status-dot { background: var(--axis); }
.seller-status .status { margin-bottom: 4px; }
.link-btn {
  background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; font-size: 12.5px;
  cursor: pointer; white-space: nowrap;
}
.link-btn:hover { text-decoration: underline; }

/* Header actions & settings button */
.header-actions { display: flex; gap: 8px; }
.settings-btn { position: relative; }
.settings-dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--warning); box-shadow: 0 0 0 2px var(--surface);
}

/* Settings sheet */
dialog.settings {
  padding: 0; border: 0; margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh;
  width: min(540px, 100vw); max-width: 100vw;
  background: transparent; color: var(--text);
}
dialog.settings::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog.settings[open] { animation: sheet-in .2s ease-out; }
@keyframes sheet-in { from { transform: translateX(24px); opacity: 0; } }
.settings-panel {
  height: 100%; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border);
}
.settings-head {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
}
.settings-head h2 { font-size: 18px; }
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: 0; padding: 10px 4px; margin-right: 10px; cursor: pointer;
  font-weight: 600; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }
.settings-body { flex: 1; overflow-y: auto; padding: 20px; }
.settings-body .checkbox { margin-bottom: 10px; }
.settings-body [role="tabpanel"]:focus-visible { outline-offset: 6px; }
.settings-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; }
.settings-foot .btn { flex: 1; }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; margin-top: 4px; }
#costs-error { margin-bottom: 8px; }

.actions { display: flex; gap: 8px; }
.btn {
  height: 42px; padding: 0 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter .15s, background .15s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); flex: 1; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .7; cursor: progress; }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.demo-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 14px; font-size: 13px; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px;
  padding: 3px 12px; font-size: 13px; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.privacy-note { margin-top: 14px; font-size: 12px; color: var(--muted); }

.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text-2);
}

/* ==========================================================================
   Results
   ========================================================================== */
.results { display: grid; gap: 20px; min-width: 0; }
.results:focus { outline: none; }
.empty-state {
  text-align: center; padding: 64px 24px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--text-2); display: grid; justify-items: center; gap: 10px;
}
.empty-state h2 { font-size: 18px; color: var(--text); }
.empty-state p { max-width: 460px; }

.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* Product header */
.product { display: flex; gap: 16px; align-items: flex-start; }
.product-img {
  width: 84px; height: 84px; flex: none; border-radius: 10px; background: #fff; border: 1px solid var(--border);
  object-fit: contain; padding: 4px; display: grid; place-items: center; color: var(--muted);
}
.product-title { font-size: 16px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.meta a { text-decoration: none; }
.elig {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
}
.elig b { display: block; font-size: 14px; }
.elig-detail { display: block; color: var(--text-2); }
.elig-icon { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; color: #fff; }
.elig-good { background: var(--good-soft); } .elig-good .elig-icon { background: var(--good); } .elig-good b { color: var(--good-ink); }
.elig-warn { background: var(--warning-soft); } .elig-warn .elig-icon { background: var(--warning); color: #3a2a00; } .elig-warn b { color: var(--warning-ink); }
.elig-bad { background: var(--critical-soft); } .elig-bad .elig-icon { background: var(--critical); } .elig-bad b { color: var(--critical-ink); }
.elig-muted { background: var(--surface-2); } .elig-muted .elig-icon { background: var(--axis); color: var(--text); }
@media (max-width: 480px) { .elig { grid-template-columns: 28px minmax(0, 1fr); } .elig .btn-link { grid-column: 1 / -1; } }
.product-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-left: 100px; }
@media (max-width: 640px) { .product-actions { padding-left: 0; } }
.btn-link { height: 36px; padding: 0 14px; font-size: 13px; text-decoration: none; color: var(--text); gap: 7px; white-space: nowrap; }
.btn-link .ext { color: var(--muted); font-weight: 400; }
.btn-link.is-disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 480px) { .product-actions .btn-link { flex: 1; } }
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2);
}
.badge.demo { background: var(--warning-soft); color: var(--warning-ink); }

/* Verdict */
.verdict { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 24px; align-items: center; }
@media (max-width: 640px) { .verdict { grid-template-columns: minmax(0, 1fr); justify-items: start; } }
.verdict.good { border-color: color-mix(in srgb, var(--good) 45%, transparent); background: linear-gradient(135deg, var(--good-soft), var(--surface) 55%); }
.verdict.warning { border-color: color-mix(in srgb, var(--warning) 55%, transparent); background: linear-gradient(135deg, var(--warning-soft), var(--surface) 55%); }
.verdict.critical { border-color: color-mix(in srgb, var(--critical) 45%, transparent); background: linear-gradient(135deg, var(--critical-soft), var(--surface) 55%); }
.gauge { position: relative; width: 132px; height: 132px; }
.gauge svg { transform: rotate(-90deg); }
.gauge-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.gauge-score { font-size: 34px; font-weight: 700; line-height: 1; }
.gauge-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.verdict-label { display: inline-flex; align-items: center; gap: 8px; font-size: 26px; font-weight: 750; letter-spacing: -.01em; }
.verdict.good .verdict-label { color: var(--good-ink); }
.verdict.warning .verdict-label { color: var(--warning-ink); }
.verdict.critical .verdict-label { color: var(--critical-ink); }
.verdict-expl { margin-top: 8px; color: var(--text-2); max-width: 720px; }
.verdict-meta { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 14px; }
.component { min-width: 130px; flex: 1; max-width: 200px; }
.component-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.component-top strong { color: var(--text); font-weight: 650; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }

/* KPIs */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { padding: 16px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tone-good { color: var(--good-ink); }
.tone-warning { color: var(--warning-ink); }
.tone-critical { color: var(--critical-ink); }
.kpi-editable { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.kpi-price-row { display: flex; align-items: center; gap: 2px; }
.kpi-currency { font-size: 22px; font-weight: 700; }
#kpi-price {
  width: 100%; min-width: 0; height: 36px; padding: 0 6px; margin-left: -2px;
  font-size: 24px; font-weight: 700; letter-spacing: -.01em; color: var(--text);
  background: transparent; border: 1px dashed var(--border-strong); border-radius: 8px;
  -moz-appearance: textfield;
}
#kpi-price::-webkit-outer-spin-button, #kpi-price::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#kpi-price:hover { border-color: var(--accent); }
#kpi-price:focus { border-style: solid; background: var(--surface); }
.kpi.is-whatif { border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent); }
@media (max-width: 480px) { .kpi-currency { font-size: 20px; } #kpi-price { font-size: 20px; } }
.kpi-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.kpi-dot.good { background: var(--good); }
.kpi-dot.warning { background: var(--warning); }
.kpi-dot.critical { background: var(--critical); }

/* Segmented control */
.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 10px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; padding: 4px 12px; border-radius: 7px; font-size: 13px; font-weight: 600;
  cursor: pointer; color: var(--text-2);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* Charts */
.chart-box { position: relative; height: 300px; }
.chart-box.small { height: 180px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.legend button {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 2px 0; cursor: pointer; color: inherit;
}
.legend button[aria-pressed="false"] { opacity: .45; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.chart-empty { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 13px; border: 1px dashed var(--border); border-radius: 10px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 700; border-top: 1.5px solid var(--border-strong); }
td.fee-note {
  text-align: left; white-space: normal; font-size: 12px; color: var(--warning-ink);
  background: var(--warning-soft); border-radius: 6px;
}
td .src { font-size: 11px; color: var(--muted); margin-left: 6px; font-weight: 500; }

/* Profit stacked bar */
.stack { display: flex; height: 26px; border-radius: 8px; overflow: hidden; gap: 2px; margin: 4px 0 14px; background: var(--surface); }
.stack > span { min-width: 3px; }
.stack-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-2); margin-bottom: 10px; }
.stack-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

/* Metric list */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; }
.metric { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.metric-label { font-size: 12px; color: var(--muted); }
.metric-value { font-size: 18px; font-weight: 650; margin-top: 2px; }
.metric-sub { font-size: 12px; color: var(--muted); }

.share-list { display: grid; gap: 8px; margin-top: 14px; }
.share-row { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr) 52px; gap: 10px; align-items: center; font-size: 13px; }
.share-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.share-row .val { text-align: right; font-variant-numeric: tabular-nums; }

/* Risks */
.risk-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.risk { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 12px; border-radius: 10px; background: var(--surface-2); }
.risk-icon { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; }
.risk.high .risk-icon { background: var(--critical); }
.risk.medium .risk-icon { background: var(--serious); }
.risk.low .risk-icon { background: var(--warning); color: #3a2a00; }
.risk-title { font-weight: 600; }
.risk-detail { font-size: 13px; color: var(--text-2); }
.sev { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.no-risks { display: flex; gap: 10px; align-items: center; padding: 14px; border-radius: 10px; background: var(--good-soft); color: var(--good-ink); font-weight: 600; }

/* Loading skeleton */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: 10px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.loading-steps { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.loading-steps li.active { color: var(--text); font-weight: 600; }
.loading-steps li.done { color: var(--good-ink); }
.loading-steps li::before { content: "○ "; }
.loading-steps li.active::before { content: "◌ "; }
.loading-steps li.done::before { content: "✓ "; }

/* Error */
.alert { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 14px; border-color: color-mix(in srgb, var(--critical) 40%, transparent); background: var(--critical-soft); }
.alert-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--critical); color: #fff; display: grid; place-items: center; font-weight: 800; }
.alert h2 { font-size: 16px; }
.alert p { margin-top: 4px; color: var(--text-2); }
.alert .btn { margin-top: 12px; margin-right: 8px; height: 36px; }

/* Data source tags & Amazon-vs-Keepa note */
.src-tag { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px; font-size: 9.5px; font-weight: 700; letter-spacing: .03em; vertical-align: 1px; background: var(--surface-2); color: var(--muted); text-transform: none; }
.src-tag.src-amazon { background: color-mix(in srgb, #ff9900 20%, transparent); color: #b36b00; }
:root[data-theme="dark"] .src-tag.src-amazon { color: #ffb84d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .src-tag.src-amazon { color: #ffb84d; } }
.data-note { margin-top: 12px; padding: 10px 14px; border-radius: 10px; font-size: 13px; background: color-mix(in srgb, #ff9900 10%, var(--surface)); border: 1px solid color-mix(in srgb, #ff9900 30%, transparent); color: var(--text-2); }
.data-note b { color: var(--text); }
.data-note ul { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 2px; }
.data-note-warn { background: var(--surface-2); border-color: var(--border); }
.data-note-problem { margin-top: 6px; color: var(--warning-ink); }

/* Left column: form + source card */
.sidebar { display: grid; gap: 20px; position: sticky; top: 84px; align-self: start; min-width: 0; }
.sidebar .form-card { position: static; }
@media (max-width: 960px) { .sidebar { position: static; } }
.source-card .card-head { margin-bottom: 10px; }
.source-card input[type="url"] { width: 100%; height: 40px; padding: 0 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.source-preview { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -4px 0 10px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.source-host { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Google Sheet */
.sheet-btn svg { flex: none; }
.sheet-btn.copied { border-color: color-mix(in srgb, var(--good) 55%, transparent); color: var(--good-ink); background: var(--good-soft); }
.sheet-result { align-self: center; font-size: 12px; }
.setup-steps { margin: 0 0 14px; padding-left: 20px; display: grid; gap: 8px; font-size: 13px; color: var(--text-2); }
.setup-steps .btn-sm { margin: 6px 6px 0 0; }
.sheet-copied { font-size: 12px; color: var(--good-ink); }
.keep-safe { margin-bottom: 14px; padding: 10px 12px; border-radius: 10px; background: var(--good-soft); font-size: 13px; color: var(--text-2); }
.keep-safe b { color: var(--good-ink); display: block; margin-bottom: 2px; }
.setup-steps code, .keep-safe code { font-size: 12px; padding: 0 4px; border-radius: 4px; background: var(--surface-2); }
.mode-choice { display: grid; gap: 6px; margin-top: 8px; padding: 10px; border-radius: 8px; border: 1px solid var(--border); }
.mode-choice input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.addon-line { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 11px; white-space: pre-wrap; word-break: break-all; }
.deploy-options { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 6px; }
.script-peek { margin-top: 14px; font-size: 12px; }
.script-peek summary { cursor: pointer; color: var(--muted); }
.script-peek pre { max-height: 220px; overflow: auto; padding: 10px; border-radius: 8px; background: var(--surface-2); font-size: 11px; white-space: pre; }
.tabs { overflow-x: auto; scrollbar-width: thin; }
.tab { white-space: nowrap; }

/* Add-to-sheet confirmation */
dialog.modal { padding: 0; border: 0; border-radius: 16px; width: min(520px, calc(100vw - 32px)); background: transparent; color: var(--text); }
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.5); }
.modal-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; display: flex; flex-direction: column; max-height: calc(100dvh - 48px); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 6px; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 8px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.hive-fields { display: grid; grid-template-columns: 0.8fr 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .hive-fields { grid-template-columns: 1fr; } }
.hive-summary { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 13px; margin-bottom: 12px; }
.hive-what { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 13px; color: var(--text-2); }
.hive-what:empty { display: none; }
.hive-duplicate { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--warning-soft); font-size: 13px; color: var(--text-2); }
.hive-duplicate b { color: var(--warning-ink); }
.hive-duplicate ul { margin: 6px 0; padding-left: 18px; }

/* History */
.history-btn { height: 38px; padding: 0 12px; gap: 6px; font-size: 13px; }
.count-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
@media (max-width: 480px) { .history-btn > span:not(.count-badge) { display: none; } }
dialog.history-sheet { width: min(1080px, 100vw); }
.history-toolbar { display: flex; gap: 8px; padding: 0 20px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.history-toolbar input[type="search"] { flex: 1; min-width: 180px; height: 36px; padding: 0 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.history-toolbar select { width: auto; height: 36px; }
.history-toolbar .btn-sm { margin-top: 0; height: 36px; }
.history-delete:not(:disabled) { color: var(--critical-ink); border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.history-delete:disabled { opacity: .5; cursor: not-allowed; }
.history-body { padding-top: 8px; }
.history-empty { padding: 40px 12px; text-align: center; color: var(--muted); }
.history-table td { vertical-align: middle; }
.history-table tr.is-selected td { background: var(--accent-soft); }
.history-table .col-check { width: 32px; text-align: center; }
.history-table .col-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.history-table .col-product { text-align: left; white-space: normal; min-width: 160px; width: 30%; }
/* Fit the dialog: tighter cells, wrapping notes, shortened source links. */
.history-table th, .history-table td { padding: 8px 6px; }
.history-table .col-check { padding-left: 4px; }
.history-table .col-when { white-space: normal; min-width: 84px; }
.history-table .col-when .h-sub { line-height: 1.3; margin-top: 2px; }
.history-table .col-source a { display: inline-block; max-width: 104px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.history-table .col-actions { padding-right: 4px; }
.history-table .col-actions .chip { padding: 4px 10px; }
.history-sheet .table-wrap { overflow-x: auto; }

/* Phones: one card per product. */
@media (max-width: 900px) {
  .history-table, .history-table tbody { display: block; }
  .history-table thead { display: none; }
  .history-table tr {
    display: grid; grid-template-columns: 28px repeat(3, minmax(0, 1fr)); gap: 6px 10px; align-items: start;
    padding: 12px 4px; border-bottom: 1px solid var(--border);
  }
  .history-table td { display: block; padding: 0; border: 0; text-align: left; white-space: normal; min-width: 0; width: auto; }
  .history-table td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 1px;
  }
  .history-table .col-check { grid-column: 1; grid-row: 1; padding-top: 12px; }
  .history-table .col-product { grid-column: 2 / -1; grid-row: 1; }
  /* Rows: product / checked / buy-sale-profit / gated-verdict / source / button */
  .history-table .col-when, .history-table .col-source { grid-column: 2 / span 3; }
  .history-table td[data-label="Buy"], .history-table td[data-label="Gated"] { grid-column: 2; }
  .history-table .col-source { order: 1; }
  .history-table .col-actions { grid-column: 2 / -1; order: 2; }
  .history-table .col-actions .chip { width: 100%; }
  .history-table .col-source a { max-width: 100%; }
  .h-title { max-width: none; }
}
.h-product { display: flex; gap: 10px; align-items: center; }
.h-product img, .h-noimg { width: 40px; height: 40px; flex: none; border-radius: 6px; background: #fff; object-fit: contain; border: 1px solid var(--border); }
.h-title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 340px; }
.h-asin, .h-sub { font-size: 11px; color: var(--muted); }
.h-sub.in-sheet { color: var(--good-ink); }
.gate { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.gate-good { background: var(--good-soft); color: var(--good-ink); }
.gate-warn { background: var(--warning-soft); color: var(--warning-ink); }
.gate-bad { background: var(--critical-soft); color: var(--critical-ink); }
.gate-muted { background: var(--surface-2); color: var(--muted); }
.prev-check { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: center; margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 13px; }
.prev-check b { display: block; font-size: 13px; }
.prev-icon { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--accent); color: #fff; }
.prev-detail { color: var(--text-2); }

.asin-wrap { display: inline-flex; align-items: center; gap: 6px; }
.copy-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px;
  border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface);
  color: var(--text-2); font-size: 12px; font-weight: 600; cursor: pointer;
}
.copy-btn:hover { background: var(--surface-2); }
.copy-btn.copied { border-color: color-mix(in srgb, var(--good) 55%, transparent); color: var(--good-ink); background: var(--good-soft); }

/* Price calculator */
.calc { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 14px; border-radius: 12px; background: var(--surface-2); margin-bottom: 16px; }
.calc-price label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.calc-price-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.calc-currency { font-size: 22px; font-weight: 700; color: var(--text-2); }
.calc-price-row input { width: 130px; height: 44px; font-size: 22px; font-weight: 700; }
#calc-slider { width: 100%; margin-top: 10px; accent-color: var(--accent); }
.calc-vs { font-size: 13px; margin-top: 4px; color: var(--text-2); }
.calc-targets { display: grid; gap: 10px; align-content: center; border-top: 1px solid var(--border); padding-top: 12px; }
.calc-target { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.calc-target label { font-weight: 600; }
.calc-inline { display: inline-flex; align-items: center; gap: 3px; }
.calc-inline input { width: 72px; height: 32px; padding: 0 8px; }
.calc-arrow { color: var(--muted); }
.calc-answer { display: inline-flex; align-items: center; gap: 6px; }
.calc-answer b { font-size: 16px; }
.calc-answer .chip { padding: 1px 10px; }

/* Recommended selling price */
.reco-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.reco-units { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.reco-units input { width: 76px; height: 32px; padding: 0 8px; }
.reco-hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: start; }
@media (max-width: 640px) { .reco-hero { grid-template-columns: minmax(0, 1fr); } }
.reco-price { font-size: 38px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin-top: 2px; }
.reco-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.reco-fit { font-size: 13px; margin-top: 8px; color: var(--text-2); }
.reco-floor { display: grid; gap: 6px; background: var(--surface-2); border-radius: 10px; padding: 10px 14px; font-size: 13px; min-width: 210px; }
.reco-floor div { display: flex; justify-content: space-between; gap: 16px; }
.reco-floor b { font-variant-numeric: tabular-nums; }

.ladder { margin: 44px 4px 6px; }
.ladder-track { position: relative; height: 8px; border-radius: 999px; background: var(--surface-2); margin-top: 30px; }
.ladder-band { position: absolute; top: 0; bottom: 0; border-radius: 999px; background: color-mix(in srgb, var(--accent) 22%, transparent); }
.ladder-mark { position: absolute; top: -5px; width: 4px; height: 18px; margin-left: -2px; border-radius: 2px; background: var(--text-2); }
.ladder-mark.bb { background: var(--series-1); }
.ladder-mark.rec { background: var(--good); width: 6px; margin-left: -3px; }
.ladder-mark.be { background: var(--critical); }
.ladder-label {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font-size: 11px; color: var(--muted); text-align: center; line-height: 1.25;
}
.ladder-label b { display: block; color: var(--text); font-size: 12px; }
.ladder-mark.bb .ladder-label { bottom: auto; top: 22px; }
.ladder-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 32px; }

.strategies { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
@media (max-width: 820px) { .strategies { grid-template-columns: minmax(0, 1fr); } }
.strategy { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface); }
.strategy.is-rec { border-color: color-mix(in srgb, var(--good) 55%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--good) 35%, transparent); background: linear-gradient(160deg, var(--good-soft), var(--surface) 60%); }
.strategy-top { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 650; color: var(--text-2); }
.rec-badge { background: var(--good-soft); color: var(--good-ink); }
.strategy-price { font-size: 24px; font-weight: 700; margin-top: 4px; }
.strategy-basis { font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 2.5em; }
.strategy-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 10px 0 0; }
.strategy-stats dt { font-size: 11px; color: var(--muted); }
.strategy-stats dd { margin: 0; font-weight: 650; font-size: 14px; font-variant-numeric: tabular-nums; }
.reco-notes { margin: 14px 0 0; padding-left: 18px; font-size: 13px; color: var(--text-2); display: grid; gap: 4px; }

.inline-note {
  margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  background: var(--warning-soft); color: var(--text-2);
}
.footnote { font-size: 12px; color: var(--muted); margin-top: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 480px) {
  .card { padding: 16px; }
  .field-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .advanced-grid { grid-template-columns: minmax(0, 1fr); }
  .verdict-label { font-size: 22px; }
  .kpi-value { font-size: 20px; }
  .metric-value { font-size: 16px; }
  .tagline { display: none; }
  .share-row { grid-template-columns: minmax(0, 100px) minmax(0, 1fr) 48px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* PC vs Google (Apps Script) version wording */
.cloud-only { display: none; }
html.gas .cloud-only { display: inline; }
html.gas .pc-only { display: none !important; }

/* Sign-in screen (Cloudflare / Supabase version) */
.auth-screen {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 24px 16px;
  background: var(--page); overflow-y: auto;
}
.auth-card {
  width: min(400px, 100%); padding: 24px; border-radius: 16px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: 0 10px 40px rgba(0, 0, 0, .12);
}
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.auth-brand b { display: block; font-size: 15px; }
.auth-brand span { display: block; font-size: 12px; color: var(--muted); }
.auth-card h1 { font-size: 20px; margin: 0 0 14px; }
.auth-card .field { display: block; margin-bottom: 12px; }
.auth-card .field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text-2); }
.auth-card input { width: 100%; height: 42px; padding: 0 12px; font-size: 16px; }
.auth-msg { min-height: 1.2em; font-size: 13px; margin: 4px 0 12px; }
.auth-msg.bad { color: var(--critical-ink); }
.auth-msg.good { color: var(--good-ink); }
.auth-submit { width: 100%; height: 44px; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.account-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13px;
}
