:root {
  color-scheme: light;
  --canvas: #fff;
  --bg: #f8f8f8;
  --sidebar-surface: #faf6fc;
  --sidebar-divider: #e7e3ea;
  --panel: #fff;
  --panel-2: #f5f5f5;
  --user-bubble: #f1f1f1;
  --surface-hover: #f0f0f0;
  --surface-active: #eaeaea;
  --sidebar-active: #e5e5e5;
  --sidebar-hover: #e1e1e1;
  --line: #e8e8e8;
  --line-strong: #d8d8d8;
  --text: #1f1f1f;
  --text-soft: #454545;
  --muted: #747474;
  --brand: #333;
  --brand-2: #1f1f1f;
  --ok: #3e3e3e;
  --warn: #525252;
  --danger: #242424;
  --automatic: #a34b20;
  --automatic-hover: #f9f0e9;
  --unread: #2788e8;
  --focus: #818181;
  --focus-ring: #0000000e;
  --scroll-thumb: #d0d0d0;
  --button-bg: #252525;
  --button-hover: #414141;
  --button-text: #fff;
  --button-disabled: #dedede;
  --button-disabled-text: #696969;
  --switch-off: #767676;
  --switch-thumb: #fff;
  --diff-add: #e8e8e8;
  --diff-del: #f2f2f2;
  --overlay: #0005;
  --drawer-overlay: #0002;
  --radius: 14px;
  --shadow-sm: 0 1px 2px #0000000a;
  --shadow-md: 0 10px 30px #00000010, 0 2px 6px #0000000a;
  --shadow-composer: 0 2px 7px #0000000b;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --rail-width: 54px;
  --rail-inset: 12px;
  --sidebar-width: 246px;
  --chat-width: 824px;
  --chat-gutter: clamp(18px, 4.2vw, 60px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #19191b;
  --bg: #171719;
  --sidebar-surface: #1f1824;
  --sidebar-divider: #353139;
  --panel: #222224;
  --panel-2: #27272a;
  --user-bubble: #2c2a2f;
  --surface-hover: #2d2b30;
  --surface-active: #36333a;
  --sidebar-active: #38343e;
  --sidebar-hover: #413c47;
  --line: #353438;
  --line-strong: #4a484e;
  --text: #eeeeef;
  --text-soft: #cfccd1;
  --muted: #aaa7af;
  --brand: #dedbe0;
  --brand-2: #eeeeef;
  --ok: #d1cfd2;
  --warn: #bdb9c0;
  --danger: #e5e2e7;
  --automatic: #f2a379;
  --automatic-hover: #382721;
  --unread: #63afff;
  --focus: #b3aeb8;
  --focus-ring: #ffffff22;
  --scroll-thumb: #555159;
  --button-bg: #e9e7ec;
  --button-hover: #fff;
  --button-text: #202024;
  --button-disabled: #333137;
  --button-disabled-text: #b5b2ba;
  --switch-off: #79757e;
  --switch-thumb: #fff;
  --diff-add: #333137;
  --diff-del: #28262a;
  --overlay: #000a;
  --drawer-overlay: #0008;
  --shadow-sm: 0 1px 2px #0004;
  --shadow-md: 0 10px 30px #0006, 0 2px 6px #0003;
  --shadow-composer: 0 2px 7px #0004;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; }
html, body { margin: 0; }

body {
  color: var(--text);
  background: var(--bg);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
a { color: inherit; }
svg { flex-shrink: 0; }
.ui-icon { display: block; width: 17px; height: 17px; }
.sess-list, .content-scroll, .composer-popover { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }

input, select, textarea {
  width: 100%;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px var(--focus-ring);
}
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--brand); }

.btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 7px 13px;
  background: var(--button-bg);
  color: var(--button-text);
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  transition: background .14s ease, border-color .14s ease;
}
.btn:hover { background: var(--button-hover); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn-ghost, .btn-danger {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line-strong);
}
.btn-ghost:hover, .btn-danger:hover { background: var(--panel-2); }
.btn-ok { background: var(--button-bg); }
.btn-sm { min-height: 30px; padding: 5px 9px; border-radius: 7px; font-size: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: max-content;
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 500;
}
.badge-ok { color: var(--text); }
.badge-warn { color: var(--muted); }
.field { min-width: 0; margin-bottom: 15px; }
.field label { display: block; margin-bottom: 6px; color: var(--text-soft); font-size: 13px; font-weight: 550; }
.row-inline { display: flex; gap: 8px; align-items: center; }

/* Authentication */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 28px; }
.auth-card { width: min(100%, 410px); }
.auth-form-pane { padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.auth-hero { padding: 0 0 22px; }
.hero-brand, .auth-brand { display: flex; align-items: center; gap: 10px; margin: 0 0 22px; }
.auth-hero .hero-brand { margin-bottom: 0; }
.hero-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; filter: grayscale(1); }
.auth-heading { display: flex; align-items: center; gap: 10px; margin: 0 0 20px; font-size: 22px; font-weight: 650; letter-spacing: -.5px; }
.auth-heading img { width: 32px; height: 32px; border-radius: 7px; object-fit: contain; filter: grayscale(1); }
.hero-title { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.5px; }
.hero-slogan, .feature-item { color: var(--text-soft); }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; padding: 3px; border-radius: 9px; background: var(--panel-2); }
.tab {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 550;
}
.tab:hover { color: var(--text); background: var(--surface-hover); }
.tab.active { background: var(--panel); border-color: var(--line); color: var(--text); box-shadow: var(--shadow-sm); }

/* Workspace */
.shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--rail-width) var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}
.rail {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 0;
  padding: var(--rail-inset) 6px;
  background: var(--sidebar-surface);
}
.rail::after {
  position: absolute;
  inset-block: var(--rail-inset);
  inset-inline-end: 0;
  width: 1px;
  background: var(--sidebar-divider);
  content: "";
  pointer-events: none;
}
.rail-top, .rail-bottom { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.rail .account-menu, .rail .composer-popover { inset: auto auto 0 calc(100% + 8px); }
.rail-btn, .mobile-sidebar-btn, .icon-btn {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.rail-btn:hover, .mobile-sidebar-btn:hover, .icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.rail-btn.active { background: var(--sidebar-active); color: var(--text); }
.rail-btn svg { width: 19px; height: 19px; }
.rail-btn:disabled { opacity: .44; cursor: not-allowed; }
.rail-badge, .rail-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
}
.rail-btn:has(.rail-dot), .rail-btn:has(.rail-badge) { position: relative; }

.sidebar {
  z-index: 4;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 0 12px 12px;
  background: var(--sidebar-surface);
  border-right: 1px solid var(--line);
}
.sidebar-brand { display: flex; align-items: center; gap: 8px; min-height: 58px; padding: 0 8px; }
.sidebar-logo { width: 25px; height: 25px; border-radius: 6px; object-fit: contain; filter: grayscale(1); }
.brand-title { color: var(--text); font-size: 16px; font-weight: 650; letter-spacing: -.35px; }
.brand-title span { margin-left: 4px; }
.sidebar-download, .sidebar-new, .new-chat-btn, .nav-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 37px;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  font-weight: 550;
  text-align: left;
  cursor: pointer;
}
.sidebar-download { margin-bottom: 4px; padding-inline-end: 13px; font-size: 13.5px; font-weight: 400; }
.sidebar-download:hover { background: var(--surface-hover); color: var(--text); }
.sidebar-download .unread-dot { margin-inline-start: auto; }
.sidebar-new:hover, .new-chat-btn:hover, .nav-btn:hover { background: var(--surface-hover); color: var(--text); }
.nav-btn.active { background: var(--surface-active); color: var(--text); }
.nav-group { display: flex; flex-direction: column; gap: 3px; }
.sidebar-new, .sidebar-label, .sess-title { font-size: 13.5px; font-weight: 400; }
.sidebar-label { margin: 19px 9px 6px; color: var(--muted); }
.sess-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  margin: 0 -3px;
  padding: 2px 3px;
  overflow: auto;
  overscroll-behavior: contain;
}
.sess-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 35px;
  padding: 3px 7px 3px 17px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
  cursor: pointer;
}
.sess-item:hover { background: var(--surface-hover); color: var(--text); }
.sess-item.active { background: var(--surface-active); color: var(--text); }
.sess-item[aria-current="true"] { background: var(--surface-active); color: var(--text); }
.sess-main { display: flex; flex: 1; align-items: center; gap: 7px; min-width: 0; min-height: 28px; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.sess-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.sess-title { padding: 3px 0; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.sess-unread, .unread-dot {
  display: block;
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--unread);
}
.sess-more { display: inline-grid; flex: 0 0 auto; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 6px; opacity: 0; background: transparent; color: var(--muted); cursor: pointer; }
.sess-more:hover { background: var(--sidebar-hover); color: var(--text); }
.sess-more svg { width: 16px; height: 16px; }
.sess-item:hover .sess-more, .sess-item:focus-within .sess-more, .sess-more[aria-expanded="true"] { opacity: 1; }
.sess-menu, .rail-menu { z-index: 12; }
.sess-running {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--scroll-thumb);
  border-top-color: var(--text-soft);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 9px; }

.main, .main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas);
}
.topbar, .header {
  z-index: 3;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 9px 22px;
  background: var(--canvas);
}
.topbar-left, .topbar-right, .header-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right, .header-actions { flex-shrink: 0; }
.header-title, .topbar-title {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.credit-status, .credit-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 31px;
  padding: 5px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
button.credit-status, button.credit-button { cursor: pointer; }
button.credit-status:hover, button.credit-button:hover { background: var(--surface-hover); color: var(--text); }
.mobile-sidebar-btn, .sidebar-scrim { display: none; }

.content-scroll, .chat-area, .messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}
.content-scroll { padding: 24px; }
#chat-scroll, .messages { padding: 20px var(--chat-gutter) 30px; }
.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 30px;
  width: min(100%, var(--chat-width));
  min-width: 0;
  margin: 0 auto;
}
.chat-welcome {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  padding-block: 20px;
  overflow: auto;
}
.chat-welcome-inner { width: 100%; margin: auto; }
.chat-welcome h2 {
  margin: 0 var(--chat-gutter) clamp(16px, 3vh, 28px);
  color: var(--text);
  font-size: clamp(24px, 4.7vw, 42px);
  font-weight: 500;
  letter-spacing: -.025em;
  text-align: center;
}
.chat-welcome .composer { padding-block: 0; }
.chat-welcome .composer-popover { max-height: min(32dvh, 320px); }

/* Messages */
.msg { min-width: 0; color: var(--text); font-size: 15px; line-height: 1.75; }
.msg.user {
  align-self: flex-end;
  width: max-content;
  max-width: min(82%, 640px);
  padding: 12px 16px;
  border-radius: 19px;
  background: var(--user-bubble);
}
.msg.assistant { align-self: stretch; }
.msg.user .msg-body { white-space: pre-wrap; }
.msg-body { overflow-wrap: anywhere; }
.msg-meta, .msg-actions, .bill-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}
.msg-meta { margin-bottom: 9px; }
.msg-actions, .bill-foot { margin-top: 9px; }
.msg-actions .icon-btn { width: 28px; height: 28px; }
.msg-actions button, .msg-action, .show-more-btn, .message-more {
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}
.msg-actions button:hover, .msg-action:hover, .show-more-btn:hover, .message-more:hover { background: var(--surface-hover); color: var(--text); }
.msg-details, .message-details { position: relative; color: var(--muted); font-size: 12px; }
.msg-details summary, .message-details summary { cursor: pointer; }
.message-icon {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.message-icon:hover, .message-info[open] .message-icon { background: var(--surface-hover); color: var(--text); }
.message-icon::-webkit-details-marker, .user-message-details > summary::-webkit-details-marker { display: none; }
.message-info { position: relative; }
.message-info .bill-foot {
  position: absolute;
  z-index: 1;
  bottom: calc(100% + 4px);
  left: 0;
  display: grid;
  gap: 3px;
  width: max-content;
  max-width: min(250px, 75vw);
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
}
.user-message-details > summary { cursor: pointer; list-style: none; }
.user-message-details[open] > summary { display: flex; justify-content: flex-end; }
.user-message-details[open] .user-preview { display: none; }
.user-message-details[open] .user-expand { transform: rotate(180deg); }
.user-preview { display: -webkit-box; overflow: hidden; overflow-wrap: anywhere; white-space: pre-wrap; -webkit-line-clamp: 5; -webkit-box-orient: vertical; }
.user-expand { display: flex; width: max-content; margin-top: 5px; padding: 3px; border-radius: 4px; color: var(--muted); }
.user-expand:hover { background: var(--surface-active); }
.msg-content-clamped, .is-collapsed .msg-body {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
}

.md-body > :first-child { margin-top: 0; }
.md-body > :last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { margin: 20px 0 9px; color: var(--text); font-weight: 650; line-height: 1.4; }
.md-body h1 { font-size: 23px; }
.md-body h2 { font-size: 20px; }
.md-body h3 { font-size: 17px; }
.md-body h4 { font-size: 15px; }
.md-body p { margin: 12px 0; }
.md-body ul, .md-body ol { margin: 10px 0; padding-left: 23px; }
.md-body li { margin: 4px 0; }
.md-body strong { color: var(--text); font-weight: 650; }
.md-body blockquote { margin: 12px 0; padding: 4px 0 4px 14px; border-left: 2px solid var(--line-strong); color: var(--text-soft); }
.md-body hr { margin: 16px 0; border: none; border-top: 1px solid var(--line); }
.md-body a { color: var(--text); text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 3px; }
.md-body a:hover { text-decoration-color: currentColor; }
code { padding: 2px 5px; border-radius: 4px; background: var(--panel-2); color: var(--text); font: .86em var(--mono); }
.md-code-wrap { overflow: hidden; margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.md-code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font: 12px var(--mono);
}
.md-copy-btn { padding: 3px 7px; border: 0; border-radius: 5px; background: transparent; color: var(--text-soft); font-size: 12px; cursor: pointer; }
.md-copy-btn:hover { background: var(--surface-active); }
.md-code-pre { overflow: auto; margin: 0; padding: 12px 14px; font: 12.5px/1.6 var(--mono); }
.md-code-pre code { padding: 0; background: transparent; color: inherit; font: inherit; }
.md-body table { display: block; max-width: 100%; overflow-x: auto; margin: 10px 0; }

.progress-pill, .thought-box, .tool-pill {
  padding: 7px 10px;
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text-soft);
  font-size: 12.5px;
}
.progress-pill { display: inline-flex; align-items: center; gap: 6px; margin: 2px 0 8px; }
.thought-box { margin: 0 0 10px; color: var(--muted); }
.tool-pill { display: flex; justify-content: space-between; gap: 10px; margin: 8px 0; }
.tool-pill span, .stream-status { color: var(--muted); }
.thought-box summary { cursor: pointer; }
details.thought-box { padding: 3px 0; background: transparent; }
details.thought-box > summary { width: max-content; max-width: 100%; padding: 2px 6px; border-radius: 6px; }
details.thought-box > summary:hover, details.thought-box[open] > summary { background: var(--surface-hover); }
.thought-content, #stream-thought { white-space: pre-wrap; overflow-wrap: anywhere; }
.thought-content { margin: 5px 0 0; }
.diff-title { display: flex; align-items: center; gap: 6px; margin: 0 0 5px; font-weight: 600; }
.approval-request { margin: 10px 0; }
.approval-request .row-inline { margin-top: 10px; }
.diff-box { overflow: auto; margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font: 12px/1.6 var(--mono); }
.diff-add, .diff-del { display: block; padding: 0 4px; border-radius: 3px; color: var(--text); }
.diff-add { background: var(--diff-add); }
.diff-del { background: var(--diff-del); text-decoration: line-through; }
.approval-card { margin: 10px 0; }

/* Composer */
.composer { flex: 0 0 auto; position: relative; z-index: 2; padding: 6px var(--chat-gutter) max(15px, env(safe-area-inset-bottom)); background: var(--canvas); }
.composer-inner, .composer-box { width: min(100%, var(--chat-width)); margin: 0 auto; }
.composer-inner, .composer-box {
  position: relative;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow-composer);
}
.composer-inner > .composer-box, .composer-box > .composer-inner { padding: 0; border: 0; border-radius: 0; box-shadow: none; }
.composer.dragover .composer-inner, .composer.dragover .composer-box { border-color: var(--focus); background: var(--panel-2); }
.composer form { display: block; }
.composer-input, #chat-input {
  display: block;
  width: 100%;
  min-height: 57px;
  max-height: min(36dvh, 290px);
  padding: 5px 7px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  font-size: 15px;
  line-height: 1.55;
  resize: none;
}
.composer-input:focus, #chat-input:focus { border: 0; box-shadow: none; }
.composer-input::placeholder, #chat-input::placeholder { color: var(--muted); }
.composer-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 7px; min-width: 0; margin-top: 4px; }
.composer-left, .composer-right { display: flex; align-items: center; gap: 4px; min-width: 0; }
.composer-right { justify-content: flex-end; margin-left: auto; }
.composer-control, .composer-button, .mode-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 33px;
  padding: 5px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.composer-control:hover, .composer-button:hover, .mode-toggle-btn:hover,
.composer-control[aria-expanded="true"], .composer-button[aria-expanded="true"] { background: var(--surface-hover); color: var(--text); }
.composer-control:disabled, .composer-button:disabled { opacity: .48; cursor: not-allowed; }
.composer-control.icon-btn, .composer-button.icon-btn, .composer-add, .add-control { width: 33px; height: 33px; padding: 0; }
.composer-control svg, .composer-button svg { width: 16px; height: 16px; }
.composer-control.automatic, .composer-button.automatic, .approval-trigger.automatic, .picker-option.automatic { color: var(--automatic); }
.composer-control.automatic:hover, .composer-button.automatic:hover, .approval-trigger.automatic:hover, .picker-option.automatic:hover { background: var(--automatic-hover); color: var(--automatic); }
.model-trigger, .model-picker-trigger { justify-content: flex-start; overflow: hidden; text-overflow: ellipsis; }
.model-trigger > span, .model-picker-trigger > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.model-meta, .model-effort, .model-multiplier, .effort-control { color: var(--muted); }
.model-controls { display: flex; align-items: center; gap: 0; min-width: 0; }
.model-control { justify-content: flex-start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.model-control > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.effort-control { flex: 0 0 auto; }
.send-btn, .composer-send {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--button-bg);
  color: var(--canvas);
  cursor: pointer;
}
.send-btn:hover, .composer-send:hover { background: var(--button-hover); }
.send-btn:disabled, .composer-send:disabled { background: var(--muted); cursor: not-allowed; }
.send-btn svg, .composer-send svg { width: 19px; height: 19px; }

.composer-anchor, .picker-anchor, .popover-anchor, .picker { position: relative; min-width: 0; }
.composer-popover, .picker-menu, .popover {
  position: absolute;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: max-content;
  min-width: 185px;
  max-width: min(360px, calc(100vw - 32px));
  max-height: min(385px, 55dvh);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
}
.composer-popover, .picker-menu { inset: auto auto calc(100% + 7px) 0; }
.composer-popover.header-popover { top: calc(100% + 6px); bottom: auto; }
.composer-popover.align-right, .picker-menu.align-right, .popover.align-right { right: 0; left: auto; }
.popover-divider, .picker-divider { flex: 0 0 1px; margin: 3px 4px; background: var(--line); }
.popover-label, .picker-label, .picker-heading { padding: 5px 8px 2px; color: var(--muted); font-size: 12px; }
.picker-option, .menu-item {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  min-height: 33px;
  width: 100%;
  padding: 5px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.picker-option:hover, .menu-item:hover, .picker-option.active, .menu-item.active { background: var(--surface-hover); }
.picker-option > :last-child:not(:first-child).picker-check, .menu-item > :last-child:not(:first-child).picker-check { margin-left: auto; }
.picker-option svg, .menu-item svg { width: 16px; height: 16px; }
.picker-option > span:first-child { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.picker-option > span + .ui-icon:last-child { margin-left: auto; }
.picker-rate { flex: 0 0 auto; margin-left: 10px; color: var(--muted); white-space: nowrap; }
.picker-option:disabled { opacity: .48; cursor: not-allowed; }
.picker-static { color: var(--muted); cursor: default; }
.picker-static:hover { background: transparent; }

.theme-switch-track {
  display: inline-flex;
  flex: 0 0 32px;
  align-items: center;
  height: 18px;
  padding: 2px;
  border-radius: 999px;
  background: var(--switch-off);
}
.theme-switch-track::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--switch-thumb);
  transition: transform .15s ease;
}
.theme-switch[aria-checked="true"] .theme-switch-track { background: var(--button-bg); }
.theme-switch[aria-checked="true"] .theme-switch-track::after { background: var(--button-text); transform: translateX(14px); }

.att-tray { display: flex; flex-wrap: wrap; gap: 7px; padding: 1px 3px 6px; }
.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 12px;
}
.att-name { min-width: 0; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip button { display: grid; place-items: center; width: 23px; height: 23px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; }
.att-chip button:hover { background: var(--surface-active); color: var(--text); }
.att-chip button svg { width: 13px; height: 13px; }
.att-thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 5px; }
.media-grid { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 8px; }
.media-img-card { max-width: min(100%, 340px); overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.media-img-card img { display: block; max-width: 100%; max-height: 280px; object-fit: contain; cursor: zoom-in; background: var(--bg); }
.media-img-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 8px; color: var(--muted); font-size: 12px; }
.file-card {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 100%;
  margin-top: 7px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  line-height: 1.45;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.file-card:hover { border-color: var(--line-strong); }
.file-card > span:first-child { filter: grayscale(1); }
.file-card .btn { flex: 0 0 auto; border-color: transparent; background: transparent; color: var(--text-soft); }
.file-card .btn:hover { background: var(--surface-active); color: var(--text); }
.lightbox-mask { position: fixed; inset: 0; z-index: 250; display: grid; place-items: center; padding: 16px; background: #111c; cursor: zoom-out; }
.lightbox-mask img { max-width: 94vw; max-height: 90dvh; border-radius: 10px; background: var(--panel); }
.skill-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.chip { padding: 4px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--muted); font-size: 12px; cursor: pointer; }
.chip:hover, .chip.on { border-color: var(--line-strong); background: var(--surface-hover); color: var(--text); }

/* Devices, settings and account pages */
.container-narrow { display: flex; flex-direction: column; gap: 16px; width: min(100%, 1100px); min-width: 0; margin: 0 auto; }
.card { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.card h3 { margin: 0 0 12px; color: var(--text); font-size: 16px; font-weight: 650; }
.card:has(table) { overflow-x: auto; }
.card .row-inline { flex-wrap: wrap; }
.grid-4, .grid-3, .grid-2, .device-grid { display: grid; gap: 12px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 238px), 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.device-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 255px), 1fr)); margin-top: 12px; }
.dl-card, .device-card, .stat-box { min-width: 0; padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); }
.dl-card, .device-card { display: flex; flex-direction: column; justify-content: space-between; gap: 10px; }
.dl-card:hover { border-color: var(--line-strong); }
.dl-icon { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 20px; filter: grayscale(1); }
.dl-card-vscode { cursor: pointer; }
.device-card.is-default, .device-select.device-online { border-color: var(--scroll-thumb); }
.device-select { width: auto; max-width: 240px; background: var(--panel); font-size: 12px; }
.stat-val { margin-top: 5px; color: var(--text); font-size: 23px; font-weight: 650; font-variant-numeric: tabular-nums; }
.code-pre { overflow: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: 12px/1.6 var(--mono); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--bg); color: var(--text-soft); font-weight: 550; }
tbody tr:last-child td { border-bottom: 0; }

.modal-mask { position: fixed; inset: 0; z-index: 99; display: grid; place-items: center; padding: 16px; background: var(--overlay); }
.modal { width: min(600px, 100%); max-height: 90dvh; overflow-y: auto; padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow-md); }
.modal > h3:first-child { margin-top: 0; }
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  max-width: calc(100vw - 32px);
  padding: 9px 13px;
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--button-text);
  box-shadow: var(--shadow-md);
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  :root { --sidebar-width: 212px; --chat-gutter: 28px; }
  .topbar, .header { padding-inline: 16px; }
}
@media (max-width: 760px) {
  :root { --rail-width: 45px; --sidebar-width: 225px; --chat-gutter: 14px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail, .sidebar {
    position: absolute;
    visibility: hidden;
    transform: translateX(-10px);
    opacity: 0;
    transition: visibility .15s, transform .15s, opacity .15s;
  }
  .rail { inset: 0 auto 0 0; width: var(--rail-width); padding-inline: 3px; }
  .sidebar { inset: 0 auto 0 var(--rail-width); width: min(var(--sidebar-width), calc(100% - var(--rail-width) - 24px)); }
  .shell.sidebar-open .rail, .shell.sidebar-open .sidebar { visibility: visible; transform: none; opacity: 1; }
  .mobile-sidebar-btn { display: inline-grid; width: 30px; height: 30px; }
  .shell.sidebar-open .sidebar-scrim { position: absolute; inset: 0; z-index: 3; display: block; padding: 0; border: 0; background: var(--drawer-overlay); }
  .topbar, .header { min-height: 49px; gap: 6px; padding: 6px 9px; }
  .topbar-left, .topbar-right, .header-actions { gap: 4px; }
  .header-title, .topbar-title { font-size: 13px; }
  .credit-status, .credit-button { font-size: 12px; padding-inline: 5px; }
  .chat-stream { gap: 23px; }
  #chat-scroll, .messages { padding-block: 14px 18px; }
  .composer { padding-top: 3px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .composer-inner, .composer-box { padding: 7px; border-radius: 16px; }
  .composer-input, #chat-input { min-height: 48px; font-size: 16px; }
  .composer-control, .composer-button { padding-inline: 5px; font-size: 12px; }
  .composer-popover, .picker-menu, .popover { max-width: min(290px, calc(100vw - 34px)); }
  .rail .composer-popover { max-width: min(290px, calc(100vw - var(--rail-width) - 15px)); }
  .device-select { max-width: 120px; }
  .content-scroll { padding: 15px; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; }
}
@media (max-width: 410px) {
  :root { --chat-gutter: 10px; }
  .composer-toolbar, .composer-left, .composer-right { gap: 2px; }
  .composer-control, .composer-button { padding-inline: 4px; }
  .send-btn, .composer-send { width: 31px; height: 31px; }
  .msg { font-size: 14px; }
  .msg.user { max-width: 90%; }
  .file-card { flex-wrap: wrap; }
  .file-card > .row-inline { margin-left: 0 !important; }
  .auth-form-pane { padding: 20px; }
}
@media (hover: none) {
  .sess-more { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
