:root{
  color-scheme: light;
  --paper:#efefef; --surface:#ffffff; --surface-2:#f4f4f2;
  --ink:#1c1c1c; --ink-soft:#54534f; --muted:#83817c;
  --line:#dcdbd7; --line-strong:#c7c5c0;
  --accent:#c93a08; --accent-ink:#ffffff; --accent-soft:#fde4d8; --accent-strong:#a83309;
  --accent-bright:#ff4a0a;
  --brass:#a9791f; --brass-soft:#f3e9d2;
  --good:#0ca30c; --good-soft:#e3f5e3; --warning:#c98500; --warning-soft:#fdefd4; --critical:#d03b3b; --critical-soft:#fbe6e6;
  --cat-1:#1baf7a; --cat-2:#2a78d6; --cat-3:#c99a2e; --cat-4:#8a8985;
  --trend-revenue:#6b6b66; --trend-profit:var(--accent-bright);
  --shadow: 0 1px 2px rgba(28,28,28,0.06), 0 8px 24px rgba(28,28,28,0.08);
  --radius: 12px; --radius-sm: 8px;
  --font-ui: 'Manrope', system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    color-scheme: dark;
    --paper:#141413; --surface:#1e1e1c; --surface-2:#242422;
    --ink:#f2f1ee; --ink-soft:#c9c7c2; --muted:#928f89;
    --line:#302f2c; --line-strong:#3d3c38;
    --accent:#ff8255; --accent-ink:#1c0d03; --accent-soft:rgba(255,130,85,0.16); --accent-strong:#ffa07a;
    --accent-bright:#ff6a3a;
    --brass:#d9ab3e; --brass-soft:rgba(217,171,62,0.14);
    --good:#3fc23f; --good-soft:rgba(63,194,63,0.14); --warning:#e0a835; --warning-soft:rgba(224,168,53,0.14); --critical:#e66767; --critical-soft:rgba(230,103,103,0.14);
    --cat-1:#199e70; --cat-2:#3987e5; --cat-3:#dcb44e; --cat-4:#9a9994;
    --trend-revenue:#9a9994; --trend-profit:var(--accent-bright);
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"]{
  color-scheme: dark;
  --paper:#141413; --surface:#1e1e1c; --surface-2:#242422;
  --ink:#f2f1ee; --ink-soft:#c9c7c2; --muted:#928f89;
  --line:#302f2c; --line-strong:#3d3c38;
  --accent:#ff8255; --accent-ink:#1c0d03; --accent-soft:rgba(255,130,85,0.16); --accent-strong:#ffa07a;
  --accent-bright:#ff6a3a;
  --brass:#d9ab3e; --brass-soft:rgba(217,171,62,0.14);
  --good:#3fc23f; --good-soft:rgba(63,194,63,0.14); --warning:#e0a835; --warning-soft:rgba(224,168,53,0.14); --critical:#e66767; --critical-soft:rgba(230,103,103,0.14);
  --cat-1:#199e70; --cat-2:#3987e5; --cat-3:#dcb44e; --cat-4:#9a9994;
  --trend-revenue:#9a9994; --trend-profit:var(--accent-bright);
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
}

*,*::before,*::after{ box-sizing:border-box; }
[hidden]{ display:none !important; }
html,body{ height:auto; }
body{
  margin:0; background:var(--paper); color:var(--ink);
  font-family:var(--font-ui); font-size:15px; line-height:1.45;
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3{ font-family:var(--font-ui); font-weight:800; letter-spacing:-0.01em; text-wrap:balance; margin:0; }
button,input,select,textarea{ font-family:inherit; font-size:inherit; color:inherit; }
button{ cursor:pointer; }
.num{ font-variant-numeric:tabular-nums; font-feature-settings:"tnum" 1; }
.mono{ font-family:var(--font-mono); }
.muted{ color:var(--muted); }
.visually-hidden{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); }
:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; border-radius:4px; }

/* ---------- auth pages ---------- */
.auth-body{
  min-height:100vh; display:flex; flex-direction:column; align-items:center; justify-content:center; padding:24px;
}
.auth-card{
  width:100%; max-width:380px; background:var(--surface); border:1px solid var(--line);
  border-radius:16px; box-shadow:var(--shadow); padding:32px 28px;
}
.auth-brand{ margin-bottom:22px; }
.auth-card h1{ font-size:22px; margin-bottom:2px; }
.auth-sub{ font-size:13.5px; margin-bottom:20px; }
.auth-error{
  background:var(--critical-soft); color:var(--critical); border-radius:8px; padding:10px 12px;
  font-size:13px; font-weight:600; margin-bottom:16px;
}
.auth-form{ display:flex; flex-direction:column; gap:14px; }
.auth-submit{ width:100%; justify-content:center; margin-top:4px; padding:11px; font-size:14.5px; }
.auth-hint{ margin-top:18px; font-size:12px; color:var(--muted); text-align:center; }

/* ---------- layout shell ---------- */
.topbar{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; gap:14px; flex-wrap:wrap;
  padding:14px 22px; background:var(--surface);
  border-bottom:1px solid var(--line);
}
@media (max-width:720px){
  .topbar{ padding:12px 16px; }
  .topbar-actions{ width:100%; justify-content:flex-end; margin-left:0; }
  .brand-name{ display:none; }
  .topbar .tabs{ display:none; }
  body{ padding-bottom:calc(64px + env(safe-area-inset-bottom, 0px)); }
}
.brand{ display:flex; align-items:center; gap:10px; margin-right:8px; }
.brand-mark{
  width:34px; height:34px; border-radius:9px; flex:none; overflow:hidden;
  border:1px solid var(--line); box-shadow:var(--shadow); background:var(--surface-2);
}
.brand-mark img{ display:block; width:100%; height:100%; object-fit:cover; }
.auth-brand .brand-mark{ width:44px; height:44px; border-radius:11px; }
.auth-brand .brand-name{ white-space:normal; font-size:16px; line-height:1.2; }
.brand-name{ font-weight:800; font-size:17px; letter-spacing:-0.01em; white-space:nowrap; }
.tabs{ display:flex; gap:4px; background:var(--surface-2); padding:4px; border-radius:10px; }
.tab{
  border:none; background:transparent; padding:8px 16px; border-radius:7px; font-weight:700;
  color:var(--ink-soft); font-size:14px;
}
.tab.active{ background:var(--surface); color:var(--ink); box-shadow:var(--shadow); }
.topbar-actions{ margin-left:auto; display:flex; align-items:center; gap:10px; }
.status-badge{
  font-size:12px; font-weight:700; padding:5px 10px; border-radius:999px;
  background:var(--warning-soft); color:var(--warning); border:1px solid transparent;
}
.btn{
  border-radius:9px; padding:9px 15px; font-weight:700; font-size:14px; border:1px solid transparent;
  display:inline-flex; align-items:center; gap:6px; white-space:nowrap; transition:background .12s ease;
}
.btn-accent{ background:var(--accent); color:var(--accent-ink); }
.btn-accent:hover{ background:var(--accent-strong); }
.btn-ghost{ background:var(--surface-2); color:var(--ink); border-color:var(--line); }
.btn-ghost:hover{ background:var(--line); }
.btn-danger{ background:var(--critical); color:#fff; }
.btn-danger-ghost{ background:transparent; color:var(--critical); border-color:var(--critical); }
.btn:disabled{ opacity:.5; cursor:not-allowed; }
.icon-btn{
  border:none; background:transparent; width:32px; height:32px; border-radius:8px;
  display:flex; align-items:center; justify-content:center; color:var(--muted); font-size:16px;
}
.icon-btn:hover{ background:var(--surface-2); color:var(--ink); }

.account-menu{ position:relative; }
.account-btn{
  display:flex; align-items:center; gap:8px; background:var(--surface-2); border:1px solid var(--line);
  border-radius:9px; padding:7px 12px 7px 8px; font-weight:700; font-size:13.5px;
}
.account-btn:hover{ background:var(--line); }
.account-avatar{
  width:24px; height:24px; border-radius:50%; background:var(--accent); color:var(--accent-ink);
  display:flex; align-items:center; justify-content:center; font-size:11px; font-weight:800; flex:none;
  text-transform:uppercase;
}
.account-dropdown{
  position:absolute; right:0; top:calc(100% + 8px); background:var(--surface); border:1px solid var(--line);
  border-radius:12px; box-shadow:var(--shadow); min-width:190px; padding:6px; z-index:50;
}
.account-dropdown[hidden]{ display:none; }
.account-dropdown button{
  display:flex; width:100%; text-align:left; background:none; border:none; padding:9px 10px; border-radius:7px;
  font-weight:600; font-size:13.5px; color:var(--ink);
}
.account-dropdown button:hover{ background:var(--surface-2); }
.account-dropdown button.danger{ color:var(--critical); }

main.view{ max-width:1240px; margin:0 auto; padding:28px 22px 64px; }
main.view[hidden]{ display:none; }

/* ---------- dashboard ---------- */
.section-heading{ display:flex; align-items:baseline; justify-content:space-between; margin:0 0 14px; }
.section-heading h2{ font-size:15px; text-transform:uppercase; letter-spacing:.06em; color:var(--ink-soft); }
.stat-grid{
  display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:12px; margin-bottom:28px;
}
.stat-tile{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  padding:16px 18px; box-shadow:var(--shadow);
}
.stat-tile .label{ font-size:11.5px; font-weight:700; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); margin-bottom:8px; }
.stat-tile .value{ font-size:26px; font-weight:800; letter-spacing:-0.02em; }
.stat-tile .value.small{ font-size:22px; }
.stat-tile .sub{ font-size:12.5px; color:var(--muted); margin-top:4px; }
.stat-tile .value.good{ color:var(--good); }
.stat-tile .value.critical{ color:var(--critical); }

.chart-grid{ display:grid; grid-template-columns:1.15fr 0.85fr; gap:16px; margin-bottom:16px; }
.chart-grid.two{ grid-template-columns:1fr 1fr; }
@media (max-width:860px){ .chart-grid, .chart-grid.two{ grid-template-columns:1fr; } }
.card{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  padding:18px 20px 16px; box-shadow:var(--shadow);
}
.card h3{ font-size:14px; font-weight:700; margin-bottom:2px; }
.card .card-sub{ font-size:12.5px; color:var(--muted); margin-bottom:14px; }
.legend{ display:flex; gap:14px; flex-wrap:wrap; margin-bottom:10px; }
.legend-item{ display:flex; align-items:center; gap:6px; font-size:12.5px; color:var(--ink-soft); font-weight:600; }
.legend-dot{ width:9px; height:9px; border-radius:2.5px; flex:none; }
.empty-note{ color:var(--muted); font-size:13px; padding:18px 2px; }

.owner-list{ display:flex; flex-direction:column; gap:10px; }
.owner-row{ display:grid; grid-template-columns:90px 1fr auto; align-items:center; gap:10px; }
.owner-row .owner-name{ font-weight:700; font-size:13px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.owner-row .owner-bar-track{ height:8px; border-radius:5px; background:var(--surface-2); overflow:hidden; }
.owner-row .owner-bar-fill{ height:100%; border-radius:5px; background:var(--accent); }
.owner-row .owner-value{ font-family:var(--font-mono); font-size:12.5px; font-weight:600; }

/* ---------- charts (svg) ---------- */
.bars{ display:flex; flex-direction:column; gap:10px; }
.bar-row{ display:grid; grid-template-columns:96px 1fr 74px; align-items:center; gap:10px; }
.bar-row .bar-label{ font-size:12.5px; font-weight:600; color:var(--ink-soft); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.bar-track{ height:16px; border-radius:4px; background:var(--surface-2); position:relative; overflow:hidden; }
.bar-fill{ position:absolute; left:0; top:0; height:100%; border-radius:4px; min-width:3px; cursor:pointer; }
.bar-row .bar-value{ font-family:var(--font-mono); font-size:12.5px; text-align:right; }

.linechart-wrap{ position:relative; }
.linechart-wrap svg{ display:block; width:100%; height:auto; overflow:visible; }
.chart-tooltip{
  position:fixed; pointer-events:none; z-index:200; background:var(--ink); color:var(--paper);
  padding:7px 10px; border-radius:7px; font-size:12px; line-height:1.4; box-shadow:var(--shadow);
  transform:translate(-50%,-115%); white-space:nowrap; opacity:0; transition:opacity .08s ease;
}
.chart-tooltip.visible{ opacity:1; }
.chart-tooltip .tt-title{ font-weight:700; margin-bottom:2px; }

/* ---------- stock view ---------- */
.toolbar{ display:flex; gap:10px; align-items:center; margin-bottom:16px; flex-wrap:wrap; }
.toolbar input[type="text"], .toolbar select{
  background:var(--surface); border:1px solid var(--line); border-radius:8px; padding:9px 12px; color:var(--ink);
}
.toolbar input[type="text"]{ flex:1; min-width:200px; }
.toolbar select{ min-width:130px; }
.toolbar .result-count{ font-size:12.5px; color:var(--muted); margin-left:auto; white-space:nowrap; }

.table-wrap{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  box-shadow:var(--shadow); overflow-x:auto;
}
table{ border-collapse:collapse; width:100%; min-width:1760px; }
td.notes-cell{ max-width:220px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
thead th{
  position:sticky; top:0; background:var(--surface); text-align:left; font-size:11px; font-weight:700;
  text-transform:uppercase; letter-spacing:.05em; color:var(--muted); padding:11px 14px; border-bottom:1px solid var(--line);
  white-space:nowrap; cursor:pointer; user-select:none;
}
thead th:hover{ color:var(--ink-soft); }
thead th.sorted{ color:var(--accent); }
thead th .arrow{ font-size:10px; margin-left:3px; }
tbody td{ padding:10px 14px; border-bottom:1px solid var(--line); font-size:13.5px; vertical-align:middle; }
tbody tr{ cursor:pointer; }
tbody tr:hover td{ background:var(--surface-2); }
tbody tr:last-child td{ border-bottom:none; }
td.sku{ font-family:var(--font-mono); color:var(--ink-soft); }
td.num{ text-align:right; }
.pill{
  display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:999px;
  font-size:11.5px; font-weight:700; white-space:nowrap; flex:none;
}
.pill-sold{ background:var(--good-soft); color:var(--good); }
.pill-stock{ background:var(--accent-soft); color:var(--accent); }
.platform-tag{ display:inline-flex; align-items:center; gap:6px; font-weight:600; }
.platform-dot{ width:8px; height:8px; border-radius:50%; flex:none; }
.row-action{ opacity:0; }
tbody tr:hover .row-action, tbody tr:focus-within .row-action{ opacity:1; }

/* ---------- modals ---------- */
.modal-overlay{
  position:fixed; inset:0; background:rgba(10,12,15,0.45); display:flex; align-items:flex-start;
  justify-content:center; padding:5vh 16px; z-index:100; overflow-y:auto;
}
.modal-overlay[hidden]{ display:none; }
.modal{
  background:var(--surface); border-radius:14px; width:100%; max-width:560px; box-shadow:var(--shadow);
  border:1px solid var(--line);
}
.modal-sm{ max-width:400px; }
.modal-header{ display:flex; align-items:center; justify-content:space-between; padding:18px 20px 4px; }
.modal-header h2{ font-size:18px; }
.modal-body{ padding:14px 20px 4px; }
.modal-footer{ display:flex; align-items:center; gap:10px; padding:16px 20px 20px; }
.spacer{ flex:1; }
.sku-preview{
  font-family:var(--font-mono); font-size:12.5px; color:var(--accent); background:var(--accent-soft);
  display:inline-block; padding:5px 10px; border-radius:7px; margin-bottom:14px; font-weight:600;
}
.form-grid{ display:grid; grid-template-columns:1fr 1fr; gap:12px 12px; margin-bottom:6px; }
.field{ display:flex; flex-direction:column; gap:5px; }
.field.span-2{ grid-column:1 / -1; }
.field label{ font-size:12px; font-weight:700; color:var(--ink-soft); }
.field input, .field select, .field textarea{
  background:var(--surface-2); border:1px solid var(--line); border-radius:8px; padding:9px 11px; color:var(--ink); width:100%;
}
.field textarea{ resize:vertical; min-height:56px; font-family:inherit; }
.field .hint{ font-size:11px; color:var(--muted); }
.derived-row{
  display:flex; gap:18px; margin:8px 0 14px; padding:11px 13px; background:var(--surface-2); border-radius:9px;
}
.derived-item .label{ font-size:11px; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; margin-bottom:2px; }
.derived-item .value{ font-family:var(--font-mono); font-weight:700; font-size:14px; }
.switch-row{ display:flex; align-items:center; gap:9px; margin:14px 0 4px; cursor:pointer; font-weight:700; font-size:13.5px; }
.switch{
  width:38px; height:22px; border-radius:999px; background:var(--line-strong); position:relative; flex:none;
  transition:background .15s ease;
}
.switch::after{
  content:""; position:absolute; width:16px; height:16px; border-radius:50%; background:var(--surface);
  top:3px; left:3px; transition:transform .15s ease; box-shadow:0 1px 2px rgba(0,0,0,.3);
}
#soldToggle:checked + .switch-row .switch{ background:var(--good); }
#soldToggle:checked + .switch-row .switch::after{ transform:translateX(16px); }
#soldToggle{ position:absolute; opacity:0; width:38px; height:22px; margin:0; cursor:pointer; }
.switch-wrap{ position:relative; display:inline-flex; }

/* ---------- toast ---------- */
.toast{
  position:fixed; bottom:22px; left:50%; transform:translateX(-50%); background:var(--ink); color:var(--paper);
  padding:11px 18px; border-radius:9px; font-size:13.5px; font-weight:600; box-shadow:var(--shadow); z-index:300;
}
.toast[hidden]{ display:none; }

/* ---------- settings ---------- */
.settings-card{ max-width:460px; }
.segmented{
  display:inline-flex; gap:4px; background:var(--surface-2); padding:4px; border-radius:10px;
}
.segmented-btn{
  border:none; background:transparent; padding:9px 18px; border-radius:7px; font-weight:700;
  color:var(--ink-soft); font-size:13.5px;
}
.segmented-btn.active{ background:var(--surface); color:var(--ink); box-shadow:var(--shadow); }

/* ---------- pagination ---------- */
.pagination{
  display:flex; align-items:center; justify-content:center; gap:16px; margin-top:16px;
}
.pagination-status{ font-size:12.5px; color:var(--muted); font-weight:600; min-width:120px; text-align:center; }
.pagination[hidden]{ display:none; }

/* ---------- mobile stock cards ---------- */
.stock-cards{ display:none; flex-direction:column; gap:10px; }
.stock-card{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  box-shadow:var(--shadow); padding:13px 15px; cursor:pointer;
}
.stock-card-top{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:6px; }
.stock-card-sku{ font-family:var(--font-mono); font-size:12px; color:var(--ink-soft); font-weight:600; }
.stock-card-desc{ font-weight:700; font-size:14.5px; margin-bottom:8px; line-height:1.3; }
.stock-card-meta{ display:flex; flex-wrap:wrap; gap:6px 14px; font-size:12.5px; color:var(--ink-soft); margin-bottom:6px; }
.stock-card-meta .meta-label{ color:var(--muted); margin-right:3px; }
.stock-card-meta .num{ font-family:var(--font-mono); }
.stock-card-notes{ font-size:12px; color:var(--muted); margin-top:4px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.stock-card-actions{ margin-top:10px; }
.stock-card-actions .row-action{ opacity:1; }

@media (max-width:860px){
  .stock-table-wrap{ display:none; }
  .stock-cards{ display:flex; }
}

/* ---------- bottom mobile nav ---------- */
.bottom-nav{
  display:none; position:fixed; left:0; right:0; bottom:0; z-index:40;
  background:var(--surface); border-top:1px solid var(--line);
  padding:6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  align-items:stretch; justify-content:space-around; gap:2px;
  box-shadow:0 -1px 2px rgba(28,28,28,0.06), 0 -8px 24px rgba(28,28,28,0.06);
}
.bottom-nav .tab{
  flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px;
  padding:6px 4px; border-radius:9px; font-size:10.5px; font-weight:700; color:var(--muted);
}
.bottom-nav .tab.active{ color:var(--accent); background:var(--accent-soft); }
.bottom-nav-icon{ font-size:19px; line-height:1; }
@media (max-width:720px){
  .bottom-nav{ display:flex; }
}

/* ---------- footer ---------- */
.app-footer{
  text-align:center; font-size:11.5px; color:var(--muted); padding:18px 16px 22px;
}
.app-footer-auth{ margin-top:16px; padding:0; }

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