/* =============================================================================
   KAR — Tools design system
   Shared by compare.html, safety.html, tco.html, ask.html, garage.html and
   shortlist.html so the six research tools read as one product.

   Layered on top of /styles/chat.css, which owns the brand tokens, the header,
   the dropdown nav and the footer. Nothing here redefines those.
   ============================================================================= */

:root {
  --tool-ok:        #16a34a;
  --tool-ok-bg:     #f0fdf4;
  --tool-ok-border: #bbf7d0;
  --tool-warn:      #d97706;
  --tool-warn-bg:   #fffbeb;
  --tool-warn-border:#fde68a;
  --tool-bad:       #dc2626;
  --tool-bad-bg:    #fef2f2;
  --tool-bad-border:#fecaca;
}

/* [hidden] has to win over the component display rules below, otherwise
   toggling the attribute silently does nothing. */
[hidden] { display: none !important; }

/* Label text that only a screen reader needs. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ── Page frame ────────────────────────────────────────────────────────────── */
/* chat.css centres <main> with flex for the chat layout; the tool pages are
   ordinary documents that flow top-to-bottom. */
main.tool-main { display: block; padding: 26px 16px 40px; }
.tool-shell { width: 100%; max-width: 960px; margin: 0 auto; }
.tool-shell.wide { max-width: 1120px; }

.tool-head { margin-bottom: 20px; }
.tool-head h2 {
  font-family: var(--font-display);
  font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em;
  color: var(--text-main); margin: 0 0 6px;
}
.tool-head p.tool-sub { color: var(--text-muted); font-size: .92rem; margin: 0; max-width: 62ch; }
.tool-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ── Panels — one level of card, never cards inside cards ──────────────────── */
.tool-panel {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.tool-panel.flush { padding: 0; overflow: hidden; }
.tool-panel > :first-child { margin-top: 0; }
.tool-panel > :last-child { margin-bottom: 0; }

.panel-title {
  font-family: var(--font-display);
  font-size: 1rem; font-weight: 700; color: var(--text-main);
  margin: 0 0 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.panel-sub { font-size: .84rem; color: var(--text-muted); margin: 0 0 16px; }

.section-label {
  font-size: .74rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-light); margin: 0 0 10px;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.field-grid + .field-grid { margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field label, .field .label {
  font-size: .8rem; font-weight: 700; color: var(--text-muted); letter-spacing: .01em;
}
.hint { font-size: .74rem; color: var(--text-light); margin: 0; }
.input, .select, .textarea {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: .94rem; color: var(--text-main);
  background: var(--bg-light); outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.textarea { resize: vertical; min-height: 62px; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-glow);
}
.input::placeholder, .textarea::placeholder { color: var(--text-light); }
.input[aria-invalid="true"] { border-color: var(--tool-bad); }
@media (max-width: 600px) { .input, .select, .textarea { font-size: 1rem; } }

.range-field { padding: 12px 14px; background: var(--bg-light); border: 1.5px solid var(--border); border-radius: var(--radius-sm); }
.range-field input[type="range"] { width: 100%; accent-color: var(--primary); }
.range-field .range-num { margin-top: 8px; text-align: center; background: #fff; }
.range-field .range-cap { display: flex; justify-content: space-between; font-size: .72rem; color: var(--text-light); margin-top: 2px; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 22px; min-height: 44px;
  border-radius: var(--radius-lg); border: 1.5px solid transparent;
  font-family: inherit; font-size: .92rem; font-weight: 700; letter-spacing: .01em;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform var(--transition), filter var(--transition), background var(--transition), border-color var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; filter: none; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; box-shadow: 0 2px 10px var(--primary-glow); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-white); border-color: var(--border); color: var(--text-main); }
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-ultra-light); }
.btn-quiet { background: none; border-color: transparent; color: var(--text-muted); padding: 8px 12px; min-height: 38px; }
.btn-quiet:hover:not(:disabled) { color: var(--primary-dark); background: var(--bg-light); }
.btn-danger { background: var(--tool-bad-bg); border-color: var(--tool-bad-border); color: var(--tool-bad); }
.btn-danger:hover:not(:disabled) { background: var(--tool-bad); color: #fff; border-color: var(--tool-bad); }
.btn-sm { padding: 7px 14px; min-height: 36px; font-size: .83rem; }
.btn-block { width: 100%; }

.submit-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 16px; }
.submit-row .field { flex: 1 1 190px; }
.submit-row .grow { flex: 1; }
@media (max-width: 600px) {
  .submit-row { flex-direction: column; align-items: stretch; }
  .submit-row .btn { width: 100%; }
}

:where(.btn, .input, .select, .textarea, .chip, .seg button, .icon-btn):focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

/* ── Chips & badges ────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 999px;
  background: var(--primary-ultra-light); border: 1px solid var(--border);
  color: var(--primary-dark); font-family: inherit; font-size: .83rem; font-weight: 600;
  cursor: pointer; transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.chip:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .03em;
  border: 1px solid var(--border); background: var(--bg-light); color: var(--text-muted);
  white-space: nowrap;
}
.badge-verified { background: var(--tool-ok-bg); border-color: var(--tool-ok-border); color: var(--tool-ok); }
.badge-estimate { background: var(--tool-warn-bg); border-color: var(--tool-warn-border); color: var(--tool-warn); }
.badge-input    { background: var(--primary-ultra-light); border-color: var(--border); color: var(--primary-dark); }

/* ── Car context bar — what the tools are currently working on ─────────────── */
.ctx-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 16px;
  background: var(--primary-ultra-light);
  border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: .86rem; color: var(--text-main);
}
.ctx-bar .ctx-car { font-weight: 700; }
.ctx-bar .ctx-label { color: var(--text-muted); }
.ctx-bar .ctx-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Next-step actions after a result ──────────────────────────────────────── */
.next-steps {
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border-subtle);
}
.next-steps .section-label { margin-bottom: 8px; }
.next-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── States: loading / empty / error ───────────────────────────────────────── */
.state {
  text-align: center; padding: 40px 22px;
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
}
.state .state-icon { font-size: 2.4rem; line-height: 1; margin-bottom: 12px; }
.state h3 { font-family: var(--font-display); font-size: 1.08rem; margin: 0 0 6px; color: var(--text-main); }
.state p { color: var(--text-muted); font-size: .9rem; margin: 0 auto 18px; max-width: 46ch; }
.state .state-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.state.state-error { border-color: var(--tool-bad-border); background: var(--tool-bad-bg); }
.state.state-error h3 { color: var(--tool-bad); }
.state.inline { padding: 26px 18px; }

.loading-row {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 26px; background: var(--bg-light);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  color: var(--text-muted); font-size: .9rem;
}
.dots span {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary); margin: 0 2px; animation: tool-dots 1.3s infinite;
}
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes tool-dots { 0%,100% { transform: translateY(0); opacity:.6 } 50% { transform: translateY(-5px); opacity:1 } }

.skeleton { background: linear-gradient(90deg, var(--bg-light) 25%, #edf1f7 37%, var(--bg-light) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes sk { 0% { background-position: 100% 50% } 100% { background-position: 0 50% } }

/* ── Notes / disclaimers ───────────────────────────────────────────────────── */
.note {
  font-size: .82rem; line-height: 1.55; padding: 10px 13px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--warning-bg); border-left: 3px solid var(--warning-border); color: var(--warning-text);
}
.note a { color: var(--primary-dark); }
.note.info { background: var(--primary-ultra-light); border-left-color: var(--primary); color: var(--text-muted); }
.note + .note { margin-top: 8px; }

/* ── Metric cards ──────────────────────────────────────────────────────────── */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.metric {
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; box-shadow: var(--shadow-xs);
}
.metric .metric-label { font-size: .76rem; font-weight: 700; color: var(--text-muted); display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.metric .metric-value { font-size: 1.18rem; font-weight: 800; color: var(--text-main); line-height: 1.15; }
.metric .metric-sub { font-size: .74rem; color: var(--text-light); margin-top: 3px; }
.metric.lead { background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%); border-color: transparent; color: #fff; }
.metric.lead .metric-label { color: rgba(255,255,255,.72); }
.metric.lead .metric-value { color: #fff; font-size: 1.5rem; }
.metric.lead .metric-sub { color: rgba(255,255,255,.7); }

/* Proportional cost bars */
.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-row .bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: .87rem; margin-bottom: 5px; }
.bar-row .bar-name { font-weight: 600; color: var(--text-main); display: flex; align-items: center; gap: 7px; min-width: 0; }
.bar-row .bar-amt { font-weight: 800; color: var(--text-main); white-space: nowrap; }
.bar-row .bar-track { height: 8px; border-radius: 999px; background: var(--mist); overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--primary-dark)); }
.bar-row .bar-meta { font-size: .74rem; color: var(--text-light); margin-top: 4px; }

/* ── Rendered AI report ────────────────────────────────────────────────────── */
.report { font-size: .93rem; line-height: 1.72; color: var(--text-main); }
.report.streaming { white-space: pre-wrap; }
.report h1, .report h2, .report h3, .report h4 {
  font-family: var(--font-display); font-size: 1rem; font-weight: 700;
  color: var(--primary-dark); margin: 18px 0 8px;
}
.report > :first-child { margin-top: 0; }
.report p { margin: 8px 0; }
.report ul, .report ol { margin: 8px 0 8px 20px; padding: 0; }
.report li { margin: 4px 0; }
.report strong { color: var(--primary-dark); }
.report a { color: var(--primary); }
.report hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.report table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: .88rem; }
.report th, .report td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.report th { background: var(--bg-light); }
.report pre { background: var(--bg-light); border-radius: var(--radius-sm); padding: 10px; overflow-x: auto; }

/* Collapsible report sections */
.report-section { border-top: 1px solid var(--border-subtle); }
.report-section:first-of-type { border-top: none; }
.report-section > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  padding: 13px 2px; font-weight: 700; font-size: .93rem; color: var(--text-main);
}
.report-section > summary::-webkit-details-marker { display: none; }
.report-section > summary::after {
  content: '\203A'; margin-left: auto; font-size: 1.3rem; color: var(--text-light);
  transform: rotate(90deg); transition: transform var(--transition);
}
.report-section[open] > summary::after { transform: rotate(-90deg); }
.report-section > summary:hover { color: var(--primary-dark); }
.report-section .report { padding: 0 2px 16px; }

/* ── Comparison layout ─────────────────────────────────────────────────────── */
.cmp-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -24px; padding: 0 24px; }
.cmp-cars { display: grid; gap: 12px; }
.cmp-cars[data-n="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cmp-cars[data-n="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cmp-car {
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px; background: var(--bg-white); min-width: 0;
  border-top: 3px solid var(--cmp-accent, var(--primary));
}
.cmp-car h4 { margin: 0 0 4px; font-size: .98rem; font-weight: 800; color: var(--text-main); line-height: 1.25; }
.cmp-car .cmp-tag { font-size: .74rem; color: var(--text-muted); }
.cmp-car .cmp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* Attribute rows — a grid on desktop, stacked groups on mobile */
.cmp-rows { display: flex; flex-direction: column; }
.cmp-row {
  display: grid; align-items: center; gap: 12px;
  padding: 11px 0; border-top: 1px solid var(--border-subtle);
}
.cmp-row[data-n="2"] { grid-template-columns: minmax(120px, 1fr) repeat(2, minmax(0, 1fr)); }
.cmp-row[data-n="3"] { grid-template-columns: minmax(120px, 1fr) repeat(3, minmax(0, 1fr)); }
.cmp-row:first-child { border-top: none; }
.cmp-attr { font-size: .82rem; font-weight: 700; color: var(--text-muted); display: flex; align-items: center; gap: 7px; }
.cmp-val { font-size: .9rem; font-weight: 600; color: var(--text-main); display: flex; align-items: center; gap: 6px; min-width: 0; }
.cmp-val.best { color: var(--tool-ok); font-weight: 800; }
.cmp-val .win { font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; background: var(--tool-ok-bg); border: 1px solid var(--tool-ok-border); color: var(--tool-ok); border-radius: 999px; padding: 1px 7px; }
.cmp-val .muted { color: var(--text-light); font-weight: 500; }

@media (max-width: 720px) {
  .cmp-cars[data-n="3"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cmp-row { grid-template-columns: 1fr !important; gap: 6px; padding: 12px 0; }
  .cmp-attr { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
  .cmp-val { justify-content: space-between; padding: 5px 10px; background: var(--bg-light); border-radius: var(--radius-sm); }
  .cmp-val::before { content: attr(data-car); font-size: .76rem; font-weight: 600; color: var(--text-muted); margin-right: 10px; }
  .cmp-scroll { margin: 0; padding: 0; }
}

/* ── Card list (shortlist) ─────────────────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
@media (max-width: 640px) { .card-grid { grid-template-columns: 1fr; } }

/* ── Sticky action bar ─────────────────────────────────────────────────────── */
.sticky-bar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; margin-top: 18px;
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md);
}
.sticky-bar .sb-text { flex: 1; font-size: .88rem; font-weight: 600; color: var(--text-main); min-width: 140px; }
@media (max-width: 600px) { .sticky-bar { flex-direction: column; align-items: stretch; } .sticky-bar .btn { width: 100%; } }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.kar-toast {
  position: fixed; bottom: 24px; left: 50%; z-index: 3000;
  transform: translateX(-50%) translateY(12px);
  background: var(--text-main); color: #fff;
  padding: 10px 20px; border-radius: var(--radius-lg);
  font-size: .87rem; font-weight: 600; box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s;
  max-width: calc(100vw - 32px); text-align: center;
}
.kar-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.kar-toast.success { background: linear-gradient(135deg, #16a34a, #15803d); }
.kar-toast.error { background: linear-gradient(135deg, #ef4444, #dc2626); }

/* ── Small screens ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  main.tool-main { padding: 18px 12px 32px; }
  .tool-panel { padding: 18px 16px; }
  .tool-head h2 { font-size: 1.3rem; }
  .field-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric.lead { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .dots span, .skeleton { animation: none; }
  .btn, .chip, .input, .select, .textarea, .report-section > summary::after { transition: none; }
  .btn:hover:not(:disabled) { transform: none; }
}
