/* Cars4Me web app stylesheet. Tokens are the website's (website/src/styles/site.css) so both share one look;
   then: base, the sign-in page, the app frame (top bar, sidebar, workspace), the chat, the results panel, phones. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;
  --bg: #F6F8FB; --bg-alt: #FFFFFF; --surface: #FFFFFF; --ink: #14212E; --ink-2: #4A5A6B; --line: #DCE3EB;
  --brand: #1F4E79; --brand-ink: #FFFFFF; --brand-soft: #E7EFF7; --accent: #B8935A; --accent-soft: #F5EDE0; --focus: #6EA8DC;
  --shadow-rgb: 20 40 60; --ok: #1E7F4F; --bad: #B42318; --bad-soft: #FEF3F2;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-700: 1.375rem; --fs-600: 1.2rem; --fs-500: 1.125rem; --fs-400: 1rem; --fs-300: 0.875rem; --fs-200: 0.8rem;
  --s-1: 0.25rem; --s-2: 0.5rem; --s-3: 0.75rem; --s-4: 1rem; --s-5: 1.5rem; --s-6: 2rem; --s-7: 3rem;
  --r-sm: 8px; --r-md: 14px; --r-lg: 22px; --r-pill: 999px;
  --sh-1: 0 1px 2px rgb(var(--shadow-rgb) / 0.06); --sh-2: 0 8px 24px rgb(var(--shadow-rgb) / 0.10); --sh-3: 0 24px 60px rgb(var(--shadow-rgb) / 0.18);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1); --top-h: 56px; --side-w: 272px; --tabs-h: 52px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1823; --bg-alt: #142232; --surface: #1A2B3D; --ink: #E8EEF5; --ink-2: #A9B7C6; --line: #27394D;
    --brand: #6EA8DC; --brand-ink: #0E1823; --brand-soft: #1B3350; --accent: #D0AD76; --accent-soft: #3A2F1E; --shadow-rgb: 0 0 0;
    --ok: #6CCB94; --bad: #FFB4AB; --bad-soft: #3A1714;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1823; --bg-alt: #142232; --surface: #1A2B3D; --ink: #E8EEF5; --ink-2: #A9B7C6; --line: #27394D;
  --brand: #6EA8DC; --brand-ink: #0E1823; --brand-soft: #1B3350; --accent: #D0AD76; --accent-soft: #3A2F1E; --shadow-rgb: 0 0 0;
  --ok: #6CCB94; --bad: #FFB4AB; --bad-soft: #3A1714;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: var(--fs-400); line-height: 1.55; overflow: hidden; }
:root[data-theme="dark"] body { -webkit-font-smoothing: antialiased; }
#root { height: 100%; }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-family: var(--font-display); font-variation-settings: "opsz" 144; font-size: clamp(1.6rem, 1.2rem + 1.5vw, 2.25rem); }
p { margin: 0 0 var(--s-3); } p:last-child { margin-bottom: 0; }
a { color: var(--brand); text-underline-offset: 0.15em; }
img, svg { display: block; max-width: 100%; height: auto; }
button { font: inherit; color: inherit; }
ul, ol { margin: 0 0 var(--s-3); padding-left: 1.25rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; background: var(--brand-soft); padding: 0.1em 0.35em; border-radius: 4px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--ink-2); } .small { font-size: var(--fs-300); } .lead { font-size: var(--fs-500); color: var(--ink-2); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); padding: 0.7rem 1.2rem; border-radius: var(--r-pill); font-weight: 600; font-size: var(--fs-300); text-decoration: none; border: 1px solid transparent; cursor: pointer; background: none; white-space: nowrap; transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s, border-color 0.2s; }
.btn:hover { transform: translateY(-1px); } .btn:active { transform: none; } .btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn--primary { background: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 18px rgb(31 78 121 / 0.25); }
.btn--ghost { color: var(--ink); border-color: var(--line); } .btn--ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn--lg { padding: 0.95rem 1.6rem; font-size: var(--fs-400); } .btn--sm { padding: 0.45rem 0.85rem; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 1px solid transparent; border-radius: var(--r-pill); background: none; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-moon { display: none; } :root[data-theme="dark"] .theme-toggle .icon-moon { display: block; } :root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; } :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; } }
.brand { display: inline-flex; align-items: center; gap: var(--s-2); text-decoration: none; color: var(--ink); font-weight: 600; letter-spacing: -0.01em; }
.brand img { border-radius: 8px; }

/* ---------- Boot and sign-in ---------- */
.boot { height: 100%; display: grid; place-items: center; }
.signin { min-height: 100%; display: grid; grid-template-rows: auto 1fr auto; padding: var(--s-4); overflow: auto; }
.signin__top { display: flex; justify-content: flex-end; }
.signin__card { width: min(100%, 440px); margin: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-6) var(--s-5); box-shadow: var(--sh-2); display: grid; gap: var(--s-4); }
.signin__card h1 { margin-top: var(--s-2); }
.signin__card .btn { justify-self: start; }
.signin__foot { text-align: center; max-width: 60ch; margin: var(--s-4) auto 0; }
.notice { background: var(--accent-soft); border-radius: var(--r-sm); padding: var(--s-2) var(--s-3); }

/* ---------- The app frame ---------- */
.app { height: 100%; display: grid; grid-template-rows: var(--top-h) 1fr; grid-template-columns: var(--side-w) 1fr; grid-template-areas: "top top" "side work"; }
.top { grid-area: top; display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-4); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); z-index: 5; }
.top__menu { display: none; }
.top__title { flex: 1; min-width: 0; font-size: var(--fs-300); font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: var(--s-2); }
.top__actions { display: flex; align-items: center; gap: var(--s-2); }
.loc { position: relative; }
.loc__form { position: absolute; right: 0; top: calc(100% + 6px); width: 280px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-2); padding: var(--s-4); display: grid; gap: var(--s-3); z-index: 20; }
.loc__form label { display: grid; gap: 4px; font-size: var(--fs-300); font-weight: 600; }
.loc__form input { font: inherit; padding: 0.5rem 0.65rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg); color: var(--ink); }
.loc__btns { display: flex; gap: var(--s-2); }
.side { grid-area: side; border-right: 1px solid var(--line); background: var(--bg-alt); overflow: auto; padding: var(--s-3); }
.chats { display: grid; gap: var(--s-3); }
.chats__new { justify-content: flex-start; }
.chats__empty { padding: 0 var(--s-2); }
.chats__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.chats__list li { display: flex; align-items: center; border-radius: var(--r-sm); }
.chats__list li.is-current { background: var(--brand-soft); }
.chats__list li:hover { background: var(--brand-soft); }
.chats__item { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0.55rem 0.65rem; border-radius: var(--r-sm); cursor: pointer; font-size: var(--fs-300); }
.chats__item span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chats__del { width: 32px; height: 32px; opacity: 0; } .chats__del svg { width: 16px; height: 16px; }
.chats__list li:hover .chats__del, .chats__list li.is-current .chats__del, .chats__del:focus-visible { opacity: 1; }
.scrim { display: none; }
.work { grid-area: work; min-height: 0; display: grid; grid-template-columns: minmax(360px, 5fr) minmax(380px, 6fr); }
.app.is-full .work { grid-template-columns: 0 1fr; }
.app.is-full .chat { display: none; }
.tabs { display: none; }
.toast { position: fixed; left: 50%; bottom: calc(var(--s-5) + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: var(--s-2) var(--s-4); border-radius: var(--r-pill); box-shadow: var(--sh-2); z-index: 30; font-size: var(--fs-300); }

/* ---------- The chat ---------- */
.chat { min-height: 0; display: grid; grid-template-rows: 1fr auto auto; border-right: 1px solid var(--line); position: relative; }
.chat__scroll { overflow: auto; padding: var(--s-5) var(--s-4) var(--s-3); scroll-behavior: smooth; }
.chat__list { display: grid; gap: var(--s-4); max-width: 760px; margin: 0 auto; }
.chat__welcome { max-width: 560px; margin: 10vh auto 0; display: grid; gap: var(--s-4); }
.chat__suggest { list-style: none; padding: 0; margin: var(--s-2) 0 0; display: grid; gap: var(--s-2); }
.chat__suggest button { width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 0.7rem 0.9rem; cursor: pointer; transition: border-color 0.2s, transform 0.2s var(--ease); }
.chat__suggest button:hover { border-color: var(--brand); transform: translateY(-1px); }
.chat__fresh { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--brand); color: var(--brand-ink); border: 0; border-radius: var(--r-pill); padding: 0.5rem 1rem; font-weight: 600; box-shadow: var(--sh-2); cursor: pointer; }
.msg { display: grid; grid-template-columns: auto 1fr; gap: var(--s-3); align-items: start; }
.msg--user { grid-template-columns: 1fr; justify-items: end; }
.msg--user .msg__body { background: var(--brand-soft); border-radius: var(--r-lg) var(--r-lg) var(--r-sm) var(--r-lg); padding: 0.65rem 1rem; max-width: min(85%, 560px); }
.msg__text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg__mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); font-size: 11px; font-weight: 700; margin-top: 2px; }
.msg__body { min-width: 0; overflow-wrap: anywhere; }
.msg--assistant .msg__body { padding-top: 0.25rem; }
.msg__err { color: var(--bad); background: var(--bad-soft); border-radius: var(--r-sm); padding: var(--s-2) var(--s-3); margin-top: var(--s-2); font-size: var(--fs-300); }
.msg__thinking { display: inline-flex; gap: 4px; padding: 0.5rem 0; }
.msg__thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); animation: blink 1.2s infinite ease-in-out; }
.msg__thinking span:nth-child(2) { animation-delay: 0.2s; } .msg__thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.tools { list-style: none; margin: 0 0 var(--s-2); padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.tools li { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-200); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 2px 10px; color: var(--ink-2); max-width: 100%; min-width: 0; }
.tools__name { white-space: nowrap; flex: none; }
.tools li::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }
.tools li.is-running::before { background: var(--accent); animation: blink 1s infinite; } .tools li.is-bad::before { background: var(--bad); }
.tools__sum { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.8; min-width: 0; }
.tools__sum::before { content: "·"; margin-right: 6px; }
.composer { display: flex; align-items: flex-end; gap: var(--s-2); margin: 0 var(--s-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); box-shadow: var(--sh-1); }
.composer:focus-within { border-color: var(--brand); }
.composer textarea { flex: 1; resize: none; border: 0; background: none; color: inherit; font: inherit; line-height: 1.5; padding: 0.45rem 0; max-height: 200px; outline: none; }
.composer__btn { flex: none; width: 40px; height: 40px; border: 0; border-radius: var(--r-pill); background: var(--brand); color: var(--brand-ink); cursor: pointer; display: grid; place-items: center; }
.composer__btn:disabled { opacity: 0.4; cursor: default; }
.composer__btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chat__disc { text-align: center; padding: var(--s-2) var(--s-4) var(--s-3); font-size: var(--fs-200); }

/* ---------- The results panel ---------- */
.results { min-height: 0; display: grid; grid-template-rows: auto 1fr; background: var(--bg-alt); }
.results__bar { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-3) 0 var(--s-4); height: 48px; border-bottom: 1px solid var(--line); }
.results__bar strong { font-size: var(--fs-300); }
.results__hist { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; flex: 1; overflow: auto; }
.results__hist button { font-size: var(--fs-200); border: 1px solid var(--line); background: none; border-radius: var(--r-pill); padding: 2px 10px; cursor: pointer; white-space: nowrap; color: var(--ink-2); }
.results__hist button.is-on { border-color: var(--brand); color: var(--brand); }
.results__bar .icon-btn { margin-left: auto; }
.results__frame { position: relative; min-height: 0; }
.results__frame iframe { width: 100%; height: 100%; border: 0; display: block; background: transparent; }
.results__empty { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s-5); text-align: center; }
.results__empty--over { pointer-events: none; background: var(--bg-alt); }

/* ---------- Phones and narrow windows ---------- */
@media (max-width: 1100px) { .app { --side-w: 240px; } .work { grid-template-columns: minmax(320px, 1fr) minmax(340px, 1fr); } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: var(--top-h) 1fr var(--tabs-h); grid-template-areas: "top" "work" "tabs"; }
  .top__menu { display: inline-grid; }
  .top .brand span, .top__title { display: none; }
  .side { position: fixed; top: var(--top-h); bottom: 0; left: 0; width: min(84vw, 320px); z-index: 25; transform: translateX(-100%); transition: transform 0.3s var(--ease); box-shadow: var(--sh-3); }
  .app.has-sidebar .side { transform: none; }
  .scrim { display: block; position: fixed; inset: var(--top-h) 0 0 0; background: rgb(0 0 0 / 0.35); border: 0; z-index: 20; }
  .work { grid-template-columns: 1fr; }
  .chat { border-right: 0; }
  .tabs { grid-area: tabs; display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); background: var(--bg-alt); padding-bottom: env(safe-area-inset-bottom); }
  .tabs button { border: 0; background: none; font-weight: 600; color: var(--ink-2); cursor: pointer; position: relative; }
  .tabs button.is-on { color: var(--brand); box-shadow: inset 0 2px 0 var(--brand); }
  .tabs .dot { position: absolute; top: 10px; margin-left: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
  .app.tab-chat .results, .app.tab-results .chat { display: none; }
  .app.is-full .work { grid-template-columns: 1fr; }
  .app.is-full.tab-chat .results { display: grid; } .app.is-full.tab-chat .chat { display: none; }
  .loc .btn span { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } .chat__scroll { scroll-behavior: auto; } }
