/* ==========================================================================
   style.css — Atlas UI Components
   Mobile-first. Uses ONLY design tokens from tokens.css.
   ZERO hardcoded colors, spacing, font-sizes, radius, z-index, or keyframes.
   ========================================================================== */


/* ==========================================================================
   1. Reset & Base
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* Scrollbars */
::-webkit-scrollbar { width: var(--space-1-5); height: var(--space-1-5); }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* Selection */
::selection {
  background: var(--accent-glow);
  color: var(--text);
}


/* ==========================================================================
   2. App Layout — mobile-first (flex column)
   ========================================================================== */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  /* JS overrides this via --app-height from visualViewport.height so the
     flex container shrinks when the software keyboard opens — pins the
     composer flush to the top of the keyboard (Claude-app behavior). */
  height: var(--app-height, 100dvh);
  overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px);
}


/* ==========================================================================
   3. Sidebar — mobile: fixed off-canvas drawer
   ========================================================================== */

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  /* Always leave a ~44px sliver of the main content visible when the drawer
     is open so users have a visual tap target to close it. The old 85vw
     cap was dead on any device wider than ~305px. */
  max-width: calc(100vw - 44px);
  padding-top: env(safe-area-inset-top, 0px);
  z-index: var(--z-sidebar);
  transform: translateX(-100%);
  transition: transform var(--duration-slow) var(--ease-ios);
  box-shadow: none;
  background: var(--bg-sidebar);
  border-right: var(--space-px) solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Don't let scrolling the channel list bounce-scroll the whole app. */
  overscroll-behavior: contain;
}

.sidebar.open {
  transform: translateX(0);
  box-shadow: var(--shadow-xl);
}

.sidebar-header {
  height: var(--topbar-height-mobile);
  padding: 0 var(--space-4);
  border-bottom: var(--space-px) solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  box-sizing: border-box;
}

.sidebar-header .logo {
  width: var(--space-8);
  height: var(--space-8);
  background: var(--accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-weight: 700;
  font-size: var(--text-base);
  letter-spacing: var(--tracking-tight);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header h1 {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
  letter-spacing: var(--tracking-tight);
}

/* Sidebar search */
.sidebar-search {
  padding: var(--space-2) var(--space-3);
  position: relative;
}

.search-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-input);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  outline: none;
  transition: border-color var(--duration-normal) var(--ease-default);
}

.search-input:focus {
  border-color: var(--accent);
}

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

.search-results {
  position: absolute;
  top: 100%;
  left: var(--space-3);
  right: var(--space-3);
  background: var(--bg-elevated);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-lg);
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: var(--z-overlay);
  box-shadow: var(--glass-highlight), var(--shadow-lg);
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .search-results {
    background: var(--bg-glass-strong);
    -webkit-backdrop-filter: var(--blur-md);
    backdrop-filter: var(--blur-md);
  }
}

.search-result-item {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  border-bottom: var(--space-px) solid var(--border-light);
  transition: background var(--duration-fast) var(--ease-default);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--bg-surface-hover);
}

.search-result-title {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-0-5);
}

.search-result-snippet {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}

.search-result-snippet mark {
  background: var(--accent-subtle);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
}

.search-empty {
  padding: var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
}


.sidebar-footer {
  padding: var(--space-3);
  padding-bottom: calc(env(safe-area-inset-bottom, var(--space-3)) + var(--space-1));
  border-top: var(--space-px) solid var(--border-light);
}

/* Sidebar overlay */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-medium);
  z-index: var(--z-sidebar-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease-ios);
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}


/* ==========================================================================
   4. Topbar — flat bg, icon buttons (40px touch targets)
   ========================================================================== */

.topbar {
  height: var(--topbar-height-mobile);
  padding: 0 var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: var(--z-sticky);
  /* Liquid-glass treatment: solid fallback first, then glass override where
     backdrop-filter is supported. The hairline border is replaced with a
     specular highlight that reads as "light hitting the top edge of glass". */
  background: var(--bg-glass-solid);
  border-bottom: var(--space-px) solid var(--border);
  box-shadow: var(--glass-highlight);
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar {
    background: var(--bg-glass);
    -webkit-backdrop-filter: var(--blur-md);
    backdrop-filter: var(--blur-md);
    border-bottom-color: transparent;
  }
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
}

.topbar-icon-btn {
  /* 44px touch target (was 40px — fat-fingered adjacent buttons on mobile). */
  width: 44px;
  height: 44px;
  /* Reset all browser-default button padding/line-height so the inner SVG
     centers exactly. Without this, <button> elements pick up a small UA
     padding that shifts the flex-centered icon by 1-2px versus the <a>
     elements that share the same class — visible as off-center icons. */
  padding: 0;
  margin: 0;
  line-height: 1;
  font: inherit;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-normal) var(--ease-default);
  text-decoration: none;
}

/* SVG inside an icon button should never inherit baseline/sizing weirdness. */
.topbar-icon-btn > svg {
  display: block;
  flex-shrink: 0;
}

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

.topbar-icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.topbar-title {
  font-size: var(--text-md);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  max-width: 140px;
}


/* ==========================================================================
   5. Main Content — flex column container
   ========================================================================== */

.main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: var(--bg);
  overflow: hidden;
}


/* ==========================================================================
   6. Chat Area — flex column, scrollable
   ========================================================================== */

.chat-area {
  flex: 1 1 auto;
  min-height: 0;  /* iOS: lets the flex child shrink when keyboard opens */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-3) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-0-5);
}


/* ==========================================================================
   7. Messages
   ========================================================================== */

.message {
  max-width: var(--message-max-width);
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  animation: fadeIn var(--duration-slow) var(--ease-default);
  transition: background var(--duration-normal) var(--ease-default);
  position: relative;
}

.message:hover {
  background: transparent;
}

.message-avatar {
  width: var(--space-8);
  height: var(--space-8);
  border-radius: var(--radius-md);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  margin-top: var(--space-0-5);
  overflow: hidden;
}

.message.user .message-avatar {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: var(--space-px) solid var(--border);
}

.message.assistant .message-avatar {
  background: var(--accent);
  color: var(--text);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-role {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-0-5);
  color: var(--text);
  letter-spacing: var(--tracking-normal);
}

.message.user .message-role {
  color: var(--text-secondary);
}

.message-text {
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  word-wrap: break-word;
  word-break: break-word;
  color: var(--text);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Smooth expand when streaming content loads (code blocks, tables, etc.) */
.message-text > * {
  animation: fadeIn var(--duration-slow) var(--ease-default);
}

.message-text pre,
.message-text table,
.message-text .tl-tool,
.message-text .code-header {
  animation: scaleIn var(--duration-slow) var(--ease-default);
  transform-origin: top left;
}

.message.user .message-text {
  color: var(--text-secondary);
}

.message-text p {
  margin-bottom: var(--space-2);
}

.message-text p:last-child {
  margin-bottom: 0;
}

.message-text pre {
  background: var(--bg-input);
  color: var(--text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  margin: var(--space-3) 0;
  border: var(--space-px) solid var(--border);
}

.message-text code {
  background: var(--accent-subtle);
  color: var(--accent);
  padding: var(--space-0-5) var(--space-1-5);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
}

.message-text pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-weight: 400;
}

/* Grouped messages (Slack-style) */
.message.grouped {
  padding-top: var(--space-0-5);
  padding-bottom: var(--space-0-5);
}

.message.grouped .message-avatar {
  visibility: hidden;
}

.message.grouped .message-role {
  display: none;
}

/* .msg-copy-btn is defined in chat.css (single source of truth). */


/* ==========================================================================
   8. Input Area — mobile: border-top, safe-area bottom padding
   ========================================================================== */

.input-area {
  position: relative;
  padding: var(--space-1-5) var(--space-2) calc(env(safe-area-inset-bottom, var(--space-2)) + var(--space-1));
  flex-shrink: 0;
  background: var(--bg);
  border-top: var(--space-px) solid var(--border);
}

/* Composer: 2-row layout matching Claude Code's VS Code extension.
   Row 1 = textarea + voice mic. Row 2 = attach + slash + spacer + send.
   The container owns the rounded border and shadow; rows are transparent. */
.input-container {
  max-width: var(--input-max-width);
  margin: 0 auto;
  background: var(--bg-elevated);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-2) var(--space-1);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--duration-normal) var(--ease-default),
              box-shadow var(--duration-normal) var(--ease-default);
}

.input-container:focus-within {
  border-color: var(--border-hover);
  box-shadow: 0 0 0 var(--space-0-5) var(--accent-subtle), var(--shadow-sm);
}

.input-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.input-row-top {
  align-items: flex-end;
}

.input-spacer { flex: 1 1 auto; }

.input-container textarea {
  flex: 1;
  border: none;
  outline: none;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-md);  /* 15px reads cleaner in a 2-row composer */
  line-height: var(--leading-normal);
  resize: none;
  min-height: 28px;
  max-height: 200px;
  background: transparent;
  color: var(--text);
}

.input-container textarea::placeholder {
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

/* All composer buttons share base layout. Variants below add color. */
.input-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default),
              transform var(--duration-fast) var(--ease-default);
  flex-shrink: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  line-height: 1;
}

.input-btn > svg { display: block; flex-shrink: 0; }

.input-btn-ghost:hover {
  background: var(--bg-surface-hover);
  color: var(--text);
}
.input-btn-ghost:focus-visible {
  outline: none;
  background: var(--bg-surface-hover);
  color: var(--text);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Send button: square-rounded, accent-filled, with stop-icon swap when
   .is-streaming is set (so the same button doubles as a stop control). */
.input-btn-send {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: var(--radius-md);
  box-shadow: var(--glass-highlight, none);
}
.input-btn-send:hover {
  background: var(--accent-hover);
}
.input-btn-send:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.input-btn-send:disabled {
  background: var(--bg-surface-hover);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}
.input-btn-send .send-icon-stop { display: none; }
.input-btn-send.is-streaming .send-icon-arrow { display: none; }
.input-btn-send.is-streaming .send-icon-stop { display: block; }
.input-btn-send.is-streaming {
  background: var(--bg-surface);
  color: var(--text);
}
.input-btn-send.is-streaming:hover {
  background: var(--bg-surface-hover);
}

/* Legacy `.input-btn.send` selector (kept as alias in case any code path
   still toggles it). New code should prefer .input-btn-send. */
.input-btn.send {
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: var(--radius-md);
}
.input-btn.send:hover {
  background: var(--accent-hover);
}

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

.input-btn.send:disabled {
  background: var(--bg-surface-hover);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.input-btn.send.stop-mode {
  background: var(--danger);
}

.input-btn.send.stop-mode:hover {
  background: var(--danger-hover);
}

.input-btn.send.stop-mode svg {
  display: none;
}

.input-btn.send.stop-mode::after {
  content: "\25A0";
  font-size: var(--text-base);
}

.input-btn.voice-active {
  background: var(--danger);
  color: var(--text);
  animation: pulse var(--duration-spring) infinite;
}

.input-btn.voice-transcribing {
  background: var(--accent);
  color: var(--text-inverse);
  animation: breathe var(--duration-spring) infinite;
}

.input-btn.drag-cancel {
  background: var(--bg-surface);
  color: var(--text-muted);
  animation: none;
  opacity: 0.5;
}

/* Voice cancel hint (slide to cancel) */
.voice-cancel-hint {
  position: absolute;
  right: clamp(60px, 20vw, 100px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
  font-size: var(--text-sm);
  color: var(--text-muted);
  opacity: 0.7;
  transition: opacity var(--duration-normal) var(--ease-default),
              color var(--duration-normal) var(--ease-default);
  pointer-events: none;
  white-space: nowrap;
}

.voice-cancel-hint.active {
  color: var(--danger);
  opacity: 1;
}

.voice-cancel-arrow {
  animation: slideArrow 1s ease-in-out infinite;
  font-size: var(--text-lg);
}

/* Voice recording timer */
.voice-rec-timer {
  position: absolute;
  left: var(--space-12);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  color: var(--danger);
  pointer-events: none;
}

.voice-rec-timer::before {
  content: '';
  width: var(--space-2);
  height: var(--space-2);
  border-radius: var(--radius-full);
  background: var(--danger);
  animation: recDot 1s ease-in-out infinite;
}

/* Chat attachments preview */
.chat-attachments-preview {
  max-width: var(--input-max-width);
  margin: 0 auto var(--space-2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}


/* ==========================================================================
   9. Welcome Screen
   ========================================================================== */

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-10) var(--space-6);
  gap: var(--space-3);
}

.welcome .logo-large {
  width: var(--space-12);
  height: var(--space-12);
  background: var(--accent);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--space-1);
  letter-spacing: var(--tracking-tight);
  overflow: hidden;
}
.welcome .logo-large.emoji { font-size: 32px; }

.welcome h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: var(--tracking-tight);
}

.welcome p {
  color: var(--text-secondary);
  max-width: 380px;
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
}

.welcome-suggestions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  max-width: 520px;
}

.welcome-suggestion {
  padding: var(--space-3) var(--space-5);
  background: var(--bg-elevated);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
  white-space: nowrap;
  min-height: var(--space-10);
  display: flex;
  align-items: center;
}

.welcome-suggestion:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--bg-surface-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.welcome-suggestion:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.welcome-hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.welcome-hint code {
  background: var(--accent-subtle);
  color: var(--accent);
  padding: var(--space-0-5) var(--space-1);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}


/* ==========================================================================
   10. Login Screen
   ========================================================================== */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  /* 100vh on iOS Safari with the URL bar visible overflows the card — use
     dvh so the viewport matches what the user can actually see. */
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-5);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

.login-card {
  background: var(--bg-sidebar);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-8) var(--space-6);
  width: 100%;
  max-width: 380px;
  text-align: center;
  animation: scaleIn var(--duration-slow) var(--ease-default);
}

.login-card .logo-large {
  width: var(--space-12);
  height: var(--space-12);
  background: var(--accent);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0 auto var(--space-4);
  letter-spacing: var(--tracking-tight);
  overflow: hidden;
}

.login-card h1 {
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: var(--space-1-5);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  font-size: var(--text-base);
}

.login-card .error {
  background: var(--danger-subtle);
  color: var(--danger);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
  display: none;
  border: var(--space-px) solid var(--danger-subtle);
}


/* ==========================================================================
   11. Setup Wizard
   ========================================================================== */

.setup-wizard {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-5);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

.setup-card {
  background: var(--bg-sidebar);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 0;
  width: 100%;
  max-width: 420px;
  overflow: hidden;
  animation: scaleIn var(--duration-slow) var(--ease-default);
}

.setup-card-header {
  background: var(--accent);
  padding: var(--space-6) var(--space-8) var(--space-6);
  text-align: center;
  color: var(--text);
}

.setup-card-header .logo-large {
  width: var(--space-12);
  height: var(--space-12);
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0 auto var(--space-3);
  letter-spacing: var(--tracking-tight);
  overflow: hidden;
}

.setup-card-header h2 {
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0 0 var(--space-1);
  letter-spacing: var(--tracking-tight);
  color: #ffffff;  /* Pure white on orange header — crisper than --text (#ececec) */
}

.setup-card-header p {
  font-size: var(--text-base);
  color: #ffffff;
  opacity: 1;
  margin: 0;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.setup-card-body {
  padding: var(--space-6) var(--space-8);
}

.setup-card h2 {
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0;
  letter-spacing: var(--tracking-tight);
  color: var(--text);
}

.setup-card p {
  font-size: var(--text-base);
  color: var(--text-secondary);
}

.setup-card .form-group {
  text-align: left;
}

/* ---- Click-to-copy chip used in the setup wizard ---- */
.setup-copy-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1-5) var(--space-3);
  margin-top: var(--space-1);
  background: var(--bg-input);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default),
              border-color var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
}
.setup-copy-chip:hover {
  background: var(--bg-elevated);
  border-color: var(--border-hover);
}
.setup-copy-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.setup-copy-chip .setup-copy-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}
.setup-copy-chip .setup-copy-label {
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
}
.setup-copy-chip.copied {
  background: var(--success-subtle);
  border-color: var(--success);
}
.setup-copy-chip.copied .setup-copy-icon,
.setup-copy-chip.copied .setup-copy-label {
  color: var(--success);
}


/* ==========================================================================
   12. Buttons
   ========================================================================== */

.btn {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: var(--space-px) solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);
  font-family: var(--font-body);
  letter-spacing: var(--tracking-normal);
  min-height: var(--space-10);
}
.btn[hidden] { display: none; }

.btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: scale(0.97);
}

/* Keyboard-only focus ring — previously buttons had no visible focus at all. */
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.btn[aria-busy="true"] {
  opacity: 0.75;
  cursor: progress;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-md);
}

.btn-danger {
  background: var(--danger);
  color: var(--text);
  border-color: var(--danger);
}

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

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  min-height: var(--space-8);
}

.btn-ghost {
  border: none;
  background: transparent;
  color: var(--text-secondary);
}

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

.btn-block {
  width: 100%;
  justify-content: center;
}


/* ==========================================================================
   13. Forms
   ========================================================================== */

.form-group {
  margin-bottom: 0;
  padding: var(--space-3) 0;
  border-bottom: var(--space-px) solid var(--border-light);
}

.form-group:last-child {
  border-bottom: none;
}

.form-group label {
  display: block;
  font-size: var(--text-base);
  font-weight: 500;
  margin-bottom: var(--space-1-5);
  color: var(--text);
}

/* Inline checkbox row — overrides .form-group label's block layout so the
   checkbox sits next to its text instead of stacking + stretching full-width.
   Higher specificity via double class is deliberate. */
.form-group label.checkbox-label,
label.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: 0;
  cursor: pointer;
  user-select: none;
}
/* Reset the full-width form-input styling when the input is a checkbox — the
   generic `.form-group input` rule paints padding/border/background across
   the whole width, which turns the checkbox into a stretched bar. */
.form-group input[type="checkbox"],
.checkbox-label input[type="checkbox"] {
  width: auto;
  height: auto;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: none;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}
.checkbox-label span {
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: var(--space-3);
  border: var(--space-px) solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg-input);
  transition: border-color var(--duration-normal) var(--ease-default),
              box-shadow var(--duration-normal) var(--ease-default),
              background-color var(--duration-fast) var(--ease-default);
}

.form-group input:hover:not(:focus),
.form-group select:hover:not(:focus),
.form-group textarea:hover:not(:focus) {
  border-color: var(--border-hover);
}

.form-group select {
  appearance: none;
  -webkit-appearance: none;
  /* Lighter chevron color matches the new --text-muted (#9a9a92). */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239a9a92' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
  background-color: var(--bg-input);
  cursor: pointer;
}

.form-group select:hover:not(:focus) {
  background-color: var(--bg-surface);
}

.form-group select option {
  background: var(--bg-elevated);
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 var(--space-0-5) var(--accent-subtle);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.form-group .secret-input {
  -webkit-text-security: disc;
}

.textarea-mono {
  font-family: var(--font-mono) !important;
  font-size: var(--text-sm) !important;
}

.form-group .hint,
.settings-section > .hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1-5);
  padding: var(--space-1) var(--space-1) var(--space-2);
  line-height: var(--leading-normal);
}

.hint a {
  color: var(--accent);
  text-decoration: none;
}

.hint a:hover {
  text-decoration: underline;
}

.hint code {
  background: var(--accent-subtle);
  color: var(--accent);
  padding: var(--space-0-5) var(--space-1);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}


/* ==========================================================================
   14. Settings Page
   ========================================================================== */

/* Mobile: horizontal scrolling pill tabs on top */
.settings-page {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn var(--duration-slow) var(--ease-default);
}

.settings-page.open {
  display: flex;
}

.settings-tabs {
  width: 100%;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-bottom: var(--space-px) solid var(--border);
  padding: var(--space-2);
  display: flex;
  flex-direction: row;
  gap: var(--space-1);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.settings-tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
  text-align: left;
  white-space: nowrap;
  min-height: var(--space-10);
}

.settings-tab:hover {
  background: var(--bg-surface-hover);
  color: var(--text);
}

.settings-tab.active {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
}

.settings-tab svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.settings-tab.active svg {
  opacity: 1;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-4);
  min-width: 0;
  max-width: 700px;
  background: var(--bg);
}

/* Voice settings state classes */
#voiceEngineStatus { color: var(--text-muted); }
#voiceEngineStatus.active { color: var(--primary); }
.inactive { opacity: 0.6; }

.settings-content h2 {
  font-size: var(--text-3xl);
  font-weight: 700;
  margin-bottom: var(--space-5);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
}

.settings-tab-panel {
  display: none;
  width: 100%;
}

.settings-tab-panel.active {
  display: block;
}

.settings-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 400;
}

/* Settings sections as cards */
.settings-section {
  margin-bottom: var(--space-6);
  padding: var(--space-4) var(--space-4);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}

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

.settings-section h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  text-transform: none;
  letter-spacing: var(--tracking-normal);
  margin-bottom: var(--space-3);
}

/* Settings → Voice → Speech-to-text: faster-whisper's status, and a row per model with its buttons. */
#sttSection [hidden] { display: none !important; }   /* .btn's inline-flex would show a hidden button */
.stt-runtime {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.stt-runtime [data-state="ready"] { color: var(--success); }
.stt-runtime [data-state="failed"] { color: var(--danger); }
.stt-progress {
  width: 100%;
  max-width: 400px;
  accent-color: var(--accent);
}
.stt-model-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-2) 0;
}
.stt-model-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
}
.stt-model-row.current { border-color: var(--accent); }
/* (.form-group label is a block, and .form-group input a full-width box: undone for the row and its radio.) */
.form-group label.stt-model-pick,
.stt-model-pick {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  flex: 1 1 260px;
  min-width: 0;
  margin-bottom: 0;
  font-weight: 400;
  cursor: pointer;
}
.form-group .stt-model-pick input[type="radio"] {
  width: auto;
  height: auto;
  padding: 0;
  margin: 3px 0 0;
  border: 0;
  border-radius: 0;
  background: none;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}
.stt-model-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stt-model-name { font-weight: 600; font-size: var(--text-sm); color: var(--text); }
.stt-model-size { font-weight: 400; color: var(--text-muted); }
.stt-model-desc { font-size: var(--text-xs); color: var(--text-muted); }
.stt-model-state { font-size: var(--text-xs); color: var(--text-muted); }
.stt-model-state[data-state="downloaded"],
.stt-model-state[data-state="image"],
.stt-model-state[data-state="cache"] { color: var(--success); }
.stt-model-state[data-state="failed"] { color: var(--danger); }
.stt-model-where {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow-wrap: anywhere;
}
.stt-model-actions { display: flex; gap: var(--space-2); flex: none; }
.stt-model-row progress { width: 100%; accent-color: var(--accent); }

/* Settings → Channels: a row of links with a status dot each, then a section per platform with its steps. */
.channel-jump {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.channel-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);
  padding: var(--space-1) var(--space-3);
  border: var(--space-px) solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: var(--text-sm);
  cursor: pointer;
}
.channel-chip:hover { border-color: var(--border-hover); }
.channel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-hover);
  flex-shrink: 0;
}
.channel-dot[data-tone="ok"]   { background: var(--success); }
.channel-dot[data-tone="bad"]  { background: var(--danger); }
.channel-dot[data-tone="wait"] { background: var(--warning); }

.channel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-1) var(--space-3);
  margin-bottom: var(--space-2);
}
.channel-head h3 { margin-bottom: 0; }
.channel-status {
  font-size: var(--text-sm);
  color: var(--text-muted);
  overflow-wrap: anywhere;
}
.channel-status[data-tone="ok"]   { color: var(--success); }
.channel-status[data-tone="bad"]  { color: var(--danger); }
.channel-status[data-tone="wait"] { color: var(--warning); }

.channel-guide {
  margin-bottom: var(--space-4);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
}
.channel-guide > summary {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.channel-guide-steps,
.channel-guide-tips {
  margin: 0;
  padding: 0 var(--space-3) var(--space-3) calc(var(--space-3) + 1.4em);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text-secondary);
}
.channel-guide-steps li { margin-bottom: var(--space-1-5); }
.channel-guide-tips { padding-left: var(--space-3); color: var(--text-muted); }
.channel-guide-tips ul { margin: var(--space-1) 0 0; padding-left: 1.4em; }
.channel-guide-tips li { margin-bottom: var(--space-1); }
.channel-guide a,
.channel-provider-note a { color: var(--accent); }
.channel-provider-note {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--accent);
  background: var(--accent-subtle);
  border-radius: var(--radius-sm);
}
.channel-section { scroll-margin-top: var(--space-4); }
.channel-section.channel-flash { animation: channel-flash 1.6s ease-out; }
@keyframes channel-flash {
  from { box-shadow: 0 0 0 3px var(--accent-glow); }
  to   { box-shadow: 0 0 0 3px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .channel-section.channel-flash { animation: none; }
}

/* Settings → AI (js/settings.js) and the setup wizard's "Choose your AI" (js/setup.js). The chips, status lines and
   guides reuse the channel ones above; these are the rest: banners, key boxes, the model row, OpenRouter's list and
   ChatGPT's sign-in code. Everything wraps, so a phone never scrolls sideways. */
.ai-chip[aria-current="true"] { border-color: var(--accent); }
.ai-banners { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.ai-banners:empty { display: none; }
.ai-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--info);
  border-radius: var(--radius-sm);
  background: var(--info-subtle);
  font-size: var(--text-sm);
  color: var(--text);
}
.ai-banner[data-level="warning"] { border-left-color: var(--warning); background: var(--warning-subtle); }
.ai-banner[data-level="error"]   { border-left-color: var(--danger); background: var(--danger-subtle); }
.ai-banner > span { flex: 1 1 16em; min-width: 0; overflow-wrap: anywhere; }
.ai-default-now {
  margin-bottom: var(--space-1);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text);
  overflow-wrap: anywhere;
}
.ai-default-now[data-tone="ok"]  { color: var(--success); }
.ai-default-now[data-tone="bad"] { color: var(--danger); }
.ai-terms {
  margin: 0 0 var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text-secondary);
}
.ai-terms a,
.ai-card a:not(.btn),
.setup-ai a:not(.btn),
.tool-perms a { color: var(--accent); }
/* Each AI's color (tokens.css --ai-*): anything marked data-ai="<id>" gets it as --ai. */
[data-ai="claude"]     { --ai: var(--ai-claude); }
[data-ai="anthropic"]  { --ai: var(--ai-anthropic); }
[data-ai="chatgpt"]    { --ai: var(--ai-chatgpt); }
[data-ai="openai"]     { --ai: var(--ai-openai); }
[data-ai="openrouter"] { --ai: var(--ai-openrouter); }
[data-ai="deepseek"]   { --ai: var(--ai-deepseek); }
[data-ai="local"]      { --ai: var(--ai-local); }
.ai-dot { display: inline-block; flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--ai, var(--text-muted)); }
.ai-dot[hidden] { display: none; }
/* Settings > AI: each card edged and dotted in its AI's color. */
.ai-card[data-ai] { border-left: 3px solid var(--ai); }
.ai-card[data-ai] .channel-head h3 { display: inline-flex; align-items: center; gap: var(--space-2); }
.ai-card[data-ai] .channel-head h3::before { content: ""; flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; background: var(--ai); }
.ai-card { scroll-margin-top: var(--space-4); }
.ai-card.channel-flash { animation: channel-flash 1.6s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .ai-card.channel-flash { animation: none; }
}
.ai-guide-cost {
  margin: 0;
  padding: 0 var(--space-3) var(--space-2);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text-secondary);
}
.ai-card-body { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.ai-notes {
  margin: 0;
  padding-left: 1.2em;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text-muted);
}
.ai-note-off,
.setup-ai-note {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text-muted);
}
.ai-keysource { font-size: var(--text-sm); color: var(--text-secondary); overflow-wrap: anywhere; }
.ai-keysource code { font-family: var(--font-mono); font-size: var(--text-xs); }
.ai-label {
  display: block;
  margin: var(--space-1) 0;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}
.ai-key-form { display: block; margin: 0; }
.ai-inline { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.ai-inline .ai-input { flex: 1 1 14em; min-width: 0; width: auto; }
.ai-input {
  width: 100%;
  min-height: var(--space-10);
  padding: var(--space-2) var(--space-3);
  border: var(--space-px) solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
}
.ai-input:hover:not(:focus) { border-color: var(--border-hover); }
.ai-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 var(--space-0-5) var(--accent-subtle); }
.ai-input::placeholder { color: var(--text-muted); }
.ai-input-short { max-width: 14em; }
select.ai-input option { background: var(--bg-elevated); color: var(--text); }
.ai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.ai-actions .setup-copy-chip { margin-top: 0; }
.ai-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.ai-test-result {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text-muted);
  overflow-wrap: anywhere;
}
.ai-test-result:empty { display: none; }
.ai-test-result[data-tone="ok"]   { color: var(--success); }
.ai-test-result[data-tone="bad"]  { color: var(--danger); }
.ai-test-result[data-tone="wait"] { color: var(--warning); }
.ai-model-row {
  margin-top: var(--space-1);
  padding-top: var(--space-3);
  border-top: var(--space-px) solid var(--border-light);
}
.ai-model-row .hint { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-1); }
.ai-default-badge { font-size: var(--text-sm); font-weight: 600; color: var(--success); white-space: nowrap; }
.ai-badge {
  display: inline-block;
  margin-left: var(--space-1-5);
  padding: 0 var(--space-1-5);
  border-radius: var(--radius-full);
  background: var(--bg-surface-hover);
  color: var(--text-secondary);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  vertical-align: middle;
}
.ai-badge[data-kind="free"] { background: var(--info-subtle); color: var(--info); }
.ai-badge[data-kind="ok"]   { background: var(--success-subtle); color: var(--success); }
.ai-badge[data-kind="warn"] { background: var(--warning-subtle); color: var(--warning); }
.ai-local-key,
.ai-custom-model,
.ai-or {
  padding: 0 var(--space-3);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
}
.ai-local-key[open],
.ai-custom-model[open],
.ai-or[open] { display: flex; flex-direction: column; gap: var(--space-2); padding-bottom: var(--space-3); }
.ai-local-key > summary,
.ai-custom-model > summary,
.ai-or > summary {
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.ai-or .hint,
.ai-custom-model .hint { font-size: var(--text-sm); color: var(--text-muted); line-height: var(--leading-normal); }
.ai-custom-model { margin-top: var(--space-2); }
.ai-or-list { max-height: 420px; overflow-y: auto; overscroll-behavior: contain; }
.ai-local-models { margin-top: var(--space-2); max-height: 320px; overflow-y: auto; overscroll-behavior: contain; }
.ai-local-models .hint { font-size: var(--text-sm); color: var(--text-muted); }
.ai-or-title {
  margin: var(--space-2) 0 var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
}
.ai-or-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-1-5) 0;
  border-bottom: var(--space-px) solid var(--border-light);
}
.ai-or-name { min-width: 0; font-size: var(--text-sm); color: var(--text); }
.ai-or-meta { font-size: var(--text-xs); color: var(--text-muted); overflow-wrap: anywhere; }
.ai-or-row .btn { flex-shrink: 0; }
.ai-device-box {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  border: var(--space-px) solid var(--accent-glow);
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
}
.ai-device-steps {
  margin: 0;
  padding-left: 1.4em;
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--text);
  overflow-wrap: anywhere;
}
.ai-device-steps a { color: var(--accent); }
.ai-device-code .setup-copy-cmd { font-size: var(--text-lg); font-weight: 700; letter-spacing: 0.08em; }
.ai-device-wait { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-secondary); }
.ai-spinner {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  border: 2px solid var(--border-hover);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ai-spin 0.9s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .ai-spinner { animation: none; }
}

/* The header chip (the AI that answers by default, with a dot) and the banner under the top bar when it can't. */
.ai-header-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);
  max-width: 20em;
  min-height: 32px;
  padding: var(--space-1) var(--space-3);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  cursor: pointer;
}
.ai-header-chip[hidden] { display: none; }
.ai-header-chip:hover { border-color: var(--border-hover); color: var(--text); }
.ai-header-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ai-header-chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* "Default: DeepSeek · DeepSeek Flash": the AI in its own color, so it can be told from a chat's own AI. */
.ai-header-chip-label { color: var(--text-muted); }
.ai-header-chip[data-ai] .ai-header-chip-ai { color: var(--ai); font-weight: 600; }
.ai-attention {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4);
  border-bottom: var(--space-px) solid var(--border);
  background: var(--danger-subtle);
  color: var(--text);
  font-size: var(--text-sm);
}
.ai-attention[hidden] { display: none; }
.ai-attention-text { flex: 1 1 18em; min-width: 0; overflow-wrap: anywhere; }
.ai-attention-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-lg);
  cursor: pointer;
}
.ai-attention-close:hover { background: var(--bg-surface-hover); color: var(--text); }
@media (max-width: 767px) {
  .ai-header-chip-model { display: none; }
}
@media (max-width: 480px) {
  /* Only the dot on a phone: the top bar's buttons need the room. */
  .ai-header-chip { padding: var(--space-1) var(--space-2); min-width: 32px; justify-content: center; }
  .ai-header-chip-text { display: none; }
  .ai-attention { padding: var(--space-2) var(--space-3); }
}

/* The wizard scrolls when its card is taller than the screen (the page itself never scrolls). The card's auto margins
   centre it while it fits, and let its top stay reachable when it doesn't. */
.setup-wizard {
  height: 100vh;
  height: 100dvh;
  align-items: flex-start;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.setup-wizard > .setup-card { margin: auto; }

/* The setup wizard's first step: who talks to it, the three choices, then the chosen one's steps. */
.setup-ai { display: flex; flex-direction: column; gap: var(--space-3); }
.setup-ai-title { margin: 0; font-size: var(--text-lg); font-weight: 700; color: var(--text); }
.setup-ai-who { margin: 0; padding: 0; border: none; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.setup-ai-who legend { margin-bottom: var(--space-1-5); padding: 0; font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.setup-ai-radio { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-base); color: var(--text); cursor: pointer; }
.setup-ai-radio input { margin: 0; accent-color: var(--accent); }
.setup-ai-env {
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--success);
  border-radius: var(--radius-sm);
  background: var(--success-subtle);
  font-size: var(--text-sm);
  color: var(--text);
  overflow-wrap: anywhere;
}
.setup-ai-env-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.setup-ai-choices,
.setup-ai-providers { display: flex; flex-direction: column; gap: var(--space-2); }
.setup-ai-choice,
.setup-ai-provider {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-0-5);
  width: 100%;
  padding: var(--space-3);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.setup-ai-provider { padding: var(--space-2) var(--space-3); }
.setup-ai-choice:hover:not(:disabled),
.setup-ai-provider:hover { border-color: var(--border-hover); }
.setup-ai-choice[aria-pressed="true"],
.setup-ai-provider[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-subtle); }
/* Each AI's button in its own color: a dot before its name, and its color when chosen. */
.setup-ai-choice[data-ai] strong::before,
.setup-ai-provider[data-ai] strong::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: var(--space-2); border-radius: 50%; background: var(--ai); vertical-align: 0.05em; }
.setup-ai-choice[data-ai][aria-pressed="true"],
.setup-ai-provider[data-ai][aria-pressed="true"] { border-color: var(--ai); box-shadow: 0 0 0 1px var(--ai); background: color-mix(in srgb, var(--ai) 12%, transparent); }
.setup-ai-choice:disabled { opacity: 0.55; cursor: not-allowed; }
.setup-ai-choice strong { font-size: var(--text-base); }
.setup-ai-choice span,
.setup-ai-provider span { font-size: var(--text-sm); color: var(--text-muted); }
.setup-ai-choice .setup-ai-choice-warn { color: var(--warning); font-weight: 500; }
.setup-ai-panel { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.setup-ai-panel:empty { display: none; }
.setup-ai-panel .channel-guide { margin-bottom: 0; }
.setup-ai-status { font-size: var(--text-sm); font-weight: 500; color: var(--text-muted); overflow-wrap: anywhere; }
.setup-ai-status[data-tone="ok"]  { color: var(--success); }
.setup-ai-status[data-tone="bad"] { color: var(--danger); }
.setup-ai-keysonly { margin-top: var(--space-1); }
.setup-ai-who[hidden],
.setup-ai-keysonly[hidden],
.setup-ai-note[hidden] { display: none; }
.setup-error { font-size: var(--text-sm); color: var(--danger); overflow-wrap: anywhere; }
.setup-error[hidden] { display: none; }
.setup-ai-later { margin: 0; text-align: center; font-size: var(--text-xs); color: var(--text-muted); }
.setup-card:has(.setup-ai) { max-width: 520px; }
@media (max-width: 480px) {
  .setup-card-body.setup-ai { padding: var(--space-4); }
}

/* Settings → Security → Tool Permissions: the registry's tools, by group. */
.tool-perm-group { margin-bottom: var(--space-4); }
.tool-perm-group h4 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
}
.tool-perm-group > .hint { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-1); }
.tool-perm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1-5) 0;
  border-bottom: var(--space-px) solid var(--border-light);
  font-size: var(--text-sm);
}
.tool-perm-name { flex: 1 1 auto; min-width: 0; color: var(--text); }
.tool-perm-desc { font-size: var(--text-xs); color: var(--text-muted); overflow-wrap: anywhere; }
.tool-perm-select {
  flex: 0 1 auto;
  max-width: 50%;
  padding: var(--space-1) var(--space-2);
  border: var(--space-px) solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: var(--text-sm);
}
.tool-perm-fixed { flex-shrink: 0; font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }


/* ==========================================================================
   15. Delete Modal
   ========================================================================== */

.delete-modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-heavy);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.delete-modal {
  background: var(--bg-elevated);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-xl);
  animation: scaleIn var(--duration-slow) var(--ease-default);
}

.delete-modal-header {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-3);
}

.delete-modal-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: var(--space-2) 0;
  line-height: var(--leading-normal);
}

.delete-modal-text strong {
  color: var(--text);
}

.delete-modal-input {
  width: 100%;
  padding: var(--space-3);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-base);
  font-family: var(--font-body);
  margin: var(--space-3) 0 var(--space-4);
  outline: none;
  transition: border-color var(--duration-normal) var(--ease-default);
}

.delete-modal-input:focus {
  border-color: var(--danger);
}

.delete-modal-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* QR modal — flex-column centering for the QR canvas + URL.
   The qrcode library renders an SVG that's a block element, so
   text-align:center on the parent doesn't center it. We use flex on a
   dedicated holder + cap the SVG width so it can never push outside. */
.qr-modal {
  max-width: 320px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.qr-modal-header {
  width: 100%;
  text-align: center;
  margin-bottom: 0;
}

.qr-canvas-holder {
  width: 240px;
  max-width: 100%;
  margin: 0 auto;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-canvas {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-canvas svg {
  width: 100%;
  height: auto;
  display: block;
}

.qr-modal-url {
  width: 100%;
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
  word-break: break-all;
  text-align: center;
  margin: 0;
}

.qr-modal .delete-modal-actions {
  width: 100%;
  justify-content: center;
}

.delete-modal-cancel {
  background: var(--bg-surface);
  border: var(--space-px) solid var(--border);
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  font-family: var(--font-body);
  transition: all var(--duration-normal) var(--ease-default);
  min-height: var(--space-10);
}

.delete-modal-cancel:hover {
  background: var(--bg-surface-hover);
  color: var(--text);
}

.delete-modal-confirm {
  background: var(--danger);
  border: none;
  color: var(--text);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-body);
  transition: all var(--duration-normal) var(--ease-default);
  min-height: var(--space-10);
}

.delete-modal-confirm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.delete-modal-confirm:not(:disabled):hover {
  background: var(--danger-hover);
  box-shadow: var(--shadow-md);
}


/* ==========================================================================
   16. Toasts
   ========================================================================== */

.toast-container {
  position: fixed;
  top: var(--space-12);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  animation: slideIn var(--duration-slow) var(--ease-default);
  max-width: 340px;
  pointer-events: auto;
  line-height: var(--leading-normal);
  color: var(--text);
}

.toast.error  { border-left: var(--space-0-5) solid var(--danger);  background: var(--danger-subtle); }
.toast.success { border-left: var(--space-0-5) solid var(--success); background: var(--success-subtle); }
.toast.info    { border-left: var(--space-0-5) solid var(--info);    background: var(--info-subtle); }
.toast.removing {
  opacity: 0;
  transform: translateX(20px);
  transition: all var(--duration-fast) var(--ease-default);
}


/* ==========================================================================
   17. Save Status
   ========================================================================== */

.save-status {
  display: inline-block;
  font-size: var(--text-xs);
  margin-left: var(--space-1);
  color: var(--text-muted);
  transition: opacity var(--duration-normal) var(--ease-default);
}

.save-status.saving {
  color: var(--warning);
}

.save-status.saved {
  color: var(--success);
}


/* ==========================================================================
   18. Typing Indicator — 3 dots with staggered pulse
   ========================================================================== */

.typing-indicator {
  display: inline-flex;
  gap: var(--space-1);
  padding: var(--space-1) 0;
}

.typing-indicator span {
  width: var(--space-1-5);
  height: var(--space-1-5);
  background: var(--text-muted);
  border-radius: var(--radius-full);
  animation: streamPulse 1.2s infinite ease-in-out;
}

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


/* ==========================================================================
   19. Memory Items
   ========================================================================== */

.memories-list {
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: var(--space-3);
}

.memory-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  background: transparent;
  border-radius: 0;
  margin-bottom: 0;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  transition: background var(--duration-normal) var(--ease-default);
  border: none;
  border-bottom: var(--space-px) solid var(--border-light);
}

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

.memory-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-normal);
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  color: var(--accent);
  flex-shrink: 0;
  margin-top: var(--space-px);
}

.memory-content {
  flex: 1;
  color: var(--text-secondary);
}

.memory-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-0-5);
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: all var(--duration-normal) var(--ease-default);
  flex-shrink: 0;
}

.memory-item:hover .memory-delete {
  opacity: 1;
}

.memory-delete:hover {
  color: var(--danger);
  background: var(--danger-subtle);
}

/* Settings → Automation → Scheduled tasks (js/cron-core.js). A task is a row: its state badge, what it does (when it
   runs, the whole prompt or the action, who made it), then Switch on or Pause, and Delete. In a row narrower than about
   520px (a phone, or a tablet with both sidebars open) the badge and buttons left the prompt a word a line, so there
   what it does takes the row's whole width, and the badge and buttons get a line of their own under it. The row
   measures itself (a container query), so this holds wherever the list sits. */
.cron-job {
  container: cron-task / inline-size;
  flex-wrap: wrap;
  row-gap: var(--space-2);
}

.cron-job .memory-content {
  min-width: 0;
}

.cron-job .cron-toggle {
  flex-shrink: 0;
}

/* Switch on (or Pause) and Delete as one piece: whatever the font, a narrow row never splits them. */
.cron-job .cron-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

@container cron-task (max-width: 520px) {
  .cron-job .memory-content {
    order: -1;
    flex: 1 0 100%;
  }

  .cron-job .cron-state,
  .cron-job .cron-actions {
    align-self: center;
  }

  .cron-job .cron-actions {
    margin-left: auto;
  }

  /* Delete shows without a mouse to hover with, and is big enough to tap. */
  .cron-job .memory-delete {
    opacity: 1;
    min-width: var(--space-8);
    min-height: var(--space-8);
  }
}

@media (hover: none) {
  .cron-job .memory-delete {
    opacity: 1;
  }
}

/* A long id or schedule wraps instead of running out of the row. */
.cron-when,
.cron-who {
  overflow-wrap: anywhere;
}

.cron-prompt {
  margin-top: var(--space-1);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.cron-what,
.cron-args {
  overflow-wrap: anywhere;
}

.cron-what {
  margin-top: var(--space-1);
}

.cron-who,
.cron-note {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.cron-state-waiting {
  background: var(--warning-subtle);
  color: var(--warning);
}

.cron-state-running {
  background: var(--success-subtle);
  color: var(--success);
}

.cron-state-off {
  background: var(--bg-surface-hover);
  color: var(--text-muted);
}


/* ==========================================================================
   20. Skills
   ========================================================================== */

.skills-section-label {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-muted);
  padding: var(--space-3) var(--space-1) var(--space-1-5);
}

.skills-section-label:first-child {
  padding-top: 0;
}

/* Skill cards — iOS grouped list style */
.skill-card {
  border: none;
  border-bottom: var(--space-px) solid var(--border-light);
  border-radius: 0;
  padding: var(--space-3) var(--space-4);
  margin-bottom: 0;
  transition: background var(--duration-normal) var(--ease-default);
  background: var(--bg-elevated);
}

.skills-section-label + .skill-card {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.skill-card:last-child,
.skill-card + .skills-section-label {
  border-bottom: none;
}

.skill-card:last-child {
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.skills-section-label + .skill-card:last-child {
  border-radius: var(--radius-lg);
}

.skill-card:hover {
  background: var(--bg-surface-hover);
}

/* Skill dialog */
.skill-dialog {
  border: var(--space-px) solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-top: var(--space-3);
  background: var(--bg);
}


/* ==========================================================================
   21. Clone Upload
   ========================================================================== */

.clone-upload {
  border: var(--space-0-5) dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
}

.clone-upload:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.clone-upload.dragover {
  border-color: var(--accent);
  background: var(--accent-subtle);
  transform: scale(1.01);
}


/* ==========================================================================
   22. Session Bar
   ========================================================================== */

.session-bar {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: var(--space-px) solid var(--border-light);
  background: var(--bg);
  flex-shrink: 0;
}

.session-bar-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.session-bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.session-model {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.session-status {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.context-bar {
  width: var(--space-12);
  height: var(--space-1);
  background: var(--border-light);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.context-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--duration-normal) var(--ease-default);
}

.context-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.badge-btn {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: var(--space-px) solid var(--border);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-default);
  font-family: var(--font-body);
}

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


/* ==========================================================================
   23. Avatar Image — reusable
   ========================================================================== */

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}


/* ==========================================================================
   24. PIN Pad — iOS Lock Screen Style (mobile only)
   ========================================================================== */

.pin-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 340px;
  padding: var(--space-6) var(--space-4);
  gap: var(--space-4);
}

.pin-logo {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.pin-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: var(--tracking-tight);
}

.pin-error {
  font-size: var(--text-sm);
  color: var(--danger);
  min-height: 20px;
  text-align: center;
}

.pin-dots {
  display: flex;
  gap: var(--space-4);
  margin: var(--space-2) 0 var(--space-6);
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  border: 2px solid var(--text-secondary);
  background: transparent;
  transition: all var(--duration-normal) var(--ease-spring);
}

.pin-dot.filled {
  background: var(--text);
  border-color: var(--text);
  transform: scale(1.15);
}

.pin-dot.error {
  border-color: var(--danger);
  background: var(--danger);
  animation: pinShake 0.5s var(--ease-default);
}

@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: var(--space-4);
  justify-content: center;
}

.pin-key {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-hover);
  background: var(--glass-subtle);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all var(--duration-fast) var(--ease-default);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pin-key:hover {
  background: var(--glass-soft);
}

.pin-key:active {
  background: var(--glass-medium);
  transform: scale(0.95);
}

.pin-key-empty {
  border: none;
  background: none;
  cursor: default;
}

.pin-key-empty:active {
  background: none;
  transform: none;
}

.pin-key-delete {
  border: none;
  background: none;
  color: var(--text-secondary);
}

.pin-key-delete:active {
  background: var(--glass-subtle);
  color: var(--text);
}

.pin-digit {
  font-size: 32px;
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.5px;
}

.pin-letters {
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* Mobile-first: hide desktop elements, show mobile elements */
/* Mobile/desktop visibility utilities.
   Each element keeps its own natural display — these rules only HIDE,
   never force a display value. So a .desktop-only .topbar-icon-btn on
   desktop stays inline-flex (its own class), instead of being clobbered
   to block (which kills SVG flex centering inside the button). */
@media (max-width: 767px) {
  .desktop-only { display: none !important; }

  /* iOS auto-zooms any focused input with computed font-size < 16px, and
     ignores user-scalable=no since iOS 10. Bump every focusable control to
     16px on phone-sized viewports to stop the zoom-in-on-tap behavior.
     Desktop keeps the designed 13–15px sizes. */
  input,
  textarea,
  select,
  [contenteditable="true"] {
    font-size: 16px !important;
  }
}
@media (min-width: 768px) {
  .mobile-only { display: none !important; }
}

/* ==========================================================================
   25. Responsive — desktop overrides
   Breakpoint at 768px: iPad (all sizes) and larger get the static-sidebar
   layout. iPad Mini portrait (744px) and phones stay on the mobile drawer.
   Mobile rules use `max-width: 768px` (inclusive), so at exactly 768 the
   later desktop rules override via cascade order — intentional.
   ========================================================================== */

@media (min-width: 768px) {

  /* App layout → grid with sidebar */
  .app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "sidebar content";
    height: 100vh;
    height: 100dvh;
    /* Keep safe area for iPad PWA — status bar still overlaps */
    padding-top: env(safe-area-inset-top, 0px);
  }

  /* Sidebar → static grid area */
  .sidebar {
    position: static;
    grid-area: sidebar;
    transform: none;
    max-width: none;
    padding-top: 0;
    z-index: auto;
    box-shadow: none;
  }

  .sidebar.open {
    box-shadow: none;
  }

  .sidebar-header {
    height: var(--topbar-height);
  }

  .sidebar-overlay {
    display: none;
  }

  /* (.mobile-only / .desktop-only display rules are media-scoped above and
     deliberately never set a display value on .desktop-only on desktop —
     so the element keeps whatever display its own class declares.
     See the comment at the top of the file's visibility utilities.) */

  /* Main content → grid area */
  .main {
    grid-area: content;
  }

  /* Topbar */
  .topbar {
    height: var(--topbar-height);
    padding: 0 var(--space-5);
  }

  .topbar-title {
    max-width: none;
  }

  /* Chat area — desktop padding */
  .chat-area {
    padding: var(--space-6) var(--space-6) var(--space-2);
  }

  /* Messages — larger avatars on desktop */
  .message {
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
  }

  .message-avatar {
    width: 36px;
    height: 36px;
  }

  .message-role {
    font-size: var(--text-sm);
  }

  .message-text {
    font-size: var(--text-md);
    line-height: var(--leading-relaxed);
  }

  /* Input area — desktop: gradient bg, no border-top */
  .input-area {
    padding: var(--space-3) var(--space-6) calc(env(safe-area-inset-bottom, var(--space-5)) + var(--space-2));
    background: linear-gradient(to top, var(--bg) 60%, transparent);
    border-top: none;
  }

  .input-container textarea {
    font-size: var(--text-md);
    padding: var(--space-3);
  }

  /* Welcome — row layout for suggestions */
  .welcome h2 {
    font-size: var(--text-2xl);
  }

  .welcome-suggestions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Settings — desktop: vertical sidebar tabs */
  .settings-page {
    flex-direction: row;
  }

  .settings-tabs {
    width: var(--settings-sidebar-width);
    flex-direction: column;
    overflow-x: visible;
    border-bottom: none;
    border-right: var(--space-px) solid var(--border);
    padding: var(--space-4) var(--space-2);
    gap: var(--space-0-5);
  }

  .settings-tab {
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
  }

  .settings-content {
    padding: var(--space-6) var(--space-8) var(--space-10);
  }

  /* Login card */
  .login-card {
    padding: var(--space-10) var(--space-8);
  }
}

/* ==========================================================================
   26. iPad / tablet tweaks (768px – 1024px)
   Narrower sidebar and tighter padding so iPad portrait (768-834px)
   doesn't feel cramped when both sidebar and chat share the viewport.
   ========================================================================== */

@media (min-width: 768px) and (max-width: 1024px) {

  :root {
    --sidebar-width: 220px;
    /* Give the settings tab column a touch more room on iPad so the labels
       don't truncate — desktop uses 180px but iPad has less horizontal real
       estate once the main sidebar and content padding are subtracted. */
    --settings-sidebar-width: 200px;
  }

  .chat-area {
    padding: var(--space-4) var(--space-4) var(--space-2);
  }

  .input-area {
    padding: var(--space-3) var(--space-4) calc(env(safe-area-inset-bottom, var(--space-5)) + var(--space-2));
  }

  .settings-content {
    padding: var(--space-4) var(--space-6) var(--space-8);
  }
}

/* ==========================================================================
   Settings Active State
   ========================================================================== */
.settings-active { color: var(--accent) !important; }

/* Audit log */
.audit-log-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-height: 500px;
  overflow-y: auto;
}

.audit-entry {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  align-items: center;
}

.audit-entry-time {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.audit-entry-action {
  color: var(--text);
  font-weight: 600;
}

.audit-entry-action.auth { color: var(--warning); }
.audit-entry-action.tool { color: var(--info); }
.audit-entry-action.setting { color: var(--accent); }

.audit-entry-detail {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

@media (max-width: 768px) {
  .audit-entry {
    grid-template-columns: 1fr;
    gap: var(--space-0-5);
  }
  .audit-entry-detail {
    text-align: left;
    max-width: none;
  }
}


/* ==========================================================================
   Audit-remediation additions: offline banner, keyboard overlay, skeletons,
   empty states, context gauge, code copy feedback, sidebar scroll fade.
   ========================================================================== */

/* ---- Keyboard shortcut overlay (triggered by `?` key) ---- */
.kbd-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--overlay-dense);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn var(--duration-normal) var(--ease-default);
}
.kbd-overlay-panel {
  background: var(--bg-elevated);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--space-6);
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  animation: scaleIn var(--duration-normal) var(--ease-spring);
}
.kbd-overlay-panel h3 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-4);
  color: var(--text);
}
.kbd-group {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2) var(--space-4);
  align-items: center;
  margin-bottom: var(--space-4);
}
.kbd-group-title {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-top: var(--space-2);
}
.kbd-label {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.kbd-keys {
  display: inline-flex;
  gap: var(--space-1);
}
.kbd-key {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--bg-input);
  border: var(--space-px) solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  color: var(--text);
  min-width: 24px;
  text-align: center;
}

/* ---- Skeleton loader ---- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-surface) 0%,
    var(--bg-surface-hover) 50%,
    var(--bg-surface) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton-line { height: 12px; margin-bottom: var(--space-2); }
.skeleton-line.short { width: 45%; }
.skeleton-line.medium { width: 70%; }
.skeleton-line.long { width: 92%; }
.skeleton-block { height: 64px; margin-bottom: var(--space-2); border-radius: var(--radius-md); }

/* ---- Empty state ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}
.empty-state-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
  font-size: var(--text-xl);
}
.empty-state-title {
  color: var(--text);
  font-size: var(--text-md);
  font-weight: 600;
  margin-bottom: var(--space-1);
}
.empty-state-text {
  font-size: var(--text-sm);
  max-width: 320px;
  line-height: var(--leading-relaxed);
}

/* ---- Code block copy feedback (success flash) ---- */
.copy-success {
  background: var(--success-subtle) !important;
  color: var(--success) !important;
  border-color: var(--success) !important;
  transition: all var(--duration-normal) var(--ease-default);
}

/* ---- Sidebar bottom scroll fade hint ---- */
.channel-list {
  position: relative;
}
.channel-list-scroll-fade {
  position: sticky;
  bottom: 0;
  height: 24px;
  margin-top: -24px;
  background: linear-gradient(to bottom, transparent, var(--bg-sidebar));
  pointer-events: none;
}

/* ---- Context bar — warn color at >80% ---- */
.context-bar-fill.warn { background: var(--warning); }
.context-bar-fill.danger { background: var(--danger); }

/* ---- save-status error variant (was only saving/saved) ---- */
.save-status.error {
  color: var(--danger);
}

/* ---- Lightbox tokenized (was hardcoded white) ---- */
.lightbox-frame,
.lightbox-sheet {
  background: var(--bg-elevated);
  color: var(--text);
}


/* ==========================================================================
   Audit round 2: Mobile + iPad polish (2026-04-21)
   ========================================================================== */

/* ---- Prevent accidental pull-to-refresh / rubber-banding on iOS ---- */
.chat-area,
.console-panel,
.sidebar,
.settings-content,
.call-transcript {
  overscroll-behavior: contain;
}
html, body {
  /* Page itself shouldn't bounce — individual scroll regions handle it. */
  overscroll-behavior-y: none;
}

/* Keyboard positioning is handled by --app-height (see .app rule above):
   the flex container shrinks, pushing .input-area up naturally. Only keep
   a small scroll-padding so the newest message isn't tucked under the
   composer when the keyboard is open. */
html.keyboard-open .chat-area {
  scroll-padding-bottom: var(--space-4);
}

/* ---- Short landscape viewports (phones rotated) ---- */
@media (max-height: 600px) and (orientation: landscape) {
  /* PIN pad: shrink the grid so it fits without scrolling. */
  .pin-grid {
    grid-template-columns: repeat(3, 56px);
    gap: var(--space-2);
  }
  .pin-key {
    width: 56px;
    height: 56px;
  }
  .pin-digit {
    font-size: 22px;
  }
  .pin-letters {
    display: none;
  }
  .pin-dots {
    margin-bottom: var(--space-2);
  }
  .pin-title {
    font-size: var(--text-lg);
    margin-bottom: var(--space-2);
  }

  /* Welcome: kill the big hero so suggestions + composer fit. */
  .welcome .logo-large {
    width: 40px;
    height: 40px;
    margin-bottom: var(--space-2);
  }
  .welcome h2 {
    font-size: var(--text-lg);
    margin-bottom: var(--space-1);
  }
  .welcome p {
    font-size: var(--text-sm);
    margin-bottom: var(--space-3);
  }
  .welcome-hint {
    display: none;
  }

  /* Chat padding collapses so the tail of the conversation is visible. */
  .chat-area {
    padding: var(--space-2) var(--space-3);
  }
}

/* ---- Tiny phones (≤360px) ---- */
@media (max-width: 360px) {
  :root {
    --sidebar-width: 240px;
  }
  .topbar {
    padding: 0 var(--space-2);
  }
  .topbar-right {
    gap: var(--space-1);
  }
}


/* ==========================================================================
   iOS 26 "Liquid Glass" treatments (mobile + iPad)
   Desktop keeps the warm-charcoal solid look; small screens get the glass
   sidebar drawer, floating composer, and specular highlights that iOS 26
   apps use. Everything wrapped in @supports so the solid fallback is safe.
   ========================================================================== */

.glass-highlight {
  box-shadow: var(--glass-highlight), var(--shadow-md);
}

/* Primary button: same light-on-edge treatment — separates it from ghost. */
.btn-primary {
  box-shadow: var(--glass-highlight), var(--shadow-sm);
}
.btn-primary:hover {
  box-shadow: var(--glass-highlight-strong), var(--shadow-md);
}

/* Mobile & iPad-portrait glass drawer + floating composer.
   Scope to max-width: 1024px so iPad lands in the glass treatment too. */
@media (max-width: 1024px) {

  /* Sidebar drawer (mobile only — desktop static sidebar stays solid). */
  @media (max-width: 767px) {
    .sidebar {
      background: var(--bg-glass-solid);
      border-right-color: transparent;
      box-shadow: var(--glass-highlight);
    }
    @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
      .sidebar {
        background: var(--bg-glass-sidebar);
        -webkit-backdrop-filter: var(--blur-lg);
        backdrop-filter: var(--blur-lg);
      }
      .sidebar.open {
        /* Drop the hard shadow + specular highlight when open so the glass
           edge catches the light against the darkened main content. */
        box-shadow: var(--glass-highlight-strong), var(--shadow-xl);
      }
    }

    /* Floating composer: the single biggest iOS-native polish lever. */
    .input-area {
      background: transparent;
      border-top: none;
      padding: 0 var(--space-2) calc(env(safe-area-inset-bottom, var(--space-2)) + var(--space-2));
    }
    .input-container {
      border-radius: var(--radius-2xl);
      background: var(--bg-glass-solid);
      border-color: transparent;
      box-shadow: var(--glass-highlight), 0 8px 24px rgba(0, 0, 0, 0.35);
    }
    @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
      .input-container {
        background: var(--bg-glass-surface);
        -webkit-backdrop-filter: var(--blur-md);
        backdrop-filter: var(--blur-md);
      }
    }
    .input-container:focus-within {
      box-shadow: var(--glass-highlight-strong),
                  0 0 0 2px var(--accent-subtle),
                  0 8px 24px rgba(0, 0, 0, 0.4);
    }
    /* Reserve bottom space in the chat so the last message isn't tucked
       behind the floating composer. */
    .chat-area {
      padding-bottom: var(--space-3);
    }

    /* Session bar on mobile — matches the glass composer aesthetic */
    .session-bar {
      border-bottom: none;
      box-shadow: var(--glass-highlight);
    }
  }

  /* Modals and the lightbox get softer rounded corners on small
     screens — not full glass (text on these needs max contrast) but
     concentric with the floating composer. */
  .delete-modal,
  .kbd-overlay-panel {
    border-radius: var(--radius-2xl);
    box-shadow: var(--glass-highlight), var(--shadow-xl);
  }

  .lightbox-img,
  .lightbox-frame,
  .lightbox-sheet {
    border-radius: var(--radius-2xl);
  }
}

/* Even on desktop, the command palette + modals benefit from the concentric
   radius bump the tokens already gave them. Specular highlight on modals
   adds depth without changing the base aesthetic. */
.delete-modal-overlay .delete-modal,
.kbd-overlay-panel {
  box-shadow: var(--glass-highlight), var(--shadow-xl);
}

.command-palette {
  box-shadow: var(--glass-highlight), var(--shadow-lg);
}


/* ==========================================================================
   Custom <select> replacement (custom-select.js auto-enhances every <select>)
   Native dropdowns can't be styled past their trigger — the popup is OS
   chrome. These styles replace the trigger and a body-attached panel that
   matches the command palette aesthetic.
   ========================================================================== */

/* Hide the native <select> visually but keep it focusable for forms / a11y. */
.cs-native-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border-width: 0 !important;
  pointer-events: none !important;
}

.cs-wrap {
  position: relative;
  display: block;
  width: 100%;
}

.cs-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3);
  border: var(--space-px) solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text);
  font-size: var(--text-base);
  font-family: var(--font-body);
  line-height: 1.2;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default);
}

.cs-trigger:hover:not([disabled]) {
  background: var(--bg-surface);
  border-color: var(--border-hover);
}

.cs-trigger:focus-visible,
.cs-trigger.is-open {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 var(--space-0-5) var(--accent-subtle);
}

.cs-trigger[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.cs-trigger-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cs-trigger-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--duration-fast) var(--ease-default);
}

.cs-trigger.is-open .cs-trigger-chevron {
  transform: rotate(180deg);
}

/* Popup panel — body-attached so overflow:hidden ancestors don't clip it.
   Uses the same glass + section grammar as the command palette. */
.cs-panel {
  position: fixed;
  z-index: var(--z-modal);
  background: var(--bg-elevated);
  border: var(--space-px) solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-highlight, none), var(--shadow-lg);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-1) 0;
  animation: paletteIn var(--duration-fast) var(--ease-default);
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .cs-panel {
    background: var(--bg-glass-strong);
    -webkit-backdrop-filter: var(--blur-md);
    backdrop-filter: var(--blur-md);
  }
}

.cs-group-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  padding: var(--space-2) var(--space-3) var(--space-1);
}
.cs-group-title:not(:first-child) {
  border-top: var(--space-px) solid var(--border-light);
  margin-top: var(--space-1);
  padding-top: var(--space-3);
}

.cs-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background var(--duration-fast) var(--ease-default);
}

.cs-item.is-active,
.cs-item:hover:not(.is-disabled) {
  background: var(--bg-surface-hover);
}

.cs-item.is-selected {
  color: var(--accent);
  font-weight: 500;
}

.cs-item.is-disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

.cs-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cs-item-check {
  flex-shrink: 0;
  color: var(--accent);
}

/* Mobile: items get a touch more padding so they're tappable. */
@media (max-width: 768px) {
  .cs-item { padding: var(--space-3); font-size: var(--text-base); }
  .cs-panel { max-height: 60vh !important; }
}



/* ==========================================================================
   Theme preview grid (Settings > Appearance, below the <select>).
   Optional visual preview tiles — mostly aspirational here; if you want
   live thumbnails wire them in later.
   ========================================================================== */
.theme-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* Sign out sits under Settings */
.sidebar-footer .btn + .btn { margin-top: var(--space-1); }

/* Phone login: the PIN pad only takes 4 digits; this reveals the password form */
.pin-use-password {
  margin-top: var(--space-4);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}
@media (max-width: 767px) {
  .login-screen.use-password .pin-pad { display: none !important; }
  .login-screen.use-password .login-card.desktop-only { display: block !important; }
}
