:root {
  --bg-main: #212121;
  --bg-sidebar: #171717;
  --bg-elevated: #2f2f2f;
  --bg-hover: #2a2a2a;
  --bg-active: #333333;
  --bg-input: #303030;
  --border: #2e2e2e;
  --border-strong: #3f3f3f;
  --text-primary: #ececec;
  --text-secondary: #b4b4b4;
  --text-muted: #8e8e8e;
  --text-disabled: #666666;
  --accent: #ffffff;
  --accent-ink: #0d0d0d;
  --danger: #ef4444;
  --warn: #f59e0b;
  --good: #10b981;
  --font-ui: ui-sans-serif, -apple-system, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif;
  --font-display: "Söhne", var(--font-ui);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
  --shadow-md: 0 6px 24px rgba(0,0,0,0.35);
  --sidebar-width: 260px;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
}

input {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  outline: 0;
  width: 100%;
}

a { color: inherit; text-decoration: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  min-height: 100vh;
}

.app[data-sidebar="closed"] {
  grid-template-columns: 0 1fr;
}

.app[data-sidebar="closed"] .sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--bg-sidebar);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 8px 8px 10px;
  border-right: 1px solid rgba(255,255,255,0.04);
  transition: transform 180ms ease-out, opacity 180ms ease-out;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 4px;
}

.sidebar__logo { color: var(--text-primary); }
.sidebar__collapse { color: var(--text-secondary); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: background 120ms ease-out, color 120ms ease-out;
}

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

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 20px;
  text-align: left;
  transition: background 120ms ease-out;
}

.nav-item:hover:not(:disabled) { background: var(--bg-hover); }
.nav-item:disabled { color: var(--text-primary); opacity: 1; cursor: default; }
.nav-item:disabled:hover { background: var(--bg-hover); }
.nav-item svg { color: var(--text-secondary); flex-shrink: 0; }

.sidebar__chats {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 8px;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar__chats::-webkit-scrollbar { width: 6px; }
.sidebar__chats::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
}
.sidebar__chats::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.16); }

.chat-group { display: flex; flex-direction: column; gap: 1px; }

.chat-group__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  padding: 6px 10px 4px;
}

.chat-item {
  display: block;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 120ms ease-out;
}

.chat-item:hover { background: var(--bg-hover); }
.chat-item--active,
.chat-item--active:hover { background: var(--bg-active); }
.chat-item--flagged { color: #f0bf7a; }

.sidebar__footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.telemetry {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.02);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.telemetry__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--text-secondary);
}

.telemetry__value {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.telemetry__bar {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}

.telemetry__fill {
  height: 100%;
  width: 56%;
  background: var(--good);
  border-radius: 2px;
  transition: width 300ms ease-out, background 300ms ease-out;
}

.telemetry__note {
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.3;
}

.account {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: var(--radius-md);
  text-align: left;
  transition: background 120ms ease-out;
}

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

.account__avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.account__meta { flex: 1; min-width: 0; }
.account__name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account__tier {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account svg { color: var(--text-muted); flex-shrink: 0; }

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

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

.main__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  gap: 10px;
  min-height: 56px;
}

.model-selector-wrap { position: relative; }

.model-selector {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px 8px 12px;
  border-radius: var(--radius-md);
  font-size: 17px;
  font-weight: 500;
  color: var(--text-primary);
  transition: background 120ms ease-out;
}

.model-selector:hover { background: var(--bg-hover); }
.model-selector[aria-expanded="true"] { background: var(--bg-hover); }
.model-selector svg { color: var(--text-muted); margin-top: 2px; transition: transform 150ms ease-out; }
.model-selector[aria-expanded="true"] svg { transform: rotate(180deg); }

.model-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 6px;
  min-width: 320px;
  background: #2f2f2f;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 6px;
  box-shadow: var(--shadow-md);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: menu-in 120ms ease-out;
}

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

.model-menu[hidden] { display: none; }

.model-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 8px;
  text-align: left;
  color: var(--text-primary);
  transition: background 100ms ease-out;
  position: relative;
}

.model-option:hover:not(:disabled) { background: var(--bg-hover); }

.model-option--selected::after {
  content: "\2713";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-primary);
  font-size: 14px;
}

.model-option__name { font-size: 14px; font-weight: 500; }
.model-option__desc { font-size: 12px; color: var(--text-muted); }

.model-option--disabled { opacity: 0.55; cursor: default; }

.model-menu__sep {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}

.main__header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: background 120ms ease-out, color 120ms ease-out;
}

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

.header-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
}

/* ---------- Conversation ---------- */

.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.conversation::-webkit-scrollbar { width: 10px; }
.conversation::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.06);
  border-radius: 5px;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px 120px;
  gap: 32px;
}

.empty-state[hidden] { display: none; }

.empty-state__logo {
  width: 62px; height: 62px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.empty-state__title {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  margin: 0;
  text-align: center;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 720px;
}

.suggestion {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: left;
  color: var(--text-primary);
  transition: background 120ms ease-out, border-color 120ms ease-out;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.suggestion__head {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.suggestion__body {
  font-size: 14px;
  color: var(--text-muted);
}

.transcript {
  width: 100%;
  max-width: 768px;
  margin: 0 auto;
  padding: 24px 24px 160px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.message {
  display: flex;
  gap: 14px;
  animation: msg-in 180ms ease-out;
}

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

.message__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.message__avatar svg { width: 18px; height: 18px; }

.message__body {
  padding-top: 3px;
  min-width: 0;
  flex: 1;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

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

.message--user .message__avatar { display: none; }

.message--user .message__body {
  background: var(--bg-elevated);
  padding: 10px 16px;
  border-radius: 20px;
  max-width: 72%;
  color: var(--text-primary);
  line-height: 1.5;
}

.message--bot .message__body {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  color: var(--text-primary);
  line-height: 1.65;
}

.message--bot .message__body p { margin: 0 0 12px; }
.message--bot .message__body p:last-child { margin-bottom: 0; }

.message--bot .message__body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.message--bot .message__body em { font-style: italic; }

.message--bot .message__body code {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  color: #f0f0f0;
}

.message--bot .message__body ol,
.message--bot .message__body ul {
  margin: 10px 0 14px;
  padding-left: 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message--bot .message__body li { line-height: 1.6; }

.message--bot .message__body blockquote {
  margin: 12px 0 14px;
  padding: 8px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 0 4px 4px 0;
}

.message--bot.message--thinking .message__body {
  color: var(--text-muted);
}

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

.thinking-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: thinking 1.2s infinite ease-in-out both;
}

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

@keyframes thinking {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

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

.composer-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 16px 12px;
  background: linear-gradient(to top, var(--bg-main) 60%, rgba(33,33,33,0));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.composer-wrap > * { pointer-events: auto; }

.composer {
  width: 100%;
  max-width: 768px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 10px 10px 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.02) inset;
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}

.composer:focus-within {
  border-color: var(--border-strong);
}

.composer textarea {
  flex: 1;
  padding: 8px 4px;
  font: inherit;
  font-size: 16px;
  color: var(--text-primary);
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
  line-height: 1.5;
  min-height: 24px;
  max-height: 192px;
  overflow-y: auto;
  width: 100%;
  scrollbar-width: thin;
}

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

.composer__attach,
.composer__voice,
.composer__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: background 120ms ease-out, color 120ms ease-out, transform 120ms ease-out;
  flex-shrink: 0;
}

.composer__attach:hover:not(:disabled),
.composer__voice:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.composer__attach:disabled,
.composer__voice:disabled { opacity: 0.7; cursor: default; }

.composer__send {
  background: var(--accent);
  color: var(--accent-ink);
}

.composer__send:hover:not(:disabled) { transform: scale(1.02); }

.composer__send:disabled {
  background: var(--bg-elevated);
  color: var(--text-disabled);
  cursor: default;
}

.disclaimer {
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 8px 0;
  line-height: 1.4;
}

.disclaimer__link {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  margin-left: 6px;
  font-size: 11.5px;
}

.disclaimer__link:hover { color: var(--text-secondary); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  opacity: 0;
  transition: opacity 200ms ease-out;
  pointer-events: none;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

.toast.visible { opacity: 1; }

/* ---------- Terms dialog ---------- */

.terms-dialog {
  border: 0;
  background: var(--bg-main);
  color: var(--text-primary);
  max-width: 720px;
  width: 90vw;
  max-height: 80vh;
  padding: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.terms-dialog::backdrop {
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
}

.terms-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.terms-dialog__header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

.terms-dialog__body {
  padding: 20px 24px 28px;
  overflow-y: auto;
  max-height: calc(80vh - 60px);
}

.terms-section { margin: 0 0 24px; }

.terms-section h3 {
  font-size: 11px;
  font-weight: 600;
  font-variant: small-caps;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.terms-section p {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 10px;
  line-height: 1.55;
}

.cert-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 4px 20px;
  font-size: 12px;
  color: var(--text-secondary);
}

.cert-list li::before {
  content: "\2713  ";
  color: var(--good);
  font-weight: 600;
}

.terms-section--fine {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.fine-print {
  font-size: 10px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  text-align: justify;
  margin: 0;
}

/* ---------- Shortcut dialog ---------- */

.shortcut-dialog {
  border: 0;
  background: var(--bg-main);
  color: var(--text-primary);
  max-width: 620px;
  width: 92vw;
  max-height: 80vh;
  padding: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.shortcut-dialog::backdrop {
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
}

.shortcut-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.shortcut-dialog__header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

.shortcut-dialog__body {
  padding: 18px 22px 26px;
  overflow-y: auto;
  max-height: calc(80vh - 60px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.shortcut-group__label {
  font-size: 11px;
  font-weight: 600;
  font-variant: small-caps;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.shortcut-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shortcut-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-primary);
}

.shortcut-list li:first-child { border-top: 0; }
.shortcut-list li > span:first-child { flex: 1; color: var(--text-primary); }

.shortcut-list--disabled li,
.shortcut-list--disabled li > span:first-child { color: var(--text-muted); }

.shortcut-list kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text-secondary);
}

.shortcut-sep {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 2px;
}

.shortcut-footnote {
  margin: 12px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

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

@media (max-width: 820px) {
  .app { grid-template-columns: 0 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    z-index: 50;
  }
  .app[data-sidebar="open"] .sidebar {
    box-shadow: var(--shadow-md);
  }
  .app[data-sidebar="closed"] .sidebar {
    transform: translateX(-100%);
  }
}

@media (max-width: 520px) {
  .empty-state__title { font-size: 24px; }
  .suggestions { grid-template-columns: 1fr; }
  .transcript { padding: 16px 16px 160px; }
}
