/* SmartRapCalc — compact, high-contrast light-mode trading tool.
   Palette: navy/blue slate (fintech). Typeface: Inter, tabular figures. */

:root {
  --primary: #0f172a;      /* navy — headings, result numbers */
  --secondary: #334155;    /* slate */
  --accent: #0369a1;       /* blue — selected states, primary CTA */
  --accent-ink: #ffffff;
  --accent-soft: #e6f0f8;
  --bg: #eef1f5;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;     /* labels — still >4.5:1 on white */
  --line: #d5dbe4;
  --line-strong: #aab3c2;
  --muted: #f1f4f8;
  --danger: #c01829;
  --danger-bg: #fdecee;
  --pos: #067a53;          /* delta up (green) */
  --neg: #c01829;          /* delta down (red) */
  --lock: #067a53;
  --radius: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
input, select, button { font-family: inherit; }
.tnum, .list-value, .result-input, .delta { font-variant-numeric: tabular-nums; }

/* ---------------- App shell ---------------- */
.app { padding: 14px 16px 32px; max-width: 1320px; margin: 0 auto; }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.app-title { margin: 0; font-size: 20px; font-weight: 800; color: var(--primary); letter-spacing: -0.02em; }
.list-date { font-size: 12px; color: var(--ink-soft); font-weight: 500; }

/* Bottom action bar */
.action-bar {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}
.action-bar .btn { min-width: 140px; }

.app-footer {
  margin-top: 16px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.btn {
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
  min-height: 40px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #02598c; }
.btn-ghost { background: var(--surface); color: var(--secondary); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--muted); }
.btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }

/* ---------------- Card grid ---------------- */
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card--base { border-top: 3px solid var(--accent); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.card-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.card--compare .card-title { color: var(--secondary); }
.close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border: 0; border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.close-btn:hover { background: var(--danger-bg); color: var(--danger); }

/* Tap-to-copy */
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--pos); border-color: var(--pos); background: #e8f6f0; }

/* Driver hint (Main card) */
.drive-tag {
  display: none;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 5px;
}
.result-row.driving .drive-tag { display: inline; }
.result-row.driving .result-label { color: var(--accent); }

/* Weight-used note */
.weight-note {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  text-align: right;
}

/* ---------------- Attributes ---------------- */
.attrs { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.bracket-hint { font-size: 11px; font-weight: 600; color: var(--accent); text-transform: none; letter-spacing: 0; }

.size-wrap { display: flex; }
.size-wrap > [hidden] { display: none; }
.size-input, .bracket-sel {
  width: 100%;
  padding: 9px 10px;
  font-size: 15px;
  font-weight: 500;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
}
.size-input:focus, .bracket-sel:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Segmented control */
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; width: 100%; }
.shape-seg, .size-mode-seg { width: 100%; }
.seg-btn {
  flex: 1;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  color: var(--secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 6px;
  cursor: pointer;
  min-height: 38px;
  transition: background 120ms ease, color 120ms ease;
}
.seg-btn:first-child { border-left: 0; }
.seg-btn:hover:not(.active):not(:disabled) { background: var(--muted); }
.seg-btn.active { background: var(--accent); color: var(--accent-ink); }
.segmented.seg-disabled { opacity: 0.5; }

/* Tap-chips */
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  min-width: 32px;
  min-height: 32px;
  padding: 4px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.chip:hover:not(.active) { background: var(--muted); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }

/* ---------------- List price ---------------- */
.list-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: var(--accent-soft);
  border-radius: 8px;
  margin-bottom: 10px;
}
.list-label { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent); }
.list-value { font-size: 20px; font-weight: 800; color: var(--primary); }

/* ---------------- Error ---------------- */
.err-banner {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f3b6bd;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
}

/* ---------------- Results ---------------- */
.results { display: flex; flex-direction: column; gap: 8px; }
.result-row { display: grid; align-items: center; gap: 8px; }
.card--base .result-row { grid-template-columns: 58px 1fr 30px; }
.card--compare .result-row { grid-template-columns: 18px 54px 1fr 30px; }
.result-label { font-size: 12px; font-weight: 600; color: var(--ink-soft); display: flex; align-items: center; gap: 5px; }
.lock { display: inline-flex; align-items: center; justify-content: center; }
.lock-radio { width: 16px; height: 16px; accent-color: var(--lock); cursor: pointer; }

.disc-controls { display: flex; gap: 6px; align-items: stretch; }
.disc-seg { width: auto; flex: 0 0 auto; }
.disc-seg .seg-btn { padding: 8px 9px; font-size: 12px; }
.pct-wrap { flex: 1; }

.affix { position: relative; display: flex; align-items: center; }
.affix-prefix, .affix-suffix {
  position: absolute; pointer-events: none;
  font-size: 13px; font-weight: 700; color: var(--ink-soft);
}
.affix-prefix { left: 10px; }
.affix-suffix { right: 10px; }
.money-input { padding-left: 22px !important; }
.disc-input { padding-right: 22px !important; }

.result-input {
  width: 100%;
  padding: 9px 10px;
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  text-align: right;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  min-height: 42px;
}
.result-input::placeholder { color: #aab3c2; font-weight: 600; }
.result-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.result-input:disabled { background: var(--muted); color: var(--secondary); -webkit-text-fill-color: var(--secondary); opacity: 1; }

/* Locked (editable driver) row in compare cards */
.locked-row .result-input { border-color: var(--lock); box-shadow: inset 0 0 0 1px var(--lock); }
.locked-row .result-label { color: var(--lock); font-weight: 700; }

/* ---------------- Delta bar ---------------- */
.delta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
}
.delta-label { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); }
.delta-none { color: var(--ink-soft); }
.delta-item { font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.delta-key { font-weight: 600; color: var(--ink-soft); }
.delta-item.up { color: var(--pos); }
.delta-item.down { color: var(--neg); }
.delta-item.same { color: var(--ink-soft); }

/* ---------------- Mobile ---------------- */
@media (max-width: 720px) {
  .app { padding: 10px 10px 28px; }
  .board { grid-template-columns: 1fr; gap: 10px; }
  .card { padding: 12px; }
  .app-title { font-size: 18px; }
  .action-bar .btn { flex: 1; min-width: 0; }
  .result-input { font-size: 17px; min-height: 44px; }
  .chip { min-height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
