/* ============================================================
   AI Chat — Powerful Matter skin
   Self-contained: imports tokens.css from the site, then carries
   the chat app's full layout. No data-theme="light" rules — the
   site is dark-only by design.
   ============================================================ */

@import url("/css-v2/tokens.css");

/* ===== Webfonts (mirrored from base.css; kept local so the chat
   doesn't depend on the marketing site's main.css) ===== */
@font-face {
  font-family: "Inter";
  src: url("/assets/fonts/inter/Inter-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/assets/fonts/fraunces/Fraunces-Latin-Roman-Full.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/assets/fonts/fraunces/Fraunces-Latin-Italic-Full.woff2") format("woff2");
  font-weight: 400 600;
  font-style: italic;
  font-display: swap;
}

/* ===== Local theme aliases mapped onto PM tokens ===== */
:root {
  --bg-primary:        var(--pm-black);
  --bg-secondary:      #111114;
  --bg-tertiary:       #1a1a1f;
  --bg-input:          rgba(255, 255, 255, 0.02);
  --bg-msg-user:       rgba(196, 0, 173, 0.10);
  --bg-msg-assistant:  transparent;
  --bg-hover:          rgba(196, 0, 173, 0.10);
  --bg-active:         rgba(196, 0, 173, 0.16);
  --bg-code:           #0d0d10;
  --bg-modal:          #0F0F12;

  --text-primary:      var(--pm-white);
  --text-secondary:    var(--pm-gray-300);
  --text-muted:        var(--pm-gray-400);
  --text-code:         #E8E6F0;

  --accent:            var(--pm-purple-400);          /* #C400AD */
  --accent-deep:       var(--pm-purple-500);
  --accent-hover:      var(--pm-purple-300);
  --focus-ring:        var(--pm-accent);              /* lime, hover/focus only */

  --border:            rgba(255, 255, 255, 0.08);
  --border-strong:     rgba(255, 255, 255, 0.14);
  --error:             #FF7B9C;
  --success:           #6BD16B;
  --warning:           #E5FF3A;
  --shadow-modal:      0 24px 64px rgba(0, 0, 0, 0.65);

  --sidebar-width:     280px;
  --radius:            10px;
  --radius-lg:         14px;
  --radius-pill:       999px;
  --transition:        180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ===== Reset ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; overflow: hidden; }

body {
  font-family: var(--ff-body);
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: -0.005em;
  color: var(--text-primary);
  background: var(--bg-primary);
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }

::selection { background: var(--accent); color: var(--pm-white); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ===== Focus ring (acid lime; CLAUDE.md brand rule) ===== */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, a:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible {
  outline-offset: 2px;
}

/* ===== Icons ===== */
.icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ===== Buttons ===== */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
  gap: 8px;
  font-size: 14px;
  font-family: inherit;
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Primary = purple-filled circular send button */
.btn-icon.btn-primary {
  background: var(--accent);
  color: var(--pm-white);
  width: 36px;
  height: 36px;
  border-radius: 50%;
}
.btn-icon.btn-primary:hover {
  background: var(--accent-hover);
  color: var(--pm-white);
}
.btn-icon.btn-primary .icon { width: 16px; height: 16px; }

.btn-icon.btn-danger { color: var(--error); }
.btn-icon.btn-danger:hover { background: rgba(255, 123, 156, 0.14); }

.btn-icon.btn-round {
  border-radius: 50%;
  width: 56px;
  height: 56px;
}

.btn-icon.recording {
  color: var(--error);
  animation: pulse 1.5s infinite;
}

/* Filled .btn (settings save) — pill, white default, purple hover */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 22px;
  font-family: var(--ff-body);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--pm-black);
  background: var(--pm-white);
  border: 1px solid var(--pm-white);
  border-radius: var(--radius-pill);
  cursor: pointer;
  overflow: hidden;
  transition: color var(--transition), border-color var(--transition);
  isolation: isolate;
}
.btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--pm-gradient-brand);
  transform: translateY(101%);
  transition: transform 500ms cubic-bezier(0.16, 1, 0.3, 1);
  z-index: -1;
}
.btn:hover {
  color: var(--pm-white);
  border-color: var(--accent);
}
.btn:hover::before { transform: translateY(0); }

.btn.btn-primary { /* settings save uses brand pill */
  color: var(--pm-black);
  background: var(--pm-white);
  border-color: var(--pm-white);
  width: auto;
  height: auto;
  border-radius: var(--radius-pill);
}
.btn.btn-primary:hover { color: var(--pm-white); }

.btn-sm {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: all var(--transition);
  margin-top: 8px;
  align-self: flex-start;
  font-family: inherit;
}
.btn-sm:hover {
  border-color: var(--accent);
  color: var(--pm-white);
}

/* ===== Brand back-link (top of sidebar) ===== */
.brand-back {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 12px;
  color: var(--text-primary);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: -0.01em;
  transition: color var(--transition), background var(--transition);
}
.brand-back:hover { color: var(--pm-white); background: var(--bg-hover); }
.brand-back__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.brand-back__mark img { display: block; }
.brand-back__text { flex: 1; }
.brand-back__arrow {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  transition: transform var(--transition), color var(--transition);
}
.brand-back:hover .brand-back__arrow {
  color: var(--accent);
  transform: translateX(-3px);
}

/* ===== Sidebar ===== */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  height: 100%;
  overflow: hidden;
}

.sidebar-header { padding: 12px; border-bottom: 1px solid var(--border); }
.sidebar-header .btn-icon {
  width: 100%;
  justify-content: flex-start;
  padding: 10px 12px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-tertiary);
}
.sidebar-header .btn-icon:hover { background: var(--bg-active); }

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-search .icon { color: var(--text-muted); width: 16px; height: 16px; }
.sidebar-search input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversation-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  gap: 8px;
  position: relative;
}
.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active {
  background: var(--bg-active);
  box-shadow: inset 2px 0 0 var(--accent);
}

.conversation-item .conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  color: var(--text-primary);
}
.conversation-item .conv-time {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.conversation-item .conv-actions { display: none; gap: 2px; }
.conversation-item:hover .conv-actions { display: flex; }
.conversation-item:hover .conv-time { display: none; }
.conversation-item .conv-actions .btn-icon { padding: 4px; }
.conversation-item .conv-actions .icon { width: 14px; height: 14px; }

.conversation-item.pinned::before {
  content: '';
  width: 4px;
  height: 4px;
  background: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

/* Date group headings in conversation list */
.conv-date-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: var(--ls-eyebrow);
  color: var(--text-muted);
  padding: 14px 12px 6px;
  font-weight: 500;
}

/* ===== Sidebar backdrop (mobile) ===== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9;
}
.sidebar-backdrop.active { display: block; }

/* ===== Main chat area ===== */
#chat-area {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  position: relative;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  min-height: 60px;
}
.chat-header h1 {
  flex: 1;
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: 18px;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.chat-header-actions select {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
}
.chat-header-actions select:hover { border-color: var(--border-strong); }

.mobile-only { display: none; }

/* ===== Messages ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  gap: 16px;
  padding: 32px 24px;
  max-width: 560px;
  margin: auto;
}
.welcome-screen .eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: var(--ls-eyebrow);
  color: var(--accent);
  font-weight: 500;
}
.welcome-screen h2 {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: clamp(2.25rem, 1.5rem + 2vw, 3rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: var(--pm-white);
}
.welcome-screen p {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 44ch;
  line-height: 1.6;
}
.welcome-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent-hover);
  border-bottom: 1px solid currentColor;
  cursor: pointer;
}
.welcome-link:hover { color: var(--pm-white); }

/* Message */
.message {
  display: flex;
  gap: 14px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.message.user { flex-direction: row-reverse; }

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.message.user .message-avatar {
  background: var(--accent);
  color: var(--pm-white);
}
.message.assistant .message-avatar {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

.message-content {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 15px;
}
.message.user .message-content {
  background: var(--bg-msg-user);
  border: 1px solid rgba(196, 0, 173, 0.18);
  border-top-right-radius: 4px;
  color: var(--pm-white);
}
.message.assistant .message-content {
  background: var(--bg-msg-assistant);
  padding-inline: 0;
  color: var(--text-primary);
}

.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity var(--transition);
}
.message:hover .message-actions { opacity: 1; }
.message-actions .btn-icon { padding: 4px; }
.message-actions .icon { width: 14px; height: 14px; }

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.message-attachment-img {
  max-width: 300px;
  max-height: 300px;
  border-radius: var(--radius);
  cursor: pointer;
  object-fit: cover;
  border: 1px solid var(--border);
}

.message-image {
  max-width: 512px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
}
.message-image-prompt {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
}

/* TTS audio message */
.tts-audio-message {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-top: 6px;
  min-width: 280px;
  max-width: 400px;
}
.tts-player-row { display: flex; align-items: center; gap: 10px; }
.tts-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--pm-white);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition);
}
.tts-play-btn:hover { background: var(--accent-hover); }
.tts-play-btn .icon { width: 16px; height: 16px; }

.tts-waveform-wrap { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tts-waveform { display: flex; align-items: flex-end; gap: 1.5px; height: 28px; cursor: pointer; position: relative; }
.tts-waveform .tts-bar {
  flex: 1;
  min-width: 2px;
  max-width: 4px;
  background: var(--text-muted);
  border-radius: 1px;
  transition: background 0.05s;
  opacity: 0.5;
}
.tts-waveform .tts-bar.played { opacity: 1; background: var(--accent); }

.tts-time-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}
.tts-controls-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.tts-speed-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: all var(--transition);
  min-width: 38px;
}
.tts-speed-btn:hover { border-color: var(--accent); color: var(--pm-white); }
.tts-rewind-btn, .tts-forward-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  transition: color var(--transition);
}
.tts-rewind-btn:hover, .tts-forward-btn:hover { color: var(--pm-white); }
.tts-controls-spacer { flex: 1; }
.tts-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  transition: all var(--transition);
}
.tts-save-btn:hover { border-color: var(--accent); color: var(--pm-white); }
.tts-save-btn .icon { width: 12px; height: 12px; }

.tts-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}
.tts-loading-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}
.tts-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.tts-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 6px;
  padding: 8px 0;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* ===== Markdown ===== */
.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5 {
  margin: 14px 0 6px;
  font-family: var(--ff-display);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.message-content h3 { font-size: 1.18em; }
.message-content h4 { font-size: 1.08em; }
.message-content h5 { font-size: 1em; }
.message-content p { margin: 6px 0; }
.message-content p:first-child { margin-top: 0; }
.message-content p:last-child { margin-bottom: 0; }

.message-content ul, .message-content ol { padding-left: 22px; margin: 6px 0; }
.message-content li { margin: 3px 0; }

.message-content a {
  color: var(--accent-hover);
  text-decoration: none;
  border-bottom: 1px solid rgba(213, 98, 201, 0.4);
  transition: color var(--transition), border-color var(--transition);
}
.message-content a:hover {
  color: var(--pm-white);
  border-bottom-color: currentColor;
}

.message-content strong { font-weight: 600; color: var(--pm-white); }
.message-content em { font-style: italic; }

.message-content code {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", "JetBrains Mono", Consolas, monospace;
  font-size: 0.88em;
  border: 1px solid var(--border);
}

.message-content pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 10px 0;
  overflow: hidden;
  position: relative;
}
.message-content pre .code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: var(--ls-eyebrow);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}
.message-content pre code {
  display: block;
  padding: 14px;
  overflow-x: auto;
  background: none;
  border-radius: 0;
  border: 0;
  line-height: 1.5;
  font-size: 13px;
}

.copy-code-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all var(--transition);
  font-family: inherit;
}
.copy-code-btn:hover { background: var(--bg-hover); color: var(--pm-white); }

.message-content blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 14px;
  margin: 10px 0;
  color: var(--text-secondary);
  font-style: italic;
}
.message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 14px;
}
.message-content th, .message-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.message-content th {
  background: var(--bg-tertiary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: var(--ls-eyebrow);
  color: var(--text-secondary);
}

/* ===== Attachments preview ===== */
.attachments-preview {
  display: flex;
  gap: 8px;
  padding: 8px 20px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}
.attachments-preview.hidden { display: none; }

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  max-width: 220px;
}
.attachment-chip img { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; }
.attachment-chip .attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip .btn-icon { padding: 2px; }
.attachment-chip .btn-icon .icon { width: 12px; height: 12px; }

/* ===== Input area ===== */
.input-area {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
}
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
  transition: border-color var(--transition);
}
.input-bar:focus-within { border-color: var(--accent); }

.input-bar textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--ff-body);
  line-height: 1.5;
  padding: 8px 10px;
  resize: none;
  outline: none;
  max-height: 200px;
  min-height: 24px;
  letter-spacing: -0.005em;
}
.input-bar textarea::placeholder { color: var(--text-muted); }

/* ===== Realtime overlay ===== */
.realtime-overlay {
  position: absolute;
  inset: 0;
  background: var(--pm-gradient-deep);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  z-index: 5;
}
.realtime-overlay.hidden { display: none; }

.realtime-orb {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--pm-purple-400) 0%, var(--pm-purple-700) 60%, transparent 80%);
  box-shadow: 0 0 80px rgba(196, 0, 173, 0.45),
              0 0 160px rgba(115, 0, 139, 0.35);
  animation: orbPulse 2.4s ease-in-out infinite;
}

.realtime-transcript {
  max-width: 540px;
  text-align: center;
  color: var(--pm-white);
  font-family: var(--ff-display);
  font-weight: 400;
  font-size: 18px;
  letter-spacing: -0.01em;
  line-height: 1.4;
  min-height: 56px;
  padding: 0 24px;
}

.realtime-controls { display: flex; gap: 24px; }
.realtime-controls .btn-icon.btn-round {
  background: rgba(255, 255, 255, 0.06);
  color: var(--pm-white);
  border: 1px solid var(--border-strong);
}
.realtime-controls .btn-icon.btn-round:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent);
}
.realtime-controls .btn-icon.btn-danger {
  background: var(--error);
  color: var(--pm-white);
  border-color: var(--error);
}
.realtime-controls .btn-icon.btn-danger:hover { background: #e85a7c; }

.realtime-timer {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 11, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.modal-content {
  position: relative;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--pm-white);
}

.modal-body {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-footer {
  padding: 18px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

/* ===== Forms (settings modal) ===== */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--ls-eyebrow);
  color: var(--text-muted);
}
.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: -2px;
  margin-bottom: 4px;
}

.models-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.models-meta-row .form-hint {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}
.models-meta-row .btn-sm {
  margin-top: 0;
  flex: 0 0 auto;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 8px 0;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--ff-body);
  letter-spacing: -0.005em;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-bottom-color: var(--accent); }

.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239D9DA6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right center;
  background-size: 16px;
  padding-right: 24px;
  cursor: pointer;
}
.form-group select option { background: var(--bg-modal); color: var(--text-primary); }

.form-group textarea { resize: vertical; min-height: 64px; }

.form-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: var(--border);
  height: 2px;
  padding: 0;
  border-radius: 0;
  width: 100%;
  margin-top: 6px;
}
.form-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 0;
}
.form-group input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 0;
}

.input-with-action { display: flex; gap: 8px; align-items: flex-end; }
.input-with-action input { flex: 1; }
.input-with-action .btn-icon { padding: 6px; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1), fadeOut 0.4s ease 2.6s;
  animation-fill-mode: forwards;
  max-width: 420px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--bg-modal);
  color: var(--text-primary);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.toast.error { border-color: rgba(255, 123, 156, 0.5); color: var(--error); }
.toast.success { border-color: rgba(107, 209, 107, 0.5); color: var(--success); }
.toast.warning { border-color: rgba(229, 255, 58, 0.5); color: var(--warning); }
.toast.info { border-color: rgba(196, 0, 173, 0.5); color: var(--accent-hover); }

/* ===== Context menu ===== */
.context-menu {
  position: fixed;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  z-index: 50;
  min-width: 160px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}
.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item .icon { width: 14px; height: 14px; }
.context-menu-item.danger { color: var(--error); }

/* ===== Drag and drop ===== */
.drag-over {
  border: 2px dashed var(--accent) !important;
  background: rgba(196, 0, 173, 0.06) !important;
}

/* ===== Hidden ===== */
.hidden { display: none !important; }

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-4px); }
}
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
@keyframes orbPulse {
  0%, 100% { transform: scale(1); filter: brightness(0.95); }
  50% { transform: scale(1.12); filter: brightness(1.1); }
}

@media (prefers-reduced-motion: reduce) {
  .realtime-orb { animation: none; opacity: 0.95; }
  .typing-indicator span,
  .tts-loading-dots span { animation: none; opacity: 0.7; }
  .toast { animation: none; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  html, body {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
  }
  body { display: block; }

  #chat-area {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: auto;
  }
  .messages { touch-action: pan-y; -webkit-overflow-scrolling: touch; }

  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width);
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #sidebar.open { transform: translateX(0); }

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

  .chat-header {
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    gap: 10px;
    min-height: calc(48px + env(safe-area-inset-top));
    flex-shrink: 0;
  }
  .chat-header h1 { font-size: 16px; }
  .chat-header-actions select { font-size: 12px; padding: 4px 6px; max-width: 110px; }

  .messages { padding: 16px 12px; gap: 14px; }
  .message { max-width: 100%; gap: 10px; }
  .message-avatar { width: 28px; height: 28px; font-size: 11px; }
  .message-content { padding: 10px 12px; font-size: 15px; overflow-x: auto; }
  .message-content pre { max-width: calc(100vw - 80px); }
  .message-content pre code { font-size: 13px; }
  .message-actions { opacity: 1; }

  .input-area {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    flex-shrink: 0;
  }
  .input-bar { max-width: 100%; gap: 2px; padding: 4px; }
  .input-bar textarea { font-size: 16px; padding: 8px 6px; }
  .input-bar .btn-icon { padding: 6px; min-width: 32px; min-height: 32px; flex-shrink: 0; }
  .input-bar .btn-icon .icon { width: 17px; height: 17px; }
  .input-bar .btn-icon.btn-primary { width: 32px; height: 32px; }

  .attachments-preview { padding: 6px 10px; }

  .modal-content {
    width: 92%;
    max-height: 80vh;
    max-height: 80dvh;
    margin-top: env(safe-area-inset-top);
  }

  .realtime-overlay {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .realtime-orb { width: 100px; height: 100px; }

  .tts-audio-message { min-width: auto; max-width: 100%; }

  .sidebar-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

  .welcome-screen { padding: 24px 16px; }
  .welcome-screen h2 { font-size: 28px; }
  .welcome-screen p { font-size: 15px; }
}

@media (max-width: 380px) {
  .chat-header h1 { font-size: 14px; }
  .chat-header-actions select { max-width: 90px; font-size: 11px; }
  .message-avatar { width: 24px; height: 24px; font-size: 10px; }
  .message-content { padding: 8px 10px; }
  .tts-controls-row { flex-wrap: wrap; }
}
