:root {
  color-scheme: light;
  --display: "Iowan Old Style", "Songti SC", "STSong", serif;
  --body: "Avenir Next", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --mono: "SFMono-Regular", "Menlo", monospace;
  --canvas: #f3efe5;
  --canvas-deep: #e9e3d5;
  --panel: rgba(251, 248, 240, 0.88);
  --panel-solid: #fbf8f0;
  --sidebar: rgba(31, 31, 27, 0.97);
  --sidebar-text: #f5f0e5;
  --sidebar-muted: #9d9a90;
  --ink: #1d1d1a;
  --muted: #777369;
  --faint: #a9a396;
  --line: rgba(42, 39, 33, 0.12);
  --line-strong: rgba(42, 39, 33, 0.22);
  --accent: #a97422;
  --accent-bright: #d9a743;
  --accent-soft: rgba(176, 125, 38, 0.12);
  --danger: #ae463b;
  --success: #39765a;
  --user-bubble: #20201c;
  --user-ink: #f8f3e8;
  --shadow: 0 26px 70px rgba(32, 27, 17, 0.14);
  --sidebar-width: 302px;
  font-family: var(--body);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #11110f;
  --canvas-deep: #0b0b0a;
  --panel: rgba(24, 24, 21, 0.9);
  --panel-solid: #191916;
  --sidebar: rgba(9, 9, 8, 0.98);
  --sidebar-text: #ece7dc;
  --sidebar-muted: #858279;
  --ink: #ebe6db;
  --muted: #99958c;
  --faint: #706d65;
  --line: rgba(236, 228, 212, 0.1);
  --line-strong: rgba(236, 228, 212, 0.18);
  --accent: #d1a047;
  --accent-bright: #f0cf78;
  --accent-soft: rgba(212, 163, 73, 0.12);
  --danger: #e47a6d;
  --success: #78b99a;
  --user-bubble: #e9e2d3;
  --user-ink: #171713;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
  background: var(--canvas);
  color: var(--ink);
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button,
input,
textarea,
select { font: inherit; }

button { color: inherit; }

button,
a,
input,
textarea,
select { -webkit-tap-highlight-color: transparent; }

button { cursor: pointer; }

[hidden] { display: none !important; }

::selection {
  color: var(--user-ink);
  background: var(--accent-bright);
}

.ambient {
  position: fixed;
  z-index: 0;
  width: 44vw;
  height: 44vw;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(1px);
  opacity: 0.48;
}

.ambient-one {
  top: -26vw;
  right: -8vw;
  background: radial-gradient(circle, rgba(211, 164, 77, 0.14), transparent 68%);
}

.ambient-two {
  bottom: -30vw;
  left: 16vw;
  background: radial-gradient(circle, rgba(105, 115, 87, 0.1), transparent 70%);
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
}

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: calc(22px + env(safe-area-inset-top)) 17px calc(16px + env(safe-area-inset-bottom));
  color: var(--sidebar-text);
  background: var(--sidebar);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.sidebar::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  opacity: 0.12;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
  pointer-events: none;
}

.sidebar-brand {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 0 5px 21px;
}

.brand-mark {
  position: relative;
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  color: #171611;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: -0.05em;
  background: #dbb45e;
  border: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42), 0 7px 24px rgba(208, 159, 63, 0.24);
}

.brand-orbit {
  position: absolute;
  inset: 5px;
  border: 1px dashed rgba(26, 23, 16, 0.42);
  border-radius: 50%;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.17em;
}

.sidebar-brand .eyebrow { color: #af8e4e; }

.sidebar-brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
}

.icon-button:hover {
  color: var(--ink);
  background: var(--accent-soft);
  border-color: var(--line);
}

.icon-button svg,
.new-chat-button svg,
.history-search svg,
.settings-glyph svg,
.model-trigger svg,
.send-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar .icon-button { color: var(--sidebar-muted); }
.sidebar .icon-button:hover { color: var(--sidebar-text); }

.new-chat-button {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 9px;
  align-items: center;
  width: 100%;
  padding: 12px 13px;
  color: #f4ecdc;
  text-align: left;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 11px;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.035);
  transition: 160ms ease;
}

.new-chat-button:hover { background: rgba(255, 255, 255, 0.09); }
.new-chat-button svg { width: 18px; height: 18px; }

kbd {
  color: #77736a;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
}

.history-search {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: center;
  margin: 16px 3px 20px;
  padding: 8px 8px;
  color: var(--sidebar-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.history-search svg { width: 17px; height: 17px; }

.history-search input {
  min-width: 0;
  padding: 0;
  color: var(--sidebar-text);
  background: transparent;
  border: 0;
  outline: 0;
}

.history-search input::placeholder { color: #6f6c65; }

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px 9px;
  color: #77746c;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.history-count {
  display: grid;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  place-items: center;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
}

.conversation-list {
  flex: 1;
  min-height: 0;
  margin: 0 -4px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.conversation-item-wrap {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  margin: 2px 0;
  border-radius: 9px;
}

.conversation-item-wrap:hover,
.conversation-item-wrap.active { background: rgba(255, 255, 255, 0.065); }

.conversation-item-wrap.active::before {
  position: absolute;
  left: 0;
  width: 2px;
  height: 26px;
  content: "";
  background: #d8ae56;
  border-radius: 2px;
}

.conversation-item {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 10px 4px 10px 12px;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
}

.conversation-title,
.conversation-preview {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-title {
  color: #ddd8ce;
  font-size: 13px;
  font-weight: 600;
}

.conversation-preview {
  margin-top: 3px;
  color: #77746c;
  font-size: 10px;
}

.conversation-more {
  width: 29px;
  height: 29px;
  padding: 0;
  color: #858178;
  line-height: 1;
  letter-spacing: 0.06em;
  background: transparent;
  border: 0;
  border-radius: 7px;
  opacity: 0;
}

.conversation-item-wrap:hover .conversation-more,
.conversation-item-wrap.active .conversation-more,
.conversation-more:focus { opacity: 1; }

.conversation-more:hover { color: #eee8dc; background: rgba(255, 255, 255, 0.08); }

.history-empty {
  margin: 30px 22px;
  color: #6f6c65;
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.settings-button {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 7px;
  color: var(--sidebar-text);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 10px;
}

.settings-button:hover { background: rgba(255, 255, 255, 0.06); }

.settings-button > span:last-child { display: flex; flex-direction: column; }
.settings-button strong { font-size: 12px; font-weight: 600; }
.settings-button small { margin-top: 2px; color: var(--sidebar-muted); font-size: 10px; }

.settings-glyph {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: #c7a157;
  background: rgba(211, 170, 84, 0.1);
  border-radius: 50%;
}

.settings-glyph svg { width: 18px; height: 18px; }

.main-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100dvh;
  background: linear-gradient(165deg, transparent, rgba(140, 111, 58, 0.025));
}

.topbar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 64px;
  padding: calc(8px + env(safe-area-inset-top)) 22px 8px;
  background: color-mix(in srgb, var(--canvas) 82%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(1.2);
}

.model-trigger {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-self: start;
  max-width: min(420px, 60vw);
  padding: 8px 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
}

.model-trigger:hover { background: var(--accent-soft); border-color: var(--line); }
.model-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-trigger svg { width: 15px; height: 15px; color: var(--muted); }

.topbar-actions { display: flex; gap: 7px; align-items: center; }

.context-meter {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  padding: 7px 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.03em;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.context-meter:hover { color: var(--ink); background: var(--accent-soft); }

.meter-dot {
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 13%, transparent);
}

.context-meter[data-tone="warning"] .meter-dot { background: var(--accent); }
.context-meter[data-tone="critical"] .meter-dot { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 13%, transparent); }
.context-meter[data-tone="disabled"] .meter-dot { background: var(--faint); box-shadow: none; }

.model-menu {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top));
  left: 22px;
  width: min(310px, calc(100vw - 30px));
  padding: 7px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  box-shadow: var(--shadow);
}

.model-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 11px;
  color: var(--ink);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
}

.model-menu button:hover,
.model-menu button.selected { background: var(--accent-soft); }
.model-provider-caption {
  padding: 6px 11px 7px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.model-menu button span { overflow: hidden; text-overflow: ellipsis; }
.model-menu button i { color: var(--accent); font-size: 9px; font-style: normal; }
.model-menu .model-settings-link { margin-top: 5px; color: var(--muted); border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; }

.chat-scroll {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.welcome-state {
  width: min(760px, calc(100% - 44px));
  margin: clamp(54px, 13vh, 140px) auto 42px;
  animation: welcome-in 650ms cubic-bezier(.2,.75,.22,1) both;
}

@keyframes welcome-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-symbol {
  position: relative;
  width: 56px;
  height: 56px;
  margin-bottom: 28px;
}

.welcome-symbol::before,
.welcome-symbol::after,
.welcome-symbol span {
  position: absolute;
  inset: 50% auto auto 50%;
  content: "";
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.welcome-symbol::before { width: 54px; height: 54px; border: 1px solid var(--line-strong); }
.welcome-symbol::after { width: 8px; height: 8px; background: var(--accent-bright); box-shadow: 0 0 20px var(--accent); }
.welcome-symbol span:nth-child(1) { width: 40px; height: 1px; background: var(--accent); transform: translate(-50%, -50%) rotate(30deg); }
.welcome-symbol span:nth-child(2) { width: 40px; height: 1px; background: var(--accent); transform: translate(-50%, -50%) rotate(150deg); }
.welcome-symbol span:nth-child(3) { width: 24px; height: 24px; border: 1px dashed var(--accent); }

.welcome-state h2 {
  max-width: 650px;
  margin: 8px 0 14px;
  font-family: var(--display);
  font-size: clamp(38px, 6.5vw, 68px);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.welcome-state > p:not(.eyebrow) {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 40px;
}

.suggestion {
  position: relative;
  min-height: 94px;
  padding: 16px 18px;
  overflow: hidden;
  color: var(--ink);
  text-align: left;
  background: color-mix(in srgb, var(--panel-solid) 76%, transparent);
  border: 1px solid var(--line);
  border-radius: 13px;
  transition: 180ms ease;
}

.suggestion::after {
  position: absolute;
  right: -20px;
  bottom: -34px;
  width: 88px;
  height: 88px;
  content: "";
  border: 1px solid var(--line);
  border-radius: 50%;
  transition: 200ms ease;
}

.suggestion:hover { transform: translateY(-2px); border-color: var(--line-strong); box-shadow: 0 12px 30px rgba(30, 26, 18, 0.06); }
.suggestion:hover::after { transform: scale(1.2); border-color: var(--accent); }
.suggestion span { display: block; margin-bottom: 14px; color: var(--accent); font-family: var(--mono); font-size: 9px; letter-spacing: 0.13em; }
.suggestion strong { font-family: var(--display); font-size: 16px; font-weight: 600; }

.messages {
  width: min(840px, calc(100% - 44px));
  margin: 0 auto;
  padding: 38px 0 50px;
}

.message-row {
  display: flex;
  gap: 13px;
  width: 100%;
  margin: 0 0 31px;
  animation: message-in 260ms ease both;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-row.user { justify-content: flex-end; }

.message-card { min-width: 0; max-width: 100%; }

.message-row.user .message-card {
  max-width: min(78%, 660px);
  padding: 11px 16px;
  color: var(--user-ink);
  background: var(--user-bubble);
  border-radius: 17px 17px 4px 17px;
  box-shadow: 0 7px 20px rgba(0, 0, 0, 0.08);
}

.message-row.assistant .message-card { width: min(100%, 760px); padding-top: 2px; }

.assistant-avatar {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.assistant-avatar::before,
.assistant-avatar::after {
  position: absolute;
  width: 14px;
  height: 1px;
  content: "";
  background: var(--accent);
}

.assistant-avatar::before { transform: rotate(45deg); }
.assistant-avatar::after { transform: rotate(-45deg); }
.assistant-avatar span { width: 4px; height: 4px; z-index: 1; background: var(--accent-bright); border-radius: 50%; }

.message-row.failed .assistant-avatar { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.message-row.failed .message-content { color: var(--danger); }

.prose {
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.78;
}

.prose p { margin: 0; min-height: 1px; }
.prose p + p { margin-top: 9px; }
.prose .paragraph-gap { height: 9px; }
.prose h3, .prose h4 { margin: 22px 0 9px; font-family: var(--display); line-height: 1.3; }
.prose h3 { font-size: 21px; }
.prose h4 { font-size: 17px; }
.prose ul { margin: 8px 0; padding-left: 20px; }
.prose li { margin: 5px 0; padding-left: 3px; }
.prose blockquote { margin: 12px 0; padding: 7px 13px; color: var(--muted); border-left: 2px solid var(--accent); }
.prose a { color: var(--accent); text-underline-offset: 3px; }
.prose code { padding: 0.15em 0.38em; font-family: var(--mono); font-size: 0.88em; background: var(--accent-soft); border: 1px solid var(--line); border-radius: 4px; }

.code-block {
  margin: 15px 0;
  overflow: hidden;
  color: #eee9dc;
  background: #151513;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
}

.code-label {
  padding: 7px 12px;
  color: #8c887f;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  background: #0e0e0d;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.code-block pre { margin: 0; padding: 15px; overflow-x: auto; }
.code-block code { padding: 0; color: inherit; font-family: var(--mono); font-size: 12px; line-height: 1.65; background: none; border: 0; }

.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 140ms ease;
}

.message-row:hover .message-actions,
.message-actions:focus-within { opacity: 1; }

.message-actions button {
  padding: 4px 7px;
  color: var(--muted);
  font-size: 10px;
  background: transparent;
  border: 0;
  border-radius: 5px;
}

.message-actions button:hover { color: var(--ink); background: var(--accent-soft); }
.message-row.user .message-actions { justify-content: flex-end; }
.message-row.user .message-actions button { color: color-mix(in srgb, var(--user-ink) 60%, transparent); }

.streaming-cursor::after {
  display: inline-block;
  width: 6px;
  height: 14px;
  margin-left: 4px;
  vertical-align: -2px;
  content: "";
  background: var(--accent);
  animation: cursor-blink 850ms steps(2, end) infinite;
}

.streaming-waiting { color: var(--muted); }

@keyframes cursor-blink { 50% { opacity: 0; } }

.composer-zone {
  position: relative;
  z-index: 8;
  padding: 8px 22px calc(9px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--canvas) 25%);
}

.mobile-context-meter { display: none; }

.composer {
  width: min(840px, 100%);
  margin: 0 auto;
  padding: 9px 10px 8px 15px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 17px;
  box-shadow: 0 15px 42px rgba(34, 29, 20, 0.1), inset 0 1px color-mix(in srgb, white 35%, transparent);
  backdrop-filter: blur(18px) saturate(1.15);
}

.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--line));
  box-shadow: 0 17px 48px rgba(34, 29, 20, 0.13), 0 0 0 3px var(--accent-soft);
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 32px;
  max-height: 180px;
  padding: 5px 2px;
  resize: none;
  overflow-y: auto;
  color: var(--ink);
  line-height: 1.55;
  background: transparent;
  border: 0;
  outline: 0;
}

.composer textarea::placeholder { color: var(--faint); }

.composer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
}

.composer-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
  max-width: 55%;
  padding: 5px 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.composer-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-light { flex: 0 0 auto; width: 5px; height: 5px; background: var(--accent); border-radius: 50%; }
.composer-actions { display: flex; gap: 9px; align-items: center; }
.send-status { color: var(--muted); font-family: var(--mono); font-size: 9px; }

.send-button {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  color: #191713;
  background: var(--accent-bright);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 6px 17px color-mix(in srgb, var(--accent) 28%, transparent);
}

.send-button:hover { transform: translateY(-1px); filter: brightness(1.06); }
.send-button svg { width: 17px; height: 17px; stroke-width: 2; }
.send-button .stop-icon { display: none; }
.send-button.is-stop .send-icon { display: none; }
.send-button.is-stop .stop-icon { display: block; }

.privacy-note {
  width: min(840px, 100%);
  margin: 7px auto 0;
  color: var(--faint);
  font-size: 9px;
  text-align: center;
}

.install-tip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(840px, 100%);
  margin: 0 auto 7px;
  padding: 9px 11px;
  color: var(--ink);
  font-size: 11px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--line));
  border-radius: 10px;
}

.install-tip button { padding: 0 3px; color: var(--muted); font-size: 20px; background: none; border: 0; }

.sidebar-scrim { display: none; }
.mobile-only { display: none; }

dialog {
  color: var(--ink);
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(9, 9, 8, 0.54);
  backdrop-filter: blur(5px);
}

.sheet-dialog {
  width: min(610px, calc(100vw - 24px));
  max-height: min(850px, calc(100dvh - 24px));
  padding: 0;
  overflow: hidden;
  border-radius: 18px;
}

.settings-sheet { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-height: calc(100dvh - 24px); }

.sheet-header,
.sheet-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 21px;
  background: var(--panel-solid);
}

.sheet-header { border-bottom: 1px solid var(--line); }
.sheet-footer { justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); }
.sheet-header h2 { margin: 0; font-family: var(--display); font-size: 26px; font-weight: 600; }
.settings-scroll { padding: 0 22px 25px; overflow-y: auto; }

.settings-section { padding: 24px 0; border-bottom: 1px solid var(--line); }
.settings-section:last-child { border-bottom: 0; }

.section-title {
  display: grid;
  grid-template-columns: 27px 1fr;
  gap: 10px;
  margin-bottom: 19px;
}

.section-title > span { padding-top: 4px; color: var(--accent); font-family: var(--mono); font-size: 9px; }
.section-title h3 { margin: 0; font-family: var(--display); font-size: 18px; font-weight: 600; }
.section-title p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 13px;
  color: var(--muted);
  font-size: 11px;
}

.field.grow { flex: 1; min-width: 0; }

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  color: var(--ink);
  background: color-mix(in srgb, var(--canvas) 68%, transparent);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
}

.field textarea { resize: vertical; line-height: 1.55; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-hint { color: var(--muted); font-size: 10px; line-height: 1.55; }
.context-limit-note {
  margin: 11px 0 0;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
  background: color-mix(in srgb, var(--accent-soft) 46%, transparent);
  border-left: 2px solid var(--accent);
  border-radius: 0 8px 8px 0;
}

.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 58px; }
.password-wrap button { position: absolute; top: 5px; right: 5px; bottom: 5px; padding: 0 9px; color: var(--muted); font-size: 10px; background: var(--panel-solid); border: 0; border-radius: 6px; }

.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-button { flex: 0 0 auto; margin-bottom: 0; min-height: 42px; }

.inline-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.inline-result { color: var(--muted); font-size: 11px; }
.inline-result[data-tone="success"] { color: var(--success); }
.inline-result[data-tone="error"] { color: var(--danger); }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 2px 0 9px;
}

.toggle-row > span { display: flex; flex-direction: column; gap: 3px; }
.toggle-row strong { font-size: 12px; }
.toggle-row small { color: var(--muted); font-size: 10px; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-row i { position: relative; flex: 0 0 auto; width: 42px; height: 24px; background: var(--line-strong); border-radius: 15px; transition: 180ms ease; }
.toggle-row i::after { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; content: ""; background: var(--panel-solid); border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,.18); transition: 180ms ease; }
.toggle-row input:checked + i { background: var(--accent); }
.toggle-row input:checked + i::after { transform: translateX(18px); }

.primary-button,
.secondary-button,
.danger-button {
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 8px;
}

.primary-button { color: #171510; font-weight: 700; background: var(--accent-bright); border: 1px solid var(--accent-bright); }
.secondary-button { color: var(--ink); background: transparent; border: 1px solid var(--line-strong); }
.secondary-button:hover { background: var(--accent-soft); }
.danger-button { color: var(--danger); background: transparent; border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); }
.danger-button:hover { background: color-mix(in srgb, var(--danger) 9%, transparent); }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.data-footnote { margin: 11px 0 0; color: var(--faint); font-size: 10px; line-height: 1.55; }

.compact-dialog {
  width: min(430px, calc(100vw - 28px));
  padding: 25px;
  border-radius: 17px;
}

.compact-dialog h2 { margin: 5px 0 9px; font-family: var(--display); font-size: 24px; }
.compact-dialog form > p:not(.eyebrow, .form-error) { margin: 0 0 18px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-error { min-height: 16px; margin: 8px 0 0; color: var(--danger); font-size: 11px; }

.toast {
  position: fixed;
  z-index: 100;
  right: 22px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  max-width: min(390px, calc(100vw - 30px));
  padding: 11px 14px;
  color: #f4efe4;
  font-size: 12px;
  line-height: 1.45;
  background: #22211d;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 9px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(9px);
  transition: 180ms ease;
}

.toast.visible { opacity: 1; transform: translateY(0); }
.toast[data-tone="error"] { border-color: rgba(226, 107, 94, 0.5); }
.toast[data-tone="warning"] { border-color: rgba(222, 175, 82, 0.5); }

.conversation-popover {
  position: fixed;
  z-index: 80;
  width: 178px;
  padding: 6px;
  color: var(--ink);
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.conversation-popover button {
  width: 100%;
  padding: 9px 10px;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
}

.conversation-popover button:hover { background: var(--accent-soft); }
.conversation-popover button.danger { color: var(--danger); }

@media (max-width: 760px) {
  :root { --sidebar-width: min(86vw, 330px); }
  .app-shell { display: block; }
  .mobile-only { display: grid; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    transform: translateX(-102%);
    transition: transform 240ms cubic-bezier(.2,.76,.25,1);
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.32);
  }

  .sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 15;
    display: block;
    padding: 0;
    visibility: hidden;
    background: rgba(0, 0, 0, 0.38);
    border: 0;
    opacity: 0;
    transition: 200ms ease;
  }

  .sidebar-open .sidebar-scrim { visibility: visible; opacity: 1; }
  .main-panel { height: 100dvh; }

  .topbar {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    min-height: 56px;
    padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  }

  .model-trigger { max-width: 100%; justify-self: stretch; padding-inline: 6px; }
  .topbar-actions .context-meter { display: none; }
  .topbar-actions .icon-button { display: none; }
  .topbar-actions { min-width: 0; }
  .model-menu { top: calc(51px + env(safe-area-inset-top)); left: 54px; }

  .welcome-state {
    width: calc(100% - 34px);
    margin-top: clamp(42px, 10vh, 90px);
  }

  .welcome-state h2 { font-size: clamp(40px, 13vw, 60px); }
  .welcome-state > p:not(.eyebrow) { font-size: 13px; }
  .suggestion-grid { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 31px; }
  .suggestion { min-height: 102px; padding: 13px; }
  .suggestion strong { font-size: 14px; line-height: 1.35; }

  .messages { width: calc(100% - 28px); padding-top: 25px; }
  .message-row { gap: 9px; margin-bottom: 26px; }
  .message-row.user .message-card { max-width: 87%; }
  .assistant-avatar { width: 26px; height: 26px; }
  .prose { font-size: 14px; line-height: 1.72; }
  .message-actions { opacity: 1; }

  .composer-zone { padding: 7px 10px calc(6px + env(safe-area-inset-bottom)); }
  .topbar-actions .mobile-context-meter {
    position: relative;
    display: grid;
    grid-template-columns: 6px minmax(0, 1fr);
    gap: 0 6px;
    width: clamp(96px, 28vw, 118px);
    min-width: 0;
    padding: 5px 7px 4px;
    overflow: hidden;
    color: var(--muted);
    text-align: left;
    background: color-mix(in srgb, var(--panel-solid) 56%, transparent);
    border: 1px solid var(--line);
    border-radius: 9px;
  }
  .mobile-context-dot {
    grid-row: 1 / 3;
    align-self: center;
    width: 5px;
    height: 5px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 12%, transparent);
  }
  .mobile-context-copy { display: flex; min-width: 0; flex-direction: column; gap: 1px; }
  .mobile-context-copy strong {
    overflow: hidden;
    color: var(--ink);
    font-family: var(--mono);
    font-size: 8px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-context-copy small { overflow: hidden; font-size: 7px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-context-track {
    grid-column: 1 / -1;
    height: 1px;
    margin-top: 3px;
    overflow: hidden;
    background: var(--line);
    border-radius: 999px;
  }
  .mobile-context-track i {
    display: block;
    width: var(--context-progress, 0%);
    height: 100%;
    background: var(--success);
    border-radius: inherit;
    transition: width 260ms ease, background 180ms ease;
  }
  .mobile-context-meter[data-tone="warning"] .mobile-context-dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .mobile-context-meter[data-tone="critical"] .mobile-context-dot { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 12%, transparent); }
  .mobile-context-meter[data-tone="disabled"] .mobile-context-dot { background: var(--faint); box-shadow: none; }
  .mobile-context-meter[data-tone="warning"] .mobile-context-track i { background: var(--accent); }
  .mobile-context-meter[data-tone="critical"] .mobile-context-track i { background: var(--danger); }
  .mobile-context-meter[data-tone="disabled"] .mobile-context-track i { background: var(--faint); }
  .composer { padding-left: 12px; border-radius: 16px; }
  .privacy-note { margin-top: 5px; font-size: 8px; }
  .send-status { display: none; }

  .sheet-dialog {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 8px);
    margin: auto 0 0;
    border-radius: 19px 19px 0 0;
  }

  .settings-sheet { max-height: calc(100dvh - 8px); }
  .settings-scroll { padding-inline: 17px; }
  .sheet-header, .sheet-footer { padding-inline: 17px; }
  .field-row { align-items: stretch; flex-direction: column; }
  .field-button { align-self: flex-start; }
  .data-actions { flex-direction: column; }
  .data-actions button { width: 100%; }

  .toast { right: 15px; bottom: calc(112px + env(safe-area-inset-bottom)); }
  .conversation-more { opacity: 1; }
}

@media (max-width: 390px) {
  .suggestion-grid { grid-template-columns: 1fr; }
  .suggestion { min-height: 78px; }
  .suggestion span { margin-bottom: 9px; }
  .welcome-state { margin-top: 34px; }
  .welcome-symbol { margin-bottom: 20px; }
}

@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;
  }
}
