/* ==========================================================================
   HuangRX AI — interface styles
   ChatGPT / Codex inspired. Hand-written, no framework, no external CDN.
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-sidebar: #f9f9f9;
  --bg-elevated: #ffffff;
  --bg-muted: #f4f4f4;
  --bg-hover: #ececec;
  --bg-user: #f4f4f4;
  --border: #e7e7e7;
  --border-strong: #d4d4d4;
  --text: #0d0d0d;
  --text-2: #5d5d5d;
  --text-3: #8f8f8f;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-contrast: #ffffff;
  --accent-soft: #eef4ff;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --success: #12b76a;
  --warning: #f79009;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 30px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 24px 70px rgba(15, 23, 42, 0.2);
  --radius: 16px;
  --font-sans: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "SFMono-Regular", "Cascadia Code", "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1a1a;
  --bg-sidebar: #141414;
  --bg-elevated: #242424;
  --bg-muted: #2a2a2a;
  --bg-hover: #303030;
  --bg-user: #2f2f2f;
  --border: #2e2e2e;
  --border-strong: #3d3d3d;
  --text: #ececec;
  --text-2: #b4b4b4;
  --text-3: #7f7f7f;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(79, 140, 255, 0.13);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.1);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 40px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.65);
}

html[data-theme="dark"] body.mode-code {
  --accent: #ededed;
  --accent-hover: #ffffff;
  --accent-contrast: #171717;
  --accent-soft: rgba(255, 255, 255, 0.09);
}

html[data-theme="light"] body.mode-code {
  --accent: #111111;
  --accent-hover: #333333;
  --accent-contrast: #ffffff;
  --accent-soft: #f1f1f1;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

a {
  color: var(--accent);
}

::selection {
  background: var(--accent-soft);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-track {
  background: transparent;
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none !important;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

kbd {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */

.app {
  display: flex;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  flex: 0 0 264px;
  flex-direction: column;
  width: 264px;
  min-width: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  transition: width 0.22s ease, flex-basis 0.22s ease, border-color 0.22s ease, transform 0.24s ease;
}

body.sidebar-collapsed .sidebar {
  width: 0;
  flex-basis: 0;
  border-right-color: transparent;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 60px;
  padding: 8px 8px 8px 10px;
  flex: none;
}

.brand {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 10px;
  text-align: left;
  transition: background 0.15s ease;
}

.brand:hover {
  background: var(--bg-hover);
}

.brand-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  color: #ffffff;
  background: linear-gradient(140deg, #4f7cff 0%, #7c5cff 55%, #b05cff 100%);
  border-radius: 9px;
  box-shadow: 0 5px 14px rgba(91, 92, 255, 0.24);
}

.brand-mark .icon {
  width: 17px;
  height: 17px;
  stroke-width: 1.7;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  line-height: 1.18;
}

.brand-name {
  max-width: 100%;
  overflow: hidden;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-mode {
  margin-top: 2px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
}

.brand-chevron {
  width: 14px;
  height: 14px;
  margin-left: auto;
  color: var(--text-3);
}

.icon-btn {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  color: var(--text-2);
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn:disabled {
  opacity: 0.35;
}

.icon-btn:disabled:hover {
  background: none;
  color: var(--text-2);
}

.icon-btn .icon {
  width: 18px;
  height: 18px;
}

.sidebar-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 0 10px;
}

.new-chat-btn {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  transition: background 0.15s ease;
}

.new-chat-btn:hover {
  background: var(--bg-hover);
}

.new-chat-btn .icon {
  color: var(--text-2);
}

.new-chat-btn span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-chat-btn kbd {
  opacity: 0;
  transition: opacity 0.15s ease;
}

.new-chat-btn:hover kbd {
  opacity: 1;
}

.side-nav {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 1px;
  margin-top: 6px;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 37px;
  padding: 0 10px;
  border-radius: 9px;
  color: var(--text);
  font-size: 13.2px;
  text-align: left;
  transition: background 0.15s ease;
}

.side-item:hover {
  background: var(--bg-hover);
}

.side-item .icon {
  width: 17px;
  height: 17px;
  color: var(--text-2);
}

.side-item span:not(.badge-soft) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-item .item-trailing {
  width: 12px;
  height: 12px;
  margin-left: auto;
  color: var(--text-3);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.side-item:hover .item-trailing {
  opacity: 1;
}

.side-item.compact {
  padding: 0 8px;
}

.badge-soft {
  flex: none;
  margin-left: auto;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-3);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.projects-section {
  flex: none;
  margin-top: 14px;
}

.section-label {
  padding: 0 10px 5px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.project-placeholder {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 33px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--text-3);
  font-size: 12.5px;
  text-align: left;
}

.project-placeholder:hover {
  background: var(--bg-hover);
  color: var(--text-2);
}

.project-placeholder .icon {
  width: 15px;
  height: 15px;
}

.side-search {
  position: relative;
  flex: none;
  margin: 12px 0 4px;
}

.side-search .search-icon {
  position: absolute;
  top: 50%;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--text-3);
  transform: translateY(-50%);
  pointer-events: none;
}

.side-search input {
  width: 100%;
  height: 34px;
  padding: 0 54px 0 31px;
  border: 1px solid transparent;
  border-radius: 9px;
  outline: none;
  background: var(--bg-muted);
  color: var(--text);
  font-size: 12.5px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.side-search input::placeholder {
  color: var(--text-3);
}

.side-search input:focus {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

.side-search input::-webkit-search-cancel-button {
  display: none;
}

.side-search kbd {
  position: absolute;
  top: 50%;
  right: 7px;
  transform: translateY(-50%);
  pointer-events: none;
  background: transparent;
  border-color: transparent;
}

.history-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 2px 0 10px;
}

.history-group {
  margin-top: 8px;
}

.history-group-label {
  padding: 5px 10px 3px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.history-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 34px;
  padding: 0 6px 0 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13px;
  text-align: left;
  transition: background 0.13s ease, color 0.13s ease;
}

.history-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.history-item.active {
  background: var(--bg-muted);
  color: var(--text);
  font-weight: 500;
}

.history-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-more {
  display: grid;
  flex: none;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--text-3);
  opacity: 0;
  transition: opacity 0.13s ease, background 0.13s ease;
}

.history-more:hover {
  background: var(--border);
  color: var(--text);
}

.history-item:hover .history-more {
  opacity: 1;
}

.history-empty {
  padding: 20px 10px;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.6;
  text-align: left;
}

.sidebar-foot {
  flex: none;
  padding: 8px 10px 10px;
}

.plan-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border-radius: 9px;
  color: var(--text-2);
  font-size: 12px;
  text-align: left;
  transition: background 0.15s ease;
}

.plan-chip:hover {
  background: var(--bg-hover);
}

.plan-orb {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #a78bfa);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.plan-chip .icon {
  width: 13px;
  height: 13px;
  margin-left: auto;
  color: var(--text-3);
}

.foot-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 2px;
}

.foot-row .side-item {
  flex: 1;
}

/* --------------------------------------------------------------------------
   Main / topbar
   -------------------------------------------------------------------------- */

.main {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  background: var(--bg);
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 14px 0 18px;
  background: var(--bg);
}

.topbar::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 1px;
  background: var(--border);
  content: "";
  opacity: 0;
  transition: opacity 0.2s ease;
}

.topbar.scrolled::after {
  opacity: 1;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.topbar-title {
  max-width: min(42vw, 440px);
  overflow: hidden;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.model-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 230px;
  height: 32px;
  margin-right: 4px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-elevated);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.model-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.model-chip span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-chip .icon {
  width: 13px;
  height: 13px;
  color: var(--text-3);
}

.provider-dot {
  display: inline-block;
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.provider-dot.provider-agnes {
  background: linear-gradient(135deg, #547dff, #b05cff);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.12);
}

.provider-dot.provider-cloudflare {
  background: #f6821f;
  box-shadow: 0 0 0 3px rgba(246, 130, 31, 0.13);
}

/* --------------------------------------------------------------------------
   Welcome
   -------------------------------------------------------------------------- */

.main-scroll {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 24px;
  scroll-behavior: smooth;
}

.welcome {
  display: flex;
  flex: 1 0 auto;
  align-items: center;
  justify-content: center;
  padding: 28px 16px 20px;
}

body.is-empty .welcome {
  min-height: calc(100dvh - 340px);
}

.welcome-inner {
  width: 100%;
  max-width: 800px;
  text-align: center;
  animation: welcomeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.welcome-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  filter: drop-shadow(0 10px 24px rgba(124, 92, 255, 0.18));
}

.asterisk-large {
  width: 58px;
  height: 58px;
  animation: logoFloat 7s ease-in-out infinite;
}

.welcome h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(27px, 3.2vw, 34px);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.2;
}

.welcome-sub {
  max-width: 560px;
  margin: 12px auto 0;
  color: var(--text-3);
  font-size: 13.5px;
  line-height: 1.6;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  max-width: 680px;
  margin: 22px auto 0;
}

.suggestion {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-2);
  font-size: 12.5px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.suggestion:hover {
  border-color: var(--border-strong);
  background: var(--bg-muted);
  color: var(--text);
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   Composer
   -------------------------------------------------------------------------- */

.composer-dock {
  position: relative;
  z-index: 15;
  flex: none;
  padding: 6px 24px 14px;
  background: var(--bg);
}

body.is-empty .composer-dock {
  padding-bottom: clamp(28px, 9vh, 104px);
}

.setup-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 760px;
  margin: 0 auto 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  animation: msgIn 0.3s ease both;
}

.setup-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}

.setup-icon .icon {
  width: 17px;
  height: 17px;
}

.setup-copy {
  flex: 1;
  min-width: 0;
}

.setup-copy strong {
  display: block;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text);
}

.setup-copy p {
  margin: 1px 0 0;
  overflow: hidden;
  color: var(--text-3);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.setup-action {
  flex: none;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 500;
  transition: background 0.15s ease;
}

.setup-action:hover {
  background: var(--bg-hover);
}

.setup-close {
  width: 28px;
  height: 28px;
  color: var(--text-3);
}

.composer {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 7px 10px 7px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-soft);
}

.composer-project {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 0;
}

.project-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 29px;
  padding: 0 9px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 12.5px;
  transition: background 0.15s ease, color 0.15s ease;
}

.project-pill:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.project-pill .icon {
  width: 14px;
  height: 14px;
}

.project-hint {
  margin-left: auto;
  color: var(--text-3);
  font-size: 11px;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 6px 3px;
}

.attachment {
  position: relative;
  width: 58px;
  height: 58px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-muted);
}

.attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.62);
  color: #ffffff;
  backdrop-filter: blur(4px);
}

.attachment-remove .icon {
  width: 11px;
  height: 11px;
  stroke-width: 2.2;
}

.composer-input-wrap {
  padding: 0 2px;
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 30px;
  max-height: 210px;
  padding: 10px 8px 2px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  overflow-y: auto;
}

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

.composer-bar {
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 38px;
  padding-top: 3px;
}

.composer-spacer {
  flex: 1;
}

.attach-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-2);
  background: var(--bg-elevated);
}

.attach-btn:hover {
  background: var(--bg-hover);
}

.model-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 215px;
  height: 32px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 12.5px;
  transition: background 0.15s ease, color 0.15s ease;
}

.model-pill:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.model-pill span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-pill .icon {
  width: 13px;
  height: 13px;
  color: var(--text-3);
}

.pill {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 12px;
  transition: background 0.15s ease, color 0.15s ease;
}

.pill:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.pill .icon {
  width: 14px;
  height: 14px;
}

.approval-pill {
  border: 1px solid var(--border);
  height: 29px;
}

.send-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
  transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.send-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.3;
  box-shadow: none;
}

.send-btn:disabled:hover {
  background: var(--accent);
  transform: none;
}

.send-btn .icon {
  width: 17px;
  height: 17px;
  stroke-width: 2.1;
}

.stop-btn {
  background: var(--text);
  color: var(--bg);
  box-shadow: none;
}

.stop-btn:hover {
  background: var(--text-2);
}

.stop-btn .icon {
  fill: currentColor;
  stroke: none;
}

.composer-hint {
  max-width: 760px;
  margin: 8px auto 0;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.5;
  text-align: center;
}

.mic-listening {
  color: var(--danger);
  animation: micPulse 1.4s ease-in-out infinite;
}

.speaking {
  color: var(--accent);
  animation: micPulse 1.6s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Messages
   -------------------------------------------------------------------------- */

.messages {
  flex: none;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 0 44px;
}

.msg {
  display: flex;
  gap: 14px;
  padding: 16px 0;
  animation: msgIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.msg.user {
  justify-content: flex-end;
}

.msg.user .msg-main {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 78%;
  flex: 0 1 auto;
}

.msg.assistant .msg-main {
  flex: 1;
  min-width: 0;
}

.msg-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: 1px;
  border-radius: 9px;
  color: #ffffff;
  background: linear-gradient(140deg, #4f7cff, #8a5cff);
  box-shadow: 0 3px 10px rgba(91, 92, 255, 0.18);
}

.msg-avatar .icon {
  width: 16px;
  height: 16px;
  stroke-width: 1.7;
}

body.mode-code .msg-avatar {
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--text);
  box-shadow: none;
}

.msg-avatar.user-avatar {
  color: #ffffff;
  background: linear-gradient(140deg, #262626, #4a4a4a);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.msg-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 20px;
  margin-bottom: 4px;
  color: var(--text-3);
  font-size: 11.5px;
}

.msg-author {
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
}

.msg-model-tag {
  max-width: 190px;
  overflow: hidden;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-3);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-time {
  color: var(--text-3);
  font-size: 10.5px;
}

.bubble {
  padding: 11px 17px;
  border-radius: 20px;
  background: var(--bg-user);
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.62;
  overflow-wrap: anywhere;
}

.user-text {
  white-space: pre-wrap;
}

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.msg-attachments:last-child {
  margin-bottom: 0;
}

.msg-attachments img {
  width: 118px;
  height: 118px;
  border: 1px solid var(--border);
  border-radius: 12px;
  object-fit: cover;
}

.markdown {
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.markdown > *:first-child {
  margin-top: 0 !important;
}

.markdown > *:last-child {
  margin-bottom: 0 !important;
}

.markdown p {
  margin: 0 0 14px;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin: 22px 0 10px;
  color: var(--text);
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.markdown h1 {
  font-size: 1.5em;
}

.markdown h2 {
  font-size: 1.3em;
}

.markdown h3 {
  font-size: 1.13em;
}

.markdown h4,
.markdown h5,
.markdown h6 {
  font-size: 1em;
}

.markdown strong {
  font-weight: 650;
}

.markdown em {
  font-style: italic;
}

.markdown ul,
.markdown ol {
  margin: 0 0 14px;
  padding-left: 24px;
}

.markdown li {
  margin: 4px 0;
}

.markdown li > p {
  margin: 0 0 6px;
}

.markdown li::marker {
  color: var(--text-3);
}

.markdown blockquote {
  margin: 14px 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-2);
}

.markdown blockquote p:last-child {
  margin-bottom: 0;
}

.markdown hr {
  margin: 22px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.markdown a:hover {
  text-decoration-thickness: 2px;
}

.markdown :not(pre) > code {
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-muted);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.markdown img {
  max-width: 100%;
  border-radius: 12px;
}

.markdown input[type="checkbox"] {
  margin-right: 6px;
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.markdown th,
.markdown td {
  padding: 7px 11px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.markdown th {
  background: var(--bg-muted);
  font-weight: 600;
}

.table-wrap {
  margin: 14px 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.table-wrap table {
  margin: 0;
}

.table-wrap th,
.table-wrap td {
  border-width: 0 1px 1px 0;
}

.code-block {
  margin: 14px 0;
  overflow: hidden;
  border: 1px solid #30363d;
  border-radius: 12px;
  background: #0d1117;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 0 12px;
  border-bottom: 1px solid #21262d;
  background: #161b22;
  color: #8b949e;
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.code-copy {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 6px;
  border-radius: 6px;
  color: #8b949e;
  font-size: 10.5px;
  transition: color 0.15s ease, background 0.15s ease;
}

.code-copy:hover {
  background: #21262d;
  color: #e6edf3;
}

.code-copy .icon {
  width: 13px;
  height: 13px;
}

.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  color: #c9d1d9;
  font-family: var(--font-mono);
  font-size: 12.8px;
  line-height: 1.62;
  tab-size: 2;
}

.code-block pre code {
  font-family: inherit;
  font-size: inherit;
}

.reasoning {
  margin: 0 0 13px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-muted);
}

.reasoning summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.reasoning summary::-webkit-details-marker {
  display: none;
}

.reasoning summary .icon {
  width: 14px;
  height: 14px;
  color: var(--text-3);
}

.reasoning summary .chev {
  margin-left: auto;
  transition: transform 0.2s ease;
}

.reasoning[open] summary .chev {
  transform: rotate(90deg);
}

.reasoning-body {
  max-height: 340px;
  padding: 10px 14px 13px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.7;
}

.reasoning-body .markdown {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.7;
}

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  color: var(--text-3);
  font-size: 13px;
}

.thinking-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: dotBounce 1.15s infinite ease-in-out;
}

.thinking-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.typing-caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  border-radius: 2px;
  background: var(--text);
  vertical-align: -2px;
  animation: blink 1s steps(1) infinite;
}

.msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  align-items: center;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

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

.msg.user .msg-actions {
  justify-content: flex-end;
}

.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 27px;
  padding: 0 7px;
  border-radius: 7px;
  color: var(--text-3);
  font-size: 10.5px;
  transition: background 0.13s ease, color 0.13s ease;
}

.msg-action:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.msg-action .icon {
  width: 13px;
  height: 13px;
}

.msg-action.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.msg-error {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, var(--danger) 28%, var(--border));
  border-radius: 11px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.55;
}

.msg-error .icon {
  width: 16px;
  height: 16px;
  margin-top: 1px;
}

.msg-error-copy {
  flex: 1;
}

.msg-error button {
  margin-top: 7px;
  padding: 3px 9px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: 6px;
  color: var(--danger);
  font-size: 11px;
  font-weight: 500;
}

.msg-error button:hover {
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.usage-line {
  margin-top: 7px;
  color: var(--text-3);
  font-size: 10px;
  letter-spacing: 0.01em;
}

.scroll-bottom {
  position: absolute;
  bottom: 168px;
  left: 50%;
  z-index: 18;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  transform: translateX(-50%);
  transition: background 0.15s ease, color 0.15s ease;
}

.scroll-bottom:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.scroll-bottom .icon {
  width: 16px;
  height: 16px;
}

/* --------------------------------------------------------------------------
   Popovers
   -------------------------------------------------------------------------- */

.popover-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
}

.popover-layer[hidden] {
  display: none;
}

.popover-panel {
  position: fixed;
  z-index: 91;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  animation: popIn 0.14s ease both;
}

.popover-panel.wide {
  width: min(390px, calc(100vw - 16px));
}

.popover-panel.narrow {
  width: 250px;
}

.popover-scroll {
  max-height: min(68vh, 600px);
  overflow-y: auto;
  padding: 6px;
}

.popover-search {
  position: relative;
  padding: 7px 7px 5px;
}

.popover-search .icon {
  position: absolute;
  top: 50%;
  left: 18px;
  width: 14px;
  height: 14px;
  color: var(--text-3);
  transform: translateY(-50%);
  pointer-events: none;
}

.popover-search input {
  width: 100%;
  height: 34px;
  padding: 0 10px 0 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--bg-muted);
  color: var(--text);
  font-size: 12.5px;
}

.popover-search input:focus {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

.provider-group {
  padding: 6px 3px 3px;
}

.provider-group + .provider-group {
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.provider-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px 5px;
  color: var(--text-3);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.provider-badge {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  color: #ffffff;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0;
}

.provider-badge.agnes {
  background: linear-gradient(140deg, #547dff, #b05cff);
}

.provider-badge.cloudflare {
  background: #f6821f;
}

.provider-heading .provider-free {
  margin-left: auto;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-3);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

.model-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 9px;
  border-radius: 9px;
  text-align: left;
  transition: background 0.12s ease;
}

.model-item:hover {
  background: var(--bg-hover);
}

.model-item.selected {
  background: var(--accent-soft);
}

.model-item-copy {
  flex: 1;
  min-width: 0;
}

.model-item-name {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.model-item-desc {
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-tag {
  flex: none;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 8px;
  font-weight: 750;
  letter-spacing: 0.05em;
}

.model-context {
  flex: none;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 9px;
}

.model-check {
  flex: none;
  width: 15px;
  height: 15px;
  color: var(--accent);
  opacity: 0;
}

.model-item.selected .model-check {
  opacity: 1;
}

.popover-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 10.5px;
}

.popover-foot .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.popover-empty {
  padding: 20px 12px;
  color: var(--text-3);
  font-size: 12px;
  text-align: center;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--text);
  font-size: 12.5px;
  text-align: left;
  transition: background 0.12s ease;
}

.menu-item:hover {
  background: var(--bg-hover);
}

.menu-item .icon {
  width: 16px;
  height: 16px;
  color: var(--text-2);
}

.menu-item-copy {
  flex: 1;
  min-width: 0;
}

.menu-item-copy strong {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
}

.menu-item-copy small {
  display: block;
  margin-top: 1px;
  color: var(--text-3);
  font-size: 10.5px;
}

.menu-item .menu-check {
  width: 15px;
  height: 15px;
  color: var(--accent);
  opacity: 0;
}

.menu-item.selected .menu-check {
  opacity: 1;
}

.menu-sep {
  height: 1px;
  margin: 5px 8px;
  background: var(--border);
}

.menu-item.danger {
  color: var(--danger);
}

.menu-item.danger .icon {
  color: var(--danger);
}

/* --------------------------------------------------------------------------
   Modals
   -------------------------------------------------------------------------- */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 120;
  pointer-events: none;
}

.modal-root.open {
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(12, 12, 12, 0.48);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.18s ease both;
}

.modal {
  display: flex;
  flex-direction: column;
  width: min(660px, 100%);
  max-height: min(86vh, 820px);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.modal.small {
  width: min(430px, 100%);
}

.modal.wide {
  width: min(760px, 100%);
}

.modal-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.modal-head p {
  margin: 2px 0 0;
  color: var(--text-3);
  font-size: 11.5px;
}

.modal-head .modal-close {
  margin-left: auto;
}

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
}

.modal-foot {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--border);
}

.modal-close {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--text-3);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-close .icon {
  width: 16px;
  height: 16px;
}

.settings-layout {
  display: flex;
  gap: 20px;
  min-height: 360px;
}

.settings-nav {
  display: flex;
  flex: 0 0 142px;
  flex-direction: column;
  gap: 2px;
}

.settings-nav button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 9px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 12.5px;
  text-align: left;
}

.settings-nav button:hover {
  background: var(--bg-hover);
}

.settings-nav button.active {
  background: var(--bg-muted);
  color: var(--text);
  font-weight: 550;
}

.settings-nav .icon {
  width: 15px;
  height: 15px;
}

.settings-panels {
  flex: 1;
  min-width: 0;
}

.settings-panel[hidden] {
  display: none;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section:last-child {
  margin-bottom: 4px;
}

.settings-section h3 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 650;
}

.settings-section > p {
  margin: 0 0 14px;
  color: var(--text-3);
  font-size: 11.5px;
  line-height: 1.55;
}

.field {
  margin-bottom: 15px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}

.field-label small {
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 400;
}

.text-input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input,
.select {
  height: 36px;
  padding: 0 10px;
}

.textarea {
  min-height: 96px;
  padding: 9px 10px;
  resize: vertical;
  line-height: 1.55;
}

.text-input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-hint {
  margin-top: 5px;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.5;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-muted);
}

.segmented button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  border-radius: 7px;
  color: var(--text-2);
  font-size: 11.5px;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.segmented button.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented .icon {
  width: 14px;
  height: 14px;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-row input[type="range"] {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  outline: none;
  background: var(--border);
  accent-color: var(--accent);
  cursor: pointer;
}

.range-value {
  flex: none;
  width: 36px;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-align: right;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.switch-row:last-child {
  border-bottom: 0;
}

.switch-row strong {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
}

.switch-row small {
  display: block;
  margin-top: 2px;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.45;
}

.switch {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 0.18s ease;
}

.switch-track::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  content: "";
  transition: transform 0.18s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(16px);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.danger {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  color: var(--danger);
}

.btn.danger:hover {
  background: var(--danger-soft);
}

.btn .icon {
  width: 14px;
  height: 14px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 15px;
}

.stat {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-muted);
}

.stat strong {
  display: block;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.stat span {
  display: block;
  margin-top: 2px;
  color: var(--text-3);
  font-size: 10px;
}

.connection-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-muted);
}

.connection-card + .connection-card {
  margin-top: 7px;
}

.connection-card .conn-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-2);
}

.connection-card .conn-icon .icon {
  width: 15px;
  height: 15px;
}

.connection-card strong {
  display: block;
  font-size: 12px;
  font-weight: 550;
}

.connection-card small {
  display: block;
  margin-top: 1px;
  color: var(--text-3);
  font-size: 10px;
}

.conn-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  color: var(--text-3);
  font-size: 10.5px;
  white-space: nowrap;
}

.conn-status i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
}

.conn-status.ok {
  color: var(--success);
}

.conn-status.ok i {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 12%, transparent);
}

.conn-status.bad {
  color: var(--danger);
}

.conn-status.bad i {
  background: var(--danger);
}

.about-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.about-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 12px;
  text-decoration: none;
}

.about-link:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.about-link .icon {
  width: 15px;
  height: 15px;
}

.about-link .trailing {
  width: 12px;
  height: 12px;
  margin-left: auto;
  color: var(--text-3);
}

.about-meta {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.7;
}

/* Help / pricing / plugins / image */

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.shortcut-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.shortcut-row:last-child {
  border-bottom: 0;
}

.shortcut-row span {
  flex: 1;
  color: var(--text-2);
}

.shortcut-row kbd {
  min-width: 28px;
  text-align: center;
}

.tip-card {
  display: flex;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-muted);
  color: var(--text-2);
  font-size: 11.5px;
  line-height: 1.6;
}

.tip-card + .tip-card {
  margin-top: 8px;
}

.tip-card .icon {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  color: var(--accent);
}

.price-card {
  position: relative;
  overflow: hidden;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: linear-gradient(150deg, var(--bg-muted), var(--bg-elevated));
}

.price-card::after {
  position: absolute;
  top: -60px;
  right: -50px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 70%);
  content: "";
}

.price-label {
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.price-value {
  margin-top: 4px;
  font-size: 32px;
  font-weight: 650;
  letter-spacing: -0.04em;
}

.price-value small {
  color: var(--text-3);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
}

.feature-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.feature-list li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
}

.feature-list .icon {
  width: 14px;
  height: 14px;
  margin-top: 2px;
  color: var(--success);
}

.plugin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.plugin-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-muted);
}

.plugin-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.plugin-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--accent);
}

.plugin-icon .icon {
  width: 15px;
  height: 15px;
}

.plugin-card strong {
  font-size: 12px;
  font-weight: 600;
}

.plugin-card p {
  flex: 1;
  margin: 0;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.5;
}

.plugin-card .plugin-action {
  align-self: flex-start;
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
}

.plugin-card .plugin-action:disabled {
  color: var(--text-3);
}

.image-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.image-form textarea {
  min-height: 120px;
}

.style-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 14px;
}

.style-chip {
  height: 27px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 10.5px;
}

.style-chip:hover {
  background: var(--bg-hover);
}

.style-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.image-result {
  display: flex;
  min-height: 290px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  background: var(--bg-muted);
  color: var(--text-3);
  font-size: 11.5px;
  text-align: center;
}

.image-result img {
  width: 100%;
  height: 100%;
  max-height: 440px;
  object-fit: contain;
}

.image-result .image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 20px;
}

.image-placeholder .icon {
  width: 28px;
  height: 28px;
  color: var(--text-3);
}

.image-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.image-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.confirm-message {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
}

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: 220;
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  width: min(92vw, 540px);
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.4;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.22s ease both;
  pointer-events: auto;
}

.toast .icon {
  width: 15px;
  height: 15px;
  flex: none;
}

.toast.success .icon {
  color: var(--success);
}

.toast.error .icon {
  color: var(--danger);
}

.toast.info .icon {
  color: var(--accent);
}

.toast.leaving {
  animation: toastOut 0.18s ease both;
}

/* --------------------------------------------------------------------------
   Codex / code mode adjustments
   -------------------------------------------------------------------------- */

body.mode-code .composer {
  border-radius: 20px;
  background: color-mix(in srgb, var(--bg-elevated) 92%, var(--bg));
}

body.mode-code .composer textarea {
  min-height: 34px;
}

body.mode-code .attach-btn {
  border-radius: 9px;
}

body.mode-code .send-btn {
  border-radius: 50%;
}

body.mode-code .welcome h1 {
  font-weight: 500;
  letter-spacing: -0.03em;
}

body.mode-code .suggestion {
  border-radius: 10px;
}

body.mode-code .bubble {
  background: var(--bg-user);
}

body.mode-code .brand-mark {
  background: linear-gradient(140deg, #2e2e2e, #464646);
  box-shadow: none;
}

html[data-theme="dark"] body.mode-code .brand-mark {
  border: 1px solid #3a3a3a;
  background: #222222;
  color: #ededed;
}

html[data-theme="light"] body.mode-code .brand-mark {
  background: #111111;
}

body.mode-code .setup-card {
  background: var(--bg-elevated);
}

/* visibility helpers per mode */
body.mode-chat .code-only {
  display: none !important;
}

body.mode-code .chat-only {
  display: none !important;
}

body.mode-chat #codeNav,
body.mode-chat #projectsSection {
  display: none;
}

body.mode-code #chatNav {
  display: none;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 860px) {
  .mobile-only {
    display: inline-grid !important;
  }

  .desktop-collapse {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    width: 282px;
    flex-basis: 282px;
    transform: translateX(-102%);
    box-shadow: var(--shadow-lg);
  }

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

  body.sidebar-collapsed .sidebar {
    width: 282px;
    flex-basis: 282px;
    border-right-color: var(--border);
    overflow: visible;
  }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.15s ease both;
  }

  .mobile-backdrop[hidden] {
    display: none;
  }

  .topbar {
    height: 52px;
    padding: 0 8px 0 8px;
  }

  .topbar-title {
    max-width: 34vw;
  }

  .model-chip {
    max-width: 160px;
  }

  .main-scroll {
    padding: 0 12px;
  }

  body.is-empty .welcome {
    min-height: calc(100dvh - 300px);
  }

  .composer-dock {
    padding: 5px 10px 10px;
  }

  body.is-empty .composer-dock {
    padding-bottom: 16px;
  }

  .setup-card {
    gap: 9px;
    padding: 9px 10px;
  }

  .setup-copy p {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .setup-action {
    display: none;
  }

  .composer {
    border-radius: 22px;
  }

  .composer-hint {
    margin-top: 6px;
    font-size: 9.5px;
  }

  .msg {
    gap: 10px;
    padding: 13px 0;
  }

  .msg.user .msg-main {
    max-width: 88%;
  }

  .msg-avatar {
    width: 27px;
    height: 27px;
    border-radius: 8px;
  }

  .msg-actions {
    opacity: 1;
  }

  .history-more {
    opacity: 1;
  }

  .scroll-bottom {
    bottom: 152px;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 8px;
  }

  .modal {
    width: 100%;
    max-height: 92dvh;
    border-radius: 18px;
  }

  .settings-layout {
    flex-direction: column;
    gap: 12px;
  }

  .settings-nav {
    flex: none;
    flex-direction: row;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .settings-nav button {
    flex: none;
    padding: 0 10px;
    background: var(--bg-muted);
  }

  .settings-nav button.active {
    background: var(--accent-soft);
    color: var(--accent);
  }

  .image-layout {
    grid-template-columns: 1fr;
  }

  .plugin-grid {
    grid-template-columns: 1fr;
  }

  .popover-panel.sheet {
    top: auto !important;
    right: 8px !important;
    bottom: 8px !important;
    left: 8px !important;
    width: auto !important;
    max-height: 72dvh;
    border-radius: 18px;
  }

  .popover-panel.sheet .popover-scroll {
    max-height: calc(72dvh - 56px);
  }

  .toast-stack {
    top: 10px;
  }
}

@media (max-width: 560px) {
  .topbar-title {
    max-width: 28vw;
    font-size: 12.5px;
  }

  .topbar-actions {
    gap: 0;
  }

  .model-chip {
    max-width: 132px;
    padding: 0 8px;
    font-size: 11px;
  }

  .model-chip .icon {
    display: none;
  }

  .topbar-actions > .icon-btn {
    width: 31px;
    height: 31px;
  }

  .welcome {
    padding: 16px 6px 10px;
  }

  .welcome h1 {
    font-size: 25px;
    letter-spacing: -0.03em;
  }

  .welcome-sub {
    margin-top: 8px;
    font-size: 12px;
  }

  .welcome-logo {
    width: 52px;
    height: 52px;
    margin-bottom: 14px;
  }

  .asterisk-large {
    width: 48px;
    height: 48px;
  }

  .suggestions {
    gap: 6px;
    margin-top: 16px;
  }

  .suggestion {
    height: 31px;
    padding: 0 11px;
    font-size: 11.5px;
  }

  .composer {
    padding: 6px 8px;
  }

  .composer textarea {
    font-size: 16px;
    padding: 8px 6px 2px;
  }

  .composer-bar {
    gap: 1px;
  }

  .model-pill {
    max-width: 138px;
    padding: 0 7px;
    font-size: 11.5px;
  }

  .approval-pill {
    max-width: 130px;
  }

  .approval-pill span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .attach-btn,
  .send-btn {
    width: 32px;
    height: 32px;
  }

  .composer-hint {
    display: none;
  }

  .messages {
    padding-bottom: 30px;
  }

  .msg {
    gap: 8px;
  }

  .msg-avatar {
    width: 25px;
    height: 25px;
  }

  .msg-avatar .icon {
    width: 14px;
    height: 14px;
  }

  .msg-head {
    gap: 5px;
  }

  .msg-model-tag {
    max-width: 110px;
  }

  .bubble {
    padding: 10px 14px;
    font-size: 15px;
  }

  .markdown {
    font-size: 15px;
  }

  .msg-attachments img {
    width: 90px;
    height: 90px;
  }

  .scroll-bottom {
    bottom: 132px;
  }

  .settings-nav {
    margin: 0 -2px;
  }

  .stats-grid {
    gap: 5px;
  }

  .stat {
    padding: 9px;
  }

  .stat strong {
    font-size: 17px;
  }

  .modal-head {
    padding: 13px 14px;
  }

  .modal-body {
    padding: 14px;
  }

  .modal-foot {
    padding: 11px 14px;
  }
}

@media (hover: none) {
  .msg-actions,
  .history-more,
  .side-item .item-trailing {
    opacity: 1;
  }
}

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

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */

@keyframes welcomeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
}

@keyframes dotBounce {
  0%,
  70%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  35% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes micPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

@keyframes logoFloat {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-4px) rotate(3deg);
  }
}
