/* ============================================================
   Peak & Pedal — Shop Assistant
   Direction: "Foothills workshop" — the warmth of a beloved
   neighborhood bike shop meets Boulder's alpine performance
   culture. Warm stone paper, deep spruce green, summit orange.
   ============================================================ */

:root {
  --bg:         #f0ece3;
  --surface:    #ffffff;
  --surface-2:  #f7f4ec;
  --surface-3:  #efeadf;
  --ink:        #1b2620;
  --ink-soft:   #47524b;
  --muted:      #7b847c;
  --line:       #e2dccf;
  --line-soft:  #ebe6dc;

  --brand:      #2f5d4b;
  --brand-deep: #234639;
  --brand-tint: #e7efe9;
  --accent:     #dc5f2c;
  --accent-deep:#c04e20;
  --accent-tint:#fbe9df;

  --user-bubble: #2f5d4b;
  --user-ink:    #f4f1e8;

  --ok:  #3f8f5f;
  --warn:#c9853a;

  --shadow-sm: 0 1px 2px rgba(27,38,32,.06), 0 1px 1px rgba(27,38,32,.04);
  --shadow-md: 0 4px 16px rgba(27,38,32,.10);
  --shadow-lg: 0 18px 50px rgba(27,38,32,.18);

  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Hanken Grotesk", system-ui, sans-serif;

  --sidebar-w: 288px;
  --thread-max: 760px;
  --radius: 14px;
  --radius-lg: 20px;

  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
}

html[data-theme="dark"] {
  --bg:         #12160f;
  --surface:    #1a1f17;
  --surface-2:  #20261d;
  --surface-3:  #262d22;
  --ink:        #ecebe1;
  --ink-soft:   #b9beb1;
  --muted:      #868c7c;
  --line:       #2d3529;
  --line-soft:  #262d22;

  --brand:      #6fb094;
  --brand-deep: #86c0a6;
  --brand-tint: #1e2a22;
  --accent:     #ef7a48;
  --accent-deep:#f28a5c;
  --accent-tint:#301c12;

  --user-bubble: #2c4a3d;
  --user-ink:    #eef3ea;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 18px rgba(0,0,0,.4);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.55;
  overflow: hidden;
}

::selection { background: var(--accent-tint); color: var(--accent-deep); }
html[data-theme="dark"] ::selection { color: var(--accent); }

button { font-family: inherit; cursor: pointer; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  width: 100%;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 40;
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-4) var(--sp-3);
}

.brand { display: flex; align-items: center; gap: var(--sp-2); }
.brand__mark {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--brand);
  color: #f2efe6;
  box-shadow: var(--shadow-sm);
}
.brand__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.18rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.sidebar__close.icon-btn { display: none; }

.new-chat {
  margin: 0 var(--sp-4) var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 11px var(--sp-4);
  background: var(--brand);
  color: #f4f1e8;
  border: none;
  border-radius: var(--radius);
  font-size: .92rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, background .2s ease, box-shadow .2s ease;
}
.new-chat:hover { background: var(--brand-deep); box-shadow: var(--shadow-md); }
.new-chat:active { transform: translateY(1px); }
.new-chat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.new-chat svg { flex: none; }

.convos {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--sp-3) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.convos__empty {
  color: var(--muted);
  font-size: .82rem;
  padding: var(--sp-3) var(--sp-2);
  text-align: center;
}

.convo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: .88rem;
  border: 1px solid transparent;
  position: relative;
  transition: background .15s ease, color .15s ease;
  cursor: pointer;
}
.convo:hover { background: var(--surface-3); color: var(--ink); }
.convo.is-active {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}
.convo__title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.convo__actions {
  display: flex; gap: 2px;
  opacity: 0;
  transition: opacity .15s ease;
}
.convo:hover .convo__actions,
.convo.is-active .convo__actions { opacity: 1; }
.convo__btn {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border: none; background: transparent;
  color: var(--muted);
  border-radius: 7px;
  transition: background .15s ease, color .15s ease;
}
.convo__btn:hover { background: var(--surface-3); color: var(--ink); }
.convo__btn.is-danger:hover { color: var(--accent-deep); background: var(--accent-tint); }
.convo__rename {
  flex: 1; min-width: 0;
  font: inherit; font-weight: 500;
  border: 1px solid var(--brand);
  background: var(--surface);
  color: var(--ink);
  border-radius: 7px;
  padding: 3px 6px;
  outline: none;
}

.sidebar__foot {
  border-top: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.shop-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
}
.shop-card__row {
  display: flex; align-items: center; gap: 7px;
  font-size: .78rem; font-weight: 600;
  color: var(--ink);
  letter-spacing: .01em;
}
.shop-card__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 22%, transparent);
}
.shop-card__dot.is-open { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.shop-card__dot.is-closed { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.shop-card__hours { font-size: .8rem; color: var(--ink-soft); margin-top: 4px; }
.shop-card__addr { font-size: .74rem; color: var(--muted); margin-top: 1px; }

.theme-toggle {
  display: flex; align-items: center; gap: var(--sp-2);
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .84rem;
  font-weight: 500;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.theme-toggle:hover { background: var(--surface); color: var(--ink); border-color: var(--muted); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle__moon { display: none; }
html[data-theme="dark"] .theme-toggle__sun { display: none; }
html[data-theme="dark"] .theme-toggle__moon { display: block; }

/* ---------- Main ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  min-height: 60px;
}
.topbar__title { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.topbar__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--ink);
}
.topbar__sub { font-size: .74rem; color: var(--muted); }
.topbar__menu.icon-btn, .topbar__new.icon-btn { display: none; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: none; background: transparent;
  color: var(--ink-soft);
  border-radius: 10px;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Thread ---------- */
.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: auto;
  outline: none;
}
.thread__inner {
  max-width: var(--thread-max);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-7);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

/* Message rows */
.msg { display: flex; flex-direction: column; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg--user { align-items: flex-end; }
.msg--user .msg__body {
  background: var(--user-bubble);
  color: var(--user-ink);
  padding: 11px 16px;
  border-radius: 18px 18px 6px 18px;
  max-width: 82%;
  box-shadow: var(--shadow-sm);
  font-size: .96rem;
}
.msg--user .msg__body p { margin: 0; }

.msg--bot { align-items: stretch; }
.msg__role {
  display: flex; align-items: center; gap: 8px;
  font-size: .74rem; font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.msg__avatar {
  display: grid; place-items: center;
  width: 24px; height: 24px;
  border-radius: 7px;
  background: var(--brand-tint);
  color: var(--brand);
  flex: none;
}
.msg__body { font-size: 1rem; color: var(--ink); }

/* Markdown inside bot messages */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.md h1, .md h2, .md h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 1.1em 0 .5em; color: var(--ink); }
.md h1 { font-size: 1.4rem; }
.md h2 { font-size: 1.2rem; }
.md h3 { font-size: 1.05rem; }
.md ul, .md ol { margin: 0 0 .8em; padding-left: 1.35em; }
.md li { margin: .28em 0; }
.md li::marker { color: var(--accent); }
.md a { color: var(--accent-deep); text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }
.md a:hover { color: var(--accent); }
.md strong { font-weight: 700; color: var(--ink); }
.md em { font-style: italic; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md blockquote {
  border-left: 3px solid var(--brand);
  padding: 2px 0 2px 14px;
  margin: .6em 0 1em;
  color: var(--ink-soft);
}
.md code {
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  font-size: .86em;
  background: var(--surface-3);
  padding: .12em .38em;
  border-radius: 5px;
}
.md table {
  border-collapse: collapse;
  width: 100%;
  margin: .4em 0 1em;
  font-size: .92rem;
  overflow: hidden;
  border-radius: 10px;
  box-shadow: 0 0 0 1px var(--line);
}
.md th, .md td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.md th { background: var(--surface-3); font-weight: 600; color: var(--ink); }
.md tr:last-child td { border-bottom: none; }

/* Code blocks */
.code-block {
  margin: .4em 0 1em;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.code-block__bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 6px 14px;
  background: var(--surface-3);
  font-size: .72rem;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.code-block__copy {
  display: flex; align-items: center; gap: 5px;
  border: none; background: transparent;
  color: var(--muted);
  font-size: .72rem; font-weight: 600;
  padding: 4px 8px; border-radius: 6px;
  transition: background .15s ease, color .15s ease;
}
.code-block__copy:hover { background: var(--surface); color: var(--ink); }
.code-block pre { margin: 0; padding: 14px; overflow-x: auto; }
.code-block code {
  background: none; padding: 0;
  font-size: .84rem; line-height: 1.6;
  color: var(--ink);
}
.tok-key { color: var(--brand); font-weight: 600; }
.tok-str { color: var(--accent-deep); }
.tok-num { color: #a86dc4; }
.tok-com { color: var(--muted); font-style: italic; }
html[data-theme="dark"] .tok-num { color: #c99ae0; }

/* Typing / streaming caret */
.stream-caret {
  display: inline-block;
  width: 8px; height: 1.05em;
  background: var(--accent);
  border-radius: 2px;
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.typing { display: inline-flex; gap: 5px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: bob 1.2s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Bot message actions */
.msg__actions {
  display: flex; gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity .18s ease;
}
.msg--bot:hover .msg__actions,
.msg--bot:focus-within .msg__actions { opacity: 1; }
.msg__action {
  display: flex; align-items: center; gap: 5px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: .76rem; font-weight: 500;
  padding: 4px 9px; border-radius: 8px;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.msg__action:hover { background: var(--surface); color: var(--ink); border-color: var(--line); }

.notice {
  background: var(--accent-tint);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent-deep);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: .9rem;
}
html[data-theme="dark"] .notice { color: var(--accent-deep); }

/* ---------- Empty state ---------- */
.hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--sp-6) 0 var(--sp-4); }
.hero__badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .74rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-tint);
  padding: 6px 12px; border-radius: 999px;
  margin-bottom: var(--sp-5);
}
.hero__mark {
  width: 66px; height: 66px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--brand);
  color: #f2efe6;
  box-shadow: var(--shadow-md);
  margin-bottom: var(--sp-4);
}
.hero__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: var(--ink);
  max-width: 15ch;
}
.hero__title em { font-style: italic; color: var(--brand); }
.hero__sub {
  color: var(--ink-soft);
  font-size: 1.02rem;
  max-width: 44ch;
  margin-top: var(--sp-3);
}
.prompts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
  width: 100%;
  max-width: 540px;
  margin-top: var(--sp-6);
}
.prompt-chip {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease;
}
.prompt-chip:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--brand); }
.prompt-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.prompt-chip__label {
  display: flex; align-items: center; gap: 8px;
  font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent-deep);
  margin-bottom: 5px;
}
.prompt-chip__text { font-size: .92rem; color: var(--ink); font-weight: 500; line-height: 1.35; }

/* ---------- Jump to latest ---------- */
.jump-latest {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: 120px;
  display: flex; align-items: center; gap: 6px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: .8rem; font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 15;
  animation: rise .25s ease both;
}
.jump-latest:hover { border-color: var(--brand); }

/* ---------- Composer ---------- */
.composer-wrap {
  padding: var(--sp-2) var(--sp-4) var(--sp-4);
  background: linear-gradient(to top, var(--bg) 55%, transparent);
}
.composer {
  max-width: var(--thread-max);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.composer:focus-within { border-color: var(--brand); box-shadow: var(--shadow-md), 0 0 0 3px var(--brand-tint); }
.composer__input {
  flex: 1;
  border: none; outline: none; resize: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  max-height: 200px;
  padding: 8px 0;
}
.composer__input::placeholder { color: var(--muted); }
.composer__send {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
  transition: background .18s ease, transform .12s ease, opacity .18s ease;
}
.composer__send:hover:not(:disabled) { background: var(--accent-deep); }
.composer__send:active:not(:disabled) { transform: scale(.94); }
.composer__send:disabled { opacity: .4; cursor: not-allowed; }
.composer__send:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.composer__send .ic-stop { display: none; }
.composer.is-streaming .composer__send { background: var(--ink); opacity: 1; cursor: pointer; }
.composer.is-streaming .composer__send:disabled { opacity: 1; cursor: pointer; }
.composer.is-streaming .ic-send { display: none; }
.composer.is-streaming .ic-stop { display: block; }
.composer__hint {
  max-width: var(--thread-max);
  margin: 8px auto 0;
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
}

/* ---------- Scrim (mobile) ---------- */
.sidebar-scrim {
  position: fixed; inset: 0;
  background: rgba(20,26,20,.45);
  z-index: 35;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Scrollbars ---------- */
.thread::-webkit-scrollbar, .convos::-webkit-scrollbar { width: 10px; }
.thread::-webkit-scrollbar-thumb, .convos::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.thread::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--muted) 70%, transparent); background-clip: content-box; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(85vw, 320px);
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .sidebar__close.icon-btn { display: grid; }
  .topbar__menu.icon-btn, .topbar__new.icon-btn { display: grid; }
  .topbar__title { align-items: center; text-align: center; }
  .jump-latest { bottom: 116px; }
}

@media (max-width: 520px) {
  .thread__inner { padding: var(--sp-5) var(--sp-4) var(--sp-6); gap: var(--sp-4); }
  .prompts { grid-template-columns: 1fr; }
  .msg--user .msg__body { max-width: 88%; }
  .composer-wrap { padding: var(--sp-2) var(--sp-3) var(--sp-3); }
  .hero__title { font-size: 1.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .stream-caret { animation: none; }
}
