:root {
  --bg: #080c14;
  --bg-elevated: #0f1522;
  --panel: #121a28;
  --panel-2: #1a2438;
  --text: #e6ecf5;
  --muted: #8b97ad;
  --accent: #4da3ff;
  --accent-2: #2dd4bf;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --success: #34d399;
  --danger: #f87171;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --icon-size: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(77, 163, 255, 0.14), transparent),
    radial-gradient(ellipse 60% 40% at 90% 0%, rgba(45, 212, 191, 0.1), transparent),
    var(--bg);
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 20px 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */

.header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: rgba(15, 21, 34, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
}

.header-compact {
  padding: 8px 12px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
}

.brand-link {
  text-decoration: none;
  color: inherit;
}

.logo {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
  flex-shrink: 0;
}

.logo-st {
  font-size: 11px;
}

.brand-text h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.header-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
}

.header-chip .chip-value {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  flex-shrink: 0;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.2s, box-shadow 0.2s;
}

.status-dot.ok {
  background: var(--success);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.status-dot.bad {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.4);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  text-decoration: none;
  font: inherit;
}

.icon-btn svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
}

.icon-btn-label {
  display: none;
}

#profile-link {
  width: auto;
  padding: 0 10px;
  max-width: 120px;
}

#profile-link .icon-btn-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn-accent {
  color: var(--accent);
  border-color: rgba(77, 163, 255, 0.25);
  background: rgba(77, 163, 255, 0.08);
}

.icon-btn-accent:hover {
  color: #fff;
  background: rgba(77, 163, 255, 0.2);
  border-color: rgba(77, 163, 255, 0.4);
}

.icon-btn-send {
  color: #fff;
  border: 0;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
}

.icon-btn-send:hover {
  filter: brightness(1.08);
}

/* ── Workspace ── */

.workspace {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.sidebar-slim {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel {
  background: rgba(15, 21, 34, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.panel-compact {
  padding: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.select,
.input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font: inherit;
  transition: border-color 0.15s;
}

.select:focus,
.input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(77, 163, 255, 0.45);
}

.select-compact {
  padding: 7px 10px;
  font-size: 0.85rem;
}

.stats-compact {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mini-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.8rem;
}

.mini-stat span:last-child {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.app-chat {
  max-width: 1400px;
}

.header-nav-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.header-nav-chip .icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.header-nav-chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
}

.header-nav-chip-active {
  border-color: rgba(77, 163, 255, 0.45);
  background: rgba(77, 163, 255, 0.12);
  color: var(--accent);
}

.header-nav-chip-btn {
  cursor: pointer;
  font: inherit;
}

.header-actions .account-link {
  width: auto;
  max-width: 140px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}

.header-actions .account-link .icon {
  color: var(--accent);
}

.header-actions .account-link #username,
.header-actions .account-link #account-username {
  font-weight: 600;
  color: var(--accent);
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-decoration: none;
  font-size: 0.82rem;
  transition: border-color 0.15s, background 0.15s;
}

.account-link svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

.account-link:hover,
.account-link-active {
  border-color: rgba(77, 163, 255, 0.35);
  background: rgba(77, 163, 255, 0.08);
}

.account-link #username,
.account-link #account-username {
  font-weight: 600;
  color: var(--accent);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-link .header-stats {
  padding: 0;
  border: 0;
  background: transparent;
  gap: 2px;
}

/* ── Chat workspace ── */

.chat-workspace {
  display: grid;
  grid-template-columns: 21% 79%;
  gap: 12px;
  flex: 1;
  min-height: calc(100vh - 100px);
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  background: rgba(15, 21, 34, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}

.chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.conversations-sidebar {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.conversations-empty {
  margin: 12px 8px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.conv-side-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  padding: 10px 34px 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.conv-side-item:hover {
  border-color: var(--border-strong);
}

.conv-side-item.active {
  border-color: rgba(77, 163, 255, 0.45);
  background: rgba(77, 163, 255, 0.1);
}

.conv-side-title {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.conv-side-item {
  padding: 8px 30px 8px 10px;
}

.conv-side-meta {
  font-size: 0.72rem;
  color: var(--muted);
}

.conv-side-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.conv-side-tokens span {
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
}

.header-stats-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  border: 1px solid transparent;
}

.stat-icon-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 36px;
}

.stat-icon-wrap .icon {
  width: 20px;
  height: 20px;
}

.stat-icon-wrap small {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1;
}

.stat-value {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
}

.stat-chip-in {
  background: rgba(77, 163, 255, 0.12);
  border-color: rgba(77, 163, 255, 0.25);
}

.stat-chip-in .icon,
.stat-chip-in small {
  color: #7ec0ff;
}

.stat-chip-out {
  background: rgba(45, 212, 191, 0.1);
  border-color: rgba(45, 212, 191, 0.22);
}

.stat-chip-out .icon,
.stat-chip-out small {
  color: #5eead4;
}

.stat-chip-cache {
  background: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.25);
}

.stat-chip-cache .icon,
.stat-chip-cache small {
  color: #fcd34d;
}

.stat-chip-balance {
  background: rgba(167, 139, 250, 0.12);
  border-color: rgba(167, 139, 250, 0.28);
  color: var(--accent);
}

.stat-chip-balance .icon,
.stat-chip-balance small {
  color: #c4b5fd;
}

.stat-chip-link {
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s, transform 0.15s;
}

.stat-chip-link:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.stat-chip-balance .chip-value {
  color: #e9d5ff;
  font-weight: 800;
}

.stats-page {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.stats-type-tabs,
.stats-period-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.stats-tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.stats-tab.active {
  color: var(--text);
  background: rgba(77, 163, 255, 0.12);
  border-color: rgba(77, 163, 255, 0.35);
}

.stats-date-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.stats-summary-card {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.stats-summary-card .label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.stats-summary-card strong {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}

.stats-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.stats-item-main strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 3px;
}

.stats-item-meta {
  font-size: 0.76rem;
  color: var(--muted);
}

.stats-item-balance {
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
}

.conv-side-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  opacity: 0;
  color: var(--muted);
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.conv-side-delete svg {
  width: 12px;
  height: 12px;
}

.conv-side-item:hover .conv-side-delete {
  opacity: 1;
}

.conv-side-delete:hover {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(15, 21, 34, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-main .messages {
  border-radius: 0;
  border: 0;
  max-height: none;
  flex: 1;
}

/* ── Settings layout ── */

.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px;
  align-items: start;
}

.settings-nav {
  position: sticky;
  top: 16px;
}

.settings-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: rgba(15, 21, 34, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.settings-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.settings-menu-item svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.settings-menu-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.settings-menu-item.active {
  background: rgba(77, 163, 255, 0.12);
  color: var(--text);
  border: 1px solid rgba(77, 163, 255, 0.25);
}

.settings-content {
  min-width: 0;
}

.settings-section {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.settings-section.active {
  display: flex;
}

.api-key-comment-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.input-inline {
  flex: 1;
  padding: 6px 10px;
  font-size: 0.88rem;
}

/* ── Chat area (legacy) ── */

.chat-area {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  min-width: 0;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(15, 21, 34, 0.9);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}

.conversations-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  min-width: 0;
  padding: 2px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.conversations-bar::-webkit-scrollbar {
  height: 4px;
}

.conversations-bar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.conversations-hint {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 8px;
  white-space: nowrap;
}

.conv-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 180px;
  padding: 5px 8px 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.conv-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.conv-chip.active {
  border-color: rgba(77, 163, 255, 0.45);
  background: rgba(77, 163, 255, 0.12);
  color: var(--text);
}

.conv-chip-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-chip-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  opacity: 0;
  color: var(--muted);
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.conv-chip-close svg {
  width: 11px;
  height: 11px;
}

.conv-chip:hover .conv-chip-close,
.conv-chip.active .conv-chip-close {
  opacity: 1;
}

.conv-chip-close:hover {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: rgba(15, 21, 34, 0.9);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 380px;
  max-height: calc(100vh - 220px);
}

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
}

.message.user .bubble {
  background: linear-gradient(135deg, rgba(77, 163, 255, 0.9), rgba(59, 130, 246, 0.85));
  border-bottom-right-radius: 4px;
  color: #fff;
}

.message.assistant .bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.error .bubble {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fecaca;
}

.workspace-full {
  grid-template-columns: 1fr;
}

.account-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.stat-chip span:last-child {
  color: var(--text);
  font-weight: 600;
}

.account-menu {
  position: relative;
}

.account-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  transition: border-color 0.15s, background 0.15s;
}

.account-trigger svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.account-trigger .chevron {
  width: 14px;
  height: 14px;
  color: var(--muted);
}

.account-trigger:hover,
.account-menu.open .account-trigger {
  border-color: rgba(77, 163, 255, 0.35);
  background: rgba(77, 163, 255, 0.08);
}

.account-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  padding: 6px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  z-index: 30;
}

.account-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: left;
}

.account-dropdown-item svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex-shrink: 0;
}

.account-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.account-dropdown-danger {
  color: #fecaca;
}

.account-dropdown-danger svg {
  color: #f87171;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: rgba(8, 12, 20, 0.5);
}

.composer > textarea {
  width: 100%;
  min-height: 96px;
  max-height: 280px;
  resize: none;
  padding: 10px 12px;
  line-height: 1.45;
  border-radius: var(--radius-sm);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.composer-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
}

.token-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s;
}

.token-ring:hover {
  transform: scale(1.04);
}

.token-ring-svg {
  width: 44px;
  height: 44px;
  transform: rotate(-90deg);
}

.token-ring-track {
  fill: none;
  stroke: rgba(167, 139, 250, 0.18);
  stroke-width: 3;
}

.token-ring-fill {
  fill: none;
  stroke: #a78bfa;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 100.53;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.35s ease, stroke 0.2s;
}

.token-ring-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.58rem;
  font-weight: 800;
  color: #e9d5ff;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  pointer-events: none;
}

.composer-select {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  max-width: 160px;
}

.composer-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer-select:focus {
  outline: none;
  border-color: rgba(77, 163, 255, 0.45);
}

.icon-btn-send {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  color: #fff;
  flex-shrink: 0;
}

.icon-btn-send svg {
  width: 18px;
  height: 18px;
}

.icon-btn-send:hover {
  filter: brightness(1.08);
  transform: scale(1.04);
}

.icon-btn-send:disabled {
  opacity: 0.5;
  cursor: wait;
  transform: none;
}

.icon-btn-danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.25);
}

.icon-btn-danger:hover {
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
}

.settings-page {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.models-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-item input {
  accent-color: var(--accent);
}

.created-key-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.22);
}

.key-display {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.key-display code {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.8rem;
  word-break: break-all;
  color: #d1fae5;
}

.api-keys-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.api-key-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.api-key-body {
  flex: 1;
  min-width: 0;
}

.api-key-body strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.api-key-meta {
  display: block;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.4;
}

code {
  font-family: Consolas, "Courier New", monospace;
}


/* ── Buttons (auth/profile) ── */

.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  color: white;
  font-weight: 600;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-compact {
  padding: 9px 14px;
  font-size: 0.9rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-small {
  padding: 7px 12px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-row:last-child {
  border-bottom: 0;
}

/* ── Auth ── */

.auth-body {
  min-height: 100vh;
  background: var(--bg);
}

.auth-page {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  min-height: 100vh;
}

.auth-banner {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  padding: 48px;
  background:
    radial-gradient(circle at 20% 20%, rgba(77, 163, 255, 0.3), transparent 40%),
    radial-gradient(circle at 80% 10%, rgba(45, 212, 191, 0.22), transparent 35%),
    linear-gradient(145deg, #0c1220 0%, #141e30 45%, #080c14 100%);
  border-right: 1px solid var(--border);
}

.auth-banner-content {
  position: relative;
  z-index: 1;
  max-width: 520px;
}

.auth-banner-glow {
  position: absolute;
  inset: auto -80px -80px auto;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(77, 163, 255, 0.2), transparent 70%);
  pointer-events: none;
}

.banner-badge {
  display: inline-block;
  margin-bottom: 18px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(77, 163, 255, 0.15);
  border: 1px solid rgba(77, 163, 255, 0.3);
  color: #a8cfff;
  font-size: 0.78rem;
  font-weight: 600;
}

.auth-banner h2 {
  margin: 0 0 14px;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  line-height: 1.15;
}

.banner-lead {
  margin: 0 0 22px;
  color: #a8b4cc;
  font-size: 0.98rem;
  line-height: 1.6;
}

.banner-features {
  margin: 0 0 28px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.banner-features li {
  position: relative;
  padding-left: 22px;
  color: var(--text);
  font-size: 0.92rem;
}

.banner-features li::before {
  content: "✦";
  position: absolute;
  left: 0;
  color: var(--accent-2);
}

.banner-bonus {
  display: grid;
  gap: 4px;
  margin-bottom: 18px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.22);
}

.banner-bonus .bonus-label {
  color: #86efac;
  font-size: 0.78rem;
}

.banner-bonus strong {
  font-size: 1.8rem;
  line-height: 1;
  color: #d1fae5;
}

.banner-bonus .bonus-unit {
  color: #a8b4cc;
  font-size: 0.88rem;
}

.banner-footnote {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.bonus-hint {
  margin-top: 0;
}

.auth-body .auth-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  padding: 32px 24px;
}

.auth-wrap {
  width: min(100%, 420px);
  padding: 24px;
}

.auth-card {
  padding: 26px;
  border-radius: 16px;
  background: rgba(15, 21, 34, 0.95);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.auth-brand h1 {
  margin: 0 0 2px;
  font-size: 1.1rem;
}

.auth-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 16px;
}

.tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
}

.tab.active {
  color: var(--text);
  background: var(--panel-2);
  border-color: rgba(77, 163, 255, 0.35);
}

.auth-form {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.auth-form.active {
  display: flex;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fecaca;
  font-size: 0.88rem;
}

.hidden {
  display: none;
}

/* ── Profile ── */

.profile-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
}

.profile-panel-wide {
  grid-column: span 1;
}

.form-section {
  padding-top: 8px;
}

.form-section h3 {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: var(--muted);
}

.section-hint {
  margin-top: -6px;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.required {
  color: var(--accent);
}

.profile-panel h2 {
  margin-top: 0;
  font-size: 0.95rem;
}

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.profile-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.form-message {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.form-message.success {
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: #86efac;
}

.form-message.error {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fecaca;
}

.cards-list {
  margin-top: 20px;
}

.cards-list h3 {
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.cards-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.card-item strong {
  display: block;
  margin-bottom: 4px;
}

.header-actions a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Responsive ── */

@media (max-width: 900px) {
  .auth-page {
    grid-template-columns: 1fr;
  }

  .auth-banner {
    min-height: auto;
    padding: 28px 24px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .profile-layout {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .inline-fields {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar-slim {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-slim .panel {
    flex: 1;
    min-width: 140px;
    margin-bottom: 0;
  }

  .stats-compact {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .mini-stat {
    flex: 1;
    min-width: 80px;
  }

  .header {
    flex-wrap: wrap;
  }

  #profile-link .icon-btn-label {
    display: none;
  }

  #profile-link {
    width: 34px;
    padding: 0;
  }

  .chat-workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .stats-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .chat-sidebar {
    max-height: 220px;
  }

  .settings-layout {
    grid-template-columns: 1fr;
  }

  .settings-nav {
    position: static;
  }

  .settings-menu {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .account-link .header-stats {
    display: none;
  }

  .composer-controls {
    flex-wrap: wrap;
  }

  .composer-select {
    max-width: 120px;
  }

  .messages {
    max-height: 55vh;
  }
}

@media (max-width: 520px) {
  .app {
    padding: 12px;
  }

  .conv-chip {
    max-width: 140px;
  }
}
