/*
  Sunrise Glass Chat — Styles
  Visual goals:
  - Warm sunrise gradient background with moving rays and subtle grain
  - Glassmorphism surfaces with frosted blur, inner highlights, and refraction accents
  - Soft micro-interactions and accessible contrast
*/

:root {
  --sunrise: linear-gradient(180deg, var(--bg-sky) 0%, var(--bg-lilac) 30%, var(--bg-rose) 60%, var(--bg-peach) 85%, var(--bg-gold) 100%);
  --bg-rose: #ffb3a7;
  --bg-peach: #ffcf9f;
  --bg-gold: #ffd873;
  --bg-sky: #d1f0ff;
  --bg-lilac: #e7d9ff;
  /* Glassmorphic white-alpha gradient like Flutter examples */
  --glass-grad: linear-gradient(135deg, rgba(255,255,255,0.20), rgba(255,255,255,0.10));
  --glass: rgba(255, 255, 255, 0.36);
  --glass-deep: rgba(255, 255, 255, 0.18);
  --glass-stroke: rgba(255, 255, 255, 0.55);
  --text-strong: #2a1e16;
  --text-dim: rgba(42, 30, 22, 0.72);
  --accent: #ff7a59;
  --accent-2: #ff9f6e;
  --danger: #c02b2b;
  --shadow: rgba(44, 28, 16, 0.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text-strong);
  overflow: hidden;
  background: #ffe9d6;
}

/* Background */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.bg-gradient {
  position: absolute; inset: -10% -10% 0 -10%;
  background: var(--sunrise);
  filter: saturate(1.05) contrast(1.02);
}
.bg-noise {
  position: absolute; inset: 0;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" viewBox="0 0 300 300"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23n)" opacity="0.05"/></svg>');
  opacity: 0.25;
  mix-blend-mode: overlay;
}
.bg-vignette {
  position: absolute; inset: 0;
  background: radial-gradient(1200px 600px at 50% 110%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.08) 100%);
}


/* App layout */
.app {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

.glass-surface {
  position: relative;
  background: var(--glass-grad);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  border: 0.5px solid rgba(255,255,255,0.35);
  box-shadow: 0 6px 18px var(--shadow), inset 0 0.5px 0 var(--glass-stroke);
  z-index: 0;
}
.glass-surface::before {
  /* Refraction layer: samples the page background at a slight offset */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 0;
  background: var(--sunrise);
  background-attachment: fixed; background-size: 140% 140%; background-position: center 55%;
  transform: translateY(-6px) translateX(-4px) scale(1.02);
  filter: url(#c7-refract) blur(18px) saturate(1.18) contrast(1.03);
  opacity: 0.5; mix-blend-mode: screen;
}
.glass-surface::after {
  /* Specular/highlight sheen */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(120% 60% at 10% -10%, rgba(255,255,255,0.55), rgba(255,255,255,0.0) 40%),
              radial-gradient(100% 50% at 80% 0%, rgba(255,180,130,0.18), rgba(255,180,130,0.0) 55%);
  mix-blend-mode: screen; opacity: 0.9;
}

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: Sora, Inter, system-ui; }
.brand-name { font-weight: 600; letter-spacing: 0.3px; }

.header-actions { display: flex; gap: 8px; }

.chat { position: relative; overflow: hidden; }
.messages {
  list-style: none; margin: 0; padding: 24px 12px 110px 12px;
  height: 100%; overflow-y: auto; scroll-behavior: smooth;
}
.messages:focus { outline: none; }

.message {
  display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: start;
  padding: 10px 8px; border-radius: 14px;
}
.avatar { width: 40px; height: 40px; border-radius: 50%; background: radial-gradient(circle at 30% 30%, #fff, #ffe8b3 60%, #ffad66 100%); box-shadow: inset 0 1px 0 rgba(255,255,255,0.6), 0 6px 14px rgba(0,0,0,0.06); }
.avatar.user { background: radial-gradient(circle at 30% 30%, #fff, #d6ecff 60%, #a6cfff 100%); }

.bubble {
  position: relative;
  padding: 12px 14px; border-radius: 16px;
  border: 0.5px solid rgba(255,255,255,0.4);
  background: var(--glass-grad);
  backdrop-filter: blur(10px) saturate(1.05);
  -webkit-backdrop-filter: blur(10px) saturate(1.05);
  box-shadow: 0 8px 18px rgba(44,28,16,0.12), inset 0 0.5px 0 rgba(255,255,255,0.6);
  z-index: 0;
}
.bubble::before {
  /* Refracted backdrop (parallax/offset) */
  content: ""; position: absolute; inset: 0; border-radius: inherit; z-index: -1; pointer-events: none;
  background: var(--sunrise);
  background-attachment: fixed; background-size: 150% 150%; background-position: center 56%;
  transform: translateY(-6px) translateX(-5px) scale(1.02);
  filter: url(#c7-refract) blur(14px) saturate(1.2) contrast(1.04);
  opacity: 0.55; mix-blend-mode: screen;
}
.bubble::after {
  content: ""; position: absolute; inset: 0; border-radius: 16px; pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0) 40%),
              radial-gradient(180px 120px at 12% 0%, rgba(255,255,255,0.7), rgba(255,255,255,0) 60%),
              radial-gradient(220px 160px at 85% 40%, rgba(255,170,120,0.18), rgba(255,170,120,0) 60%);
  mix-blend-mode: screen; opacity: 0.9;
}

.message.assistant .bubble { background: linear-gradient(180deg, rgba(255,255,255,0.78), rgba(255,255,255,0.4)); }
.message.user .bubble { background: linear-gradient(180deg, rgba(255,255,255,0.58), rgba(255,255,255,0.28)); }

.message .meta { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.message .content { line-height: 1.55; }
.message .content code { background: rgba(255,255,255,0.6); padding: 2px 6px; border-radius: 6px; }
.message .content pre { background: rgba(255,255,255,0.6); padding: 12px; border-radius: 10px; overflow: auto; }

.message-attachments { margin-top: 8px; padding: 8px 10px; border-radius: 12px; background: rgba(255,255,255,0.4); border: 1px solid rgba(255,255,255,0.55); list-style: none; display: flex; flex-direction: column; gap: 6px; }
.message-attachment-item { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.message-attachment-label { font-weight: 500; font-size: 13px; }
.message-attachment-meta { display: inline-flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-dim); }
.message-attachment-size { font-size: 11px; color: var(--text-dim); }
.message-attachment-status { font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-dim); }

.typing { position: absolute; left: 70px; bottom: 92px; display: inline-flex; gap: 6px; align-items: center; }
.typing.hidden { display: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.9); box-shadow: 0 3px 10px rgba(0,0,0,0.1); animation: bounce 1.2s infinite ease-in-out; }
.dot:nth-child(2) { animation-delay: 0.12s; }
.dot:nth-child(3) { animation-delay: 0.24s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.8; } 40% { transform: translateY(-6px); opacity: 1; } }

.composer { padding: 10px 12px; position: sticky; bottom: 0; }

.composer form { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.composer form textarea { grid-column: 1; grid-row: 1; }
.composer form .composer-actions { grid-column: 2; grid-row: 1; justify-content: flex-end; align-self: end; }
.composer-attachments { grid-column: 1 / -1; grid-row: 2; display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0 0; }
.composer-attachments.hidden { display: none; }
.attachment-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 16px; background: rgba(255,255,255,0.35); border: 1px solid rgba(255,255,255,0.55); font-size: 12px; color: var(--text-strong); box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.7); }
.attachment-pill .attachment-status { font-size: 11px; color: var(--text-dim); }
.attachment-pill button { border: none; background: none; color: inherit; cursor: pointer; font-size: 12px; padding: 0; display: inline-flex; align-items: center; }
.attachment-pill button:hover { text-decoration: underline; }
.attachment-pill.is-uploading { opacity: 0.8; }
.attachment-pill.is-error { background: rgba(255,220,220,0.75); border-color: rgba(200,80,80,0.6); color: rgba(140,40,40,0.95); }
.attachment-pill.is-ready { border-color: rgba(170,220,170,0.8); }
.input {
  width: 100%;
  padding: 12px 12px;
  border-radius: 12px;
  background: var(--glass-grad);
  border: 0.5px solid rgba(255,255,255,0.45);
  box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.8);
  color: var(--text-strong);
  resize: none;
}
.input:focus { outline: 2px solid rgba(255, 140, 100, 0.45); outline-offset: 2px; }

.glass-button {
  border: 0.5px solid rgba(255,255,255,0.55);
  background: var(--glass-grad);
  color: var(--text-strong);
  padding: 10px 14px; border-radius: 12px;
  box-shadow: 0 6px 14px rgba(44,28,16,0.12), inset 0 0.5px 0 rgba(255,255,255,0.7);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.glass-button.primary { background: linear-gradient(180deg, rgba(255,230,200,0.9), rgba(255,200,150,0.65)); border-color: rgba(255, 160, 120, 0.8); }
.glass-button.danger { background: linear-gradient(180deg, rgba(255,220,220,0.8), rgba(255,190,190,0.5)); border-color: rgba(200, 80, 80, 0.6); }
.glass-button:hover { transform: translateY(-1px); box-shadow: 0 10px 18px rgba(44,28,16,0.14), inset 0 1px 0 rgba(255,255,255,0.8); }
.glass-button:active { transform: translateY(0); box-shadow: 0 6px 14px rgba(44,28,16,0.12); }

.composer-actions { display: flex; gap: 8px; }
.composer-actions .glass-button.is-active {
  background: rgba(255, 255, 255, 0.32);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Modal */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(20, 12, 8, 0.25); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.overlay.hidden { display: none; }
.modal { width: min(680px, calc(100vw - 32px)); border-radius: 16px; padding: 14px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 6px 12px 6px; }
.modal-body { display: grid; gap: 10px; padding: 0 6px 12px 6px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; padding: 6px; }
.label { font-size: 13px; color: var(--text-dim); }
.icon-button { background: none; border: none; cursor: pointer; font-size: 18px; }

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

/* Markdown adjustments */
.message .content h1, .message .content h2, .message .content h3 { margin: 0.6em 0 0.3em; font-family: Sora, Inter, system-ui; }
.message .content p { margin: 0.5em 0; }
.message .content ul { padding-left: 18px; }

/* Scrollbar styling */
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-track { background: rgba(255,255,255,0.4); border-radius: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(255, 180, 120, 0.7); border-radius: 8px; border: 2px solid rgba(255,255,255,0.5); }

/* Responsive tweaks */
@media (max-width: 640px) {
  .messages { padding: 16px 10px 108px 10px; }
  .typing { left: 58px; bottom: 94px; }
}

/* =============================
   Terminal Theme Overrides
   Black & white, monospace, faint separators
   ============================= */
:root {
  --bg: #0b0b0b;
  --panel: #0e0e0e;
  --ink: #e7e7e7;
  --ink-dim: #a9a9a9;
  --muted: #141414;
  --line: rgba(255,255,255,0.08);
  --line-strong: rgba(255,255,255,0.14);
}

body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color: var(--ink);
  background: var(--bg);
}

.bg { display: none !important; }

.app-header { padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand-name { color: var(--ink); }

.chat { background: var(--bg); }
.messages { padding: 12px 12px 96px 12px; border-top: 1px solid var(--line); }

.message { grid-template-columns: 18px 1fr; gap: 10px; padding: 10px 4px; border-radius: 0; }
.message + .message { border-top: 1px dashed var(--line); }
.avatar { width: 18px; height: 18px; border-radius: 2px; background: var(--muted); border: 1px solid var(--line); box-shadow: none; }

.bubble { padding: 6px 8px; border-radius: 0; background: transparent; border: none; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
.bubble::before, .bubble::after { content: none; }

.message.assistant .meta::before { content: "assistant$"; color: var(--ink-dim); margin-right: 6px; }
.message.user .meta::before { content: "you$"; color: var(--ink-dim); margin-right: 6px; }

.message .meta { font-size: 12px; color: var(--ink-dim); margin-bottom: 2px; }
.message .content { line-height: 1.6; white-space: pre-wrap; }
.message .content code { background: #0f0f0f; padding: 0 4px; border-radius: 2px; border: 1px solid var(--line); color: var(--ink); }
.message .content pre { background: #0f0f0f; padding: 10px; border-radius: 2px; overflow: auto; border: 1px solid var(--line); color: var(--ink); }
.katex { font-size: 1.05em; }
.message .content .katex-display { display: block; margin: 12px 0; overflow-x: auto; }

.typing { left: 34px; bottom: 84px; }
.dot { width: 6px; height: 6px; background: var(--ink-dim); box-shadow: none; }

.composer { padding: 8px 10px; background: var(--panel); border-top: 1px solid var(--line); }
.input { padding: 10px 10px; border-radius: 2px; background: #0f0f0f; border: 1px solid var(--line-strong); color: var(--ink); }
.input:focus { outline: 1px solid var(--ink-dim); outline-offset: 0; }

.glass-button { border: 1px solid var(--line-strong); background: #0f0f0f; color: var(--ink); padding: 8px 12px; border-radius: 2px; box-shadow: none; }
.glass-button.primary { background: #131313; }
.glass-button.danger { background: #131313; border-color: #3a3a3a; }

.overlay { background: rgba(0,0,0,0.6); backdrop-filter: none; -webkit-backdrop-filter: none; z-index: 1000; }
#confirm-overlay { z-index: 1100; }
.modal { width: min(560px, calc(100vw - 32px)); border-radius: 4px; padding: 10px; background: #0f0f0f; border: 1px solid var(--line-strong); }
.modal-header { padding: 6px 4px 8px 4px; }
.modal-body { gap: 8px; padding: 0 4px 8px 4px; }
.modal-footer { gap: 8px; padding: 4px; }
.label { font-size: 12px; color: var(--ink-dim); }

.hint { color: var(--ink-dim); }

.messages::-webkit-scrollbar-track { background: #0f0f0f; }
.messages::-webkit-scrollbar-thumb { background: #1a1a1a; border: 2px solid #0f0f0f; }

/* =============================
   Black & White Theme Overrides
   Clean layout, centered column, balanced spacing
   ============================= */
:root {
  --bw-bg: #ffffff;
  --bw-ink: #111111;
  --bw-ink-dim: #6b6b6b;
  --bw-panel: #ffffff;
  --bw-line: #eaeaea;
  --bw-line-strong: #d9d9d9;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--bw-ink);
  background: var(--bw-bg);
}

.bg { display: none !important; }

.glass-surface { background: var(--bw-panel) !important; border: none !important; box-shadow: none !important; }
.glass-surface::before, .glass-surface::after { content: none !important; }

.app-header { padding: 8px 12px 0 12px !important; background: var(--bw-panel) !important; border-bottom: 1px solid var(--bw-line) !important; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; gap: 6px 12px; align-items: center; }
.brand-name { color: var(--bw-ink) !important; }
.app-header .brand { grid-column: 1 / 2; }
.app-header .header-actions { grid-column: 2 / 3; justify-self: end; }
.graph { grid-column: 1 / 3; max-width: 100%; margin: 0 auto; padding: 6px 0 8px 0; overflow: auto; border-top: 1px solid var(--bw-line); height: 140px; }
.graph-svg { display: block; }
.graph .node text { fill: var(--bw-ink-dim); font-size: 12px; dominant-baseline: middle; }
.graph .node text { paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.graph .node circle { fill: #111; stroke: var(--bw-line-strong); stroke-width: 2; }
.graph .node.active circle { stroke: #111; }
.graph path.edge { stroke: var(--bw-line-strong); stroke-width: 2; fill: none; }

.chat { background: var(--bw-bg) !important; }
.messages { padding: 24px 16px 128px 16px !important; border-top: 1px solid var(--bw-line) !important; max-width: 760px; margin: 0 auto; }

.message { grid-template-columns: 32px 1fr !important; gap: 14px !important; margin: 16px 0 !important; padding: 0 !important; border-radius: 0 !important; }
.message + .message { border-top: 1px solid #f3f3f3; padding-top: 16px; }
.avatar { width: 32px !important; height: 32px !important; border-radius: 10px !important; position: relative; background: linear-gradient(135deg, #111 0%, #2a2a2a 100%) !important; border: 1px solid var(--bw-line) !important; box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset !important; overflow: hidden; }
.message.user .avatar { background: linear-gradient(135deg, #e0e0e0 0%, #bdbdbd 100%) !important; border-color: #dcdcdc !important; }
.avatar::after { content: ""; position: absolute; inset: 0; background: radial-gradient(100% 100% at 30% 20%, rgba(255,255,255,0.28), rgba(255,255,255,0) 60%), radial-gradient(120% 100% at 80% 100%, rgba(0,0,0,0.18), rgba(0,0,0,0) 60%); pointer-events: none; }

/* Message enter animations */
.message.anim-in { animation: slideFadeIn 220ms ease-out both; }
@keyframes slideFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.message.anim-in .avatar { animation: avatarPop 220ms cubic-bezier(.2,.7,.3,1) both; }
@keyframes avatarPop { from { transform: scale(0.85); } to { transform: scale(1); } }

.bubble { padding: 12px 14px !important; border-radius: 12px !important; background: #ffffff !important; border: 1px solid var(--bw-line) !important; box-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
.bubble::before, .bubble::after { content: none !important; }
.message.assistant .bubble { background: #fafafa !important; }
.message.user .bubble { background: #ffffff !important; }

.message .meta::before { content: none !important; }
.message .meta { font-size: 12px !important; color: var(--bw-ink-dim) !important; margin-bottom: 6px !important; }
.message .content { line-height: 1.65 !important; }
.message .content code { background: #f6f6f6 !important; border: 1px solid var(--bw-line) !important; border-radius: 6px !important; padding: 2px 6px !important; color: var(--bw-ink) !important; }
.message .content pre { background: #f6f6f6 !important; border: 1px solid var(--bw-line) !important; border-radius: 10px !important; padding: 12px !important; color: var(--bw-ink) !important; }
.context-quote .content.context-dim { color: var(--bw-ink-dim); }
.context-quote .content .ctx-selected { color: var(--bw-ink); background: #fffbe6; border-radius: 4px; padding: 0 2px; }

.composer { background: var(--bw-panel) !important; border-top: 1px solid var(--bw-line) !important; padding: 12px 16px !important; }
.composer form { max-width: 760px; margin: 0 auto; grid-template-columns: 1fr auto; gap: 12px; }
.input { background: #ffffff !important; border: 1px solid var(--bw-line-strong) !important; border-radius: 10px !important; color: var(--bw-ink) !important; padding: 12px 12px !important; }
.input:focus { outline: 2px solid #e5e5e5 !important; outline-offset: 2px !important; }

.glass-button { background: #ffffff !important; border: 1px solid var(--bw-line-strong) !important; border-radius: 10px !important; color: var(--bw-ink) !important; padding: 10px 14px !important; box-shadow: none !important; }
.glass-button.primary { background: #ffffff !important; }
.glass-button.danger { background: #ffffff !important; border-color: #e5e5e5 !important; }

.typing { left: 44px !important; bottom: 112px !important; }
.dot { width: 8px !important; height: 8px !important; background: var(--bw-ink-dim) !important; box-shadow: none !important; }

.messages::-webkit-scrollbar-track { background: #fafafa !important; }
.messages::-webkit-scrollbar-thumb { background: #e1e1e1 !important; border: 2px solid #fafafa !important; }

/* Card stack */
.card-stack { position: relative; max-width: 760px; margin: 0 auto; padding: 16px; }
.chat-card { background: #ffffff; border: 1px solid var(--bw-line); border-radius: 14px; box-shadow: 0 8px 28px rgba(0,0,0,0.05); overflow: hidden; position: absolute; inset: 16px; transform: translateX(100%); opacity: 0; transition: transform 220ms ease, opacity 220ms ease; display: none; grid-template-rows: 1fr auto; }
.chat-card .thread-refs { padding: 10px 12px; border-bottom: 1px solid var(--bw-line); font-size: 12px; color: var(--bw-ink-dim); display: none; }
.chat-card .thread-refs a { color: inherit; text-decoration: underline; }
.chat-card.is-active { display: grid; transform: translateX(0); opacity: 1; position: relative; z-index: 2; }
.chat-card.is-below { display: none; }
.chat-card.hidden { display: none !important; }

/* Ensure chat and composer sit within card */
.chat-card .chat { background: #fff !important; overflow: hidden; }
.chat-card .messages { max-width: none !important; margin: 0 !important; padding: 20px 16px 120px 16px !important; border-top: none !important; height: 100%; overflow-y: auto; }
.chat-card .composer { border-top: 1px solid var(--bw-line) !important; }

/* Scrolling fixes: allow inner lists to scroll within grid/flex parents */
body { overflow: auto !important; }
.app { min-height: 0; }
.card-stack { min-height: 0; }
.chat-card { min-height: 0; }
.chat-card .chat { min-height: 0; }
.messages { -webkit-overflow-scrolling: touch; }

/* Thread panel */
#thread-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.35); }
#thread-overlay.active { display: block; }
.thread { position: fixed; top: 0; right: 0; width: min(520px, 100%); height: 100dvh; background: #ffffff; border-left: 1px solid var(--bw-line); box-shadow: -12px 0 24px rgba(0,0,0,0.06); display: grid; grid-template-rows: auto 1fr auto; }
.thread.hidden { display: none; }
.thread-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--bw-line); }
.thread-chat { background: #fff; }
.thread .messages { max-width: none; margin: 0; padding: 16px 12px 110px 12px !important; border-top: none !important; }
.thread-composer { background: #fff; border-top: 1px solid var(--bw-line); padding: 10px 12px; }
.thread-composer form { grid-template-columns: 1fr auto; gap: 10px; }

/* Selection toolbar */
.selection-toolbar { position: fixed; z-index: 50; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--bw-line-strong); background: #fff; color: var(--bw-ink); box-shadow: 0 6px 20px rgba(0,0,0,0.08); transform: translate(-50%, -120%); }
.selection-toolbar.hidden { display: none; }
/* Follow-up references */
.follow-ref-highlight { background: #fff6b7; border-radius: 3px; padding: 0 2px; }
.follow-ref-marker { color: var(--bw-ink-dim); margin-left: 4px; cursor: pointer; vertical-align: super; font-size: 0.75em; user-select: none; }

/* =============================
   Windows 98 Minimal Theme Overrides
   Sharp corners, strong borders, rectangular UI
   ============================= */
:root {
  --w98-bg: #c0c0c0;
  --w98-panel: #ffffff;
  --w98-ink: #000000;
  --w98-line: #000000;
  --w98-muted: #dcdcdc;
  --w98-3dface: #d4d0c8;
  --w98-highlight: #ffffff;
  --w98-light: #e5e5e5;
  --w98-shadow: #808080;
  --w98-dark: #404040;
}

body {
  font-family: Tahoma, "MS Sans Serif", Segoe UI, Inter, system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif !important;
  color: var(--w98-ink) !important;
  background: var(--w98-bg) !important;
  background-image:
    linear-gradient(45deg, rgba(0,0,0,0.06) 25%, rgba(0,0,0,0) 25%, rgba(0,0,0,0) 75%, rgba(0,0,0,0.06) 75%),
    linear-gradient(45deg, rgba(0,0,0,0.06) 25%, rgba(0,0,0,0) 25%, rgba(0,0,0,0) 75%, rgba(0,0,0,0.06) 75%);
  background-size: 2px 2px, 2px 2px;
  background-position: 0 0, 1px 1px;
}

.bg { display: none !important; }

.glass-surface { background: var(--w98-panel) !important; border: 2px solid var(--w98-line) !important; box-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; border-radius: 0 !important; }
.glass-surface::before, .glass-surface::after { content: none !important; }

.app-header { padding: 6px 8px !important; background: #000080 !important; border-bottom: 2px solid var(--w98-dark) !important; display: grid !important; grid-template-columns: 1fr auto !important; grid-template-rows: auto auto !important; align-items: center !important; gap: 6px 8px !important; }
.brand-name { color: #ffffff !important; font-weight: 600 !important; }
/* Place brand left, actions right, graph full width below */
.app-header .brand { grid-column: 1 / 2 !important; }
.app-header .header-actions { grid-column: 2 / 3 !important; justify-self: end !important; display: inline-flex !important; gap: 6px !important; position: relative !important; }
.graph { grid-column: 1 / 3 !important; }
/* Compact select for chats */
#chat-select { height: 28px; padding: 2px 6px !important; }

/* Win98 menu */
.menu { position: absolute; top: 0; left: 0; min-width: 240px; background: var(--w98-3dface); border: 2px solid var(--w98-line); border-top-color: var(--w98-highlight); border-left-color: var(--w98-highlight); border-right-color: var(--w98-dark); border-bottom-color: var(--w98-dark); box-shadow: none; z-index: 9999; max-height: min(60vh, 360px); overflow-y: auto; }
.menu.hidden { display: none; }
.menu .menu-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; color: #000; cursor: default; }
.menu .menu-item:hover, .menu .menu-item.active { background: #000080; color: #fff; }
.menu .menu-sep { height: 2px; background: var(--w98-dark); border-top: 2px solid var(--w98-highlight); margin: 4px 2px; }
.menu .menu-right { margin-left: auto; opacity: 0.7; }
.menu .menu-section { padding: 4px 0; }

.chat { background: var(--w98-bg) !important; }
.messages { padding: 16px 10px 120px 10px !important; border-top: 2px solid var(--w98-line) !important; max-width: 780px !important; margin: 0 auto !important; }

.message { grid-template-columns: 28px 1fr !important; gap: 10px !important; margin: 12px 0 !important; padding: 0 !important; border-radius: 0 !important; }
.message + .message { border-top: 1px dashed #555 !important; padding-top: 12px !important; }
.avatar { width: 28px !important; height: 28px !important; border-radius: 0 !important; background: #ffffff !important; border: 2px solid var(--w98-line) !important; box-shadow: none !important; }
.message.user .avatar { background: #ffffff !important; }

.bubble { padding: 10px 10px !important; border-radius: 0 !important; background: #ffffff !important; border: 2px solid var(--w98-line) !important; box-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; border-top-color: var(--w98-highlight) !important; border-left-color: var(--w98-highlight) !important; border-right-color: var(--w98-dark) !important; border-bottom-color: var(--w98-dark) !important; }
.bubble::before, .bubble::after { content: none !important; }
.message.assistant .bubble { background: #f8f8f8 !important; }

.message .meta { font-size: 12px !important; color: #333 !important; margin-bottom: 6px !important; }
.message .content { line-height: 1.6 !important; }
.message .content code { background: #f0f0f0 !important; border: 2px solid var(--w98-line) !important; border-radius: 0 !important; padding: 2px 4px !important; color: var(--w98-ink) !important; }
.message .content pre { background: #f0f0f0 !important; border: 2px solid var(--w98-line) !important; border-radius: 0 !important; padding: 10px !important; color: var(--w98-ink) !important; }

.typing { left: 40px !important; bottom: 112px !important; }
.dot { width: 8px !important; height: 8px !important; background: #ffffff !important; border: 2px solid var(--w98-line) !important; border-radius: 0 !important; box-shadow: none !important; animation: win98-blink 1s infinite steps(1, end) !important; }
.dot:nth-child(2) { animation-delay: .2s !important; }
.dot:nth-child(3) { animation-delay: .4s !important; }
@keyframes win98-blink { 0%, 10%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.composer { background: var(--w98-panel) !important; border-top: 2px solid var(--w98-line) !important; padding: 10px 10px !important; }
.composer form { max-width: 780px !important; margin: 0 auto !important; grid-template-columns: 1fr auto !important; gap: 10px !important; }
.input { background: #ffffff !important; border: 2px solid var(--w98-line) !important; border-radius: 0 !important; color: var(--w98-ink) !important; padding: 10px 10px !important; resize: vertical !important; border-top-color: var(--w98-dark) !important; border-left-color: var(--w98-dark) !important; border-right-color: var(--w98-highlight) !important; border-bottom-color: var(--w98-highlight) !important; }
.input:focus { outline: 2px dashed #333 !important; outline-offset: 0 !important; }

.glass-button { background: #e0e0e0 !important; border: 2px solid var(--w98-line) !important; border-radius: 0 !important; color: var(--w98-ink) !important; padding: 8px 12px !important; box-shadow: none !important; border-top-color: var(--w98-highlight) !important; border-left-color: var(--w98-highlight) !important; border-right-color: var(--w98-dark) !important; border-bottom-color: var(--w98-dark) !important; }
.glass-button.primary { background: #e0e0e0 !important; }
.glass-button.danger { background: #e0e0e0 !important; border-color: var(--w98-line) !important; }
.glass-button:hover { filter: brightness(0.98) !important; transform: none !important; }
.glass-button:active { filter: brightness(0.92) !important; border-top-color: var(--w98-dark) !important; border-left-color: var(--w98-dark) !important; border-right-color: var(--w98-highlight) !important; border-bottom-color: var(--w98-highlight) !important; }

.overlay { background: rgba(0,0,0,0.4) !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
.modal { width: min(540px, calc(100vw - 32px)) !important; border: 2px solid var(--w98-line) !important; border-radius: 0 !important; padding: 10px !important; background: var(--w98-panel) !important; border-top-color: var(--w98-highlight) !important; border-left-color: var(--w98-highlight) !important; border-right-color: var(--w98-dark) !important; border-bottom-color: var(--w98-dark) !important; }
.modal-header { background: #000080 !important; color: #ffffff !important; border-bottom: 2px solid var(--w98-dark) !important; }
.modal-header { padding: 6px 4px 8px 4px !important; }
.modal-body { gap: 8px !important; padding: 0 4px 8px 4px !important; }
.modal-footer { gap: 8px !important; padding: 4px !important; }
.label { font-size: 12px !important; color: #333 !important; }
.subtle { font-size: 12px; color: #333; opacity: 0.85; margin: 4px 0 0 0; }

.selection-toolbar { border: 2px solid var(--w98-line) !important; background: var(--w98-panel) !important; border-radius: 0 !important; box-shadow: none !important; }

.card-stack { padding: 12px !important; }
.chat-card { background: var(--w98-panel) !important; border: 2px solid var(--w98-line) !important; border-radius: 0 !important; box-shadow: none !important; }
.chat-card .thread-refs { border-bottom: 1px dashed #555 !important; }
.chat-card .chat { background: var(--w98-panel) !important; }
.chat-card .messages { padding: 16px 12px 120px 12px !important; }
.chat-card .composer { border-top: 2px solid var(--w98-line) !important; }

.thread { background: var(--w98-panel) !important; border-left: 2px solid var(--w98-line) !important; box-shadow: none !important; }
.thread-header { border-bottom: 2px solid var(--w98-line) !important; }
.thread-composer { border-top: 2px solid var(--w98-line) !important; }

.messages::-webkit-scrollbar-track { background: #dcdcdc !important; }
.messages::-webkit-scrollbar-thumb { background: #bdbdbd !important; border: 2px solid #dcdcdc !important; }

/* Graph tweaks for Win98 look */
.graph .node rect { fill: var(--w98-3dface) !important; stroke: var(--w98-dark) !important; stroke-width: 1 !important; }
.graph .node.active rect { fill: #e0e0e0 !important; }
.graph path.edge { stroke: var(--w98-line) !important; stroke-width: 2 !important; fill: none !important; shape-rendering: crispEdges !important; }
/* Dial back text highlight stroke for readability */
.graph .node text { paint-order: stroke; stroke: var(--w98-light) !important; stroke-width: 1 !important; }
/* Bevel lines on button nodes */
.graph .node .bevel-light { stroke: var(--w98-highlight) !important; stroke-width: 2 !important; }
.graph .node .bevel-shadow { stroke: var(--w98-shadow) !important; stroke-width: 2 !important; }
/* 3D cable effect */
.graph path.edge-light { stroke: var(--w98-highlight) !important; stroke-width: 1 !important; shape-rendering: crispEdges !important; fill: none !important; }
.graph path.edge-shadow { stroke: var(--w98-shadow) !important; stroke-width: 1 !important; shape-rendering: crispEdges !important; fill: none !important; }

/* Brand tagline layout in Win98 header */
.app-header .brand { flex-direction: column !important; align-items: flex-start !important; gap: 2px !important; }
.brand-tagline { color: #ffffff !important; opacity: 0.85 !important; font-size: 11px !important; letter-spacing: 0.2px !important; }

/* Compact prompt modal overrides */
#prompt-overlay .modal { width: 360px !important; padding: 6px !important; }
#prompt-overlay .modal-header { padding: 4px 6px !important; }
#prompt-overlay .modal-body { padding: 6px !important; }
#prompt-overlay .modal-footer { padding: 6px !important; }
#prompt-overlay .input { height: 28px !important; }

/* Confirm modal (Win98 style) */
#confirm-overlay .modal { width: 340px !important; padding: 10px !important; }
#confirm-overlay .modal-header { padding: 6px 6px 8px 6px !important; position: relative !important; }
#confirm-overlay .modal-body { padding: 8px 6px !important; }
#confirm-overlay .modal-footer { padding: 6px !important; display: flex !important; justify-content: flex-end !important; gap: 8px !important; }
#confirm-overlay .confirm-message { font-size: 13px !important; color: #000 !important; line-height: 1.4 !important; }
#confirm-overlay .glass-button.danger { background: #c0c0c0 !important; color: #a40000 !important; }
#confirm-overlay .icon-button { background: transparent !important; border: none !important; color: #ffffff !important; position: absolute !important; top: 4px !important; right: 4px !important; }
#confirm-overlay .icon-button { color: #ffffff !important; }

.settings-section { display: grid; gap: 10px; margin-bottom: 16px; }
.access-mode { display: grid; gap: 12px; }
.access-option { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 500; cursor: pointer; }
.access-option input { margin: 0; }
.access-panel { display: grid; gap: 8px; padding: 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.45); background: rgba(255,255,255,0.22); box-shadow: inset 0 1px 0 rgba(255,255,255,0.35); }
.access-panel.hidden { display: none; }
.subscription-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.subscription-status { font-weight: 500; margin: 0; }
.label.small { font-size: 13px; font-weight: 600; }
.settings-hint { margin: 0; font-size: 13px; color: var(--text-dim); }

/* Splash (Windows 98 style) */
.splash { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
.splash.hidden { display: none; }
.splash-card { min-width: 320px; max-width: 520px; padding: 16px; background: var(--w98-panel); border: 2px solid var(--w98-line); border-radius: 0; border-top-color: var(--w98-highlight); border-left-color: var(--w98-highlight); border-right-color: var(--w98-dark); border-bottom-color: var(--w98-dark); box-shadow: none; text-align: center; }
.splash-title { font-family: Tahoma, "MS Sans Serif", sans-serif; font-size: 28px; font-weight: 700; color: var(--w98-ink); }
.splash-tagline { margin-top: 6px; font-size: 13px; color: #222; opacity: 0.9; }
.splash-actions { margin-top: 16px; display: flex; justify-content: center; gap: 8px; }
