/* ============================================================
   Night — web client for custom Ollama models
   Visual system derived from the Cosmic project (frontend/style.css):
   flat dark "deep-space terminal", blue-shifted greys, single azure
   accent, elevation by fill rather than shadow, alpha-tinted hovers.
   ============================================================ */

/* ---------- Font + base ---------- */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/inter-latin-var.woff2') format('woff2');
}
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* surfaces: blue-shifted greys, near-black upward */
  --bg: #0a0a0f;
  --bg-well: #0d0d13;
  --bg-chrome: #12121a;
  --bg-card: #14141c;
  --bg-panel: #151520;
  --bg-modal: #1a1a24;
  --bg-hover: #1d1d2b;

  --border: #333;
  --border-card: #26263a;
  --border-raised: #2f2f3f;
  --border-hair: rgba(255, 255, 255, 0.12);

  --text: #e5e5e5;
  --text-strong: #fff;
  --text-muted: #999;
  --text-faint: #666;

  --accent: #4da6ff;
  --accent-hover: #6bb8ff;
  --accent-light: #7fd1ff;
  --accent-text: #9cc7ff;
  --accent-deep: #2f80d6;
  --accent-wash: rgba(77, 166, 255, 0.18);

  --bubble-mine: #2f80d6;
  --bubble-theirs: #26263a;

  --ok: #6bff6b;
  --ok-bg: #1c3a1c;
  --warn: #ffcf6b;
  --err: #ff9b9b;
  --staff: #d8b4fe;
  --staff-bg: rgba(168, 85, 247, 0.18);

  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-xl: 12px;
  --r-panel: 14px;
  --r-pill: 999px;
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: var(--font-sans); }
/* A class that sets `display` outranks the UA's `[hidden]` rule, which would
   otherwise leave "hidden" forms on screen. */
[hidden] { display: none !important; }
html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
}
button, input, select, textarea, option { font-family: inherit; }
/* Only icon-only buttons need line-height:0 (to kill the inline baseline gap);
   setting it globally squashes the label on text buttons. */
.icon-btn { line-height: 0; }

/* ---------- Top bar (mirrors Cosmic's fixed navbar) ---------- */
.navbar {
  background: var(--bg-chrome);
  padding: 0.7rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border-card);
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 0 0 auto;
}
.navbar-mark {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2b4a7d, #16233a);
  border: 1px solid #2f4a7d;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-text);
  font-weight: 600;
  font-size: 0.72rem;
  flex: 0 0 auto;
}
.navbar-title { font-size: 0.95rem; font-weight: 600; color: var(--text-strong); letter-spacing: 0.02em; }
.navbar-sub { font-size: 0.7rem; color: var(--text-faint); letter-spacing: 0.04em; text-transform: uppercase; }

.navbar-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* Ghost outline button — Cosmic's default navbar button */
.btn {
  background: var(--bg-modal);
  border: 1px solid #2a2a3d;
  padding: 0.45rem 0.85rem;
  border-radius: var(--r-md);
  color: #cfcfda;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.btn:hover:not(:disabled) { background: #25253a; color: var(--accent); border-color: var(--accent); }
.btn:active:not(:disabled) { background: #2a2a3d; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); color: #fff; border-color: var(--accent-hover); }
/* Secondary tinted button */
.btn-secondary { background: #101a2b; border-color: #23395c; color: var(--accent-text); }
.btn-secondary:hover:not(:disabled) { background: #16243c; border-color: var(--accent); color: #cfe3ff; }

/* Model picker */
.model-picker { display: flex; align-items: center; gap: 0.45rem; }
.model-picker label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
select {
  background: var(--bg-well);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-strong);
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  max-width: 15rem;
}
select:focus { outline: none; border-color: var(--accent); }

/* ---------- Sign-in gate ---------- */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: none;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 2rem 1rem;
  background: radial-gradient(120% 80% at 50% 0%, #14142a 0%, var(--bg) 60%);
}
.auth-gate.show { display: flex; }
.auth-card {
  background: var(--bg-modal);
  border: 1px solid var(--border-raised);
  border-radius: var(--r-panel);
  padding: 1.6rem;
  width: 400px;
  max-width: 100%;
  margin: auto;
  animation: slideIn 0.3s ease;
}
.auth-brand { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1.25rem; }
.auth-tabs {
  display: flex;
  gap: 0.25rem;
  background: #232327;
  border-radius: var(--r-md);
  padding: 0.2rem;
  margin-bottom: 1rem;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 0.45rem;
  border-radius: var(--r-sm);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.auth-tab:hover { color: var(--text-strong); }
.auth-tab.active { background: var(--accent-deep); color: #fff; }
.auth-sub { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; line-height: 1.45; }
.auth-form { display: flex; flex-direction: column; }
.auth-form .field { margin-bottom: 0.9rem; }
.auth-submit { width: 100%; padding: 0.7rem; margin-top: 0.2rem; line-height: 1.2; }
.auth-error { color: var(--err); font-size: 0.78rem; margin-top: 0.6rem; min-height: 1em; }
.auth-note {
  color: var(--accent-text);
  font-size: 0.74rem;
  margin-top: 0.6rem;
  line-height: 1.45;
  word-break: break-all;
}
.auth-back {
  background: transparent;
  border: 1px solid var(--border-raised);
  color: var(--text-muted);
  padding: 0.5rem;
  border-radius: var(--r-sm);
  font-size: 0.78rem;
  cursor: pointer;
  margin-top: 0.5rem;
}
.auth-back:hover { border-color: var(--accent); color: var(--accent-text); }
.auth-note-shared {
  background: #1c3a5e;
  border: 1px solid #2d5a8e;
  color: #cfe6ff;
  border-radius: var(--r-sm);
  padding: 0.55rem 0.65rem;
  margin-top: 0.9rem;
  word-break: normal;
}
.auth-note-shared code {
  font-family: var(--font-mono);
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--r-sm);
  padding: 0.05rem 0.25rem;
  word-break: break-all;
}
.auth-foot {
  margin-top: 1.25rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border-card);
  font-size: 0.68rem;
  color: var(--text-faint);
  text-align: center;
  letter-spacing: 0.03em;
}

/* ---------- Workspace: sidebar + chat ---------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}
.sidebar {
  width: 240px;
  flex: 0 0 auto;
  border-right: 1px solid var(--border-card);
  background: var(--bg-chrome);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border-card);
}
.sidebar-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.chat-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0.5rem; }
.chat-list-empty { color: var(--text-faint); font-size: 0.78rem; padding: 0.75rem; text-align: center; }

/* Reuses Cosmic's conversation-item look: hover lifts, active gets an accent edge. */
.chat-item {
  padding: 0.6rem 0.65rem;
  border-radius: var(--r-md);
  cursor: pointer;
  margin-bottom: 0.35rem;
  background: #15151f;
  transition: background 0.2s;
  border-left: 3px solid transparent;
  position: relative;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-hover); border-left-color: var(--accent); }
.chat-item-title {
  font-size: 0.82rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 1rem;
}
.chat-item-meta {
  font-size: 0.68rem;
  color: var(--text-faint);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item-del {
  position: absolute;
  top: 0.4rem;
  right: 0.35rem;
  background: transparent;
  border: 0;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.1rem 0.25rem;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}
.chat-item:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { color: var(--accent-light); }

.sidebar-toggle {
  display: none;
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 20;
  background: var(--bg-modal);
  border: 1px solid var(--border-raised);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0 0.5rem;
  border-bottom: 1px solid var(--border-card);
  margin-bottom: 0.4rem;
  flex: 0 0 auto;
}
.chat-head-title {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- User menu ---------- */
.user-menu { position: relative; }
.user-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 200px;
  background: var(--bg-card);
  border: 1px solid var(--border-raised);
  border-radius: var(--r-lg);
  padding: 0.3rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  z-index: 120;
}
.user-popover-head { padding: 0.5rem 0.6rem 0.6rem; border-bottom: 1px solid var(--border-card); margin-bottom: 0.25rem; }
.user-popover-name { font-size: 0.85rem; color: var(--text-strong); font-weight: 500; }
.user-popover-mail { font-size: 0.72rem; color: var(--text-faint); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.user-popover-item {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text);
  text-align: left;
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.user-popover-item:hover { background: var(--accent-wash); color: #fff; }

/* ---------- Layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding-top: 58px;
}
.app[hidden] { display: none; }
.chat-column {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 1rem;
}

/* ---------- Message thread ---------- */
.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 0.5rem;
}
.thread-empty {
  color: var(--text-faint);
  text-align: center;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 2rem 1rem;
}
.thread-empty svg { opacity: 0.5; }
.thread-empty h2 { font-size: 1.35rem; font-weight: 400; color: var(--text-strong); }
.thread-empty p { font-size: 0.9rem; opacity: 0.7; max-width: 30rem; line-height: 1.5; }
.thread-empty code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--bg-modal);
  border: 1px solid var(--border-raised);
  border-radius: var(--r-sm);
  padding: 0.05rem 0.3rem;
  color: var(--accent-text);
}

.turn { display: flex; gap: 0.55rem; align-items: flex-end; max-width: 100%; }
.turn.mine { flex-direction: row-reverse; }
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #2b4a7d, #16233a);
  color: #cfe3ff;
  font-weight: 600;
  flex: 0 0 auto;
  border: 1px solid #2f4a7d;
}
.avatar-sm { width: 28px; height: 28px; font-size: 0.7rem; }
.avatar-letter { line-height: 1; }

/* Signature Cosmic bubble: 12px radius with the tail corner squared to 3px. */
.bubble {
  max-width: min(78%, 46rem);
  padding: 0.55rem 0.8rem;
  border-radius: var(--r-xl);
  font-size: 0.92rem;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble.mine {
  background: var(--bubble-mine);
  color: #fff;
  border-bottom-right-radius: var(--r-sm);
}
.bubble.theirs {
  background: var(--bubble-theirs);
  color: #eee;
  border-bottom-left-radius: var(--r-sm);
}
.bubble.streaming { border-bottom-left-radius: var(--r-sm); }
.bubble-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.4rem;
  font-size: 9px;
  opacity: 0.7;
}
.bubble-mine .bubble-meta { justify-content: flex-end; }
.bubble-stats { font-variant-numeric: tabular-nums; }
.bubble-error {
  background: #241a1a;
  border: 1px solid var(--accent);
  color: var(--err);
  font-size: 0.85rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--r-md);
  margin: 0.5rem auto 0;
  max-width: 46rem;
}
.bubble-error code { font-family: var(--font-mono); font-size: 0.8rem; }

/* Typing caret while the model is generating */
.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent-light);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* ---------- Rendered markdown ---------- */
.bubble .md > * + * { margin-top: 0.6rem; }
.md h1, .md h2, .md h3, .md h4 { color: var(--text-strong); font-weight: 600; line-height: 1.3; }
.md h1 { font-size: 1.2rem; }
.md h2 { font-size: 1.1rem; }
.md h3 { font-size: 1rem; }
.md p { line-height: 1.55; }
.md ul, .md ol { padding-left: 1.3rem; line-height: 1.55; }
.md li + li { margin-top: 0.25rem; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md blockquote {
  border-left: 2px solid var(--accent-deep);
  padding-left: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}
.md hr { border: 0; border-top: 1px solid var(--border-raised); margin: 0.8rem 0; }
.md code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-raised);
  border-radius: var(--r-sm);
  padding: 0.08rem 0.32rem;
}
.md pre {
  background: #0b0b12;
  border: 1px solid var(--border-raised);
  border-radius: var(--r-lg);
  padding: 0.8rem;
  overflow-x: auto;
  line-height: 1.45;
}
.md pre code { background: none; border: 0; padding: 0; font-size: 0.82rem; }
.bubble.mine .md code { background: rgba(0, 0, 0, 0.22); border-color: rgba(255, 255, 255, 0.2); }
.bubble.mine .md a { color: #dceaff; }
.bubble.mine .md pre { background: rgba(0, 0, 0, 0.28); border-color: rgba(255, 255, 255, 0.18); }
.md table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
.md th, .md td { border: 1px solid var(--border-raised); padding: 0.35rem 0.5rem; text-align: left; }
.md th { background: rgba(255, 255, 255, 0.04); color: var(--text-strong); }

/* Copy button injected into each code block */
.code-wrap { position: relative; }
.code-copy {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border-raised);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  padding: 0.2rem 0.45rem;
  font-size: 0.65rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
  line-height: 1.4;
}
.code-wrap:hover .code-copy { opacity: 1; }
.code-copy:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Composer ---------- */
.composer {
  border-top: 1px solid var(--border-card);
  padding: 0.7rem 0 0.85rem;
  background: var(--bg);
}
.composer-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.composer textarea {
  flex: 1;
  background: var(--bg-well);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0.65rem 0.8rem;
  color: var(--text-strong);
  font-size: 0.92rem;
  line-height: 1.45;
  resize: none;
  max-height: 12rem;
  /* 44px is the smallest reliably tappable target. */
  min-height: 44px;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer textarea::placeholder { color: var(--text-faint); }
.composer-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.45rem;
  font-size: 0.68rem;
  color: var(--text-faint);
  flex-wrap: wrap;
}
.composer-hint kbd {
  font-family: var(--font-sans);
  background: var(--bg-modal);
  border: 1px solid var(--border-raised);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  padding: 0 0.3rem;
  font-size: 0.65rem;
}
.stop-btn {
  background: #24243a;
  border: 1px solid var(--border-raised);
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: var(--r-md);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 44px;
}
.stop-btn:hover { border-color: var(--accent); color: var(--accent-light); }

/* ---------- Settings modal (Cosmic modal pattern) ---------- */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  justify-content: center;
  /* flex-start + margin:auto centres the panel while it fits and top-aligns it
     once it does not; align-items:center would push half of it off-screen. */
  align-items: flex-start;
  overflow-y: auto;
  padding: 1rem;
  z-index: 200;
}
.modal.active { display: flex; }
.modal-content {
  background: var(--bg-modal);
  padding: 1.6rem;
  border-radius: var(--r-lg);
  width: 460px;
  max-width: 100%;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  /* Scrolling the panel should not chain to the page behind the overlay. */
  overscroll-behavior: contain;
  margin: auto;
  position: relative;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
.modal-close {
  position: absolute;
  top: 0.9rem;
  right: 1.1rem;
  background: transparent;
  border: 0;
  color: var(--text-faint);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}
.modal-close:hover { color: #fff; }
.modal h3 { font-size: 1.15rem; color: var(--text-strong); margin-bottom: 0.3rem; font-weight: 500; }
.modal .modal-sub { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 1.1rem; }
.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.field textarea, .field input {
  width: 100%;
  background: var(--bg-well);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-strong);
  padding: 0.65rem 0.7rem;
  font-size: 0.9rem;
}
.field textarea { min-height: 90px; resize: vertical; line-height: 1.45; }
.field textarea:focus, .field input:focus { outline: none; border-color: var(--accent); }
.field .field-note { font-size: 0.68rem; color: var(--text-faint); margin-top: 0.3rem; }
.field-row { display: flex; gap: 0.75rem; }
.field-row .field { flex: 1; margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.4rem; }

/* ---------- Status banner ---------- */
/* Sits in flow directly below the fixed navbar, inside .app. */
.banner {
  display: none;
  background: #1c3a5e;
  color: #cfe6ff;
  border-bottom: 1px solid #2d5a8e;
  padding: 0.55rem 1rem;
  font-size: 0.78rem;
  font-weight: 500;
  text-align: center;
  flex: 0 0 auto;
}
.banner.show { display: block; }
.banner-warning { background: #5e4a1c; color: #ffe9b8; border-bottom-color: #8e732d; }
.banner code {
  font-family: var(--font-mono);
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--r-sm);
  padding: 0.05rem 0.3rem;
}

/* ---------- Spinner (Cosmic's cp-spin) ---------- */
.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--accent-light);
  animation: cp-spin 0.85s linear infinite;
  display: inline-block;
  vertical-align: -4px;
}
@keyframes cp-spin { to { transform: rotate(360deg); } }

/* ---------- Cosmic's workhorse small button ---------- */
.tiny-btn {
  background: #222; color: #888;
  padding: 0.25rem 0.5rem; border-radius: var(--r-sm);
  font-size: 0.65rem; cursor: pointer; border: none;
  line-height: 1.4;
}
.tiny-btn:hover { background: #333; color: var(--text); }
.tiny-btn.danger { background: #14243d; color: #8ec6ff; }
.tiny-btn.danger:hover { background: #1b3557; }

/* ---------- Badges ---------- */
.tiny-badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: var(--r-pill);
  border: 1px solid rgba(255, 255, 255, 0.25);
  opacity: 0.85;
  white-space: nowrap;
}

/* ---------- Focus visibility ---------- */
.btn:focus-visible, .stop-btn:focus-visible, .nav-toggle:focus-visible,
select:focus-visible, .code-copy:focus-visible, .modal-close:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------- Highlight.js — recoloured to Cosmic's palette ---------- */
.hljs { color: #ddd; background: transparent; }
.hljs-comment, .hljs-quote { color: #5c6b7a; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag { color: #d8b4fe; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #9cc7ff; }
.hljs-number, .hljs-symbol, .hljs-bullet { color: #ffd27a; }
.hljs-title, .hljs-section, .hljs-name { color: #7fd1ff; }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable { color: #ffcf6b; }
.hljs-type, .hljs-class .hljs-title, .hljs-built_in { color: #6bb8ff; }
.hljs-meta { color: #7d8b99; }
.hljs-deletion { color: #ff9b9b; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* ---------- Mobile ---------- */
@media (max-width: 700px) {
  .navbar { padding: 0.6rem 0.75rem; gap: 0.5rem; }
  .navbar-sub { display: none; }
  .navbar-actions { gap: 0.35rem; }
  select { max-width: 7.5rem; font-size: 0.75rem; }
  .btn { padding: 0.45rem 0.6rem; font-size: 0.75rem; }
  .chat-column { padding: 0 0.6rem; }
  .bubble { max-width: 88%; }
  .composer-foot { font-size: 0.65rem; }
  .modal-content { padding: 1.25rem; }

  /* Sidebar becomes an overlay drawer, the pattern Cosmic uses for mobile nav. */
  .sidebar-toggle { display: block; }
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: min(16rem, 84vw);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.55);
    transform: translateX(-102%);
    transition: transform 0.24s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body:not(.sidebar-open) .sidebar { visibility: hidden; }
  .chat-head { padding-left: 2.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: rgba(255, 255, 255, 0.22); border-right-color: #fff; }
  .caret { animation: none; }
  .modal-content { animation: none; }
}