/* ============================================================
   2Selly Components — "The Sorter"
   Composable classes built on tokens.css. Colour only ever
   carries a verdict; chrome is bone-and-ink.
   ============================================================ */

/* ---- Page scaffold ---- */
.page { background: var(--ground); color: var(--ink); font-family: var(--font-ui); min-height: 100vh; }
.page-title { font: var(--text-page-title); letter-spacing: -0.02em; }
.page-subtitle { font: 500 13px/1.4 var(--font-ui); color: var(--ink-tertiary); margin-top: 2px; }
@media (min-width: 880px) { .page-title { font: var(--text-page-title-lg); letter-spacing: -0.02em; } }

/* ---- Cards ---- */
/* border: 0 neutralises app.css's legacy bordered-card idiom (this file loads
   after app.css so the Sorter shadow-only card wins everywhere). */
.card { background: var(--surface); border: 0; border-radius: var(--radius-card); box-shadow: var(--shadow-card); overflow: hidden; }
.card--selected { box-shadow: var(--shadow-selected); }
.card--ghost { background: transparent; box-shadow: none; border: 1.5px dashed var(--ink-faint); }

/* ---- Verdict block (card mode) ----
   86px column (96px desktop) on the card's left edge. */
.verdict { width: var(--verdict-block-width); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 14px 0; flex: none; }
@media (min-width: 880px) { .verdict { width: 96px; } }
.verdict--buy { background: var(--verdict-buy); }
.verdict--risky { background: var(--verdict-risky); }
.verdict--restock { background: var(--verdict-restock); }
.verdict__value { font-size: 22px; font-weight: 900; letter-spacing: -0.02em; }
@media (min-width: 880px) { .verdict__value { font-size: 24px; } }
.verdict__label { font-size: 9px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.85; }

/* ---- Verdict badge (inline, tables/feeds) ----
   Base props live on the modifiers so legacy .badge-* pills keep app.css's
   sizing. */
.badge--buy, .badge--risky, .badge--restock, .badge--rise, .badge--minor {
  display: inline-block; text-align: center; padding: 7px 0; min-width: 52px;
  border-radius: var(--radius-badge); color: #fff; font-size: 12.5px; font-weight: 900;
  line-height: 1; font-variant-numeric: tabular-nums;
}
.badge--buy { background: var(--verdict-buy); }
.badge--risky { background: var(--verdict-risky); }
.badge--restock { background: var(--verdict-restock); }
.badge--rise { background: var(--surface-muted); color: var(--alert); }
.badge--minor { background: var(--surface-muted); color: var(--ink-secondary); }

/* ---- Dense rows (lists > ~10 items) ---- */
.dense-row { display: flex; align-items: center; gap: 10px; padding: 11px 14px 11px 20px; background: var(--surface); border-bottom: 1px solid var(--divider); min-height: var(--tap-target); }
.dense-row:nth-child(even) { background: var(--surface-alt); }
.dense-row__spine { width: var(--spine-width); align-self: stretch; border-radius: var(--radius-spine); flex: none; background: transparent; }
.dense-row__spine--buy { background: var(--verdict-buy); }
.dense-row__spine--risky { background: var(--verdict-risky); }
.dense-row__spine--restock { background: var(--verdict-restock); }
.dense-row__title { font: var(--text-row-title); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dense-row__meta { font: var(--text-meta); color: var(--ink-tertiary); margin-top: 1px; }
.dense-row__nums { display: flex; gap: 12px; align-items: baseline; font-variant-numeric: tabular-nums; flex: none; }
/* Fixed-width numeric cells; right-aligned */
.num { text-align: right; font-weight: 800; font-size: 13px; font-variant-numeric: tabular-nums; }
.num--profit { color: var(--verdict-buy-ink); width: 34px; font-size: 12px; }
.num--velocity { color: var(--ink-tertiary); font-weight: 600; width: 30px; font-size: 11px; }

/* ---- Sticky group headers ---- */
.group-header { position: sticky; top: 0; z-index: 2; background: var(--ground); padding: 14px 20px 6px; font: var(--text-section); letter-spacing: var(--tracking-section); text-transform: uppercase; color: var(--ink-faint); border-bottom: 1.5px solid var(--ink); display: flex; justify-content: space-between; }
.group-header--buy { color: var(--verdict-buy-ink); }
.group-header--risky { color: var(--verdict-risky-ink); }
.group-header--restock { color: var(--verdict-restock-ink); }

/* ---- Filter chips ---- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 7px 13px; border-radius: var(--radius-chip); background: var(--surface-muted); color: var(--ink-secondary); font: var(--text-chip); border: none; cursor: pointer; }
.chip[aria-pressed="true"], .chip--active { background: var(--ink); color: var(--ground); font-weight: 700; }

/* ---- Stat cards (dashboard) ---- */
.stat-card { background: var(--surface); border: 0; border-radius: var(--radius-card); padding: 16px 18px; box-shadow: var(--shadow-card); }
.stat-card--primary { background: var(--ink); color: var(--ground); }
.stat-card__value { font: var(--text-stat); letter-spacing: -0.02em; }
.stat-card__label { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); margin-top: 2px; }
.stat-card--primary .stat-card__label,
.stat-card--primary .stat-card__note { color: color-mix(in srgb, var(--ground) 70%, transparent); }
.stat-card__note { font-size: 12px; font-weight: 600; margin-top: 8px; color: var(--ink-tertiary); }

/* ---- Panel (dashboard widget) ---- */
.panel { background: var(--surface); border: 0; border-radius: var(--radius-card); box-shadow: var(--shadow-card); display: flex; flex-direction: column; overflow: hidden; }
.panel__header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px 10px; border-bottom: 2px solid var(--ink); font: var(--text-section); letter-spacing: 0.08em; text-transform: uppercase; flex: none; }
.panel__header a { color: var(--ink-faint); text-decoration: none; font-weight: 700; letter-spacing: 0; text-transform: none; font-size: 12px; }
.panel__header a:hover { color: var(--ink); }

/* ---- Desktop nav rail (primary navigation ≥880px) ----
   Two clusters: the 5 primary pages, then a compact cluster referencing every
   other page so nothing lives only behind the drawer. Scrolls on short
   viewports (scrollbar hidden). */
.rail { display: none; width: var(--rail-width); background: var(--ink); color: var(--ground); flex-direction: column; align-items: center; padding: 16px 0; gap: 5px; flex: none; position: sticky; top: 0; height: 100vh; z-index: var(--z-topbar); overflow-y: auto; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail__logo { width: 40px; height: 40px; border-radius: 12px; background: var(--ground); color: var(--ink); display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 900; margin-bottom: 10px; flex: none; text-decoration: none; }
.rail__item { width: 52px; padding: 9px 0; border-radius: var(--radius-control); display: flex; flex-direction: column; align-items: center; gap: 3px; color: #7d7a70; font-size: 9px; font-weight: 600; cursor: pointer; text-decoration: none; border: none; background: none; font-family: var(--font-ui); flex: none; }
.rail__item i { font-size: 15px; }
.rail__item:hover { color: var(--ground); }
.rail__item.active, .rail__item--active { background: rgba(242, 241, 236, 0.14); color: var(--ground); font-weight: 700; }
.rail__item--sm { padding: 6px 0; gap: 2px; font-size: 8px; }
.rail__item--sm i { font-size: 13px; }
.rail__divider { width: 34px; height: 1px; background: rgba(242, 241, 236, 0.18); margin: 7px 0 6px; flex: none; }
.rail__spacer { flex: 1; min-height: 6px; }
[data-theme="dark"] .rail { background: var(--surface); border-right: 1px solid var(--divider-strong); }
[data-theme="dark"] .rail__item.active { background: rgba(242, 241, 236, 0.1); }
[data-theme="dark"] .rail__logo { background: var(--ink); color: var(--ground); }

/* ---- Off-canvas drawer (More / Admin navigation) ----
   Mobile: opened from the tab bar's More. Desktop: opened from the rail's
   Admin item. Holds every secondary page + theme/account. */
.sidebar {
  width: var(--sidebar-w); background: var(--surface);
  display: flex; flex-direction: column; flex: none;
  position: fixed; inset: 0 auto 0 0; z-index: var(--z-sidebar);
  transform: translateX(-100%); transition: transform var(--t);
  border-right: 1px solid var(--divider-strong);
}
.sidebar__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 16px 10px; }
.sidebar__brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; font-size: 15.5px; letter-spacing: -.01em; text-decoration: none; }
.sidebar__logo { width: 32px; height: 32px; border-radius: 10px; flex: none; display: grid; place-items: center; font-family: var(--font-ui); font-weight: 900; font-size: 13px; color: var(--ground); background: var(--ink); }
.sidebar__word { white-space: nowrap; }
.sidebar__close { flex: none; width: 30px; height: 30px; border: none; background: none; color: var(--ink-faint); border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
.sidebar__close:hover { background: var(--surface-muted); color: var(--ink); }

.sidebar__search { margin: 2px 14px 6px; width: calc(100% - 28px); display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: var(--radius-control); background: var(--surface-muted); border: none; color: var(--ink-tertiary); font: var(--text-chip); cursor: pointer; }
.sidebar__search:hover { color: var(--ink); }
.sidebar__search kbd { margin-left: auto; font: 700 10.5px var(--font-ui); background: var(--surface); border-radius: 5px; padding: 2px 6px; color: var(--ink-faint); }

.sidebar__nav { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 14px 10px; }
.navgroup { margin-top: 12px; }
.navgroup:first-child { margin-top: 4px; }
.navgroup__toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px 7px; border: none; border-radius: var(--radius-chip); background: transparent; color: var(--ink-faint); font: var(--text-section); letter-spacing: var(--tracking-section); text-align: left; text-transform: uppercase; cursor: pointer; }
.navgroup__toggle:hover { background: var(--surface-alt); color: var(--ink-secondary); }
.navgroup__toggle i { font-size: 11px; transition: transform var(--t); }
.navgroup.is-collapsed .navgroup__toggle i { transform: rotate(-90deg); }
.navgroup__links { display: grid; gap: 1px; overflow: hidden; }
.navgroup.is-collapsed .navgroup__links { display: none; }
.navlink { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: var(--radius-chip); color: var(--ink-secondary); font-size: 13.5px; font-weight: 600; white-space: nowrap; text-decoration: none; }
.navlink i { font-size: 15px; width: 18px; text-align: center; flex: none; color: var(--ink-faint); }
.navlink:hover { background: var(--surface-alt); color: var(--ink); }
.navlink.active { background: var(--ink); color: var(--ground); font-weight: 700; }
.navlink.active i { color: var(--ground); }

.sidebar__foot { border-top: 1px solid var(--divider); padding: 9px 14px calc(9px + env(safe-area-inset-bottom)); }
.sidebar__account { position: relative; }
.sidebar__account-trigger { width: 100%; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 7px 8px; border: 1px solid transparent; border-radius: 11px; background: transparent; color: var(--ink); cursor: pointer; text-align: left; transition: background var(--t), border-color var(--t), transform var(--t); }
.sidebar__account-trigger:hover, .sidebar__account-trigger[aria-expanded="true"] { background: var(--surface-alt); border-color: var(--divider); }
.sidebar__account-trigger[aria-expanded="true"] { transform: translateY(-1px); }
.sidebar__avatar { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; color: var(--ground); background: var(--ink); font: 800 12px/1 var(--font-ui); letter-spacing: -.03em; }
.sidebar__account-copy { min-width: 0; display: grid; gap: 2px; flex: 1; }
.sidebar__account-copy strong, .sidebar__account-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__account-copy strong { color: var(--ink); font: 700 12.5px/1.1 var(--font-ui); }
.sidebar__account-copy small { color: var(--ink-faint); font: 500 10.5px/1.15 var(--font-ui); }
.sidebar__account-chevron { color: var(--ink-faint); font-size: 12px; transition: transform var(--t), color var(--t); }
.sidebar__account-trigger[aria-expanded="true"] .sidebar__account-chevron { transform: rotate(180deg); color: var(--ink); }

/* Account popover: deliberately anchored to the bottom-left identity control,
   so it feels like an extension of the sidebar rather than a floating modal. */
.account-menu { position: absolute; z-index: calc(var(--z-sidebar) + 2); bottom: calc(100% + 10px); left: 0; right: 0; padding: 8px; border: 1px solid var(--divider-strong); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-lg); transform-origin: bottom left; animation: account-menu-in .16s ease-out; }
.account-menu[hidden] { display: none; }
.account-menu__identity { display: flex; align-items: center; gap: 10px; padding: 7px 6px 11px; border-bottom: 1px solid var(--divider); }
.account-menu__avatar { width: 34px; height: 34px; border-radius: 10px; }
.account-menu__identity div { min-width: 0; display: grid; gap: 2px; }
.account-menu__identity strong, .account-menu__identity small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu__identity strong { font: 750 12.5px/1.15 var(--font-ui); color: var(--ink); }
.account-menu__identity small { font: 500 10.5px/1.15 var(--font-ui); color: var(--ink-faint); }
.account-menu__section { padding: 10px 6px 8px; }
.account-menu__label { display: block; margin-bottom: 7px; color: var(--ink-faint); font: var(--text-section); letter-spacing: var(--tracking-section); text-transform: uppercase; }
.account-menu__themes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 3px; border-radius: 9px; background: var(--surface-muted); }
.account-menu__themes button { min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 7px 5px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ink-faint); font: 700 11px/1 var(--font-ui); cursor: pointer; transition: background var(--t), color var(--t), box-shadow var(--t); }
.account-menu__themes button:hover { color: var(--ink-secondary); }
.account-menu__themes button.is-active { background: var(--surface); border-color: var(--divider); box-shadow: var(--shadow-sm); color: var(--ink); }
.account-menu__themes button i { font-size: 12px; }
.account-menu__action { width: 100%; display: flex; align-items: center; gap: 9px; padding: 9px 7px; border-radius: 8px; color: var(--ink-secondary); font: 700 12px/1 var(--font-ui); text-decoration: none; }
.account-menu__action:hover { background: var(--surface-alt); color: var(--ink); }
.account-menu__action > i:first-child { width: 15px; text-align: center; color: var(--ink-faint); }
.account-menu__action > i:last-child { margin-left: auto; color: var(--ink-faint); font-size: 11px; }
.account-menu__action--quiet { margin-top: 2px; border-top: 1px solid var(--divider); border-radius: 0 0 8px 8px; color: var(--ink-faint); }
@keyframes account-menu-in { from { opacity: 0; transform: translateY(5px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.sidebar__backdrop { position: fixed; inset: 0; background: rgba(25, 25, 20, .4); z-index: calc(var(--z-sidebar) - 1); opacity: 0; pointer-events: none; transition: opacity var(--t); }

/* ---- Mobile tab bar ---- */
.tabbar { display: flex; background: var(--surface); border-top: 1px solid var(--divider-strong); padding: 10px 8px calc(10px + env(safe-area-inset-bottom)); }
.tabbar__item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--ink-faint); font: 600 10px/1 var(--font-ui); min-height: var(--tap-target); cursor: pointer; border: none; background: none; padding: 4px 0; text-decoration: none; }
.tabbar__item i { font-size: 17px; }
.tabbar__item--active, .tabbar__item.active { color: var(--ink); font-weight: 700; }

/* ---- Buttons ----
   Base props live on the modifiers so legacy .btn/.btn-sm/.btn-primary
   controls keep app.css's sizing. */
.btn--primary, .btn--secondary, .btn--danger {
  padding: 13px 20px; border-radius: var(--radius-control); font: 800 13px/1 var(--font-ui);
  text-align: center; justify-content: center; border: none; cursor: pointer; min-height: var(--tap-target);
}
.btn--primary { background: var(--ink); color: var(--ground); }
.btn--primary:hover { background: var(--primary-hover); color: var(--ground); }
.btn--secondary { background: transparent; border: 1.5px solid var(--divider-strong); color: var(--ink-tertiary); }
.btn--secondary:hover { color: var(--ink); border-color: var(--border-strong); background: transparent; }
/* Destructive: ink-weight type, alert only on the edge until hover. */
.btn--danger { background: transparent; border: 1.5px solid var(--divider-strong); color: var(--ink-tertiary); }
.btn--danger:hover { color: var(--alert); border-color: var(--alert); background: transparent; }
.btn--danger[disabled] { opacity: .45; cursor: default; }
.btn--danger[disabled]:hover { color: var(--ink-tertiary); border-color: var(--divider-strong); }

/* Toolbar-sized action buttons (page heads, detail panes). */
.btn--sm {
  min-height: 36px; padding: 9px 14px; border-radius: var(--radius-chip);
  font: 700 12px/1 var(--font-ui); display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; white-space: nowrap;
}
.btn--sm i { font-size: 13px; }
/* A toggle that is currently on (e.g. Watch → Watching). */
.btn--on { background: var(--primary-soft); border-color: var(--primary-border); color: var(--ink); }
.btn--on:hover { color: var(--ink); border-color: var(--ink); }

/* ---- App shell / responsive scaffold ----
   Mobile-first: content is full width with a bottom tab bar; the More tab
   opens the drawer. At >=880px the full navigation sidebar is permanently
   visible, so the active page is readable at a glance. */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; background: var(--ground); color: var(--ink); font-family: var(--font-ui); }
.app-body { flex: 1; min-width: 0; display: flex; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: var(--z-topbar); }
.detail-pane { display: none; }                       /* desktop-only */

/* Drawer open (any width) */
.app-shell.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
.app-shell.nav-open .sidebar__backdrop { opacity: 1; pointer-events: auto; }

@media (min-width: 880px) {
  .app-main { padding-bottom: 0; }
  .rail { display: none; }
  .tabbar { display: none; }
  .sidebar { position: sticky; inset: auto; top: 0; height: 100vh; transform: none; box-shadow: none; }
  .sidebar__close, .sidebar__backdrop { display: none; }
  .app-shell.nav-open .sidebar { box-shadow: none; }
  .detail-pane { display: flex; flex-direction: column; width: var(--detail-pane-width); flex: none; background: var(--surface); border-left: 1px solid var(--divider-strong); }
}

/* ---- Command-palette trigger chip (in-page header) ---- */
.cmdk-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: var(--radius-chip); background: var(--surface-muted); border: none; color: var(--ink-secondary); font: 700 12px/1 var(--font-ui); cursor: pointer; }
.cmdk-chip:hover { color: var(--ink); }
.cmdk-chip .kbd { font-size: 11px; color: var(--ink-faint); }

/* ---- Content column padding ---- */
.content-col { flex: 1; min-width: 0; padding: 18px 16px 0; }
@media (min-width: 880px) { .content-col { padding: 26px 28px 24px; } }

/* ---- Standard page wrapper ----
   Every page's <main class="app-content"> gets the same page gutter + max
   width as .content-col. Full-bleed two-column shells (Deals) opt out. */
.app-content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 18px 16px 0; }
.app-content:has(.deals-desktop), .app-content:has(.deals-mobile),
.app-content:has(.bleed) { max-width: none; padding: 0; }
@media (min-width: 880px) { .app-content { padding: 26px 28px 24px; } }

/* ---- Prices/deals tables (desktop) ---- */
.table__head { display: grid; align-items: center; padding: 11px 18px; border-bottom: 2px solid var(--ink); font: 800 10px/1 var(--font-ui); letter-spacing: var(--tracking-section); text-transform: uppercase; color: var(--ink-faint); }
.table__row { display: grid; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--divider); font-variant-numeric: tabular-nums; }
/* Grid columns are per-page; keep the 1fr name column >= 260px. */

/* ---- Sparklines ---- */
.spark { display: block; flex: none; }
.spark polyline { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.spark--rise polyline { stroke: var(--alert); }

/* ---- Status pill (header, e.g. "28/30 scrapers ok") ---- */
.status-pill { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-card); font: 700 12px/1 var(--font-ui); color: var(--ink); text-decoration: none; white-space: nowrap; }
.status-pill__dot { width: 8px; height: 8px; border-radius: 99px; background: var(--verdict-buy); flex: none; }
.status-pill--warn .status-pill__dot { background: var(--warn); }
.status-pill--bad .status-pill__dot { background: var(--alert); }

/* ---- Ghost expander row ("n hidden · show ›") ---- */
.ghost-row { border: 1.5px dashed var(--border-strong); border-radius: var(--radius-card); padding: 13px 18px; display: flex; justify-content: space-between; align-items: center; background: transparent; width: 100%; cursor: pointer; font-family: var(--font-ui); }
.ghost-row__label { font-size: 12.5px; color: var(--ink-tertiary); font-weight: 500; }
.ghost-row__cta { font-size: 12.5px; font-weight: 800; color: var(--ink); }
