/*
 * styles.css: lead marketplace demo.
 * Plain CSS, no web fonts. Light and dark themes follow the system setting;
 * the footer switch can force one by setting data-theme on <html>.
 */

/* ---------- Theme tokens ---------- */

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e6e9ee;
  --border: #dde2e8;
  --border-strong: #c3cad4;
  --text: #17202b;
  --text-muted: #556171;
  --accent: #2b59c3;
  --accent-hover: #2249a6;
  --accent-soft: #e8eefb;
  --accent-soft-text: #1e4296;
  --on-accent: #ffffff;
  --success: #176c43;
  --success-soft: #e3f3ea;
  --warning: #835000;
  --warning-soft: #fcf0d9;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 6%);
  --shadow-md: 0 6px 20px rgb(16 24 40 / 8%);
  --shadow-lg: 0 18px 48px rgb(16 24 40 / 22%);
  --backdrop: rgb(15 20 28 / 45%);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --gutter: 16px;
  --cart-bar-height: 0px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1c212a;
    --surface-3: #252b36;
    --border: #2a313c;
    --border-strong: #3b4452;
    --text: #e7eaf0;
    --text-muted: #a1aab9;
    --accent: #7f9eff;
    --accent-hover: #9cb4ff;
    --accent-soft: #1d2843;
    --accent-soft-text: #bccdff;
    --on-accent: #0b1222;
    --success: #5ccf97;
    --success-soft: #13291f;
    --warning: #f1b866;
    --warning-soft: #2f2413;
    --danger: #ff8f85;
    --danger-soft: #341917;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-md: 0 6px 20px rgb(0 0 0 / 35%);
    --shadow-lg: 0 18px 48px rgb(0 0 0 / 55%);
    --backdrop: rgb(0 0 0 / 60%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116;
  --surface: #161a21;
  --surface-2: #1c212a;
  --surface-3: #252b36;
  --border: #2a313c;
  --border-strong: #3b4452;
  --text: #e7eaf0;
  --text-muted: #a1aab9;
  --accent: #7f9eff;
  --accent-hover: #9cb4ff;
  --accent-soft: #1d2843;
  --accent-soft-text: #bccdff;
  --on-accent: #0b1222;
  --success: #5ccf97;
  --success-soft: #13291f;
  --warning: #f1b866;
  --warning-soft: #2f2413;
  --danger: #ff8f85;
  --danger-soft: #341917;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-md: 0 6px 20px rgb(0 0 0 / 35%);
  --shadow-lg: 0 18px 48px rgb(0 0 0 / 55%);
  --backdrop: rgb(0 0 0 / 60%);
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, ol, dl, dd, fieldset {
  margin: 0;
}

h1 {
  font-size: 1.625rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

h2 {
  font-size: 1.125rem;
  line-height: 1.3;
}

h3 {
  font-size: 1rem;
  line-height: 1.35;
}

ul, ol {
  padding: 0;
  list-style: none;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

fieldset {
  border: 0;
  padding: 0;
  min-width: 0;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  width: 1.1em;
  height: 1.1em;
  flex: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.skip-link:focus {
  top: 12px;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

@media (min-width: 768px) {
  :root {
    --gutter: 24px;
  }
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.875rem;
}

.mono {
  font-family: var(--mono);
  font-size: 0.9375em;
  letter-spacing: 0.01em;
}

.with-icon {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

:root[data-theme="dark"] .btn-danger {
  color: #1a0b0a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-danger {
    color: #1a0b0a;
  }
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(0.92);
}

.btn-danger-text {
  color: var(--danger);
}

.btn-added {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.btn-added:hover {
  box-shadow: inset 0 0 0 1px var(--success);
}

/* ---------- Header ---------- */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "brand tools"
    "switch switch";
  align-items: center;
  gap: 12px 12px;
  padding-top: 12px;
  padding-bottom: 12px;
}

/* Small screens: the demo badge sits under the name. Wider screens: one row. */
.brand {
  grid-area: brand;
  display: grid;
  grid-template-columns: auto minmax(0, auto);
  justify-content: start;
  align-items: center;
  gap: 2px 10px;
  min-width: 0;
}

.brand .brand-mark {
  grid-row: 1 / span 2;
}

.brand .demo-badge {
  justify-self: start;
}

@media (min-width: 560px) {
  .brand {
    display: flex;
    gap: 10px;
  }
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 800;
  font-size: 1.05rem;
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.demo-badge {
  display: inline-block;
  padding: 2px 8px;
  line-height: 1.4;
  border: 1px solid var(--warning);
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
  border-radius: 999px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.demo-badge strong {
  font-weight: 800;
  letter-spacing: 0.04em;
}

.header-tools {
  grid-area: tools;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-switch {
  grid-area: switch;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-width: 0;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.segmented button {
  min-height: 34px;
  padding: 6px 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9375rem;
  white-space: nowrap;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
}

.credit-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  font-weight: 700;
  white-space: nowrap;
}

.credit-chip:hover {
  border-color: var(--accent);
}

.credit-value {
  font-variant-numeric: tabular-nums;
}

.credit-unit {
  font-weight: 500;
}

.hide-sm {
  display: none;
}

@media (min-width: 560px) {
  .hide-sm {
    display: inline;
  }
}

@media (max-width: 480px) {
  .segmented button {
    padding: 6px 11px;
  }

  .credit-chip {
    padding: 6px 10px;
  }

  /* The chip's aria-label still says "credits". */
  .credit-unit {
    display: none;
  }
}

@media (min-width: 900px) {
  .header-inner {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "brand switch tools";
    gap: 16px 24px;
  }

  .header-switch {
    justify-content: flex-end;
  }
}

/* ---------- Tabs ---------- */

.tabs-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}

body[data-view="admin"] .tabs-bar {
  box-shadow: inset 0 3px 0 var(--accent);
}

/* On very narrow screens the tab strip scrolls by itself; the page never scrolls sideways. */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-current="page"] {
  color: var(--accent);
}

.tab[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
}

.tab-count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.75rem;
  font-weight: 700;
}

@media (max-width: 420px) {
  .tab {
    padding: 0 8px;
    font-size: 0.9375rem;
  }
}

/* ---------- Layout and page heads ---------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 24px;
  padding-bottom: calc(48px + var(--cart-bar-height));
}

.main:focus {
  outline: none;
}

body.has-cart-bar {
  --cart-bar-height: 72px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lede {
  margin-top: 6px;
  max-width: 62ch;
  color: var(--text-muted);
}

.mode-note {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

@media (min-width: 768px) {
  .card {
    padding: 20px 24px;
  }
}

.card > h2 + * {
  margin-top: 12px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 16px;
}

.card-head p {
  margin-top: 4px;
  max-width: 60ch;
}

.two-col {
  display: grid;
  gap: 20px;
}

@media (min-width: 960px) {
  .two-col {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    align-items: start;
  }
}

/* ---------- Tags, badges, notices ---------- */

.tag-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.tag .icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.tag-accent {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-soft-text);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-neutral {
  background: var(--surface-3);
  color: var(--text-muted);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
}

.notice > .icon {
  margin-top: 3px;
}

.notice .btn {
  margin-top: 8px;
}

.notice-info {
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.notice-success {
  background: var(--success-soft);
  color: var(--success);
}

.notice-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.notice-warning p {
  color: var(--text);
}

/* ---------- Empty states ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.empty-state p {
  max-width: 44ch;
  color: var(--text-muted);
}

.empty-state .btn {
  margin-top: 8px;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 4px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}

.empty-icon .icon {
  width: 26px;
  height: 26px;
}

.empty-inline {
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
}

/* ---------- Form controls ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

select,
input[type="search"],
input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23808a99' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
}

select:hover,
input:hover {
  border-color: var(--text-muted);
}

input::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}

.input-icon {
  position: relative;
  display: block;
}

.input-icon .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.input-icon input {
  padding-left: 38px;
}

/* ---------- Browse: filters ---------- */

.filters {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 38px;
  padding: 6px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9375rem;
}

.chip:hover {
  background: var(--surface-2);
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 12px;
}

@media (min-width: 900px) {
  .filter-grid {
    grid-template-columns: 1fr 1fr 1fr 1.6fr;
  }
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  margin-bottom: -8px;
}

.result-count {
  font-weight: 600;
  color: var(--text-muted);
}

/* ---------- Browse: lead cards ---------- */

.lead-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 16px;
}

.lead-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.lead-card:hover {
  box-shadow: var(--shadow-md);
}

.lead-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-md);
}

.lead-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.age {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.lead-req {
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.lead-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}

.lead-facts dt,
.detail-grid dt,
.summary-rows dt {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.lead-facts dd {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.avail-low {
  color: var(--warning);
}

.masked {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.9375rem;
}

.masked-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.masked-line {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-wrap: anywhere;
}

.masked-line .icon {
  color: var(--text-muted);
}

.lead-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.price {
  color: var(--text-muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

.price-value {
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

/* ---------- Smart search ---------- */

.smart {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background:
    linear-gradient(180deg, var(--accent-soft), transparent 140px),
    var(--surface);
}

.smart-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.smart-head p {
  margin-top: 4px;
}

.smart-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
}

.smart-sub {
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
}

.smart-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.smart-form input {
  flex: 1 1 240px;
  min-height: 46px;
}

.smart-form .btn {
  flex: 0 0 auto;
  min-height: 46px;
}

@media (max-width: 480px) {
  .smart-form .btn {
    flex: 1 1 100%;
  }
}

.smart-examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.link-chip {
  padding: 4px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: left;
}

.link-chip:hover {
  border-style: solid;
  border-color: var(--accent);
}

.smart-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
}

.understood {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.understood .btn {
  margin-left: auto;
}

.match-title {
  margin-top: 4px;
  font-size: 0.9375rem;
}

.match-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.match {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.match-best {
  border-left: 4px solid var(--accent);
}

.match-body {
  flex: 1 1 280px;
  min-width: 0;
}

.match-req {
  font-weight: 650;
  overflow-wrap: anywhere;
}

.match-meta {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.match-reason {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 6px;
  color: var(--accent-soft-text);
  font-size: 0.875rem;
  font-weight: 600;
}

.match-reason .icon {
  margin-top: 2px;
  color: var(--accent);
}

.match-side {
  display: flex;
  align-items: center;
  gap: 12px;
}

.match-list-others .match {
  background: var(--surface-2);
}

/* ---------- Cart ---------- */

.cart-layout {
  display: grid;
  gap: 20px;
}

@media (min-width: 900px) {
  .cart-layout {
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
  }

  .summary {
    position: sticky;
    top: 72px;
  }
}

.cart-list > li + li {
  border-top: 1px solid var(--border);
}

.cart-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 14px 0;
}

.cart-item:first-child {
  padding-top: 0;
}

.cart-item:last-child {
  padding-bottom: 0;
}

.cart-item-main {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cart-req {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.cart-item-side {
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.summary-rows > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}

.summary-rows dt {
  font-size: 0.9375rem;
}

.summary-rows dd {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.summary-total {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 1.125rem;
}

.summary-total dt {
  color: var(--text);
  font-weight: 700;
}

/* ---------- Wallet ---------- */

.wallet-grid {
  display: grid;
  gap: 20px;
}

@media (min-width: 860px) {
  .wallet-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    align-items: start;
  }
}

.balance-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.balance {
  color: var(--text-muted);
  font-size: 1.125rem;
}

.balance-value {
  color: var(--text);
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.balance-card .notice {
  margin-top: 8px;
}

.amount-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 16px;
}

@media (min-width: 560px) {
  .amount-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.amount-option,
.radio-card {
  position: relative;
  cursor: pointer;
}

.amount-option input,
.radio-card input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.amount-option > span {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: center;
}

.amount-option strong {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.amount-option input:checked + span,
.radio-card input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}

.amount-option input:focus-visible + span,
.radio-card input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.gateway-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.gateway-box > .icon {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  color: var(--text-muted);
}

.activity > li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}

.activity > li + li {
  border-top: 1px solid var(--border);
}

.activity-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.activity-amount.is-plus {
  color: var(--success);
}

/* ---------- My leads ---------- */

.owned-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
  gap: 16px;
}

.owned {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.owned-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 10px 16px;
}

.detail-grid dd {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.owned-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ---------- Admin: upload ---------- */

.step {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-no {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  font-size: 0.875rem;
  font-weight: 800;
}

.upload-actions,
.step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.file-btn {
  position: relative;
  cursor: pointer;
}

.file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-btn:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.table-wrap-narrow {
  max-width: 760px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table tbody tr:last-child > * {
  border-bottom: 0;
}

.data-table thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}

.data-table tbody th {
  font-weight: 600;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mapping-table {
  table-layout: fixed;
}

.mapping-table th:first-child {
  width: 45%;
}

.mapping-table select {
  min-width: 0;
}

.col-name {
  display: block;
}

.col-example {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 400;
  overflow-wrap: anywhere;
}

.preview-table td {
  min-width: 110px;
}

.preview-table td:nth-child(3) {
  min-width: 220px;
}

.file-cell {
  overflow-wrap: anywhere;
}

.import-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  color: var(--text-muted);
}

.import-summary strong {
  color: var(--text);
}

.result-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-color: var(--success);
  box-shadow: 0 0 0 1px var(--success), var(--shadow-sm);
}

.result-card h2 {
  color: var(--success);
}

.result-line {
  font-size: 1.375rem;
  font-weight: 750;
}

.result-notes {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 20px;
  list-style: disc;
  color: var(--text-muted);
}

/* ---------- Admin: prices and sale setting ---------- */

.radio-cards {
  display: grid;
  gap: 10px;
}

@media (min-width: 700px) {
  .radio-cards {
    grid-template-columns: 1fr 1fr;
  }
}

.radio-cards legend {
  margin-bottom: 10px;
  font-weight: 600;
}

.radio-card > span {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.price-table td {
  min-width: 96px;
}

.price-input {
  max-width: 110px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Admin: sales ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 900px) {
  .stat-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.stat-value {
  font-size: 1.625rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(80px, 110px) 1fr 36px;
  align-items: center;
  gap: 12px;
}

.bar-label {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.bar-value {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.refund-list > li + li,
.buyer-list > li + li {
  border-top: 1px solid var(--border);
}

.refund {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 14px 0;
}

.refund:first-child,
.buyer:first-child {
  padding-top: 0;
}

.refund:last-child,
.buyer:last-child {
  padding-bottom: 0;
}

.refund-main {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.refund-lead {
  overflow-wrap: anywhere;
}

.refund-actions,
.buyer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Admin: buyers ---------- */

.buyer {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 8px 14px;
  padding: 14px 0;
}

.buyer .buyer-actions {
  grid-column: 2;
}

@media (min-width: 600px) {
  .buyer {
    grid-template-columns: 40px minmax(0, 1fr) auto;
  }

  .buyer .buyer-actions {
    grid-column: auto;
  }
}

.buyer-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 800;
}

.buyer-main {
  flex: 1 1 220px;
  min-width: 0;
}

/* ---------- Cart bar ---------- */

.cart-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 24px rgb(16 24 40 / 10%);
}

.cart-bar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding-top: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

.cart-bar-actions {
  display: flex;
  gap: 8px;
}

/* ---------- Toasts ---------- */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--cart-bar-height));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(calc(100% - 32px), 480px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 0.9375rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease, transform 200ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast .icon {
  margin-top: 2px;
}

/* Toast icons sit on an inverted background, so they use the other theme's colours. */
.toast-success .icon { color: #6fe0a6; }
.toast-info .icon { color: #a8bfff; }
.toast-error .icon { color: #ffa39b; }

:root[data-theme="dark"] .toast-success .icon { color: #176c43; }
:root[data-theme="dark"] .toast-info .icon { color: #2b59c3; }
:root[data-theme="dark"] .toast-error .icon { color: #b42318; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toast-success .icon { color: #176c43; }
  :root:not([data-theme="light"]) .toast-info .icon { color: #2b59c3; }
  :root:not([data-theme="light"]) .toast-error .icon { color: #b42318; }
}

/* ---------- Modal ---------- */

.modal {
  width: min(calc(100% - 32px), 480px);
  max-height: calc(100% - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.modal::backdrop {
  background: var(--backdrop);
}

.modal-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-lead {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-weight: 600;
}

.reason-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reason-list legend {
  margin-bottom: 6px;
  font-weight: 600;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.radio-row:hover {
  background: var(--surface-2);
}

.radio-row input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- Footer ---------- */

.app-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.875rem;
  padding-bottom: var(--cart-bar-height);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
  padding-top: 16px;
  padding-bottom: 16px;
}

.storage-note {
  color: var(--warning);
  font-weight: 600;
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.theme-label {
  margin-right: 4px;
}

.theme-switch button {
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.theme-switch button[aria-pressed="true"] {
  background: var(--surface-3);
  color: var(--text);
}

/* ---------- Motion ---------- */

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