/* AeroScan Web Chat — public UI */

:root {
  --bg0: #070b14;
  --bg1: #0f172a;
  --bg2: #1e293b;
  --bg3: #312e81;
  --glass: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --dim: #64748b;
  --accent: #818cf8;
  --accent2: #a78bfa;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --user-bubble: rgba(99, 102, 241, 0.22);
  --assistant-bubble: rgba(255, 255, 255, 0.06);
  --sidebar-w: 300px;
  --top-h: 56px;
  --radius: 14px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: radial-gradient(1200px 800px at 10% -10%, rgba(99, 102, 241, 0.18), transparent 55%),
              radial-gradient(900px 600px at 90% 0%, rgba(139, 92, 246, 0.14), transparent 50%),
              linear-gradient(160deg, var(--bg0) 0%, var(--bg1) 45%, var(--bg2) 75%, var(--bg3) 100%);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #c4b5fd; }

.hidden { display: none !important; }

/* ─── Connect overlay ─────────────────────────────────────────────── */

.connect-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.connect-card {
  width: min(520px, 100%);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2rem;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.connect-logo {
  text-align: center;
  margin-bottom: 0.35rem;
}

.brand-logo {
  display: block;
  object-fit: contain;
}

.brand-logo-lg {
  width: 72px;
  height: 72px;
  margin: 0 auto;
}

.brand-logo-sm {
  width: 28px;
  height: 28px;
}

.connect-card h1 {
  margin: 0 0 0.35rem;
  text-align: center;
  font-size: 1.65rem;
  color: #fff;
}

.connect-sub {
  text-align: center;
  color: var(--muted);
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.45rem;
}

.key-input {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.35);
  color: #6ee7b7;
  font-family: var(--mono);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.key-input:focus {
  border-color: rgba(129, 140, 248, 0.6);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  width: 100%;
  margin-top: 1rem;
  padding: 0.85rem 1.25rem;
  font-size: 1rem;
  color: #fff;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.45);
}

.btn-ghost {
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--glass-border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(148, 163, 184, 0.35);
}

.connect-footer {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--dim);
}

.connect-error {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fca5a5;
  font-size: 0.88rem;
}

/* ─── App shell ───────────────────────────────────────────────────── */

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--top-h) 1fr auto;
  grid-template-areas:
    "top top"
    "sidebar main"
    "sidebar composer";
}

.topbar {
  grid-area: top;
  position: relative;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(7, 11, 20, 0.72);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  color: #fff;
  min-width: 0;
}

.brand-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer { flex: 1; }

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin-left: 0.25rem;
}

.topbar-nav a {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
}

.topbar-nav a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.topbar-nav a.active {
  color: #fff;
  background: rgba(99, 102, 241, 0.22);
}

.model-picker {
  position: relative;
  max-width: min(320px, 42vw);
  flex-shrink: 1;
}

.model-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.model-picker-btn:hover {
  border-color: rgba(129, 140, 248, 0.45);
  background: rgba(99, 102, 241, 0.12);
}

.model-picker-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-picker-chevron {
  color: var(--dim);
  font-size: 0.72rem;
  flex-shrink: 0;
}

.model-picker-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  width: min(380px, 88vw);
  max-height: min(480px, 65vh);
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(10, 14, 24, 0.96);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  z-index: 40;
  overflow: hidden;
}

.model-picker-head {
  padding: 0.65rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.model-picker-menu .model-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  max-height: none;
}

.thinking-mode-panel {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.thinking-mode-head {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.thinking-mode-back {
  align-self: flex-start;
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.15rem 0;
}

.thinking-mode-back:hover {
  color: #c4b5fd;
}

.thinking-mode-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
}

.thinking-mode-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.thinking-mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.thinking-mode-btn {
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.thinking-mode-btn:hover {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(129, 140, 248, 0.35);
}

.thinking-mode-btn.active {
  background: rgba(99, 102, 241, 0.22);
  border-color: rgba(129, 140, 248, 0.45);
  color: #fff;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dim);
}

.status-pill.online .status-dot { background: var(--success); box-shadow: 0 0 8px rgba(52, 211, 153, 0.6); }
.status-pill.online { color: #a7f3d0; border-color: rgba(52, 211, 153, 0.25); }
.status-pill.offline .status-dot { background: var(--warn); }
.status-pill.offline { color: #fde68a; border-color: rgba(251, 191, 36, 0.25); }

.sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--glass-border);
  background: rgba(7, 11, 20, 0.55);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 0.75rem 0.65rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.sidebar-icon-btn {
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.sidebar-icon-btn:hover,
.sidebar-icon-btn.active {
  background: rgba(99, 102, 241, 0.15);
  color: #fff;
  border-color: rgba(129, 140, 248, 0.35);
}

.chat-sidebar-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem 0;
  flex-shrink: 0;
}

.chat-tab {
  flex: 1;
  padding: 0.4rem 0.5rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.chat-tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.chat-tab.active {
  background: rgba(99, 102, 241, 0.18);
  color: #fff;
}

.chat-sidebar-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
  padding: 0.55rem 0.75rem 0.35rem;
  flex-shrink: 0;
}

.chat-sort {
  padding: 0.55rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
}

.chat-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  padding: 0 0.75rem 0.45rem;
  flex-shrink: 0;
}

.chat-filter-row.hidden { display: none; }

.chat-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.chat-bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.75rem;
  color: var(--muted);
  flex-shrink: 0;
}

.chat-bulk-bar.hidden { display: none; }

.sidebar-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

.model-search {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

.model-search:focus {
  border-color: rgba(129, 140, 248, 0.5);
}

.model-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.chat-history-empty {
  padding: 1rem 0.75rem;
  font-size: 0.82rem;
  color: var(--dim);
  line-height: 1.5;
}

.chat-history-item {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.chat-history-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-history-item.active {
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(129, 140, 248, 0.35);
}

.chat-history-item.focused {
  outline: 1px solid rgba(129, 140, 248, 0.45);
  outline-offset: -1px;
}

.chat-history-item.unread .chat-history-title {
  color: #fff;
}

.chat-history-color {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 10px 0 0 10px;
  background: var(--chat-color, var(--accent));
}

.chat-history-check {
  margin: auto 0 auto 0.45rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.chat-history-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 0.6rem 0.35rem 0.6rem 0.65rem;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.chat-history-item:has(.chat-history-color) .chat-history-open {
  padding-left: 0.85rem;
}

.chat-history-title-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.chat-history-title {
  flex: 1;
  min-width: 0;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-pin,
.chat-history-icon {
  font-size: 0.72rem;
  flex-shrink: 0;
}

.chat-history-unread {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.chat-history-preview {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.74rem;
  color: var(--dim);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.chat-history-tag {
  font-size: 0.62rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
}

.chat-history-meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.66rem;
  color: var(--dim);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-menu {
  align-self: center;
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  margin-right: 0.25rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
}

.chat-history-item:hover .chat-history-menu,
.chat-history-item.active .chat-history-menu,
.chat-history-item.focused .chat-history-menu {
  opacity: 1;
}

.chat-history-menu:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.chat-context-menu {
  position: fixed;
  z-index: 100;
  min-width: 200px;
  padding: 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(10, 14, 24, 0.98);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.chat-context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.65rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}

.chat-context-menu button:hover {
  background: rgba(99, 102, 241, 0.15);
}

.chat-context-menu button.chat-color-dot:hover {
  background: var(--dot-color, transparent);
}

.chat-context-menu button.danger { color: #fca5a5; }
.chat-context-menu button.hidden { display: none; }

.chat-context-divider {
  height: 1px;
  margin: 0.25rem 0;
  background: var(--glass-border);
}

.chat-context-label {
  display: block;
  padding: 0.25rem 0.65rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--dim);
}

.chat-color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem 0.45rem;
}

.chat-context-menu .chat-color-dot {
  display: inline-block;
  width: 1.15rem;
  height: 1.15rem;
  min-width: 1.15rem;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--dot-color, transparent);
  cursor: pointer;
  padding: 0;
}

.chat-context-menu .chat-color-dot.none {
  background: transparent;
  border-color: var(--glass-border);
}

.chat-context-menu .chat-color-dot.active {
  border-color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.chat-context-menu .chat-color-dot:hover {
  filter: brightness(1.12);
}

.chat-context-menu .chat-color-dot.none:hover {
  background: transparent;
  border-color: var(--text);
}

.chat-modal {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.chat-modal.hidden { display: none; }

.chat-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.chat-modal-card {
  position: relative;
  width: min(400px, 100%);
  padding: 1.15rem;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(10, 14, 24, 0.98);
  box-shadow: var(--shadow);
}

.chat-modal-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: #fff;
}

.chat-modal-hint {
  margin: -0.35rem 0 0.65rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.chat-modal-input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.chat-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.model-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  padding: 0.65rem 0.5rem 0.35rem;
}

.model-item {
  width: 100%;
  text-align: left;
  padding: 0.7rem 0.75rem;
  margin-bottom: 0.3rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.model-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.model-item.active {
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(129, 140, 248, 0.35);
}

.model-item-name {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.3;
}

.model-item-provider {
  font-size: 0.72rem;
  color: var(--dim);
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: capitalize;
}

.sidebar-foot {
  padding: 0.75rem;
  border-top: 1px solid var(--glass-border);
  display: flex;
  gap: 0.5rem;
}

.usage-panel {
  padding: 0.75rem;
  border-top: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.18);
}

.usage-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.usage-panel-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

.usage-panel-link {
  text-decoration: none;
}

.usage-panel-link:hover {
  color: var(--accent);
}

.usage-plan,
.usage-bar-plan {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #c4b5fd;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(99, 102, 241, 0.12);
}

.usage-bars {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.usage-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.usage-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

.quota-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.quota-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.quota-icon-requests-per-day { color: #60a5fa; }
.quota-icon-tokens-per-day { color: #a78bfa; }
.quota-icon-images-per-day { color: #22d3ee; }
.quota-icon-videos-per-day { color: #f472b6; }
.quota-icon-music-per-day { color: #fbbf24; }

.usage-val {
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--dim);
}

.usage-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.usage-fill {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  transition: width 0.25s ease;
}

.usage-fill.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.usage-fill.danger { background: linear-gradient(90deg, #ef4444, #f87171); }
.usage-fill.unlimited {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.5), rgba(139, 92, 246, 0.85));
}

.usage-row.disabled .usage-val {
  color: var(--dim);
  font-family: var(--font);
  font-size: 0.68rem;
}

.usage-row.unlimited .usage-val {
  color: var(--muted);
}

.usage-bar {
  max-width: 820px;
  margin: 0 auto 0.65rem;
}

.usage-bar-inner {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.22);
}

.usage-bar-metrics {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  flex-wrap: wrap;
  min-width: 0;
}

.usage-metric {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.usage-metric-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
}

.usage-metric-label.quota-label .quota-icon {
  width: 13px;
  height: 13px;
}

.usage-metric-track {
  display: block;
  width: 56px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  flex-shrink: 0;
}

.usage-metric-fill {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  transition: width 0.25s ease;
}

.usage-metric-fill.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.usage-metric-fill.danger { background: linear-gradient(90deg, #ef4444, #f87171); }
.usage-metric-fill.unlimited {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.5), rgba(139, 92, 246, 0.85));
}

.usage-metric-val {
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--muted);
  white-space: nowrap;
}

@media (max-width: 900px) {
  .usage-panel {
    display: none;
  }
}

.main {
  grid-area: main;
  overflow-y: auto;
  padding: 1.25rem 1rem 2rem;
  scroll-behavior: smooth;
}

.messages {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.empty-state {
  max-width: 520px;
  margin: 4rem auto 0;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  color: #fff;
  font-size: 1.35rem;
  margin: 0 0 0.5rem;
}

.empty-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1.25rem;
}

.chip {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.chip:hover {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(129, 140, 248, 0.35);
}

.msg {
  display: flex;
  gap: 0.75rem;
  animation: fadeUp 0.25s ease;
}

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

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
}

.msg.user .msg-avatar { background: rgba(99, 102, 241, 0.2); }
.msg.assistant .msg-avatar { background: rgba(52, 211, 153, 0.12); }
.msg.tool .msg-avatar { background: rgba(251, 191, 36, 0.12); }

.msg-tool-calls {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.msg-tool-call {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  background: rgba(129, 140, 248, 0.12);
  border: 1px solid rgba(129, 140, 248, 0.22);
}

.msg-tool-call-name {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: #c4b5fd;
}

.msg-tool-call-args {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-tool-result {
  margin: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--glass-border);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.45;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow: auto;
}

.msg.tool .msg-bubble {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.18);
}

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

.msg-role {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.35rem;
}

.msg-bubble {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  line-height: 1.6;
  font-size: 0.95rem;
  white-space: normal;
  word-break: break-word;
}

.msg-para {
  margin: 0 0 0.65rem;
}

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

.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3,
.msg-bubble h4,
.msg-bubble h5,
.msg-bubble h6,
.msg-bubble .msg-h1,
.msg-bubble .msg-h2,
.msg-bubble .msg-h3,
.msg-bubble .msg-h4,
.msg-bubble .msg-h5,
.msg-bubble .msg-h6 {
  margin: 0.85rem 0 0.45rem;
  line-height: 1.35;
  color: #f8fafc;
  font-weight: 700;
}

.msg-bubble h1:first-child,
.msg-bubble h2:first-child,
.msg-bubble h3:first-child,
.msg-bubble .msg-h1:first-child,
.msg-bubble .msg-h2:first-child,
.msg-bubble .msg-h3:first-child {
  margin-top: 0;
}

.msg-bubble h1, .msg-bubble .msg-h1 { font-size: 1.35rem; }
.msg-bubble h2, .msg-bubble .msg-h2 { font-size: 1.2rem; }
.msg-bubble h3, .msg-bubble .msg-h3 { font-size: 1.05rem; }
.msg-bubble h4, .msg-bubble .msg-h4 { font-size: 1rem; }
.msg-bubble h5, .msg-bubble .msg-h5 { font-size: 0.95rem; color: #e2e8f0; }
.msg-bubble h6, .msg-bubble .msg-h6 { font-size: 0.88rem; color: var(--muted); }

.msg-list {
  margin: 0.45rem 0 0.75rem;
  padding-left: 1.35rem;
}

.msg-list.ordered {
  padding-left: 1.55rem;
  list-style-type: decimal;
  list-style-position: outside;
}

.msg-list li {
  display: list-item;
  margin: 0.4rem 0;
  padding-left: 0.15rem;
}

.msg-list li::marker {
  color: var(--accent);
  font-weight: 600;
}

.msg-quote {
  margin: 0.55rem 0 0.75rem;
  padding: 0.35rem 0 0.35rem 0.85rem;
  border-left: 3px solid rgba(129, 140, 248, 0.45);
  color: var(--muted);
}

.msg-quote > :first-child { margin-top: 0; }
.msg-quote > :last-child { margin-bottom: 0; }

.msg-hr {
  border: none;
  border-top: 1px solid var(--glass-border);
  margin: 0.85rem 0;
}

.msg-bubble strong {
  color: #f1f5f9;
  font-weight: 650;
}

.msg-bubble em {
  color: #cbd5e1;
}

.msg-bubble del {
  color: var(--dim);
}

.msg-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-link:hover {
  color: #c4b5fd;
}

.code-block {
  margin: 0.75rem 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.95), rgba(2, 6, 23, 0.98));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.code-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.code-block-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

.code-lang {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.code-copy-btn {
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(99, 102, 241, 0.15);
  color: #c7d2fe;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.code-copy-btn:hover {
  background: rgba(99, 102, 241, 0.28);
  color: #fff;
}

.code-copy-btn.copied {
  background: rgba(52, 211, 153, 0.2);
  border-color: rgba(52, 211, 153, 0.35);
  color: #6ee7b7;
}

.code-download-btn {
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: rgba(56, 189, 248, 0.12);
  color: #bae6fd;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.code-download-btn:hover {
  background: rgba(56, 189, 248, 0.22);
  color: #fff;
}

.code-block-scroll {
  overflow: auto;
  max-height: min(420px, 55vh);
}

.code-block-view {
  display: flex;
  min-width: max-content;
}

.code-gutter {
  flex: 0 0 auto;
  padding: 0.75rem 0.85rem 0.75rem 0.75rem;
  text-align: right;
  user-select: none;
  background: rgba(0, 0, 0, 0.22);
  border-right: 1px solid rgba(148, 163, 184, 0.14);
}

.code-gutter .code-ln {
  display: block;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.65;
  color: rgba(100, 116, 139, 0.9);
  white-space: pre;
}

.code-pre {
  margin: 0;
  flex: 1;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  background: transparent;
}

.code-pre code {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.65;
  tab-size: 2;
}

.chat-search {
  width: 100%;
  margin-top: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
}

.quota-warn {
  max-width: 820px;
  margin: 0 auto 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.28);
  color: #fde68a;
  font-size: 0.82rem;
}

.composer-inner {
  align-items: flex-end;
}

.composer-tools {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0.15rem;
  flex-shrink: 0;
}

.btn-attach {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.btn-attach:hover {
  border-color: rgba(129, 140, 248, 0.45);
  background: rgba(99, 102, 241, 0.12);
  color: #fff;
}

.btn-attach.needs-vision {
  color: var(--muted);
  border-style: dashed;
}

.btn-attach .attach-icon {
  width: 1.15rem;
  height: 1.15rem;
}

.btn-web-search.active {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(14, 165, 233, 0.16);
  color: #7dd3fc;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.18);
}

.btn-web-search.active:hover {
  border-color: rgba(56, 189, 248, 0.7);
  background: rgba(14, 165, 233, 0.22);
  color: #bae6fd;
}

.msg-web-search {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.35rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.28);
  background: rgba(14, 165, 233, 0.1);
  color: #7dd3fc;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.msg-web-search.pending {
  color: #bae6fd;
  animation: pulse-soft 1.2s ease-in-out infinite;
}

@keyframes pulse-soft {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

.btn-icon {
  min-width: 2.25rem;
  padding: 0.45rem 0.55rem;
}

.attachment-preview {
  max-width: 820px;
  margin: 0 auto 0.55rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.attachment-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
}

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

.attachment-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 1.25rem;
  height: 1.25rem;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
}

.btn-stop {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.15);
  color: #fca5a5;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-send.hidden { display: none; }

.msg-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.45rem;
  flex-wrap: wrap;
}

.msg-action-btn {
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
}

.msg-action-btn:hover {
  color: var(--text);
  border-color: rgba(129, 140, 248, 0.35);
}

.msg-document-downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.msg-document-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.35);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(56, 189, 248, 0.12));
  color: #e0e7ff;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.msg-document-download-btn:hover:not(:disabled) {
  border-color: rgba(129, 140, 248, 0.65);
  transform: translateY(-1px);
}

.msg-document-download-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.msg-document-download-icon {
  font-size: 0.85rem;
}

.msg-usage {
  margin-top: 0.45rem;
  font-size: 0.68rem;
  color: var(--dim);
  font-family: var(--mono);
}

.msg-images {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.55rem;
}

.msg-image {
  max-width: 220px;
  max-height: 160px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  object-fit: cover;
}

.reasoning-block {
  margin-bottom: 0.55rem;
  border-radius: 10px;
  border: 1px solid rgba(251, 191, 36, 0.2);
  background: rgba(251, 191, 36, 0.08);
  overflow: hidden;
}

.reasoning-block.thinking-live {
  border-color: rgba(251, 191, 36, 0.35);
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.08);
}

.reasoning-block.thinking-live summary {
  cursor: default;
}

.reasoning-block summary {
  cursor: pointer;
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fde68a;
  list-style: none;
}

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

.reasoning-body {
  padding: 0 0.65rem 0.65rem;
  color: #fde68a;
  font-size: 0.82rem;
}

.reasoning-block.thinking-live .reasoning-body {
  max-height: min(42vh, 320px);
  overflow-y: auto;
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 0.35rem;
  vertical-align: middle;
}

.thinking-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fde68a;
  opacity: 0.35;
  animation: thinking-dot 1.2s infinite ease-in-out;
}

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

@keyframes thinking-dot {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.model-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem;
}

.model-fav-btn {
  border: none;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  line-height: 1;
}

.model-fav-btn.active { color: #fbbf24; }

.model-item-meta {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.model-item-details {
  margin-top: 0.3rem;
  font-size: 0.68rem;
  color: var(--dim);
  line-height: 1.35;
}

.model-feature {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.14rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  color: var(--muted);
}

.model-feature-chat {
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.22);
}

.model-feature-vision {
  color: #c4b5fd;
  border-color: rgba(129, 140, 248, 0.28);
  background: rgba(99, 102, 241, 0.1);
}

.model-feature-thinking {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.28);
  background: rgba(251, 191, 36, 0.08);
}

.model-feature-tools {
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.28);
  background: rgba(52, 211, 153, 0.08);
}

.model-feature-design {
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.28);
  background: rgba(59, 130, 246, 0.08);
}

.model-feature-json {
  color: #fcd34d;
  border-color: rgba(234, 179, 8, 0.28);
  background: rgba(234, 179, 8, 0.08);
}

.model-item.active .model-feature {
  border-color: rgba(129, 140, 248, 0.35);
}

.msg.user .msg-bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(129, 140, 248, 0.2);
}

.msg.assistant .msg-bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--glass-border);
}

.msg-bubble code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.reasoning-block .msg-para {
  color: inherit;
}

.reasoning-block .code-block {
  border-color: rgba(251, 191, 36, 0.25);
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 0.25rem 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.composer {
  grid-area: composer;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--glass-border);
  background: rgba(7, 11, 20, 0.78);
  backdrop-filter: blur(12px);
}

.composer-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  gap: 0.65rem;
  align-items: flex-end;
}

.composer-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem 0.75rem;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.28);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer-box:focus-within {
  border-color: rgba(129, 140, 248, 0.45);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.composer textarea {
  width: 100%;
  min-height: 24px;
  max-height: 160px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

.composer-hint {
  font-size: 0.72rem;
  color: var(--dim);
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) { transform: translateY(-1px); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-enhance {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(167, 139, 250, 0.35);
  background: rgba(139, 92, 246, 0.12);
  color: #c4b5fd;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color 0.12s, background 0.12s, transform 0.12s, opacity 0.12s;
}

.btn-enhance:hover:not(:disabled) {
  border-color: rgba(167, 139, 250, 0.55);
  background: rgba(139, 92, 246, 0.22);
  color: #ede9fe;
  transform: translateY(-1px);
}

.btn-enhance:disabled,
.btn-enhance.busy {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-enhance .enhance-icon {
  width: 1.15rem;
  height: 1.15rem;
}

.error-banner {
  max-width: 820px;
  margin: 0 auto 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fca5a5;
  font-size: 0.88rem;
}

.tunnel-panel {
  max-width: 820px;
  margin: 0 auto 1rem;
}

.tunnel-panel-inner {
  padding: 1rem 1.1rem;
  border-radius: 14px;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.28);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.tunnel-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.tunnel-panel-head h3 {
  margin: 0 0 0.35rem;
  color: #fde68a;
  font-size: 1rem;
}

.tunnel-panel-head p {
  margin: 0;
  color: #fcd34d;
  font-size: 0.88rem;
  line-height: 1.5;
}

.tunnel-steps {
  margin: 0 0 0.85rem 1.1rem;
  padding: 0;
  color: #fef3c7;
  font-size: 0.86rem;
  line-height: 1.55;
}

.tunnel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn-inline {
  width: auto;
  margin-top: 0;
  padding: 0.55rem 0.9rem;
  font-size: 0.88rem;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.82rem;
}

.tunnel-note {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
  color: #fde68a;
}

.tunnel-panel.online-state {
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.28);
}

.tunnel-panel.online-state .tunnel-panel-head h3 { color: #a7f3d0; }
.tunnel-panel.online-state .tunnel-panel-head p { color: #6ee7b7; }

.mobile-toggle {
  display: none;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "main"
      "composer";
  }

  .sidebar {
    position: fixed;
    top: var(--top-h);
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 88vw);
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

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

  .mobile-toggle { display: inline-flex; }

  .brand-text { display: none; }

  .topbar-nav {
    display: none !important;
  }

  .topbar-overflow-menu {
    display: block;
  }

  .composer-hint {
    display: none;
  }

  .model-picker {
    max-width: min(240px, 50vw);
  }

  .topbar-account { display: none; }
  .thinking-bar { display: none; }
}

/* Thinking mode top bar */
.thinking-bar {
  position: relative;
  flex-shrink: 0;
}

.thinking-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.thinking-bar-btn:hover {
  border-color: rgba(129, 140, 248, 0.45);
  background: rgba(99, 102, 241, 0.12);
}

.thinking-bar-icon { color: #a78bfa; font-size: 0.85rem; }
.thinking-bar-chevron { color: var(--dim); font-size: 0.65rem; }

.thinking-bar-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 120px;
  padding: 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 50;
}

.thinking-bar-option {
  display: block;
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
}

.thinking-bar-option:hover { background: rgba(255, 255, 255, 0.06); }
.thinking-bar-option.active {
  background: rgba(99, 102, 241, 0.22);
  color: #fff;
}

/* Chat / Agent mode toggle */
.chat-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.2rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
  flex-shrink: 0;
}

.chat-mode-btn {
  padding: 0.35rem 0.65rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chat-mode-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.chat-mode-btn.active {
  color: #fff;
  background: rgba(99, 102, 241, 0.28);
  box-shadow: inset 0 0 0 1px rgba(129, 140, 248, 0.35);
}

/* Agent workspace bar */
.agent-workspace-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  max-width: 820px;
  margin: 0 auto 0.55rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(52, 211, 153, 0.22);
  background: rgba(52, 211, 153, 0.06);
}

.agent-workspace-main {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  flex: 1;
}

.agent-workspace-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--success);
}

.agent-workspace-path {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.agent-workspace-status {
  font-size: 0.75rem;
  font-weight: 600;
}

.agent-workspace-status.ok { color: var(--success); }
.agent-workspace-status.warn { color: var(--warn); }

.agent-setup-panel {
  max-width: 820px;
  margin: 0 auto 0.55rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px dashed rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.06);
  font-size: 0.82rem;
  color: var(--muted);
}

.agent-setup-panel p { margin: 0 0 0.5rem; }

.agent-setup-steps {
  margin: 0.35rem 0 0.65rem 1.1rem;
  padding: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.agent-setup-steps li { margin-bottom: 0.25rem; }

.agent-setup-note {
  font-size: 0.78rem;
  color: var(--dim);
}

.agent-setup-note code {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: #cbd5e1;
}

.agent-setup-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.agent-setup-cmd {
  display: block;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.5rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  font-family: var(--mono);
  font-size: 0.74rem;
  color: #e2e8f0;
  overflow-x: auto;
}

/* Account strip */
.topbar-account {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: 0.35rem;
  flex-shrink: 0;
}

.account-plan {
  font-size: 0.72rem;
  font-weight: 600;
  color: #a5b4fc;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: rgba(99, 102, 241, 0.15);
}

.account-user {
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-key-btn {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
}

.topbar-icon-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 8px;
  font-weight: 700;
}

/* Sidebar compact mode */
.sidebar-compact .chat-history-meta,
.sidebar-compact .chat-history-tags,
.sidebar-compact .chat-history-icon,
.sidebar-compact .chat-history-unread {
  display: none;
}


.topbar-overflow-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0.5rem;
  min-width: 200px;
  padding: 0.45rem;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: #0f172a;
  box-shadow: var(--shadow);
  z-index: 60;
}

.topbar {
  position: relative;
}

.topbar-overflow-section {
  padding: 0.35rem 0.55rem 0.55rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 0.25rem;
}

.topbar-overflow-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: #c4b5fd;
  text-transform: uppercase;
}

.topbar-overflow-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.topbar-overflow-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}

.topbar-overflow-item:hover {
  background: rgba(99, 102, 241, 0.15);
}

.chat-filter-tags {
  flex: 1;
  min-width: 0;
  padding: 0.25rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-size: 0.72rem;
}

.chat-filter-row {
  flex-wrap: wrap;
}

@media (min-width: 901px) {
  .topbar-overflow-menu {
    display: none !important;
  }
  #topbarOverflowBtn {
    display: none;
  }
}

/* Web search sources */
.msg-sources {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.msg-sources-head {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.msg-source-card {
  display: block;
  padding: 0.45rem 0.55rem;
  margin-bottom: 0.35rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  text-decoration: none;
  color: inherit;
}

.msg-source-card:hover {
  border-color: rgba(129, 140, 248, 0.35);
  background: rgba(99, 102, 241, 0.08);
}

.msg-source-title {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #a5b4fc;
}

.msg-source-snippet {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
  line-height: 1.35;
}

/* Token usage tooltip */
.msg-usage {
  cursor: help;
}

.msg-usage-detail {
  color: var(--dim);
  font-size: 0.72rem;
}

/* Text file attachments */
.attachment-text {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.78rem;
  color: var(--muted);
}

.attachment-text-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Shortcuts modal */
.shortcuts-modal-card { max-width: 420px; }

.shortcuts-list {
  margin: 0.75rem 0 1rem;
  display: grid;
  gap: 0.45rem;
}

.shortcuts-list > div {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 0.5rem;
  align-items: center;
}

.shortcuts-list dt { margin: 0; }

.shortcuts-list kbd {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.72rem;
  font-family: ui-monospace, monospace;
}

.shortcuts-list dd {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Toasts (shared with portal) */
.portal-toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.portal-toast {
  padding: 0.65rem 1rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
  max-width: min(360px, 90vw);
}

.portal-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.portal-toast-success { background: #065f46; color: #ecfdf5; }
.portal-toast-warn { background: #92400e; color: #fffbeb; }
.portal-toast-error { background: #991b1b; color: #fef2f2; }
.portal-toast-info { background: #1e3a5f; color: #eff6ff; }
