:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #24211d;
  background: #f7f5f0;
  font-synthesis: none;
  --ink: #24211d;
  --muted: #746f68;
  --line: #e5e0d7;
  --surface: #fffefa;
  --orange: #f48120;
  --orange-dark: #c94f08;
  --navy: #172131;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow: hidden;
  background: #f7f5f0;
}

button, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: rgba(244, 129, 32, 0.18); touch-action: manipulation; }
button { color: inherit; }

.skip-link {
  position: fixed;
  z-index: 20;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: 0.55rem;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 0 0 3px var(--orange);
  transform: translateY(-200%);
}
.skip-link:focus { transform: translateY(0); }

.app-shell {
  width: min(1440px, 100%);
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(17.5rem, 28%) minmax(0, 1fr);
  padding: clamp(0.65rem, 1.4vw, 1.25rem);
  gap: clamp(0.65rem, 1.4vw, 1.25rem);
}
.app-shell.sidebar-collapsed { grid-template-columns: 5rem minmax(0, 1fr); }

.sidebar {
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(1.5rem, 3vw, 2.75rem);
  border-radius: 1.5rem;
  background: var(--navy);
  color: #fff;
}
.sidebar::after {
  content: "";
  position: absolute;
  right: -7rem;
  bottom: 7rem;
  width: 17rem;
  height: 17rem;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 50%;
  box-shadow: 0 0 0 3.5rem rgba(255,255,255,.025), 0 0 0 7rem rgba(255,255,255,.018);
  pointer-events: none;
}

.sidebar-toggle {
  position: absolute;
  z-index: 3;
  top: 1.55rem;
  right: 1.2rem;
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 0.7rem;
  background: rgba(255,255,255,.06);
  color: #cbd2dc;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
.sidebar-toggle:hover { border-color: rgba(255,255,255,.24); background: rgba(255,255,255,.11); color: #fff; }
.sidebar-toggle svg { width: 1.2rem; fill: currentColor; transition: transform 180ms ease; }

.brand {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.85rem;
  background: var(--orange);
  box-shadow: 0 0.75rem 2rem rgba(244,129,32,.25);
}
.brand-mark svg { width: 1.75rem; fill: white; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: 0.08em; }
.brand small { margin-top: 0.15rem; color: #aeb7c5; font-size: 0.72rem; }

.sidebar-copy { position: relative; z-index: 1; margin-top: clamp(5rem, 15vh, 10rem); }
.eyebrow { margin: 0 0 1rem; color: #f5a65f !important; font-size: 0.76rem !important; font-weight: 700; letter-spacing: 0.13em; text-transform: uppercase; }
.sidebar h1 { max-width: 22rem; margin: 0; font-size: clamp(2rem, 3.35vw, 3.55rem); line-height: 1.12; letter-spacing: -0.045em; text-wrap: balance; }
.sidebar-copy > p:last-child { max-width: 24rem; margin: 1.35rem 0 0; color: #aeb7c5; font-size: 0.9rem; line-height: 1.8; text-wrap: pretty; }

.provider {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: fit-content;
  margin-top: 3rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 0.8rem;
  background: rgba(255,255,255,.05);
}
.provider-icon { display: grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 0.55rem; background: rgba(244,129,32,.18); color: #ffad65; }
.provider small, .provider strong { display: block; }
.provider small { color: #8f9aaa; font-size: 0.62rem; }
.provider strong { margin-top: 0.12rem; font-size: 0.72rem; }

.sidebar-collapsed .sidebar { align-items: center; padding: 1rem; }
.sidebar-collapsed .sidebar::after,
.sidebar-collapsed .brand > span:last-child,
.sidebar-collapsed .sidebar-copy,
.sidebar-collapsed .provider { display: none; }
.sidebar-collapsed .brand { display: flex; justify-content: center; }
.sidebar-collapsed .sidebar-toggle { top: 4.65rem; right: 50%; transform: translateX(50%); }
.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }

.workspace {
  min-width: 0;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--surface);
  box-shadow: 0 1.25rem 4rem rgba(58, 46, 31, 0.07);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 5.2rem;
  padding: 1rem clamp(1.1rem, 3.5vw, 3rem);
  border-bottom: 1px solid var(--line);
}
.topbar h2 { margin: 0; font-size: 1.05rem; letter-spacing: -0.02em; }
.mobile-brand { display: none; }
.status { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.75rem; }
.status-dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: #b7b2aa; }
.status.online .status-dot { background: #39a26b; box-shadow: 0 0 0 0.22rem rgba(57,162,107,.12); }
.status.error .status-dot { background: #d45f4c; box-shadow: 0 0 0 0.22rem rgba(212,95,76,.12); }

.messages {
  min-height: 15rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(1.5rem, 4vw, 3.5rem) clamp(1.1rem, 6vw, 5.5rem);
  scroll-behavior: smooth;
  scrollbar-color: #d5d0c8 transparent;
}

.message { display: flex; align-items: flex-start; gap: 0.8rem; max-width: 48rem; margin: 0 0 1.8rem; }
.message.user { margin-left: auto; flex-direction: row-reverse; }
.avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 0.7rem;
  background: var(--navy);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.message.user .avatar { background: #eee9df; color: #67615a; }
.message-body { min-width: 0; }
.message.user .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.message-author { margin: 0 0 0.38rem; color: #8a847c; font-size: 0.67rem; font-weight: 650; }
.bubble {
  max-width: 100%;
  padding: 0.9rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 0.35rem 1rem 1rem 1rem;
  background: #f7f5f0;
  color: #34302b;
  font-size: 0.93rem;
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.user .bubble { border-color: var(--navy); border-radius: 1rem 0.35rem 1rem 1rem; background: var(--navy); color: #fff; }
.message.pending .bubble { color: var(--muted); }
.thinking { display: inline-flex; align-items: center; gap: 0.28rem; padding: 0.2rem 0; }
.thinking i { width: 0.32rem; height: 0.32rem; border-radius: 50%; background: #99938a; animation: pulse 1.2s ease-in-out infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 70%, 100% { opacity: .35; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-.18rem); } }

.composer-area { position: sticky; z-index: 5; bottom: 0; padding: 0 clamp(1.1rem, 6vw, 5.5rem) clamp(1rem, 2.5vw, 2rem); background: linear-gradient(180deg, rgba(255,254,250,0), #fffefa 1.5rem); }
.suggestions { display: flex; gap: 0.5rem; overflow-x: auto; padding: 1.2rem 0 0.7rem; scrollbar-width: none; }
.suggestions::-webkit-scrollbar { display: none; }
.suggestions button {
  flex: 0 0 auto;
  padding: 0.52rem 0.78rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffefa;
  color: #625d56;
  font-size: 0.72rem;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease, transform 150ms ease;
}
.suggestions button:hover { border-color: #f2b079; background: #fff7ef; color: var(--orange-dark); }
.suggestions button:active { transform: translateY(1px); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.7rem;
  padding: 0.65rem 0.65rem 0.65rem 1rem;
  border: 1px solid #d8d2c8;
  border-radius: 1rem;
  background: #fff;
  box-shadow: 0 0.8rem 2.4rem rgba(67, 52, 33, .08);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.composer:focus-within { border-color: var(--orange); box-shadow: 0 0 0 0.2rem rgba(244,129,32,.11), 0 0.8rem 2.4rem rgba(67,52,33,.08); }
textarea { width: 100%; max-height: 9rem; min-height: 2.5rem; padding: 0.55rem 0; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); line-height: 1.5; }
textarea::placeholder { color: #a39d94; }
.send {
  flex: 0 0 auto;
  min-width: 5.6rem;
  min-height: 2.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  padding: 0.65rem 0.9rem;
  border: 0;
  border-radius: 0.72rem;
  background: var(--orange);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 150ms ease, transform 150ms ease;
}
.send:hover { background: #de6812; }
.send:active { transform: translateY(1px); }
.send:disabled { cursor: wait; background: #d8a47d; }
.send svg { width: 1.05rem; fill: currentColor; }

.composer-meta { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; padding: 0.62rem 0.15rem 0; color: #918b82; font-size: 0.64rem; }
.composer-meta > span:nth-child(2) { text-align: center; }
.composer-meta button { justify-self: end; padding: 0.2rem; border: 0; background: transparent; color: #7c766e; font-size: 0.68rem; cursor: pointer; }
.composer-meta button:hover { color: var(--orange-dark); }

button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 3px solid rgba(244,129,32,.42); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 840px) {
  .app-shell { display: block; height: 100vh; height: 100dvh; min-height: 0; padding: 0; }
  .sidebar { display: none; }
  .sidebar-toggle { display: none; }
  .workspace { height: 100vh; height: 100dvh; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
  .topbar { min-height: 4.6rem; padding-inline: 1rem; }
  .mobile-brand { display: block; margin: 0 0 0.1rem; color: var(--orange-dark); font-size: 0.62rem; font-weight: 800; letter-spacing: .09em; }
  .messages { padding: 1.5rem 1rem; }
  .composer-area { padding-inline: 1rem; padding-bottom: max(0.9rem, env(safe-area-inset-bottom)); }
  .composer-meta { display: flex; justify-content: space-between; }
  .composer-meta > span:first-child { display: none; }
}

@media (max-width: 520px) {
  .message { gap: 0.6rem; }
  .avatar { width: 1.9rem; height: 1.9rem; }
  .bubble { font-size: 0.88rem; }
  .composer { padding-left: 0.85rem; }
  .send { min-width: 2.7rem; width: 2.7rem; padding-inline: 0; }
  .send span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .composer-meta > span:nth-child(2) { display: none; }
  .composer-meta { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
