/* ==========================================================================
   Themes
   Every color in the app comes from the variables below. The page's <html>
   element carries data-theme="<name>". Each theme block defines the full set
   of variables, so any element can carry its own data-theme too (the theme
   preview cards in Settings use this).

   Order matters: light base -> light themes -> dark base -> dark themes ->
   System in dark mode (last, so it wins when the device is dark).
   ========================================================================== */

/* ---------- Light base (also the Teal theme, the default) ---------- */
:root,
[data-theme="teal"],
[data-theme="light"],
[data-theme="system"],
[data-theme="ocean"],
[data-theme="forest"],
[data-theme="sunset"] {
  color-scheme: light;
  --bg: #f3f1ee;
  --surface: #ffffff;
  --sidebar: #ebe8e3;
  --border: #d6d1c9;
  --text: #1f2a2a;
  --muted: #5f6664;
  --accent: #0f5c5c;
  --accent-hover: #0b4747;
  --accent-soft: #e3eeee;
  --accent-text: #0f5c5c;
  --on-accent: #ffffff;
  --hover: rgba(15, 92, 92, 0.08);
  --user-bubble: #e3eeee;
  --user-border: #c6dcdc;
  --error-bg: #fdecec;
  --error-border: #f0b9b9;
  --error-text: #9b1c1c;
  --ok-bg: #e6f4ea;
  --ok-border: #b5dcc0;
  --ok-text: #1e6b34;
  --shadow: rgba(0, 0, 0, 0.05);
  --backdrop: rgba(0, 0, 0, 0.3);
  --code-bg: #1e2626;
  --code-header: #273232;
  --code-text: #e6efef;
  --code-muted: #a9bcbc;
  --code-border: #3d4c4c;
  --sandbox-bg: #e3eef8;
  --sandbox-text: #1d4f7a;
  --sandbox-border: #b9d3ea;
  --prod-bg: #fdf0dc;
  --prod-text: #7f4500;
  --prod-border: #f0c98a;
  --danger: #b42318;
  --danger-hover: #912018;
  --danger-text: #b42318;
}

/* ---------- Light: neutral greys with a slate accent ---------- */
[data-theme="light"],
[data-theme="system"] {
  --bg: #f5f6f7;
  --sidebar: #eceef0;
  --border: #d5dade;
  --text: #1d2125;
  --muted: #586069;
  --accent: #2f3b48;
  --accent-hover: #1f2933;
  --accent-soft: #e6eaee;
  --accent-text: #2f3b48;
  --hover: rgba(47, 59, 72, 0.08);
  --user-bubble: #e9edf1;
  --user-border: #cfd6dd;
}

/* ---------- Ocean: blue accent ---------- */
[data-theme="ocean"] {
  --bg: #eef3f8;
  --sidebar: #e2eaf3;
  --border: #c9d6e4;
  --text: #142233;
  --muted: #4f5e70;
  --accent: #1b5a9e;
  --accent-hover: #144778;
  --accent-soft: #dde9f6;
  --accent-text: #174f8c;
  --hover: rgba(27, 90, 158, 0.08);
  --user-bubble: #dde9f6;
  --user-border: #bcd2ea;
}

/* ---------- Forest: green accent ---------- */
[data-theme="forest"] {
  --bg: #f1f4ef;
  --sidebar: #e5ebe2;
  --border: #cdd7c7;
  --text: #1b261c;
  --muted: #556356;
  --accent: #2e6b3c;
  --accent-hover: #23542f;
  --accent-soft: #e0ece2;
  --accent-text: #285f35;
  --hover: rgba(46, 107, 60, 0.08);
  --user-bubble: #e0ece2;
  --user-border: #c3d9c8;
}

/* ---------- Sunset: warm orange accent ---------- */
[data-theme="sunset"] {
  --bg: #faf4ee;
  --sidebar: #f3e8dd;
  --border: #e3d0bd;
  --text: #2b1d14;
  --muted: #6b5747;
  --accent: #a8401a;
  --accent-hover: #883313;
  --accent-soft: #f8e3d6;
  --accent-text: #963a17;
  --hover: rgba(168, 64, 26, 0.08);
  --user-bubble: #f8e3d6;
  --user-border: #efc8b1;
}

/* ---------- Dark base (the Dark theme) ---------- */
[data-theme="dark"],
[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #181b1b;
  --surface: #222727;
  --sidebar: #1d2121;
  --border: #3a4242;
  --text: #e4e9e8;
  --muted: #a3adab;
  --accent: #127070;
  --accent-hover: #0e5c5c;
  --accent-soft: #1c3636;
  --accent-text: #6cc8c8;
  --on-accent: #ffffff;
  --hover: rgba(108, 200, 200, 0.1);
  --user-bubble: #1c3636;
  --user-border: #2b5151;
  --error-bg: #3a2020;
  --error-border: #6e3030;
  --error-text: #f4b4b4;
  --ok-bg: #1d3325;
  --ok-border: #2f5c3c;
  --ok-text: #a6e3b6;
  --shadow: rgba(0, 0, 0, 0.35);
  --backdrop: rgba(0, 0, 0, 0.55);
  --code-bg: #121616;
  --code-header: #1b2222;
  --code-text: #e6efef;
  --code-muted: #a9bcbc;
  --code-border: #334040;
  --sandbox-bg: #1b2d40;
  --sandbox-text: #9cc7ef;
  --sandbox-border: #2d4a66;
  --prod-bg: #3a2a12;
  --prod-text: #f5c27a;
  --prod-border: #6b4a1c;
  --danger: #b3261e;
  --danger-hover: #93201a;
  --danger-text: #ff9b93;
}

/* ---------- Midnight: dark blue, high contrast ---------- */
[data-theme="midnight"] {
  --bg: #0a0f1c;
  --surface: #131b2e;
  --sidebar: #0e1525;
  --border: #4a5d82;
  --text: #ffffff;
  --muted: #cfd8e6;
  --accent: #2459d6;
  --accent-hover: #1c47ad;
  --accent-soft: #1b2b52;
  --accent-text: #a9c8ff;
  --hover: rgba(169, 200, 255, 0.14);
  --user-bubble: #1b2b52;
  --user-border: #4466a8;
  --error-bg: #3d1218;
  --error-border: #a3394a;
  --error-text: #ffd0d0;
  --ok-bg: #0f3320;
  --ok-border: #2f8a55;
  --ok-text: #c2f5d2;
  --code-bg: #05080f;
  --code-header: #0e1525;
  --code-text: #f8fafc;
  --code-muted: #cfd8e6;
  --code-border: #33476e;
  --sandbox-bg: #10284a;
  --sandbox-text: #c4dcff;
  --sandbox-border: #3d68a8;
  --prod-bg: #3d2a08;
  --prod-text: #ffd899;
  --prod-border: #a8772a;
  --danger-text: #ffb0aa;
}

/* ---------- System: same as Dark when the device is in dark mode ---------- */
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    color-scheme: dark;
    --bg: #181b1b;
    --surface: #222727;
    --sidebar: #1d2121;
    --border: #3a4242;
    --text: #e4e9e8;
    --muted: #a3adab;
    --accent: #127070;
    --accent-hover: #0e5c5c;
    --accent-soft: #1c3636;
    --accent-text: #6cc8c8;
    --on-accent: #ffffff;
    --hover: rgba(108, 200, 200, 0.1);
    --user-bubble: #1c3636;
    --user-border: #2b5151;
    --error-bg: #3a2020;
    --error-border: #6e3030;
    --error-text: #f4b4b4;
    --ok-bg: #1d3325;
    --ok-border: #2f5c3c;
    --ok-text: #a6e3b6;
    --shadow: rgba(0, 0, 0, 0.35);
    --backdrop: rgba(0, 0, 0, 0.55);
    --code-bg: #121616;
    --code-header: #1b2222;
    --code-text: #e6efef;
    --code-muted: #a9bcbc;
    --code-border: #334040;
    --sandbox-bg: #1b2d40;
    --sandbox-text: #9cc7ef;
    --sandbox-border: #2d4a66;
    --prod-bg: #3a2a12;
    --prod-text: #f5c27a;
    --prod-border: #6b4a1c;
    --danger: #b3261e;
    --danger-hover: #93201a;
    --danger-text: #ff9b93;
  }
}

/* Non-color design tokens */
:root {
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
}

[hidden] { display: none !important; }

button, select, textarea { font: inherit; color: inherit; }

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Layout ---------- */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Sidebar ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 8px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  display: grid;
  place-items: center;
}

.brand-name { font-weight: 700; font-size: 17px; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
}

.new-chat:hover { border-color: var(--accent); color: var(--accent-text); }

.sidebar-heading {
  margin: 8px 6px 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

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

.conversation-list button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-list button:hover { background: var(--hover); }
.conversation-list button.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

.sidebar-empty { margin: 0 6px; font-size: 13px; color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }

.model-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.usage {
  font-size: 13px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  white-space: nowrap;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

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

.menu-btn { display: none; }

/* ---------- Center content ---------- */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
}

.welcome {
  max-width: 720px;
  margin: 12vh auto 0;
  text-align: center;
}

.welcome h1 { font-size: 28px; margin: 0 0 8px; line-height: 1.25; }
.welcome p { margin: 0 0 28px; color: var(--muted); }

.examples {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.example {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

.example:hover { border-color: var(--accent); color: var(--accent-text); }

/* ---------- Thread ---------- */
.thread {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-color: var(--user-border);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message.error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.code-block {
  margin: 8px 0;
  border-radius: 10px;
  background: var(--code-bg);
  color: var(--code-text);
  overflow: hidden;
  white-space: normal;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--code-muted);
  background: var(--code-header);
}

.copy-btn {
  border: 1px solid var(--code-border);
  border-radius: 6px;
  background: transparent;
  color: var(--code-text);
  font-size: 12px;
  padding: 3px 10px;
  cursor: pointer;
}

.copy-btn:hover { background: var(--code-border); }

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
}

.code-block code {
  font-family: var(--mono);
  font-size: 13.5px;
  white-space: pre;
}

/* Typing indicator */
.typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 16px 18px;
}

.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: blink 1.2s infinite ease-in-out;
}

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

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

/* ---------- Composer ---------- */
.composer-wrap {
  padding: 8px 20px 12px;
  background: var(--bg);
}

.composer {
  max-width: 820px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 12px 8px;
  box-shadow: 0 2px 10px var(--shadow);
}

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

.composer textarea {
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  padding: 6px 6px 8px;
  line-height: 1.45;
  max-height: 200px;
}

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.composer-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}

.select {
  max-width: 220px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  cursor: pointer;
}

.send-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.hint {
  margin: 6px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Phones ---------- */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  z-index: 9;
}

@media (max-width: 768px) {
  .menu-btn { display: inline-grid; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 16px var(--shadow);
  }

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

  .topbar { padding: 8px 12px; }
  .content { padding: 16px 12px; }
  .composer-wrap { padding: 6px 10px 10px; }
  .welcome { margin-top: 6vh; }
  .welcome h1 { font-size: 22px; }
  .message { max-width: 92%; }
  .select { max-width: 150px; }
}

/* ---------- Sign out (sidebar) ---------- */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 6px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.signed-in-as {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sign-out {
  flex-shrink: 0;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
}

.sign-out:hover { border-color: var(--accent); color: var(--accent-text); }

/* ---------- Login page ---------- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 4px 20px var(--shadow);
}

.login-card .brand { padding: 0 0 12px; }
.login-card h1 { font-size: 22px; margin: 4px 0 16px; }

.login-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--error-border);
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 14px;
}

.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form label { font-size: 14px; font-weight: 600; margin-top: 8px; }

.login-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font: inherit;
}

.login-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.login-btn {
  margin-top: 18px;
  padding: 11px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  cursor: pointer;
}

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

a.icon-btn { text-decoration: none; }
.link-btn { display: block; text-align: center; text-decoration: none; }

/* ---------- Settings page ---------- */
.settings-page { min-height: 100vh; }

.settings-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.settings-header h1 { margin: 0; font-size: 20px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px 6px 4px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.back-link:hover { background: var(--hover); color: var(--accent-text); }

.settings-layout {
  display: flex;
  gap: 24px;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px;
}

.settings-nav {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-tab {
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

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

.settings-panels { flex: 1; min-width: 0; }

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: 0 2px 10px var(--shadow);
}

.settings-card h2 { margin: 0 0 6px; font-size: 18px; }
.settings-card p { margin: 0 0 8px; }
.settings-help { color: var(--muted); }

.theme-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 16px 0 0;
  padding: 0;
  border: 0;
}

.theme-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 8px 10px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

.theme-card:hover { border-color: var(--accent); }
.theme-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.theme-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The radio stays in the page for keyboards and screen readers. */
.theme-card input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.theme-card-name { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-weight: 600; font-size: 14px; }
.theme-card-note { font-size: 12px; color: var(--muted); font-weight: 400; }

.theme-check {
  display: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  place-items: center;
  flex-shrink: 0;
}

.theme-check svg { width: 12px; height: 12px; stroke-width: 3; }
.theme-card:has(input:checked) .theme-check { display: inline-grid; }

/* Mini preview. Each part carries its own data-theme, so it uses that
   theme's variables rather than the page's. */
.theme-preview {
  display: flex;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.theme-preview-half {
  flex: 1;
  display: flex;
  background: var(--bg);
  min-width: 0;
}

.theme-preview-side { width: 26%; background: var(--sidebar); border-right: 1px solid var(--border); }

.theme-preview-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 7px;
  gap: 4px;
  min-width: 0;
}

.theme-preview-bubble { height: 9px; width: 70%; border-radius: 4px; background: var(--surface); border: 1px solid var(--border); }
.theme-preview-bubble.user { align-self: flex-end; width: 50%; background: var(--user-bubble); border-color: var(--user-border); }
.theme-preview-bar { display: flex; justify-content: flex-end; height: 12px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); padding: 1px; }
.theme-preview-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }


.settings-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 420px;
  margin-top: 10px;
}

.settings-form label,
.settings-form .field-label { font-size: 14px; font-weight: 600; margin-top: 10px; }

.settings-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.settings-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.settings-form input[readonly] { color: var(--muted); cursor: default; }
.settings-form input[readonly]:focus { outline: none; border-color: var(--border); }

.field-note { font-size: 13px; color: var(--muted); margin: 0; }
.readonly-value { margin: 0; color: var(--muted); }

.primary-btn {
  align-self: flex-start;
  margin-top: 16px;
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  cursor: pointer;
}

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

.settings-status { min-height: 1.4em; margin-top: 10px; font-size: 14px; color: var(--ok-text); }
.settings-status.status-error { color: var(--error-text); }

.notice {
  margin: 10px 0 4px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid;
  font-size: 14px;
}

.notice-ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }
.notice-error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }

.login-form input { color: var(--text); }

@media (max-width: 768px) {
  .settings-header { padding: 10px 12px; }
  .settings-layout { flex-direction: column; gap: 14px; padding: 14px 12px; }
  .settings-nav { width: auto; flex-direction: row; overflow-x: auto; }
  .settings-tab { white-space: nowrap; }
  .settings-card { padding: 18px 16px; }
}

/* ---------- Connections ---------- */
.settings-card h3 { margin: 4px 0 6px; font-size: 16px; }

.divider { border: 0; border-top: 1px solid var(--border); margin: 24px 0 18px; }

.org-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.org-item {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.org-main { min-width: 0; flex: 1 1 240px; }
.org-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.org-label { font-weight: 600; overflow-wrap: anywhere; }
.org-url { margin-top: 2px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.org-status { margin-top: 6px; font-size: 14px; display: flex; align-items: center; gap: 6px; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-connected { background: var(--ok-text); }
.status-expired { background: var(--prod-text); }

.org-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.org-item .org-edit-form,
.org-item .confirm-box,
.org-item .org-test-status { flex-basis: 100%; }
.org-item .org-test-status:empty { display: none; }

.confirm-box {
  padding: 12px 14px;
  border: 1px solid var(--error-border);
  border-radius: 10px;
  background: var(--error-bg);
  color: var(--error-text);
}

.confirm-box p { margin: 0 0 10px; }

.env-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--sandbox-border);
  background: var(--sandbox-bg);
  color: var(--sandbox-text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.env-badge.env-production {
  border-color: var(--prod-border);
  background: var(--prod-bg);
  color: var(--prod-text);
}

.secondary-btn,
.danger-btn,
.small-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.secondary-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.secondary-btn:hover { border-color: var(--accent); color: var(--accent-text); }
.danger-btn { border: 1px solid var(--danger-text); background: var(--surface); color: var(--danger-text); }
.danger-btn:hover { border-color: var(--danger); background: var(--danger); color: var(--on-accent); }
.secondary-btn:disabled, .danger-btn:disabled, .primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.primary-btn.small-btn { margin-top: 0; align-self: auto; display: inline-block; }

.form-buttons { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-buttons .primary-btn { margin-top: 0; }
.org-edit-form .form-buttons { margin-top: 14px; }

.form-select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.copy-field { display: flex; gap: 8px; }
.copy-field input { flex: 1; min-width: 0; }

/* Selected org shown in the chat input bar */
.org-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 3px 4px 3px 10px;
  border: 1px solid var(--sandbox-border);
  border-radius: 999px;
  background: var(--sandbox-bg);
  color: var(--sandbox-text);
  font-size: 12px;
  font-weight: 600;
}

.org-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.org-chip .env-badge { font-size: 11px; padding: 1px 7px; }
.org-chip.org-chip-production { border-color: var(--prod-border); background: var(--prod-bg); color: var(--prod-text); }

/* ---------- Back to home (Immotus main site) ---------- */
.home-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 4px 12px 4px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.home-link svg { width: 18px; height: 18px; }
.home-link:hover { border-color: var(--accent); color: var(--accent-text); }
.home-link-login { margin-bottom: 16px; }

@media (max-width: 768px) {
  .home-link { padding: 4px 8px 4px 4px; }
  .home-link-text { display: none; }   /* icon only on phones; aria-label keeps the name */
}

/* ---------- Attachments (paperclip, drag-and-drop, paste) ---------- */
.composer { position: relative; }

.attachment-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 2px 8px;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  padding: 6px 6px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.chip-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.chip-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-text);
  flex-shrink: 0;
}

.chip-icon svg { width: 22px; height: 22px; stroke-width: 1.6; }

.chip-ext {
  position: absolute;
  bottom: 2px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.chip-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.chip-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-meta { font-size: 12px; color: var(--muted); }

.chip-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.chip-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.15s linear;
}

.chip-remove {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.chip-remove:hover { background: var(--hover); color: var(--text); }

.attachment-error {
  margin: 0 4px 6px;
  font-size: 13px;
  color: var(--error-text);
}

.drop-hint {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 22px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
  pointer-events: none;
}

.composer.is-dragging .drop-hint { display: grid; }

/* File names under a sent message */
.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  white-space: normal;
}

.message-files li {
  padding: 2px 8px;
  border: 1px solid var(--user-border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  overflow-wrap: anywhere;
}

@media (max-width: 768px) {
  .attachment-chip { max-width: 100%; flex: 1 1 100%; }
}

/* ---------- Dictation (mic button) ---------- */
.mic-btn.is-listening {
  background: var(--danger);
  color: var(--on-accent);
  border-radius: 50%;
}

.mic-btn.is-listening:hover { background: var(--danger-hover); color: var(--on-accent); }

@media (prefers-reduced-motion: no-preference) {
  .mic-btn.is-listening { animation: mic-pulse 1.4s ease-out infinite; }
}

@keyframes mic-pulse {
  0% { box-shadow: 0 0 0 0 var(--danger); }
  70% { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.listening-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--danger-text);
  white-space: nowrap;
}

.select-compact { max-width: 92px; padding: 6px 4px; }

.voice-error {
  margin: 0 4px 6px;
  font-size: 13px;
  color: var(--error-text);
}

/* The text box and its overlay sit in the same place and use the same text
   settings, so the overlay lines up letter for letter. */
.input-wrap { position: relative; }

.dictation-mirror {
  position: absolute;
  inset: 0;
  display: none;
  padding: 6px 6px 8px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow: hidden;
  color: var(--text);
  pointer-events: none;
}

.dictation-mirror .interim { color: var(--muted); }

.input-wrap.is-dictating .dictation-mirror { display: block; }

.input-wrap.is-dictating textarea {
  color: transparent;
  caret-color: var(--text);
}

.input-wrap.is-dictating textarea::placeholder { color: transparent; }

/* ---------- Microphone picker (arrow next to the mic) ---------- */
.mic-group {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.mic-menu-btn {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 36px;
  margin-left: -4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.mic-menu-btn svg { width: 14px; height: 14px; }
.mic-menu-btn:hover,
.mic-menu-btn[aria-expanded="true"] { background: var(--hover); color: var(--accent-text); }
.mic-menu-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.mic-menu {
  position: absolute;
  bottom: calc(100% + 8px);   /* opens upward: the message box is at the bottom */
  left: 0;
  z-index: 20;
  width: 300px;
  max-width: calc(100vw - 32px);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 10px 30px var(--shadow);
}

.mic-meter-wrap { padding: 4px 6px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.mic-meter-label { display: block; margin-bottom: 6px; font-size: 12px; color: var(--muted); }

.mic-meter {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.mic-meter-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.06s linear;
}

.mic-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.mic-empty { padding: 8px; font-size: 13px; color: var(--muted); }

.mic-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.mic-item:hover,
.mic-item:focus-visible { background: var(--hover); outline: none; }
.mic-item:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }

.mic-check { width: 14px; flex-shrink: 0; color: var(--accent-text); font-weight: 700; visibility: hidden; }
.mic-item[aria-checked="true"] .mic-check { visibility: visible; }
.mic-item[aria-checked="true"] { font-weight: 600; }
.mic-item-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mic-note { margin: 8px 6px 2px; font-size: 12px; color: var(--muted); }

/* ---------- Voice mode ---------- */
.composer-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

body.voice-open { overflow: hidden; }

.voice-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
}

.voice-mic { margin: 0; font-size: 13px; color: var(--muted); text-align: center; max-width: 90%; }

.voice-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
  max-width: 680px;
  min-height: 0;
}

/* The orb grows with your voice while listening (--level is 0 to 1). */
.voice-orb {
  --level: 0;
  position: relative;
  width: min(200px, 50vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--accent-soft), var(--accent) 72%);
  box-shadow: 0 20px 60px var(--shadow);
  transform: scale(calc(1 + var(--level) * 0.3));
  transition: transform 0.08s linear;
}

.voice-orb-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .voice-overlay[data-state="thinking"] .voice-orb { animation: orb-breathe 1.6s ease-in-out infinite; }
  .voice-overlay[data-state="speaking"] .voice-orb { animation: orb-talk 0.9s ease-in-out infinite; }
  .voice-overlay[data-state="listening"] .voice-orb-ring { animation: orb-ring 2s ease-out infinite; }
}

@keyframes orb-breathe {
  0%, 100% { transform: scale(0.94); filter: saturate(0.8); }
  50% { transform: scale(1.02); filter: saturate(1.1); }
}

@keyframes orb-talk {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.08); }
  60% { transform: scale(0.98); }
}

@keyframes orb-ring {
  0% { opacity: 0.6; transform: scale(0.95); }
  100% { opacity: 0; transform: scale(1.25); }
}

.voice-overlay[data-state="muted"] .voice-orb,
.voice-overlay[data-state="paused"] .voice-orb,
.voice-overlay[data-state="error"] .voice-orb { filter: grayscale(1); opacity: 0.5; }

.voice-status { margin: 0; font-size: 20px; font-weight: 600; }

.voice-transcript {
  margin: 0;
  max-height: 30vh;
  overflow-y: auto;
  font-size: 17px;
  line-height: 1.5;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.voice-transcript[data-who="user"] { color: var(--muted); }

.voice-hint {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--error-border);
  border-radius: 10px;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 14px;
  text-align: center;
}

.voice-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  font-size: 13px;
  color: var(--muted);
}

.voice-name { font-weight: 600; color: var(--text); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-slider { display: inline-flex; align-items: center; gap: 6px; }
.voice-slider input { accent-color: var(--accent); width: 110px; }

.voice-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

.voice-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.voice-control:hover { border-color: var(--accent); color: var(--accent-text); }
.voice-control[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }

.voice-end { background: var(--danger); border-color: var(--danger); color: var(--on-accent); }
.voice-end:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: var(--on-accent); }

@media (max-width: 480px) {
  .voice-control { padding: 0 14px; }
  .voice-slider input { width: 80px; }
}
