/* Minimal Step-1 styling. Vendored, no CDN — the strict CSP added in Step 9
   allows only 'self', so all assets live under static/. HTMX and a fuller
   stylesheet are vendored here in Step 2. */
:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --muted: #666;
  --bg: #fafafa;
  --card: #fff;
  --border: #e2e2e2;
  --accent: #2b6cb0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e8e8e8;
    --muted: #9aa0a6;
    --bg: #16181c;
    --card: #1f2228;
    --border: #2c313a;
    --accent: #6aa9e9;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
}
.topbar {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; }
.topbar .tagline { color: var(--muted); font-size: 0.9rem; }
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.topbar-right .nav-user { color: var(--muted); font-size: 0.9rem; }
.lang-form, .logout-form { display: flex; align-items: center; gap: 0.35rem; margin: 0; }
/* Language toggle: two immediate-apply buttons, current one highlighted. */
.lang-form { gap: 0; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.lang-btn {
  cursor: pointer; border: 0; border-radius: 0; padding: 0.35rem 0.6rem;
  background: var(--bg); color: var(--muted); font-size: 0.85rem;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn:hover { color: var(--fg); }
.lang-btn.active { background: var(--accent); color: #fff; }
.container { max-width: 960px; margin: 2rem auto; padding: 0 1.25rem; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem 1.75rem;
}
.card-narrow { max-width: 24rem; margin: 0 auto; }
.card h1 { margin-top: 0; font-size: 1.4rem; }
.card p { color: var(--muted); margin-bottom: 0; }
a { color: var(--accent); }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 0.5rem; }
.stack label { font-size: 0.9rem; font-weight: 600; }
.stack input, select, button {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}
.stack button, .logout-form button {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}
.stack button { margin-top: 0.5rem; }
.form-error {
  color: #b00020;
  background: rgba(176, 0, 32, 0.08);
  border: 1px solid rgba(176, 0, 32, 0.3);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-top: 0;
}
@media (prefers-color-scheme: dark) {
  .form-error { color: #ff8a9a; }
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Step 4: read surfaces --------------------------------------------- */
/* Primary nav in the top bar */
.mainnav { display: flex; gap: 0.25rem; margin-left: 1rem; flex-wrap: wrap; }
.mainnav a {
  padding: 0.3rem 0.6rem; border-radius: 6px; text-decoration: none;
  color: var(--fg); font-size: 0.92rem;
}
.mainnav a:hover { background: var(--bg); }
.mainnav a.active { background: var(--accent); color: #fff; }

/* Wider working area than the narrow card container */
.container { max-width: 1400px; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
.panel { margin-bottom: 2.5rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.75rem; }
.empty {
  color: var(--muted); background: var(--card); border: 1px dashed var(--border);
  border-radius: 8px; padding: 1.25rem 1.5rem; text-align: center;
}

/* Filters */
.filters {
  display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem;
  margin-bottom: 1rem;
}
.filters label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.82rem; color: var(--muted); }
.filters input, .filters select { min-width: 10rem; }
.btn-reset {
  padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 6px;
  text-decoration: none; color: var(--muted); background: var(--bg);
}

/* Live filters (/grid, /competitors, /review/errors): the form fires an hx-get
   as you type or choose, so there is no Apply button to style — it was removed
   rather than hidden. htmx sets .htmx-request on the hx-indicator element for
   the request's duration; dimming the results is enough feedback at ~350 ms,
   where a spinner would be more distracting than the wait itself. */
#grid-results.htmx-request,
#competitor-results.htmx-request,
#error-results.htmx-request { opacity: 0.55; transition: opacity 0.1s; }

/* Export (Step 8) — sits between the filters and the table, because it exports
   the filtered selection rather than the page. */
.export-bar { display: flex; align-items: center; gap: 0.75rem; margin: 0 0 1rem; }
.export-bar .hint { margin: 0; }
.btn-export {
  padding: 0.45rem 0.7rem; border: 1px solid var(--border); border-radius: 6px;
  text-decoration: none; color: var(--fg); background: var(--card); font-size: 0.9rem;
}
.btn-export:hover { border-color: var(--accent); color: var(--accent); }
table.grid td.day { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Tables — always horizontally scrollable inside their own wrapper so the page
   body never scrolls sideways. */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 0.9rem; background: var(--card); }
table.grid th, table.grid td { padding: 0.5rem 0.7rem; text-align: left; white-space: nowrap; }
table.grid thead th { background: var(--bg); border-bottom: 1px solid var(--border); font-weight: 600; }
table.grid tbody tr { border-top: 1px solid var(--border); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.notes { white-space: normal; max-width: 22rem; color: var(--muted); }
.url-cell {
  display: inline-block; max-width: 20rem; overflow: hidden; text-overflow: ellipsis;
  vertical-align: bottom; white-space: nowrap;
}
.methods { font-variant-numeric: tabular-nums; color: var(--muted); }

/* Product grouping in the grid */
tbody.product-group { border-top: 2px solid var(--border); }
tr.group-header th {
  background: var(--bg); text-align: left; font-weight: 600;
  position: sticky; left: 0;
}
tr.group-header .lb { font-family: ui-monospace, monospace; }
tr.group-header .pname { color: var(--muted); margin-left: 0.6rem; font-weight: 400; }

/* Sort links — inactive columns show a muted ⇅ so they read as clickable; the
   one active column shows ▲/▼ in the accent colour. Exactly one is ever active. */
.sort-link { text-decoration: none; color: var(--fg); white-space: nowrap; cursor: pointer; }
.sort-link:hover { text-decoration: underline; }
.sort-link .sort-ind { color: var(--muted); font-size: 0.8em; }
.sort-link.active { color: var(--accent); }
.sort-link.active .sort-ind { color: var(--accent); }

/* Badges */
.badge {
  display: inline-block; padding: 0.1rem 0.45rem; border-radius: 999px;
  font-size: 0.78rem; border: 1px solid var(--border); background: var(--bg);
}
.badge-ok { color: #1a7f37; border-color: #1a7f3733; background: #1a7f3714; }
.badge-warn { color: #9a6700; border-color: #9a670033; background: #9a670014; }
.badge-muted { color: var(--muted); }
.status-error, .status-implausible { color: #b00020; border-color: #b0002033; background: #b0002012; }
.status-not_found { color: #9a6700; }
.status-ok { color: #1a7f37; }
.row-warn td { background: #b0002008; }

/* Pager */
.pager { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
.pager a { text-decoration: none; padding: 0.35rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; }
.pager .disabled { color: var(--muted); padding: 0.35rem 0.7rem; }
.pager-status { color: var(--muted); font-size: 0.9rem; }

/* Write-back controls (Step 5). Inline forms sit tight to the value they act on;
   the HTMX post swaps just the row (or the pricing cell) in place. */
.inline-decide, .inline-toggle, .inline-resolve, .pricing-toggle {
  display: inline-flex; align-items: center; gap: 0.3rem; margin: 0.2rem 0 0;
}
.inline-decide select, .inline-resolve input[type="text"] {
  font-size: 0.82rem; padding: 0.1rem 0.3rem;
}
.inline-decide button, .inline-toggle button, .inline-resolve button,
.pricing-toggle button {
  font-size: 0.8rem; padding: 0.15rem 0.5rem; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg); color: var(--fg); cursor: pointer;
}
.inline-decide button:hover, .inline-toggle button:hover,
.inline-resolve button:hover, .pricing-toggle button:hover {
  border-color: var(--accent); color: var(--accent);
}
.pricing-cell { white-space: nowrap; }
.htmx-request.pricing-toggle, .htmx-request .inline-decide button { opacity: 0.5; }

/* Threshold editor (Step 6) */
.form-ok {
  color: #0a6b2e;
  background: rgba(10, 107, 46, 0.08);
  border: 1px solid rgba(10, 107, 46, 0.3);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin: 0 0 1rem;
}
@media (prefers-color-scheme: dark) {
  .form-ok { color: #7ee0a1; }
}
.settings-form button[type="submit"] { margin-top: 0.5rem; }
.setting-row {
  display: flex; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.75rem 0; border-top: 1px solid var(--border);
}
.setting-label { flex: 1 1 22rem; }
.setting-label label { display: block; font-weight: 600; }
.setting-label .hint { margin: 0.25rem 0 0; }
.setting-value { flex: 0 0 14rem; display: flex; flex-direction: column; gap: 0.35rem; }
.setting-value input[type="number"] { width: 8rem; padding: 0.3rem 0.4rem; }
.setting-static { font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.setting-updated { color: var(--muted); font-size: 0.8rem; }
.setting-row.has-error input[type="number"] { border-color: #b00020; }

/* --- User management (Step 7) -------------------------------------------- */
.user-create-form { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.user-create-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.user-create-form input, .user-create-form select { padding: 0.3rem 0.4rem; }
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.row-actions form { display: inline; }
.row-inactive td { opacity: 0.55; }
/* The one-time credential. Loud on purpose: it is shown exactly once. */
.credential {
  border: 1px solid #9a6700; background: #9a670012;
  border-radius: 6px; padding: 0.75rem 1rem;
}
.credential h2 { margin-top: 0; }
.credential-pair { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; }
.credential-pair dt { color: var(--muted); }
.credential-pair dd { margin: 0; }
.credential-value { font-size: 1.15rem; user-select: all; }
a.nav-user { color: inherit; }
/* A plain vertical form (own-account password change). Narrow on purpose —
   three password fields side by side read as a single cramped row. */
.stack-form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 22rem; }
.stack-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.stack-form input { padding: 0.35rem 0.45rem; }
.stack-form button[type="submit"] { align-self: flex-start; margin-top: 0.25rem; }
