/* ===== Design Tokens — Claude-style warm paper palette ===== */
:root, [data-theme='light'] {
  /* Surfaces — warm cream paper */
  --color-bg: #faf9f5;
  --color-surface: #ffffff;
  --color-surface-2: #fbfaf7;
  --color-surface-offset: #f0eee6;
  --color-surface-offset-2: #e8e5da;
  --color-divider: #eae7dd;
  --color-border: #ddd9cd;

  --color-text: #1f1e1d;
  --color-text-muted: #6b6862;
  --color-text-faint: #97948c;
  --color-text-inverse: #fdfcfa;

  /* Primary accent — Claude clay */
  --color-primary: #c96442;
  --color-primary-hover: #b05233;
  --color-primary-active: #954429;
  --color-primary-highlight: #f6e9e2;

  --color-warning: #93601a;
  --color-warning-highlight: #f4ead4;
  --color-error: #a8322f;
  --color-error-highlight: #f6dedc;
  --color-success: #3d7d54;
  --color-success-highlight: #e0eee4;
  --color-danger: #a8322f;

  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(31, 30, 29, 0.05);
  --shadow-md: 0 4px 14px rgba(31, 30, 29, 0.07);
  --shadow-lg: 0 18px 44px rgba(31, 30, 29, 0.16);

  --font-display: 'Source Serif 4', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', monospace;
}

[data-theme='dark'] {
  --color-bg: #262624;
  --color-surface: #30302e;
  --color-surface-2: #333331;
  --color-surface-offset: #3a3a37;
  --color-surface-offset-2: #45443f;
  --color-divider: #3d3c38;
  --color-border: #4a4944;

  --color-text: #f5f4ee;
  --color-text-muted: #b0aea6;
  --color-text-faint: #86847d;
  --color-text-inverse: #1f1e1d;

  --color-primary: #d97757;
  --color-primary-hover: #e69377;
  --color-primary-active: #c96442;
  --color-primary-highlight: #3b2b24;

  --color-warning: #d7a55c;
  --color-warning-highlight: #3a2f1d;
  --color-error: #e08880;
  --color-error-highlight: #3b2422;
  --color-success: #7cc297;
  --color-success-highlight: #1f3327;
  --color-danger: #e08880;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --color-bg: #262624;
    --color-surface: #30302e;
    --color-surface-2: #333331;
    --color-surface-offset: #3a3a37;
    --color-surface-offset-2: #45443f;
    --color-divider: #3d3c38;
    --color-border: #4a4944;
    --color-text: #f5f4ee;
    --color-text-muted: #b0aea6;
    --color-text-faint: #86847d;
    --color-text-inverse: #1f1e1d;
    --color-primary: #d97757;
    --color-primary-hover: #e69377;
    --color-primary-active: #c96442;
    --color-primary-highlight: #3b2b24;
    --color-warning: #d7a55c;
    --color-warning-highlight: #3a2f1d;
    --color-error: #e08880;
    --color-error-highlight: #3b2422;
    --color-success: #7cc297;
    --color-success-highlight: #1f3327;
    --color-danger: #e08880;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.5);
  }
}

:root {
  --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.84rem + 0.2vw, 0.9375rem);
  --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.3125rem);
  --text-xl: clamp(1.375rem, 1.2rem + 0.9vw, 1.75rem);
  --text-2xl: clamp(1.75rem, 1.4rem + 1.6vw, 2.375rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
}

/* ===== Layout ===== */
html, body { height: 100%; overflow-x: hidden; }
#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5) var(--space-3);
  position: sticky;
  top: 0;
  background: color-mix(in oklab, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
}
.brand svg { width: 24px; height: 24px; color: var(--color-primary); flex-shrink: 0; }

.topbar-right { display: flex; align-items: center; gap: var(--space-2); }

/* Live session counter — hidden unless the self-hosted server answers */
.presence {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}
.presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-success);
  flex-shrink: 0;
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
}
.icon-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; }

main { flex: 1; padding: 0 var(--space-5) var(--space-16); }

/* ===== Composer ===== */
.composer-wrap { margin-top: var(--space-6); margin-bottom: var(--space-6); }
.greeting {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 400;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-5);
  color: var(--color-text);
}
.greeting .greeting-accent { color: var(--color-primary); }

.composer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  box-shadow: var(--shadow-sm);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.composer:focus-within {
  border-color: color-mix(in oklab, var(--color-primary) 55%, var(--color-border));
  box-shadow: 0 0 0 4px var(--color-primary-highlight);
}
#query {
  flex: 1;
  border: none;
  background: none;
  padding: var(--space-3) 0;
  font-size: var(--text-base);
  outline: none;
  min-width: 0;
}
#query::placeholder { color: var(--color-text-faint); }

.clear-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  flex-shrink: 0;
}
.clear-btn.visible { display: flex; }
.clear-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.clear-btn svg { width: 16px; height: 16px; }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:hover { background: var(--color-primary-hover); }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { background: var(--color-surface-offset-2); color: var(--color-text-faint); cursor: default; transform: none; }

/* Suggestion pills */
.chips {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-4);
}
.chip {
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}
.chip:hover { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-highlight); }
.chip:active { transform: scale(0.96); }

.search-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-4);
  line-height: 1.6;
}

/* ===== Results — styled as an assistant answer ===== */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--color-text-faint);
}
.empty-state svg { width: 40px; height: 40px; margin: 0 auto var(--space-4); color: var(--color-text-faint); opacity: 0.55; }
.empty-state p { font-size: var(--text-sm); max-width: 34ch; margin: 0 auto; line-height: 1.6; }

.answer {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  margin-bottom: var(--space-4);
}
.answer-mark {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  color: var(--color-primary);
  margin-top: 2px;
}
.answer-text {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.answer-text strong { font-weight: 600; }
.answer-text .answer-rate { color: var(--color-primary); font-weight: 600; }
.answer-credit {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
  margin-top: var(--space-2);
}
.answer-credit strong { color: var(--color-text); font-weight: 600; }
.answer-value {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
  margin-top: var(--space-2);
}
.answer-value strong { color: var(--color-primary); font-weight: 700; font-family: var(--font-mono); }

/* Optional purchase amount, under the composer */
.amount-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}
.amount-field {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.amount-field:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-highlight);
}
.amount-prefix { color: var(--color-text-faint); font-size: var(--text-sm); }
.amount-field input {
  width: 5.5rem;
  border: none;
  background: none;
  outline: none;
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  min-width: 0;
}
.amount-field input::placeholder { font-family: var(--font-body); color: var(--color-text-faint); }
.amount-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  flex: 1 1 12rem;
  line-height: 1.45;
}

.rate-value {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-primary);
  margin-top: var(--space-1);
  white-space: nowrap;
}

/* Statement credits that apply to this purchase (credits.js) */
.result-credits {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: var(--space-3);
  border: 1px dashed color-mix(in oklab, var(--color-primary) 35%, var(--color-border));
  border-radius: var(--radius-md);
  background: color-mix(in oklab, var(--color-primary-highlight) 55%, transparent);
}
.credit-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); font-size: var(--text-sm); }
.credit-amount {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-xs);
  color: var(--color-primary);
  white-space: nowrap;
}
.credit-label { font-weight: 600; }
.credit-enroll {
  margin-left: var(--space-2);
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-warning);
  background: var(--color-warning-highlight);
  white-space: nowrap;
}
.credit-note {
  flex-basis: 100%;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
}
.credit-status {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-left: auto;
  white-space: nowrap;
}
.credit-toggle {
  order: 3;
  flex-basis: 100%;
  align-self: flex-start;
  padding: var(--space-1) var(--space-3);
  border: 1px solid color-mix(in oklab, var(--color-primary) 40%, var(--color-border));
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-primary);
  background: var(--color-surface);
  -webkit-tap-highlight-color: transparent;
}
.credit-toggle:hover { background: var(--color-primary-highlight); }
.credit-toggle:active { transform: scale(0.97); }

/* A credit already spent this period: still listed, visibly not in play. */
.credit-row.spent { opacity: 0.6; }
.credit-row.spent .credit-amount { text-decoration: line-through; }
.credit-row.spent .credit-toggle { color: var(--color-text-muted); border-color: var(--color-border); }

/* Credits panel in the settings sheet */
.credits-section { margin-top: var(--space-5); }
.credits-blurb {
  padding: 0 var(--space-5);
  margin-bottom: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
}
.credit-manage-row {
  margin: 0 var(--space-5) var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.credit-manage-row.spent { opacity: 0.62; }
.credit-manage-head { display: flex; align-items: center; gap: var(--space-2); }
.credit-manage-name { font-size: var(--text-sm); font-weight: 600; }
.credit-manage-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}
.credit-manage-controls { margin-top: var(--space-2); }
.credit-manage-input {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.credit-manage-input input {
  width: 5.5rem;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
}
.credit-manage-toggle {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--color-surface-2);
}

.results { display: flex; flex-direction: column; gap: var(--space-3); }

.result-card {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: rise 320ms cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
.result-card:nth-child(1) { animation-delay: 0ms; }
.result-card:nth-child(2) { animation-delay: 40ms; }
.result-card:nth-child(3) { animation-delay: 80ms; }
.result-card:nth-child(n+4) { animation-delay: 120ms; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-card.best {
  border-color: color-mix(in oklab, var(--color-primary) 45%, var(--color-border));
  background: var(--color-surface);
  box-shadow: 0 0 0 3px var(--color-primary-highlight), var(--shadow-md);
  padding-top: calc(var(--space-5) + var(--space-4)); /* clears the "Best match" tab */
}
.result-card.best::before {
  content: 'Best match';
  position: absolute;
  top: 0;
  right: var(--space-5);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 4px 10px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.result-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.result-identity { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.card-swatch {
  width: 44px;
  height: 30px;
  border-radius: 6px;
  flex-shrink: 0;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15), var(--shadow-sm);
}
.card-swatch::after {
  content: '';
  position: absolute;
  top: 6px; left: 6px;
  width: 12px; height: 8px;
  border-radius: 2px;
  background: rgba(255,255,255,0.55);
}
.result-name { font-weight: 600; font-size: var(--text-base); line-height: 1.3; }
.result-network { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: 2px; }

.result-rate { text-align: right; flex-shrink: 0; }
.rate-number {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-xl);
  color: var(--color-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.rate-unit { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: 4px; }

.result-category {
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}
.result-category .cat-label { font-weight: 600; }
.result-category .cat-cap { color: var(--color-text-muted); font-size: var(--text-xs); display: block; margin-top: 2px; }

.result-fallback-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  color: var(--color-warning);
  background: var(--color-warning-highlight);
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.switch-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-2);
  margin-top: var(--space-2);
  line-height: 1.5;
}
.switch-hint strong { color: var(--color-text); }

.result-note {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-2);
  line-height: 1.5;
}

/* ===== Settings Sheet ===== */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 30, 29, 0.42);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 720px;
  margin: 0 auto;
  max-height: 86vh;
  background: var(--color-bg);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 41;
  transform: translateY(100%);
  transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
  margin: var(--space-3) auto var(--space-2);
  flex-shrink: 0;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5) var(--space-4);
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-divider);
}
.sheet-header h2 { font-size: var(--text-lg); font-weight: 600; font-family: var(--font-display); }
.sheet-body { overflow-y: auto; padding: var(--space-4) var(--space-5) var(--space-8); }

.settings-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0;
  margin-bottom: var(--space-3);
  overflow: hidden;
  background: var(--color-surface);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.settings-card.disabled { border-color: var(--color-divider); background: var(--color-surface-2); }
.settings-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: 56px;
  padding: var(--space-3) var(--space-4);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.settings-card-head:hover { background: var(--color-surface-offset); }
.settings-card-head:active { background: var(--color-surface-offset); }
.settings-card-head .name {
  font-weight: 600;
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
  transition: color 0.15s ease, opacity 0.15s ease;
}
.settings-card.disabled .settings-card-head .name { color: var(--color-text-muted); opacity: 0.6; }
.settings-card-head .swatch-mini { width: 22px; height: 16px; border-radius: 4px; flex-shrink: 0; transition: opacity 0.15s ease; }
.settings-card.disabled .swatch-mini { opacity: 0.35; }

/* iOS-style switch: large, unambiguous tap target */
.toggle-visibility {
  position: relative;
  flex-shrink: 0;
  width: 51px;
  height: 31px;
  border-radius: var(--radius-full);
  background: var(--color-surface-offset-2);
  padding: 2px;
  display: flex;
  align-items: center;
  transition: background 0.2s ease;
  pointer-events: none; /* row click drives the toggle */
}
.toggle-visibility svg { display: none; }
.toggle-visibility::after {
  content: '';
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transform: translateX(0);
  transition: transform 0.2s ease;
}
.settings-card:not(.disabled) .toggle-visibility { background: var(--color-primary); }
.settings-card:not(.disabled) .toggle-visibility::after { transform: translateX(20px); }
.settings-card.disabled { opacity: 1; }

.field-row { padding: 0 var(--space-4) var(--space-4); }
.field-row label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: block;
  margin-bottom: var(--space-1);
}
.field-row select, .field-row input[type=number] {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  background: var(--color-surface-2);
}

.remove-card-btn {
  display: block;
  width: calc(100% - var(--space-8));
  margin: 0 var(--space-4) var(--space-4);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--color-danger);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}
.remove-card-btn:hover, .remove-card-btn:active { background: var(--color-error-highlight); }

.settings-subhead {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin: var(--space-5) 0 var(--space-2);
}
.wallet-section:first-child .settings-subhead { margin-top: 0; }

.add-card-section { margin-top: var(--space-5); }
.add-card-controls {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.add-card-search {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
.add-card-search:focus { outline: none; border-color: var(--color-primary); }
.add-card-issuer-select {
  flex: 0 0 auto;
  max-width: 42%;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
.add-card-issuer-select:focus { outline: none; border-color: var(--color-primary); }

.add-card-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.add-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: 52px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.add-card-row:hover, .add-card-row:active { border-color: var(--color-primary); background: var(--color-primary-highlight); }
.add-card-row .name {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 500;
  font-size: var(--text-sm);
}
.add-card-row .swatch-mini { width: 22px; height: 16px; border-radius: 4px; flex-shrink: 0; }
.badge-business {
  display: inline-flex;
  align-items: center;
  margin-left: var(--space-2);
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-warning);
  background: var(--color-warning-highlight);
  vertical-align: middle;
  white-space: nowrap;
}
.badge-cobrand {
  display: inline-flex;
  align-items: center;
  margin-left: var(--space-2);
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  vertical-align: middle;
  white-space: nowrap;
}
.add-card-row .add-icon {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.add-empty {
  padding: var(--space-3) 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.settings-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-divider);
  flex-shrink: 0;
  display: flex;
  gap: var(--space-3);
}
.btn {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--text-sm);
  text-align: center;
}
.btn-primary { background: var(--color-primary); color: var(--color-text-inverse); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface-offset); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-surface-offset-2); }

.install-hint {
  margin: var(--space-2) 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: var(--color-primary-highlight);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--color-text);
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  line-height: 1.5;
}
.install-hint svg { width: 16px; height: 16px; color: var(--color-primary); flex-shrink: 0; margin-top: 1px; }
.install-hint.dismissed { display: none; }
.install-hint button.dismiss { margin-left: auto; color: var(--color-text-muted); flex-shrink: 0; }

footer.legal {
  text-align: center;
  padding: var(--space-6) var(--space-5) var(--space-8);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  line-height: 1.6;
}
footer.legal a { color: var(--color-text-muted); text-decoration: underline; }

@media (min-width: 640px) {
  main { padding-left: var(--space-8); padding-right: var(--space-8); }
  .topbar { padding-left: var(--space-8); padding-right: var(--space-8); }
}
