/*
 * Components. Only var(--…) from tokens.css / theme-*.css; no colour, font or radius literals here
 * (tests/test_ui.py enforces it). color-mix() of a token with transparent is allowed.
 */

/* ------------------------------------------------------------------ base */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  background: var(--color-bg);
  /* Room for the scrollbar on every page, scrolling or not: otherwise the right part of the top
     bar jumps by the bar's width between pages (same rule in admin.css). */
  scrollbar-gutter: stable;
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg);
  background-image: var(--app-bg-image);
  background-size: var(--app-bg-size);
  background-attachment: fixed;
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  font-weight: var(--weight-regular);
  line-height: 1.45;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
a {
  color: var(--color-text-soft);
}
a:hover {
  color: var(--color-text-strong);
}
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.num,
.tabular {
  font-variant-numeric: tabular-nums;
}
.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-text-faint);
}
.muted {
  color: var(--color-text-muted);
}
.faint {
  color: var(--color-text-faint);
}
.sep {
  color: var(--color-text-ghost);
  margin: 0 6px;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
/* Header (.app-header), .icon, .dot, .count-badge, .btn-logout: header.css (shared with the admin). */

/* ------------------------------------------------------------------ page */
.page {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 18px var(--page-gutter) 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--gap-lg) var(--gap-xl);
}
.page-head-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}
.breadcrumb a {
  color: var(--color-text-muted);
  text-decoration: none;
}
.breadcrumb a:hover {
  color: var(--color-text-strong);
}
.title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.page-title {
  margin: 0;
  font-size: var(--fs-title);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-title);
  line-height: 1.2;
}
.page-meta {
  font-size: 13px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-sm);
}
.toolbar-divider {
  width: 1px;
  height: 22px;
  background: var(--button-border);
  margin: 0 var(--gap-xs);
}

/* ----------------------------------------------------------------- cards */
.card {
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 16px 18px;
}
.card-elevated {
  box-shadow: var(--shadow-card);
}
.card-accent {
  border-radius: 16px;
  background: var(--accent-card-bg);
  border: 1px solid var(--color-border-strong);
  box-shadow: var(--shadow-pop);
  padding: 10px 16px 12px;
}
.section-label {
  margin: 0;
  font-size: var(--fs-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-faint);
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-value {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: var(--fs-kpi);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}
.kpi-note {
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--gap-md);
}
.empty-state {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 28px 24px;
  text-align: left;
}
.empty-state h2 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--weight-bold);
}
.empty-state p {
  margin: 0;
  color: var(--color-text-muted);
}

/* --------------------------------------------------------------- buttons */
.btn {
  height: var(--button-height);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--button-radius);
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--color-text);
  font-size: var(--fs-sm);
  font-weight: var(--weight-strong);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover {
  color: var(--color-text-strong);
  border-color: color-mix(in srgb, var(--color-text-strong) 22%, transparent);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  border: 0;
  background: var(--button-primary-bg);
  color: var(--color-accent-ink);
  font-weight: var(--weight-heavy);
  box-shadow: var(--button-primary-shadow);
  padding: 0 14px;
}
.btn-primary:hover {
  color: var(--color-accent-ink);
  filter: brightness(1.06);
}
.btn-warning {
  border-color: color-mix(in srgb, var(--color-warning) 40%, transparent);
  background: color-mix(in srgb, var(--color-warning) 7%, transparent);
  color: var(--color-warning-text);
}
.btn-danger {
  border-color: color-mix(in srgb, var(--color-danger) 40%, transparent);
  background: color-mix(in srgb, var(--color-danger) 8%, transparent);
  color: var(--color-danger-text);
}
.btn-warning:hover {
  color: var(--color-warning-text);
}
.btn-danger:hover {
  color: var(--color-danger-text);
}
.btn-lg {
  height: var(--button-height-lg);
  padding: 0 16px;
  font-size: var(--fs-md);
}
.btn-icon {
  width: var(--button-height);
  padding: 0;
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text-soft);
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-hover-faint);
  border: 1px solid var(--color-border);
}
.segmented > button,
.segmented > a {
  height: var(--segment-height);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: var(--weight-bold);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.segmented > [aria-pressed="true"],
.segmented > [aria-current="true"] {
  border-color: var(--color-accent-line);
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.kbd {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: inline-block;
  border-radius: var(--radius-xs);
  border: 1px solid var(--button-border);
  background: var(--color-hover-faint);
  color: var(--color-text-soft);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 20px;
  text-align: center;
}

/* ---------------------------------------------------------------- fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}
.input,
.field input,
.field select,
.field textarea {
  height: var(--field-height);
  width: 100%;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--color-border-strong);
  background: var(--color-field);
  color: var(--color-text);
  font-size: var(--fs-md);
  outline: none;
}
.field textarea {
  height: auto;
  min-height: 80px;
  padding: 8px 12px;
}
.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--color-accent);
  background: var(--color-field-focus);
  color: var(--color-text-strong);
  box-shadow: 0 0 0 3px var(--color-accent-soft), 0 0 16px var(--color-accent-soft);
}
.field [aria-invalid="true"],
.field .is-invalid {
  border-color: color-mix(in srgb, var(--color-danger) 60%, transparent);
}
.field-error,
.errorlist {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--color-danger-text);
  font-size: 12px;
}
.search {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search .icon {
  position: absolute;
  left: 11px;
  color: var(--color-text-faint);
}
.search input {
  width: 200px;
  height: var(--button-height);
  padding: 0 12px 0 31px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border-strong);
  background: var(--color-field);
  color: var(--color-text);
  font-size: var(--fs-sm);
  outline: none;
}
.search input:focus {
  border-color: var(--color-accent-line);
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: 13px;
  color: var(--color-text-soft);
  cursor: pointer;
}
.checkbox input {
  accent-color: var(--color-accent);
  width: 15px;
  height: 15px;
  margin: 0;
}

/* ------------------------------------------------- dots, pills, statuses */
/* .dot itself is in header.css; --tone is inherited from the closest [data-status] / [data-tone] /
   [data-state] ancestor. */
.status-pill {
  --tone: var(--status-retired);
  --tone-text: var(--status-retired-text);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: var(--status-pill-width);
  height: var(--pill-height);
  padding: 0 10px;
  border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, var(--tone) 45%, transparent);
  background: color-mix(in srgb, var(--tone) 10%, transparent);
  color: var(--tone-text);
  font-size: var(--fs-sm);
  font-weight: var(--weight-strong);
  white-space: nowrap;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--tone);
  box-shadow: 0 0 9px color-mix(in srgb, var(--tone) 75%, transparent);
}
[data-status="candidate"] {
  --tone: var(--status-candidate);
  --tone-text: var(--status-candidate-text);
}
[data-status="needs_review"] {
  --tone: var(--status-needs-review);
  --tone-text: var(--status-needs-review-text);
}
[data-status="approved"] {
  --tone: var(--status-approved);
  --tone-text: var(--status-approved-text);
}
[data-status="rejected"] {
  --tone: var(--status-rejected);
  --tone-text: var(--status-rejected-text);
}
[data-status="retired"] {
  --tone: var(--status-retired);
  --tone-text: var(--status-retired-text);
}
[data-tone="ok"] {
  --tone: var(--status-approved);
  --tone-text: var(--status-approved-text);
}
[data-tone="warning"] {
  --tone: var(--color-warning);
  --tone-text: var(--color-warning-text);
}
[data-tone="danger"] {
  --tone: var(--color-danger);
  --tone-text: var(--color-danger-text);
}
[data-tone="info"] {
  --tone: var(--color-info);
  --tone-text: var(--color-info-text);
}
[data-tone="neutral"] {
  --tone: var(--status-retired);
  --tone-text: var(--status-retired-text);
}
.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border-strong);
  background: var(--color-hover-faint);
  color: var(--color-text-soft);
  font-size: 12px;
  font-weight: var(--weight-strong);
  white-space: nowrap;
}
.tag[data-tone] {
  border-color: color-mix(in srgb, var(--tone) 45%, transparent);
  background: transparent;
  color: var(--tone-text);
}

/* ----------------------------------------------------------- data tables */
.table-card {
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
}
.data-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-variant-numeric: tabular-nums;
}
.data-table th,
.data-table td {
  height: var(--row-height);
  padding: 0 14px;
  white-space: nowrap;
}
.data-table thead th {
  height: 44px;
  vertical-align: bottom;
  padding-bottom: 9px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-size: 12px;
  font-weight: var(--weight-strong);
  letter-spacing: var(--tracking-th);
  text-transform: uppercase;
  color: var(--color-text-faint);
}
.data-table tbody th {
  text-align: left;
  font-weight: var(--weight-strong);
  color: var(--color-text-row);
}
.data-table tbody tr:hover {
  background: var(--color-hover);
}
.data-table tbody tr:hover > th {
  color: var(--color-text-strong);
}
.data-table .col-num,
.data-table thead th.col-num {
  text-align: right;
}
.data-table th:first-child,
.data-table td:first-child {
  padding-left: 22px;
}
.data-table .row-stripe {
  position: relative;
}
.data-table .row-stripe::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: var(--stripe-width);
  border-radius: 2px;
  background: var(--tone, transparent);
  box-shadow: 0 0 8px var(--tone, transparent);
}
.data-table .group-row th {
  height: 34px;
  padding-top: 14px;
  vertical-align: bottom;
  font-size: var(--fs-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-faint);
}
.data-table .group-row:hover {
  background: transparent;
}

/* ------------------------------------------------------------ price cell */
.price {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  color: var(--color-text-row);
  font-weight: var(--weight-regular);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.price-dec {
  color: var(--color-text-faint);
}
.price[data-state="min"] {
  --tone: var(--price-min);
  color: var(--price-min-text);
  font-weight: var(--weight-bold);
}
.price[data-state="max"] {
  --tone: var(--price-max);
  color: var(--price-max-text);
  font-weight: var(--weight-bold);
}
.price[data-state="min"] .price-dec,
.price[data-state="max"] .price-dec {
  color: inherit;
  opacity: 0.6;
}
.price[data-state="min"] .dot,
.price[data-state="max"] .dot {
  width: 6px;
  height: 6px;
}
.price[data-state="suspect"] {
  color: var(--color-warning-text);
}
.price[data-state="suspect"] .icon {
  color: var(--color-warning);
}
.price[data-state="stale"] {
  color: var(--price-stale-text);
}
.price[data-state="used"] {
  color: var(--price-used-text);
}
.price[data-state="missing"],
.price[data-state="review"] {
  color: var(--color-text-faint);
  font-weight: var(--weight-bold);
}
.review-ring {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--status-needs-review);
}
.used-chip {
  height: 16px;
  padding: 0 5px;
  border-radius: 5px;
  border: 1px solid color-mix(in srgb, var(--color-text-strong) 18%, transparent);
  color: var(--color-text-soft);
  font-size: 10px;
  font-weight: var(--weight-bold);
  line-height: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-sm) 20px;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}
.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* --------------------------------------------------------- alerts, toast */
.alert-row {
  position: relative;
  padding: 10px 14px 10px 16px;
  border-radius: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.alert-row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: var(--stripe-width);
  border-radius: 2px;
  background: var(--tone);
  box-shadow: 0 0 8px var(--tone);
}
.alert-title {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: 13.5px;
  font-weight: var(--weight-bold);
  color: var(--tone-text);
}
.alert-title time {
  margin-left: auto;
  font-size: 12px;
  font-weight: var(--weight-regular);
  color: var(--color-text-faint);
}

.toasts {
  position: fixed;
  right: var(--page-gutter);
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  max-width: min(440px, calc(100vw - 2 * var(--page-gutter)));
  margin: 0;
  padding: 0;
  list-style: none;
}
.toast {
  --tone: var(--color-accent);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--color-surface-raised);
  border: 1px solid color-mix(in srgb, var(--tone) 45%, transparent);
  box-shadow: var(--shadow-pop);
  font-size: 13px;
}
.toast[data-tone="warning"] .icon {
  color: var(--color-warning);
}
.toast[data-tone="danger"] .icon {
  color: var(--color-danger);
}
.toast .icon {
  color: var(--color-accent);
}

/* ----------------------------------------------------------------- login */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px var(--page-gutter);
}
.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: var(--gap-lg);
  padding: 26px 26px 24px;
  box-shadow: var(--shadow-card);
}
.login-card .brand {
  padding: 0;
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card .btn-primary {
  height: var(--button-height-lg);
  font-size: var(--fs-md);
}

/* ------------------------------------------------------------- utilities */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
}
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.chart {
  width: 100%;
  height: 320px;
}

/* ------------------------------------------------------- match tokens */
.match-title {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  font-size: var(--fs-lg);
  line-height: 26px;
}
.match-token {
  padding: 0 6px;
  border-radius: var(--radius-xs);
  border: 1px solid transparent;
  color: var(--color-text-soft);
}
.match-token[data-match="ok"] {
  background: var(--token-ok-bg);
  border-color: var(--token-ok-border);
  color: var(--token-ok-text);
  font-weight: var(--weight-bold);
}
.match-token[data-match="ambiguous"] {
  background: var(--token-ambiguous-bg);
  border-color: var(--token-ambiguous-border);
  color: var(--token-ambiguous-text);
  font-weight: var(--weight-bold);
}
.match-token[data-match="excluded"] {
  background: var(--token-excluded-bg);
  border-color: var(--token-excluded-border);
  color: var(--token-excluded-text);
  font-weight: var(--weight-bold);
}

/* Matrix summary columns */
.price-min-col {
  color: var(--price-min-text);
  font-weight: var(--weight-strong);
}
.price-max-col {
  color: var(--price-max-text);
  font-weight: var(--weight-strong);
}

/* ------------------------------------------------------- style guide */
.sg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 14px;
}
.sg-accent {
  width: 340px;
  max-width: 100%;
}
.sg-spread {
  justify-content: space-between;
  font-size: 13px;
}
