/* Amazon Checker — design tokens + base styles (08-ui-ux.md).
   No build step by design (matches the Chart.js CDN approach in base.html):
   plain CSS, W3C-token-style custom properties, WCAG 2.2 AA contrast pairs
   taken from 41-accessibility.md §4. */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
h1, h2, h3, h4, p, dl, dd, figure { margin: 0 0 var(--space-4); }
ul, ol { margin: 0 0 var(--space-4); padding-inline-start: 1.25em; }
img, canvas { max-width: 100%; }

/* ---------- Design tokens ---------- */
:root {
  --color-bg: #f6f7f9;
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-border: #e2e5eb;

  --color-text: #1a1a1a;
  --color-text-secondary: #595959;
  --color-text-muted: #767676;

  --color-link: #005fcc;
  --color-primary: #005fcc;
  --color-primary-hover: #00489c;
  --color-primary-contrast: #ffffff;

  --color-danger-text: #842029;
  --color-danger-bg: #f8d7da;
  --color-danger-border: #f5c2c7;

  --color-success-text: #0f5132;
  --color-success-bg: #d1e7dd;
  --color-success-border: #badbcc;

  --color-warning-text: #664d03;
  --color-warning-bg: #fff3cd;
  --color-warning-border: #ffecb5;

  --color-info-text: #055160;
  --color-info-bg: #cff4fc;
  --color-info-border: #b6effb;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 1px rgba(16, 24, 40, .04);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, .10);

  --header-height: 64px;
  --control-height: 40px;
  --content-max: 1180px;
  --auth-card-max: 420px;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f1216;
    --color-surface: #171b21;
    --color-surface-raised: #1d222a;
    --color-border: #2a2f38;

    --color-text: #f2f3f5;
    --color-text-secondary: #c7cbd2;
    --color-text-muted: #9098a3;

    --color-link: #7fb2ff;
    --color-primary: #3f7fe0;
    --color-primary-hover: #5a92e6;
    --color-primary-contrast: #04101f;

    --color-danger-text: #ffb4b4;
    --color-danger-bg: #3a1518;
    --color-danger-border: #5c2126;

    --color-success-text: #9be3b6;
    --color-success-bg: #0f2b1c;
    --color-success-border: #1c4a30;

    --color-warning-text: #ffd97d;
    --color-warning-bg: #332705;
    --color-warning-border: #4d3a08;

    --color-info-text: #9fe0f2;
    --color-info-bg: #0c2c33;
    --color-info-border: #164450;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .5);
  }
}

/* ---------- Base typography ---------- */
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.375rem; font-weight: 600; margin-top: var(--space-2); }
h3 { font-size: 1.0625rem; font-weight: 600; color: var(--color-text-secondary); }

a { color: var(--color-link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Accessibility helpers ---------- */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0, 0, 0, 0);
  overflow: hidden;
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-3);
  z-index: 100;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
}
.skip-link:focus {
  top: var(--space-3);
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

/* ---------- Layout ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.site-header__inner {
  max-width: var(--content-max);
  height: 100%;
  margin-inline: auto;
  padding-inline: var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.brand {
  font-weight: 700;
  font-size: 1.0625rem;
  color: var(--color-text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; opacity: .8; }

.main-nav {
  display: flex;
  gap: var(--space-5);
  flex: 1;
  flex-wrap: wrap;
}
.main-nav a {
  color: var(--color-text-secondary);
  font-size: .9375rem;
  font-weight: 500;
  padding-block: var(--space-2);
  border-bottom: 2px solid transparent;
}
.main-nav a:hover { color: var(--color-text); text-decoration: none; }
.main-nav a[aria-current="page"] {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.header-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  flex-shrink: 0;
}
.header-icon-btn:hover { background: var(--color-bg); color: var(--color-text); }

.header-divider {
  width: 1px;
  height: var(--space-5);
  background: var(--color-border);
  flex-shrink: 0;
}

/* Anonymous header state (landing page + any other public page): Log in /
   Sign up, right-aligned like `.account-menu` is for signed-in users. */
.auth-links {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-inline-start: auto;
}
.auth-links a { color: var(--color-text-secondary); font-weight: 500; }
.auth-links a:hover { color: var(--color-text); text-decoration: none; }
.auth-links a[aria-current="page"] { color: var(--color-primary); }
.auth-links__register {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height);
  padding-inline: var(--space-4);
  border-radius: var(--radius-sm);
}
.auth-links__register:hover { text-decoration: none; }

/* ---------- Account menu (hover/focus dropdown) ---------- */
/* `align-self: stretch` + inner flex centering makes this item span the
   header's full height (siblings stay content-height via the header's own
   `align-items: center`). Without it, `.account-menu`'s hoverable box was
   only as tall as the trigger button, leaving a dead zone between the
   trigger and the header's bottom border — the mouse left `:hover` before
   reaching the panel below, closing it instantly on the way down. */
.account-menu {
  position: relative;
  flex-shrink: 0;
  align-self: stretch;
  display: flex;
  align-items: center;
}

.account-menu__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: transparent;
  border: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  min-height: auto;
  color: var(--color-text);
}
.account-menu__trigger:hover { background: var(--color-bg); }

.account-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-size: .8125rem;
  font-weight: 700;
  flex-shrink: 0;
}

.account-menu__label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.25;
  text-align: left;
}
.account-menu__email {
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-text);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-menu__role {
  font-size: .75rem;
  color: var(--color-text-muted);
}

.account-menu__panel {
  display: none;
  position: absolute;
  /* Flush against the now full-height `.account-menu` box (see above) —
     no margin-top gap, so the hover chain from trigger to panel stays
     unbroken; `padding` further down keeps the visual breathing room. */
  top: 100%;
  right: 0;
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-2);
  z-index: 20;
}
.account-menu:hover .account-menu__panel,
.account-menu:focus-within .account-menu__panel {
  display: block;
}

.account-menu__item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--color-text-secondary);
  border: none;
  border-radius: var(--radius-sm);
  min-height: auto;
  font-weight: 500;
  font-size: .875rem;
  padding: var(--space-2) var(--space-3);
}
.account-menu__item:hover {
  background: var(--color-bg);
  color: var(--color-text);
  text-decoration: none;
}
.account-menu__item--button { font: inherit; }

.account-settings__signed-in {
  color: var(--color-text-muted);
  font-size: .875rem;
}

/* ---------- Account health (account-menu dropdown, scan-quota indicator) --
   Traffic-light bar showing this period's scan usage against
   `UserProfile.monthly_scan_quota`. The green/yellow/red level is decided
   server-side by `UserProfile.scan_health_level` — this file only maps
   that level onto color tokens, no thresholds live here. The fill's
   `width` is set inline per-request (real usage data, not a design value),
   everything else — color, spacing, radius — comes from tokens. */
.account-health {
  padding: var(--space-1) var(--space-3) var(--space-3);
}
.account-health__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}
.account-health__label {
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .02em;
  color: var(--color-text-muted);
}
.account-health__value {
  font-size: .75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-secondary);
}
.account-health__bar {
  height: 6px;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  overflow: hidden;
}
.account-health__bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
}
.account-health__bar-fill--success { background: var(--color-success-text); }
.account-health__bar-fill--warning { background: var(--color-warning-text); }
.account-health__bar-fill--danger { background: var(--color-danger-text); }

.account-health__status {
  margin-top: var(--space-1);
  font-size: .75rem;
  font-weight: 600;
}
.account-health__status--success { color: var(--color-success-text); }
.account-health__status--warning { color: var(--color-warning-text); }
.account-health__status--danger { color: var(--color-danger-text); }

/* ---------- Pricing plans (stub page) ---------- */
.plans-intro {
  color: var(--color-text-secondary);
  max-width: 640px;
}

.plans-calculator { margin-top: var(--space-6); }
.plans-calculator__title { margin-bottom: var(--space-2); }
.plans-calculator__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-top: var(--space-4);
  max-width: 720px;
}
@media (max-width: 560px) {
  .plans-calculator__grid { grid-template-columns: 1fr; }
}
.plans-calculator__result {
  margin-top: var(--space-4);
  margin-bottom: 0;
  font-size: .9375rem;
}

/* Numeric stepper: pairs a text input (see plans.html's sanitizeDigits
   comment for why it's type="text", not type="number") with its own
   up/down buttons plus ArrowUp/ArrowDown keydown handling, so the field
   still displays exactly what a screen-reader/user sees. */
.stepper { display: flex; position: relative; }
.stepper input {
  padding-right: calc(var(--space-3) + 1.5rem);
}
.stepper__buttons {
  position: absolute;
  right: 1px;
  top: 1px;
  bottom: 1px;
  display: flex;
  flex-direction: column;
  width: 1.5rem;
}
.stepper__btn {
  flex: 1;
  min-height: 0;
  padding: 0;
  line-height: 1;
  font-size: .5625rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: none;
  border-left: 1px solid var(--color-border);
}
.stepper__btn:first-child { border-bottom: 1px solid var(--color-border); }
.stepper__btn:hover { background: var(--color-bg); color: var(--color-text); }

.billing-toggle {
  display: inline-flex;
  margin-top: var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.billing-toggle__option {
  padding: var(--space-2) var(--space-4);
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: none;
  border-radius: 0;
}
.billing-toggle__option:hover { background: var(--color-bg); color: var(--color-text); }
.billing-toggle__option.is-active {
  background: var(--color-primary);
  color: var(--color-primary-contrast, #fff);
}

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-5);
  margin-top: var(--space-6);
}
@media (max-width: 900px) {
  .pricing-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .pricing-grid { grid-template-columns: 1fr; }
}

.pricing-card {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
}
.pricing-card--highlight {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}
/* Set by the calculator's JS on whichever plan is the cheapest one that
   covers the entered ASINs/ZIPs/frequency — same visual treatment as
   `--highlight` (a plan can be both "most popular" and "fits your usage"
   at once) so the recommendation reads as one more reason to pick it,
   not a competing signal. */
.pricing-card--fits {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.pricing-card__badge {
  position: absolute;
  top: calc(-1 * var(--space-3));
  right: var(--space-4);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-size: .75rem;
  font-weight: 700;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
}

.pricing-card__name { margin-bottom: var(--space-3); }

.pricing-card__price {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
}
.pricing-card__amount { font-size: 2rem; font-weight: 700; }
.pricing-card__period { color: var(--color-text-muted); font-size: .875rem; }

.pricing-card__yearly {
  color: var(--color-text-muted);
  font-size: .8125rem;
  margin-bottom: var(--space-4);
}

.pricing-card__features {
  list-style: none;
  padding-inline-start: 0;
  margin-bottom: var(--space-5);
  flex: 1;
}
.pricing-card__features li {
  padding-block: var(--space-2);
  border-top: 1px solid var(--color-border);
  font-size: .875rem;
  color: var(--color-text-secondary);
}
.pricing-card__features li:first-child { border-top: none; }

.pricing-card__cta {
  display: block;
  width: 100%;
  text-align: center;
}

.pricing-card__note {
  text-align: center;
  font-size: .75rem;
  color: var(--color-text-muted);
  margin: var(--space-2) 0 0;
}

.page {
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--space-6) var(--space-5) var(--space-7);
}

/* Auth pages (login/register): narrow centered card instead of the full
   dashboard-width layout used everywhere else. */
body.auth .page {
  max-width: var(--auth-card-max);
  margin-top: var(--space-7);
}
body.auth .card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-6);
}

/* ---------- Home hub (home.html) ---------- */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}
.hero h1 { margin: 0 0 var(--space-2); }
.hero__subtitle {
  margin: 0;
  color: var(--color-text-secondary);
}
.hero__cta {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height);
  padding-inline: var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 600;
  font-size: .9375rem;
  white-space: nowrap;
}
.hero__cta:hover {
  background: var(--color-primary-hover);
  text-decoration: none;
}

.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.quick-link {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.quick-link:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  transform: translateY(-2px);
}
.quick-link__title {
  font-weight: 600;
  color: var(--color-text);
}
.quick-link__desc {
  font-size: .875rem;
  color: var(--color-text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .quick-link:hover { transform: none; }
}

@media (max-width: 720px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }
  .hero__cta { align-self: stretch; justify-content: center; }
}

/* ---------- Landing page (public marketing, landing.html) ---------- */
.landing-hero {
  text-align: center;
  max-width: 720px;
  margin: var(--space-6) auto;
}
.landing-hero__subtitle {
  color: var(--color-text-secondary);
  font-size: 1.0625rem;
}
.landing-hero__actions {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  margin-top: var(--space-5);
}
.landing-hero__login {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height);
  padding-inline: var(--space-4);
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.landing-hero__login:hover { text-decoration: none; }

.landing-audience {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}
.landing-audience__card h2 { margin-bottom: var(--space-3); }
.landing-audience__card p { margin: 0; color: var(--color-text-secondary); }

.landing-features { margin-bottom: var(--space-6); }

@media (max-width: 720px) {
  .landing-audience { grid-template-columns: 1fr; }
  .landing-hero__actions { flex-direction: column; }
}

/* ---------- Buttons ---------- */
button,
input[type="submit"] {
  font: inherit;
  font-weight: 600;
  font-size: .9375rem;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  min-height: var(--control-height);
  padding-inline: var(--space-4);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  transition: background-color .15s ease, box-shadow .15s ease;
}
button:hover, input[type="submit"]:hover { background: var(--color-primary-hover); }
button:disabled { opacity: .55; cursor: not-allowed; }

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
.btn--ghost:hover { background: var(--color-bg); color: var(--color-text); }

/* Explicit danger variant for buttons the `form[action*="delete"]` hook
   below can't reach — e.g. the confirm dialog's "Delete" button lives in
   its own `<form method="dialog">` with no delete URL in its action. */
.btn--danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border-color: var(--color-danger-border);
}
.btn--danger:hover { background: var(--color-danger-border); }

/* Delete forms: action URL always contains "delete/" in this app
   (tracking/urls.py, dashboard/urls.py) — used as a hook to give
   destructive actions a visually distinct, non-primary color without
   touching every template. `min-width` here is the shared reference value
   `.btn--table-action`'s "Add" button also uses below, so both buttons
   render the same width regardless of "Add" being shorter than "Delete"
   (repo owner: same width, not just same padding/font-size). */
form[action*="delete"] button[type="submit"] {
  min-width: 88px;
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border-color: var(--color-danger-border);
}
form[action*="delete"] button[type="submit"]:hover { background: var(--color-danger-border); }

.inline-form { display: inline; }

/* Admin user table (admin_user_list.html): the "Scans remaining" cell holds
   just the quota `<input>` — no Save button, it auto-submits its row's
   shared `<form>` on change (see the template's bottom <script>; `Role`
   still gets its own separate cell instead of merging both fields under one
   header — see `UserProfileAdminForm`'s docstring for why they're still one
   `<form>` via `form="..."`). */
.admin-users__quota-cell input { width: 7rem; }

/* Pending-approval / all-active-users accordion (admin_user_list.html): a
   plain stack of two `.panel` <section>s had no gap between them and read
   as one fused block — `gap` here is the fix, not a margin on `.panel`
   itself (that's shared by other pages that don't have this problem). */
.admin-accordion {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Plan/Role `<select>`s (UserProfileAdminForm): plain `select { width: 100% }`
   just fills whatever the table's auto column-layout gives it, which shrinks
   below the selected option's own text ("Unlimited" -> "Unlir", "Editor" ->
   "Edito") — `min-width` here forces the column itself wider instead. */
.cell-select--plan { min-width: 9.5rem; }
.cell-select--role { min-width: 7.5rem; }

/* ---------- Forms ---------- */
form p {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  max-width: 480px;
}
/* Author `display` always beats the UA `[hidden] { display: none }` rule
   regardless of specificity (origin order, not specificity, decides that
   fight) — without this, a `<p hidden>` inside any `<form>` (e.g. the ZIP
   quota warning below) renders visible despite the attribute. */
form p[hidden] { display: none; }

form label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-text-secondary);
}

input, select, textarea {
  font: inherit;
  font-size: .9375rem;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-3);
  width: 100%;
}
textarea { min-height: 6em; padding-block: var(--space-2); }

/* Bulk-add ASIN textarea (dashboard/brand_detail.html): width already
   100% of its container via the rule above — only the resize handle needs
   disabling so the box can't be dragged taller/narrower than its fixed
   `rows` height. */
.textarea--fixed { resize: none; }

input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
}

.helptext {
  font-size: .8125rem;
  color: var(--color-text-muted);
}

.errorlist {
  list-style: none;
  margin: 0 0 var(--space-1);
  padding: 0;
  color: var(--color-danger-text);
  font-size: .8125rem;
}
.errorlist li::before { content: "⚠ "; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }

/* Sticky header variant (tracking/zip_list.html, portfolio_list.html,
   tracking/proxy_list.html): the page itself scrolls (no bounded inner
   scrollport) — the header row just sticks to the viewport, docked
   against `.site-header` with the "pushed down a bit" look coming from
   `padding-top` instead of an actual positioning offset — a real gap
   between the two sticky boxes is a seam neither of them paints, so
   whatever body row is mid-scroll at that exact band shows through it
   (see the `top` comment below for why it's a deliberate 1px *overlap*,
   not an exact `top: var(--header-height)` flush join). `.site-header`'s
   `z-index: 10` staying above this header's `z-index: 1` is what makes
   that overlap invisible.

   Two overflow overrides are required for `position: sticky` to actually
   track the viewport instead of silently no-opping (confirmed by hand:
   without these, the `th` renders at "natural position + top", i.e. it
   never detaches, it just sits permanently offset and scrolls away with
   the page):
   - `.table-scroll--sticky` itself: cancels the bare `.table-scroll`'s
     `overflow-x: auto`, which per the CSS overflow-computation rule
     silently forces `overflow-y` to `auto` too (you can't have one axis
     `visible` and the other not) — that makes this div its own "scroll
     container" with an empty scrollport `position: sticky` sticks to
     instead of the real viewport.
   - `.table-scroll--sticky table`: the plain `table` rule below sets
     `overflow: hidden` (to clip cell backgrounds to its rounded corners),
     which is exactly the same kind of non-scrolling "scroll container"
     ancestor and just as fatal to sticky here — this override wins on
     specificity (one class + one element beats one element) regardless
     of the two rules' source order. */
.table-scroll--sticky {
  overflow: visible;
}
.table-scroll--sticky table {
  overflow: visible;
}
.table-scroll--sticky thead th {
  position: sticky;
  /* 1px *up* from flush, not exactly flush: two independent `position:
     sticky` elements (this and `.site-header`) can each round their
     sub-pixel scroll offset to a different physical pixel on non-integer
     DPR displays, leaving a hairline gap even though both compute to
     "touching" in CSS px. Overlapping on purpose instead of touching
     removes the seam regardless of rounding — `.site-header`'s higher
     z-index (10 vs this rule's 1) paints over the 1px overlap. */
  top: calc(var(--header-height) - 1px);
  z-index: 1;
  padding-top: var(--space-4);
  background: var(--color-bg);
  box-shadow: inset 0 -1px 0 var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-size: .9375rem;
}

caption { text-align: left; margin-bottom: var(--space-2); color: var(--color-text-muted); }

th, td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

thead th {
  background: var(--color-bg);
  font-size: .8125rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-muted);
  font-weight: 600;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-bg); }

/* ---------- Messages / alerts ---------- */
.messages {
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.messages li,
.budget-warning {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: .9375rem;
}

.messages li.success { color: var(--color-success-text); background: var(--color-success-bg); border-color: var(--color-success-border); }
.messages li.error   { color: var(--color-danger-text);  background: var(--color-danger-bg);  border-color: var(--color-danger-border); }
.messages li.warning  { color: var(--color-warning-text); background: var(--color-warning-bg); border-color: var(--color-warning-border); }
.messages li.info,
.messages li.debug     { color: var(--color-info-text);    background: var(--color-info-bg);    border-color: var(--color-info-border); }

.messages li.success::before { content: "✓ "; }
.messages li.error::before   { content: "⚠ "; }
.messages li.warning::before  { content: "⚠ "; }
.messages li.info::before,
.messages li.debug::before    { content: "ℹ "; }

.budget-warning {
  color: var(--color-warning-text);
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
  font-weight: 600;
}
.budget-warning::before { content: "⚠ "; }

/* ---------- ZIP tabs (dashboard/asin_detail.html) ---------- */
.zip-tabs {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0;
  margin: 0 0 var(--space-5);
}
.zip-tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 5.5rem;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: .875rem;
  font-weight: 500;
  text-align: center;
  line-height: 1.25;
}
.zip-tabs a:hover { text-decoration: none; border-color: var(--color-primary); }
.zip-tabs a[aria-selected="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-contrast);
}
.zip-tab__city {
  font-weight: 600;
  color: var(--color-text);
}
.zip-tab__meta {
  font-size: .6875rem;
  font-weight: 500;
  text-transform: lowercase;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.zip-tabs a[aria-selected="true"] .zip-tab__city,
.zip-tabs a[aria-selected="true"] .zip-tab__meta {
  color: var(--color-primary-contrast);
}

/* ---------- Definition lists (dashboard/worker_status.html) ---------- */
dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: var(--space-5);
  row-gap: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  max-width: 480px;
}
dt { font-weight: 600; color: var(--color-text-muted); }
dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Wider variant for worker_status.html only — keeps long timestamp values
   ("2026-07-10 22:25:01") on one line without widening every other bare
   `dl` (e.g. asin_detail.html's "Additional signals" panel). */
.stats-card {
  max-width: 640px;
}

/* ---------- Table header action button (tracking/zip_list.html,
   dashboard/brand_list.html) ----------
   The "Add" control lives in the table's own header row (last column)
   instead of floating above the table — clicking it reveals a real
   `<tr id="add-...-row">` inside `<tbody>` (a `<details>` can't wrap a
   table row — invalid content model — so this needs the tiny JS block at
   the bottom of those templates instead of the details/summary trick used
   elsewhere on this page). Same footprint as the default `button` rule
   below (repo owner: "Add" should be the same width/text size as
   "Delete") — only `text-transform`/`letter-spacing` are reset, since
   `thead th` sets both uppercase + letter-spacing and, being inherited
   properties, they'd otherwise bleed into the button's own text
   ("Add" → "ADD"). */
.btn--table-action {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  min-height: var(--control-height);
  padding-inline: var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-size: .9375rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
}
.btn--table-action:hover { background: var(--color-primary-hover); }

/* ---------- Sortable table headers ---------- */
.sort-link {
  color: var(--color-text-muted);
  font-size: inherit;
  font-weight: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  white-space: nowrap;
}
.sort-link:hover { color: var(--color-text); text-decoration: none; }
.sort-link--active { color: var(--color-primary); }

/* Header cell holding both a sort link and the "activate/deactivate all"
   master toggle (tracking/zip_list.html) side by side. */
.th-with-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ---------- Active toggle switch (no JS: a submit button per row) ---------- */
.toggle {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-block;
  width: 40px;
  height: 22px;
  padding: 2px;
  border-radius: 999px;
  background: var(--color-border);
  vertical-align: middle;
}
.toggle[data-state="on"] { background: var(--color-primary); }
.toggle__knob {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease;
}
.toggle[data-state="on"] .toggle__knob { transform: translateX(18px); }

/* ---------- Inline-editable cell values (tracking/zip_list.html) ----------
   ZIP code and Label are always-editable inputs right in the cell — no
   click-to-reveal step and no separate row/block opening (repo owner:
   editing should happen directly on the text itself). Styled to read as
   plain table text until the user actually interacts with it; the global
   `input:focus` border-color rule above still applies on top of this. */
.cell-form { margin: 0; }
.cell-input {
  min-height: unset;
  width: 100%;
  padding: var(--space-1) var(--space-2);
  background: transparent;
  border-color: transparent;
  border-radius: var(--radius-sm);
}
.cell-input:hover { border-color: var(--color-border); }
.cell-input:focus { background: var(--color-surface); }

/* ---------- Title cell click-to-edit (dashboard/asin_list.html,
   dashboard/portfolio_detail.html) ----------
   Product titles run long and need to wrap across several lines when NOT
   being edited — the always-editable `.cell-input` above can't do that (an
   `<input>` is always one line) — so this shows wrapped, clamped plain
   text plus a pencil trigger (the SAME `.btn--icon-rename` affordance as
   portfolio_list.html's per-row rename, not a whole-cell hover highlight)
   until the pencil is clicked, then swaps in the same `.cell-input` styling
   to actually edit (asin-title-edit.js). */
.title-cell { max-width: 480px; }
.title-cell__view {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--space-2);
  width: 100%;
}
.title-cell__view .btn--icon-rename { flex-shrink: 0; }
.title-cell__text {
  flex: 1 1 auto;
  min-width: 0;
  /* Clamps to 4 lines with an ellipsis instead of growing the row to fit
     the longest scanned Amazon title (some run 15+ words). */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
  word-break: break-word;
}
/* Same gotcha as `form p[hidden]` above: this wrapper's own `display:
   inline-flex` is author CSS and beats the UA `[hidden] { display: none }`
   rule on origin order alone — without this, asin-title-edit.js's
   `view.hidden = true` has no visual effect and it stays stacked on top of
   the input it's supposed to be replaced by. */
.title-cell__view[hidden] { display: none; }

/* ---------- ASIN thumbnail + hover preview (dashboard/asin_list.html,
   dashboard/portfolio_detail.html) ----------
   Thumbnail sized to the row's own height; hovering swaps in a larger,
   fixed-position preview (asin-thumb-preview.js) rather than a CSS
   transform/absolute zoom — the table's ancestors (`.table-scroll`, and
   `table`'s own `overflow: hidden` for its rounded corners) would clip an
   enlarged image drawn inside the cell's stacking context. */
.asin-thumb-cell { width: 1%; white-space: nowrap; }
.asin-thumb,
.asin-thumb--placeholder {
  display: block;
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
}
/* ASIN/Portfolio/Active/Archive read as one row of controls next to a tall
   (up to 100px) thumbnail and a title that may wrap to several lines —
   vertical-align: top (the table-wide default) would otherwise pin them to
   the row's top edge instead of centering with the thumbnail. Scoped to
   this table only (dashboard/asin_list.html, dashboard/portfolio_detail.html)
   so it doesn't touch matrix/zip-list/scan-log tables, which rely on the
   table-wide top-alignment default. */
.asin-table td { vertical-align: middle; }
.asin-thumb-preview {
  display: none;
  position: fixed;
  width: 300px;
  height: 300px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  background: var(--color-surface);
  z-index: 1000;
  pointer-events: none;
}
.asin-thumb-preview--visible { display: block; }

/* ---------- Inline per-row edit (the "Add" row) ---------- */
.editing-row td {
  background: var(--color-bg);
}

/* ---------- Portfolio list: name link + inline rename trigger
   (dashboard/portfolio_list.html) ----------
   The name cell's link still navigates to portfolio_detail, so renaming
   needs its own pencil-button affordance next to it rather than
   overloading the link's click (unlike portfolio_detail.html's
   click-the-heading rename, where the heading isn't a link). */
.name-cell {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.btn--icon-rename {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
}
.btn--icon-rename:hover { background: var(--color-bg); color: var(--color-text); }
.btn--icon-rename:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* ---------- Delete confirmation dialog (tracking/zip_list.html) ----------
   A native <dialog> instead of window.confirm(): keyboard/focus-trapped
   and visually consistent with the rest of the UI, per 41-accessibility.md.
   Escape or the backdrop close it with returnValue "" (not "confirm"), so
   the default is always "don't delete" (fail-closed). */
.confirm-dialog {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
  max-width: 420px;
  width: 90vw;
  background: var(--color-surface);
  color: var(--color-text);
}
.confirm-dialog::backdrop { background: rgba(16, 24, 40, .45); }
.confirm-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin: var(--space-4) 0 0;
  padding: 0;
  list-style: none;
}

/* ---------- Generic panel/card (dashboard/brand_detail.html) ---------- */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

/* ASIN list + archived-ASINs get the whole page width — the ZIP selector and
   bulk-add forms moved into modals (see .form-dialog below), so there's no
   grid column to squeeze this table into anymore. */
.asin-list-panel, .asin-archived-panel { margin-top: var(--space-6); }

/* ---------- Page header: title + status pill + actions ---------- */
.portfolio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}
.portfolio-header__title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.portfolio-header__title h2 { margin: 0; }
.portfolio-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ---------- Disclosure: collapsible section (native <details>/<summary>) —
   used to keep a large ZIP-catalog table or an archived-items table out of
   the way until the user asks for it, without any JS (keyboard/toggle
   behavior is native to <details>, so this needs no extra a11y wiring). */
.disclosure summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  cursor: pointer;
  list-style: none;
  padding: var(--space-2) 0;
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary h3 { margin: 0; }
.disclosure summary::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: rotate(45deg);
  transition: transform .15s ease;
}
.disclosure[open] summary::after { transform: rotate(-135deg); }
.disclosure__body { margin-top: var(--space-4); }

.zip-panel__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.zip-panel__filter { margin: 0; }

/* The bulk-add ASIN textarea sits inside `#asin-bulk-dialog` — override the
   generic `form p { max-width: 480px }` cap here so the box fills the
   dialog's full width and keeps equal left/right padding instead of being
   capped narrow and stranding empty space on the right (repo owner: right
   gap should match the left, not be wider). */
#asin-bulk-dialog form p { max-width: none; }

.zip-panel__master {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.zip-panel__master-label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-text-secondary);
}

/* The list scrolls inside its own fixed-height box — the page itself does
   not need to be scrolled to reach the bottom of a ~140-row catalog
   (repo owner's explicit ask; 08-ui-ux.md doesn't mandate a number, this
   is simply "a few rows visible at once + the rest one scroll away"). */
.zip-panel__scroll {
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

/* Fixed layout + percentage widths (summing to 100%) guarantee the table
   never exceeds the panel's width, regardless of how long a city name is —
   no horizontal scrollbar, ever (repo owner's explicit ask). Overflowing
   text truncates with an ellipsis instead of forcing the column to grow. */
.zip-table {
  border: none;
  border-radius: 0;
  font-size: .8125rem;
  table-layout: fixed;
  width: 100%;
}
.zip-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.zip-table th, .zip-table td {
  padding: var(--space-2) var(--space-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zip-table th:nth-child(1), .zip-table td:nth-child(1) { width: 8%; padding-inline-start: var(--space-2); }
.zip-table th:nth-child(2), .zip-table td:nth-child(2) { width: 34%; }
.zip-table th:nth-child(3), .zip-table td:nth-child(3) { width: 17%; }
.zip-table th:nth-child(4), .zip-table td:nth-child(4) { width: 19%; }
.zip-table th:nth-child(5), .zip-table td:nth-child(5) {
  width: 22%;
  overflow: visible;
  text-align: center;
  padding-inline-end: var(--space-2);
}
.zip-table__rank {
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.zip-table__zip {
  font-variant-numeric: tabular-nums;
  color: var(--color-text-secondary);
}

/* ---------- Toggle switch (checkbox-based, for multi-select forms) ----------
   Distinct from the button-based `.toggle` above (tracking/zip_list.html),
   which submits immediately per row. This variant wraps a real checkbox so
   many of them can be batched into one form submission (the ZIP selector's
   "Save ZIP selection" button) while still looking/behaving like a switch. */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 40px;
  height: 22px;
  cursor: pointer;
}
.toggle-switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.toggle-switch__track {
  display: inline-block;
  width: 40px;
  height: 22px;
  padding: 2px;
  border-radius: 999px;
  background: var(--color-border);
  transition: background-color .15s ease;
}
.toggle-switch__thumb {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease;
}
.toggle-switch input:checked + .toggle-switch__track {
  background: var(--color-primary);
}
.toggle-switch input:checked + .toggle-switch__track .toggle-switch__thumb {
  transform: translateX(18px);
}
.toggle-switch input:indeterminate + .toggle-switch__track {
  background: var(--color-text-muted);
}
.toggle-switch input:focus-visible + .toggle-switch__track {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- ASIN × ZIP matrix (dashboard/matrix.html) ---------- */
.matrix-filter {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
.matrix-filter select { width: auto; min-width: 220px; }
.matrix-filter__hint {
  font-size: .8125rem;
  color: var(--color-text-muted);
}

/* The matrix page runs its table flush to the viewport edges (this task's
   spec: table replaces the page, not just fills it) — override the global
   `.page` centered/max-width/padded shell only on this page. Scan log
   (dashboard/scan_log.html) deliberately stays on the default centered
   `.page` shell instead — its 6 columns don't need the full bleed, and
   stretching them across the whole viewport just leaves the last column's
   header controls floating in dead space. */
body.matrix-page .page {
  max-width: none;
  margin: 0;
  padding: 0;
}

.matrix-form { display: block; }

.matrix-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-inline: none;
  box-shadow: none;
}

/* A bounded height + overflow on both axes makes this box the containing
   scrollport for every `position: sticky` cell inside it (08-ui-ux.md
   Doherty threshold / scanability): the header row and the frozen
   Brand/ASIN columns stay in place while only the table's own content
   scrolls underneath — the page itself never needs to move to keep them
   in view. Height accounts for the sticky site header above and the
   sticky pagination footer below (`.matrix-pagination`), both fixed-height. */
.matrix-scroll {
  max-height: calc(100vh - var(--header-height) - 60px);
  min-height: 240px;
  overflow: auto;
}

.matrix-table {
  width: 100%;
  min-width: 100%;
  border: none;
  border-radius: 0;
  font-size: .9375rem;
  /* The global `table` rule sets `overflow: hidden` (for rounded corners),
     but any ancestor with overflow != visible becomes the nearest
     "scrolling ancestor" for `position: sticky` — which would make the
     table itself that ancestor instead of `.matrix-scroll`, and since the
     table never scrolls internally, its sticky header/columns would just
     scroll away with the rest of the content. Reset to visible so
     `.matrix-scroll` is the sticky containing block. */
  overflow: visible;
}
.matrix-table th, .matrix-table td { white-space: nowrap; }

/* Sticky header row. A SOLID background here is load-bearing, not
   decorative — without it the body rows scrolling underneath show through
   the "fixed" header, which is the exact glitch this task calls out. */
.matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-bg);
  box-shadow: inset 0 -1px 0 var(--color-border);
}

/* Frozen Brand (col 1) + ASIN (col 2) columns: fixed widths so the second
   column's `left` offset is a known constant, with an ellipsis for brand
   names that don't fit — same solid-background rule as the header so ZIP
   columns scrolling underneath don't bleed through either. */
.matrix-table__sticky {
  position: sticky;
  z-index: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--color-surface);
}
.matrix-table__sticky--1 {
  left: 0;
  width: 180px;
  min-width: 180px;
  max-width: 180px;
  box-shadow: inset -1px 0 0 var(--color-border);
}
.matrix-table__sticky--2 {
  left: 180px;
  width: 210px;
  min-width: 210px;
  max-width: 210px;
  box-shadow: inset -1px 0 0 var(--color-border);
}

/* ASIN cell (matrix-table__sticky--2): the ASIN link plus its "open on
   Amazon" / "copy" icon buttons, all on one line — the column above was
   widened from 150px to 210px to fit a full 10-char ASIN plus both icons
   without truncating. */
.matrix-table__asin-cell {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.matrix-table__asin-link {
  /* Flex items default to min-width: auto, which overrides text-overflow
     and lets the link push the icons out past the column's fixed width
     instead of shrinking — min-width: 0 is what makes the ellipsis rule
     below actually take effect. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.matrix-table__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.matrix-table__icon-btn:hover,
.matrix-table__icon-btn:focus-visible {
  color: var(--color-text);
  background: var(--color-bg);
}
.matrix-table__icon-btn--copied {
  color: var(--color-success-text);
}
/* Cells sticky on BOTH axes (header row × frozen columns) need to sit
   above every other sticky cell and match the header's background, not
   the body's. */
.matrix-table thead th.matrix-table__sticky {
  z-index: 3;
  background: var(--color-bg);
}

/* Header cells hosting the live Brand/ASIN filter controls: reset the
   generic uppercase `thead th` letter styling (07/18-ui rules: form
   controls show real values, not a transformed label) and give the
   select/input room to breathe against the sticky column's fixed width. */
.matrix-table__filter-cell {
  text-transform: none;
  letter-spacing: normal;
  padding: var(--space-2) var(--space-3);
  vertical-align: middle;
}
.matrix-table__filter-cell select,
.matrix-table__filter-cell input {
  min-height: 2rem;
  font-size: .8125rem;
  padding: var(--space-1) var(--space-2);
}

/* Column-header sort toggle (Portfolio/ASIN only — the ZIP columns each
   carry several sub-metrics per cell, so they have no single sort key).
   Reuses the existing `.sort-link`/`.sort-link--active` pair (see
   tracking/zip_list.html) — this just gives it room above the filter
   select/input already sitting in the same header cell. */
.matrix-table__filter-cell .sort-link {
  display: block;
  margin-bottom: var(--space-1);
}

.matrix-table__col { vertical-align: bottom; }
.matrix-table__city {
  display: block;
  font-size: .8125rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 600;
  color: var(--color-text);
}
.matrix-table__meta {
  display: block;
  margin-top: 2px;
  font-size: .6875rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.matrix-table tbody tr:hover td,
.matrix-table tbody tr:hover th.matrix-table__corner { background: var(--color-bg); }

/* ---------- Matrix pagination footer ---------- */
.matrix-pagination {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.matrix-pagination__summary {
  font-size: .8125rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.matrix-pagination__page-size {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: .8125rem;
  color: var(--color-text-muted);
}
.matrix-pagination__page-size select {
  width: auto;
  min-height: 2rem;
  padding: var(--space-1) var(--space-2);
}
.matrix-pagination__controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.matrix-pagination__pages {
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
}
.matrix-pagination__link { text-decoration: none; }
.matrix-pagination__link--disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}

@media (max-width: 720px) {
  /* `.site-header` drops its sticky positioning and wraps onto multiple
     lines below this breakpoint (see the responsive block further down),
     so `var(--header-height)` alone undercounts it — same for the
     pagination footer, which also wraps. */
  .matrix-scroll { max-height: calc(100vh - var(--header-height) - 200px); }
  /* No sticky nav above it to clear anymore — dock flush against the
     viewport edge instead of leaving a `--header-height`-tall gap. */
  .table-scroll--sticky thead th { top: 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .site-header__inner { flex-wrap: wrap; height: auto; padding-block: var(--space-3); }
  .site-header { position: static; }
  .main-nav { order: 3; width: 100%; gap: var(--space-4); }
  .page { padding-inline: var(--space-4); }
  dl { grid-template-columns: 1fr; }
  dt { margin-top: var(--space-2); }
}

/* ---------- ASIN detail: additional signals (T15, dashboard/asin_detail.html) ----------
   Compact card below the existing charts — Hick's Law (08-ui-ux.md §1): one
   small block for all T13 bonus fields (badge_type/discount_pct/coupon/
   social_proof_text) instead of a new chart per field. Only rendered when
   the latest scan for the selected ZIP actually has one of these set. */
.signals-panel {
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.signals-panel__title {
  margin: 0 0 var(--space-3);
  font-size: .8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .02em;
  color: var(--color-text-muted);
}
.signals-panel__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-6);
  margin: 0;
}
.signals-panel__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.signals-panel__item dt {
  font-size: .75rem;
  color: var(--color-text-muted);
}
.signals-panel__item dd {
  margin: 0;
  font-size: .9375rem;
  font-weight: 600;
  color: var(--color-text);
}

/* ---------- Matrix badge cell (T15, dashboard/matrix.html) ----------
   badge_type (T13) shown in preference to the raw badge_text join, when
   present; falls back to badge_text (older/other scraper paths that never
   populate badge_type, e.g. PlaywrightScraper's dp-page "Lowest price in
   30 days" badge). */
.matrix-table__badge {
  display: inline-block;
  margin-inline-end: var(--space-1);
  padding: 1px 6px;
  font-size: .6875rem;
  font-weight: 600;
  color: var(--color-info-text);
  background: var(--color-info-bg);
  border: 1px solid var(--color-info-border);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
/* T17: classify_badge() level modifiers — base rule above already matches
   the "info" level's colors (unrecognized-but-present badge, e.g. the
   legacy "Lowest price in 30 days" text), so only success/warning need an
   override; --info is still listed explicitly so the modifier class the
   template always adds (`matrix-table__badge--{{ cell.badge.level }}`)
   never silently falls through to an unstyled/undefined selector. */
.matrix-table__badge--success {
  color: var(--color-success-text);
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
}
.matrix-table__badge--warning {
  color: var(--color-warning-text);
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}
.matrix-table__badge--info {
  color: var(--color-info-text);
  background: var(--color-info-bg);
  border-color: var(--color-info-border);
}

/* ---------- Matrix stock/delivery pills (T17, dashboard/matrix.html) ----
   Color-coded stock-level / delivery-speed signal per cell, always paired
   with a text label so color is never the sole signal (08-ui-ux.md §2).
   Thresholds are decided server-side in dashboard/views.py's
   classify_stock_level/classify_delivery_days — this file only maps the
   resulting "level" onto the existing success/warning/danger/muted design
   tokens, no new colors, no logic. */
.pill {
  display: inline-block;
  margin-inline-end: var(--space-1);
  padding: 1px 6px;
  font-size: .6875rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.pill--success {
  color: var(--color-success-text);
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
}
.pill--warning {
  color: var(--color-warning-text);
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}
.pill--danger {
  color: var(--color-danger-text);
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
}
.pill--unknown {
  color: var(--color-text-muted);
  background: transparent;
  border-color: var(--color-text-muted);
}

/* ---------- Matrix cell history modal (T19, dashboard/matrix.html) ----------
   Extends .confirm-dialog (tracking/zip_list.html) rather than duplicating
   the base <dialog> chrome — only the size and internal layout differ, since
   this dialog holds 4 charts plus a change-log table instead of a single
   confirmation message. */
.history-dialog {
  max-width: 720px;
  width: min(92vw, 720px);
  max-height: 85vh;
  overflow-y: auto;
}
.history-dialog__title-meta {
  margin-left: var(--space-2);
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.history-dialog__meta {
  margin: 0 0 var(--space-4);
  font-size: .8125rem;
  color: var(--color-text-muted);
}
.history-dialog__charts {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

/* Change-log table (newest scan first) — reuses the base `table`/`th`/`td`
   rules already defined above; this only adds the spacing needed to sit
   below the charts inside the dialog. */
.history-log {
  margin: 0;
  font-size: .8125rem;
}

/* ---------- Form-in-modal dialog (dashboard/portfolio_detail.html) ----------
   Extends .confirm-dialog like .history-dialog does. Unlike the delete
   confirm dialog (a two-step confirm that submits a *different* form on
   close), the ZIP selector and bulk-add-ASIN forms live directly inside
   these — opened from a header button instead of an inline
   <details>/<summary>, closed by the header's × button, Escape, or a
   backdrop click, same as every other native <dialog> here. */
.form-dialog {
  max-width: 640px;
  width: min(92vw, 640px);
  max-height: 85vh;
  overflow-y: auto;
}
.form-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.form-dialog__header h3 { margin: 0; }
.btn--icon-close {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 1.25rem;
  line-height: 1;
}
.btn--icon-close:hover { background: var(--color-bg); color: var(--color-text); }
.btn--icon-close:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* ---------- Insights: alert feed (T20, dashboard/insights.html) ----------
   Sorted-list presentation instead of a grid — severity/level is carried
   purely via the existing .pill--<level> tokens (T17), no new colors. */
.alert-feed {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-2) var(--space-5);
}
.alert-feed__table { width: 100%; }
.alert-feed__table th, .alert-feed__table td {
  padding: var(--space-3) var(--space-2);
}
/* This table's `.table-scroll--sticky thead th` sticky header defaults to
   `background: var(--color-bg)` (the page background — correct for
   zip_list.html/portfolio_list.html, which sit directly on the page). The
   alert feed instead sits inside a `--color-surface` panel (`.alert-feed`
   above), so that default would paint a visibly different shade than the
   card around it once the header detaches and sticks — override to match
   the panel it actually lives in. */
.alert-feed__table thead th {
  background: var(--color-surface);
}
.alert-row__detail {
  color: var(--color-text-muted);
  font-size: .875rem;
}
.alert-feed__empty {
  margin: var(--space-2) 0;
  color: var(--color-text-muted);
}
/* ZIP cell: city as the headline, "zip_code, ST" in small print below —
   same .zip-tab__city/__meta tokens as the brand-detail ZIP tab strip and
   Scan log's ZIP cell, with the same uppercase-state override as Scan log
   (.zip-tab__meta lowercases by default). */
.alert-row__zip {
  display: flex;
  flex-direction: column;
}
.alert-row__zip .zip-tab__meta {
  text-transform: uppercase;
}
.history-log th, .history-log td { padding: var(--space-2) var(--space-3); }

/* ---------- Scan log (dashboard/scan_log.html) ---------- */
/* Every column stays on one line (scanned-at/ASIN/brand/ZIP/method are all
   short, fixed-shape values) except the last (Result), which legitimately
   needs to wrap once an `error_message` is long. */
.scan-log-table th, .scan-log-table td {
  padding: var(--space-3) var(--space-2);
  white-space: nowrap;
}
.scan-log-table th:last-child, .scan-log-table td:last-child {
  white-space: normal;
}
.scan-log-zip {
  display: flex;
  flex-direction: column;
}
/* .zip-tab__meta (shared with the brand-detail ZIP tab strip) lowercases
   its state abbreviation by design there; the scan log instead spells the
   state out in caps ("NY", not "ny"), so this scopes the override to just
   this table's cells. */
.scan-log-zip .zip-tab__meta {
  text-transform: uppercase;
}

/* Result column header: carries the "Errors only" toggle (moved out of the
   standalone filter bar above the table, matrix-page style) alongside the
   plain column label. Applied to an inner <div> inside the <th>, NOT the
   <th> itself — a table cell that computes to `display: flex` stops being
   a `display: table-cell` box, which silently breaks `position: sticky`
   for that one cell (confirmed live: every other header cell stuck at
   `top`, this one scrolled away with the body). Every other header cell in
   this table is plain text, so they never hit this. */
.scan-log-table__result-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  white-space: nowrap;
}

/* Page-level sticky header (`.table-scroll--sticky`, same pattern as
   portfolio_list.html/tracking/zip_list.html/dashboard/insights.html) —
   product decision (2026-07): the previous `.matrix-scroll`-bounded
   scrollport (own max-height + its own inner scrollbar) read as a cramped
   box-within-a-page; scrolling the whole page like every other list here
   is the expected behavior. Trade-off: dropping the bounded box also drops
   the old right-frozen "Result" column (`position: sticky` pinned to a
   local horizontal scrollport doesn't mean anything once there is no local
   scrollport) — a long `error_message` just wraps (see the last-child rule
   above) instead of the column staying pinned during horizontal scroll.*/
