/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252542;
  --surface3: #2f2f52;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);
  --text: #eaeaf0;
  --text2: #a0a0b8;
  --text3: #6b6b82;
  --accent: #7c6cf0;
  --accent-dim: rgba(124,108,240,0.12);
  --accent-glow: rgba(124,108,240,0.25);
  --accent2: #e8a87c;
  --user-bg: rgba(124,108,240,0.18);
  --bg1: #0f0f1a;
  --bg2: #1a1a2e;
  --text1: #eaeaf0;
  --code-bg: #0c0c1a;
  --topbar-bg: rgba(15,15,26,0.75);
  --input-focus-bg: rgba(26,26,46,0.95);
  --selection-bg: rgba(124,108,240,0.35);
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.25);
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}
.tag-route {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

html, body {
  height: 100%; width: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  /* Block iOS/Android pull-to-refresh + chained overscroll bounce that
     was firing a page reload when a scroll container hit its top or
     bottom and the gesture bubbled to the root element. `none` is the
     hard stop; `.messages` keeps its own `contain` since the chat
     scroller wants the normal in-container bounce. */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Selection color */
::selection {
  background: var(--selection-bg, rgba(124,108,240,0.35));
  color: #fff;
}
::-moz-selection {
  background: var(--selection-bg, rgba(124,108,240,0.35));
  color: #fff;
}

/* ===== App Shell ===== */
.app {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
}

.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.view.hidden { display: none; }

/* ===== Top Bar ===== */
.topbar {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 8px;
  padding-top: var(--safe-top);
  min-height: calc(56px + var(--safe-top));
  background: var(--topbar-bg, rgba(15,15,26,0.75));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.topbar-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text2);
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}
.topbar-btn:active { background: var(--surface2); transform: scale(0.95); }

.topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  -webkit-user-select: text;
  user-select: text;
  letter-spacing: -0.01em;
}
.topbar-title.editing {
  outline: none;
  border-bottom: 1px solid var(--accent);
  padding-bottom: 2px;
  overflow: visible;
  text-overflow: clip;
}

.model-badge {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.02em;
  transition: all var(--transition-fast);
}
.model-badge.hidden { display: none; }
.badge-fast { background: rgba(52,168,83,0.15); color: #6ee7b7; border: 1px solid rgba(52,168,83,0.2); }
.badge-deep { background: rgba(244,162,97,0.15); color: #f4a261; border: 1px solid rgba(244,162,97,0.2); }
.badge-speculative { background: rgba(196,181,253,0.15); color: #c4b5fd; border: 1px solid rgba(196,181,253,0.2); }

.rag-btn, .council-btn {
  padding: 5px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text3);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all var(--transition-normal);
}
.rag-btn.active {
  background: rgba(124,108,240,0.15);
  color: #a78bfa;
  border-color: rgba(124,108,240,0.4);
  box-shadow: 0 0 12px rgba(124,108,240,0.1);
}
.council-btn.active {
  background: rgba(196,181,253,0.12);
  color: #c4b5fd;
  border-color: rgba(196,181,253,0.35);
  box-shadow: 0 0 12px rgba(196,181,253,0.1);
}
.rag-show-btn {
  padding: 5px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text3);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all var(--transition-normal);
}
.rag-show-btn.active {
  background: rgba(56,189,248,0.12);
  color: #38bdf8;
  border-color: rgba(56,189,248,0.35);
  box-shadow: 0 0 12px rgba(56,189,248,0.1);
}

/* ChatGPT-style routing picker */
.routing-picker-slot {
  display: inline-flex;
}
.routing-picker-wrap {
  position: relative;
  display: inline-block;
}
.routing-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all var(--transition-normal);
  white-space: nowrap;
}
.routing-picker-btn:hover,
.routing-picker-btn:focus-visible {
  background: var(--surface2);
  border-color: var(--border-strong);
  outline: 2px solid transparent;
}
.routing-picker-btn.mode-fast {
  background: rgba(110,231,183,0.1);
  color: #6ee7b7;
  border-color: rgba(110,231,183,0.3);
}
.routing-picker-btn.mode-deep {
  background: rgba(244,162,97,0.12);
  color: #f4a261;
  border-color: rgba(244,162,97,0.35);
}
.routing-picker-btn.mode-override {
  background: rgba(167,139,250,0.12);
  color: #c4b5fd;
  border-color: rgba(167,139,250,0.38);
}
.routing-picker-dropdown.hidden {
  display: none;
}
.routing-picker-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 6px;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  animation: dropdownFadeIn 0.15s ease-out;
  max-height: min(70vh, 520px);
  overflow-y: auto;
}
@keyframes dropdownFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.routing-option {
  display: flex;
  flex-direction: column;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition-fast);
}
.routing-option:hover,
.routing-option:focus-visible {
  background: var(--surface2);
  outline: none;
}
.routing-option.selected {
  background: var(--accent-dim);
}
.routing-option.selected .routing-option-name {
  color: var(--accent);
}
.routing-option-model-first {
  margin-top: 5px;
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  padding-top: 14px;
}
.routing-option-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text1);
}
.routing-option-desc {
  font-size: 11px;
  color: var(--text3);
  margin-top: 1px;
}
.reasoning-effort-group {
  margin: 5px 8px;
  padding: 10px 6px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.reasoning-effort-group.hidden {
  display: none;
}
.reasoning-effort-title {
  display: block;
  margin: 0 4px 7px;
  color: var(--text2);
  font-size: 11px;
  font-weight: 600;
}
.reasoning-effort-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}
.reasoning-effort-option {
  min-width: 0;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text2);
  font-size: 11px;
  cursor: pointer;
}
.reasoning-effort-option:hover,
.reasoning-effort-option:focus-visible {
  background: var(--surface2);
  border-color: var(--border-strong);
  outline: none;
}
.reasoning-effort-option.selected {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent);
}
.reasoning-effort-desc {
  display: block;
  margin: 7px 4px 0;
  color: var(--text3);
  font-size: 10px;
  line-height: 1.35;
}
.routing-option-badge {
  position: absolute;
  top: 9px;
  right: 12px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(232,168,124,0.14);
  border: 1px solid rgba(232,168,124,0.32);
  color: var(--accent2);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.tool-free-warning {
  margin: 4px 8px 2px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(232,168,124,0.10);
  border: 1px solid rgba(232,168,124,0.28);
  color: var(--accent2);
  font-size: 10px;
  line-height: 1.45;
}
.tool-free-warning.hidden {
  display: none;
}
.routing-model-note {
  margin-top: 4px;
  padding: 7px 12px 5px;
  border-top: 1px solid var(--border);
  color: var(--text3);
  font-size: 11px;
  line-height: 1.55;
}
.routing-model-note b {
  color: var(--accent2);
  font-weight: 600;
}

/* Council details: collapsible advisor cards */
.council-details {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.council-details summary {
  cursor: pointer;
  color: var(--text2);
  font-size: 13px;
  padding: 4px 0;
  user-select: none;
}
.council-details summary:hover {
  color: var(--text1);
}
.council-advisor-card {
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.5;
}
.council-advisor-card .advisor-header {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 13px;
}
.council-advisor-card .advisor-body {
  color: var(--text2);
  white-space: pre-wrap;
}
.council-status {
  font-size: 12px;
  color: var(--text3);
  padding: 2px 0;
}
.council-status .done { color: #95d5b2; }
.council-status .working { color: #f4a261; }
.badge-council { background: rgba(196,181,253,0.15); color: #c4b5fd; border: 1px solid rgba(196,181,253,0.2); }
.badge-override { background: rgba(110,231,183,0.1); color: #6ee7b7; border: 1px solid rgba(110,231,183,0.2); }

.save-notes-btn {
  padding: 5px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text3);
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all var(--transition-normal);
  display: flex;
  align-items: center;
}
.save-notes-btn:hover { background: var(--surface2); color: var(--text2); border-color: var(--border-strong); }
.save-notes-btn:disabled { opacity: 0.5; cursor: default; }

/* --- Topbar actions wrapper (mode buttons) --- */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  position: relative;
}
/* "More" button: hidden on desktop, shown on mobile */
.topbar-more-btn {
  display: none;
}
/* On desktop the list is a plain inline flex row */
.topbar-actions-list {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Mobile: collapse topbar mode buttons into dropdown */
@media (max-width: 767px) {
  .topbar-more-btn {
    display: flex;
  }
  .topbar-actions-list {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    flex-direction: column;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 8px;
    gap: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    min-width: 150px;
    animation: dropdownFadeIn 0.15s ease-out;
  }
  .topbar-actions-list.open {
    display: flex;
  }
  /* Make buttons full-width inside the dropdown */
  .topbar-actions-list .rag-btn,
  .topbar-actions-list .council-btn,
  .topbar-actions-list .save-notes-btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
  .topbar-actions-list .routing-picker-slot,
  .topbar-actions-list .routing-picker-wrap,
  .topbar-actions-list .routing-picker-btn {
    width: 100%;
  }
  .topbar-actions-list .routing-picker-btn {
    justify-content: center;
  }
  .topbar-actions-list .routing-picker-dropdown {
    right: 0;
    left: auto;
    min-width: min(280px, calc(100vw - 32px));
  }
  .topbar-actions-list .save-notes-btn {
    justify-content: center;
    gap: 6px;
  }
}

/* ===== Messages ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px 16px;
  padding-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.empty-icon { opacity: 0.3; }
.empty-icon svg { stroke: var(--accent); }
.empty-text { font-size: 20px; color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.empty-sub { font-size: 14px; color: var(--text3); font-weight: 400; }

/* Messages */
.msg {
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  animation: msgIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-queued {
  opacity: 0.5;
}
.msg-highlight {
  background: rgba(255, 193, 7, 0.15) !important;
  transition: background 3s ease;
}

.msg-user {
  background: var(--user-bg);
  color: var(--text);
  align-self: flex-end;
  max-width: 85%;
  padding: 12px 18px;
  border-radius: 20px;
  border-bottom-right-radius: 6px;
  position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

/* Edit message button — only visible on hover of last user message */
.msg-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  opacity: 0;
  transition: opacity 0.2s;
  position: absolute;
  left: -32px;
  top: 50%;
  transform: translateY(-50%);
}
.msg-user:hover .msg-edit-btn { opacity: 0.7; }
.msg-edit-btn:hover { opacity: 1 !important; }

/* Editing state — marks messages that will be replaced */
.msg.editing {
  opacity: 0.4;
  border-left: 3px solid #f59e0b;
}

.msg-assistant {
  /* Clean card style with subtle surface background */
  background: var(--surface);
  color: var(--text);
  align-self: stretch;
  padding: 16px 20px;
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--border);
}

.msg-model-tag {
  font-size: 11px;
  margin-top: 8px;
  display: flex;
  gap: 4px;
}
.tag-fast {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 8px;
  background: rgba(52,168,83,0.12);
  color: #6ee7b7;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.tag-deep {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 8px;
  background: rgba(244,162,97,0.12);
  color: #f4a261;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.tag-override {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 8px;
  background: rgba(110,231,183,0.1);
  color: #6ee7b7;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.tag-time {
  color: var(--text3);
  font-size: 10px;
}

/* Markdown rendering in assistant messages */
.msg-assistant { white-space: normal; }
.msg-assistant p { margin: 0 0 10px 0; }
.msg-assistant p:last-child { margin-bottom: 0; }
.msg-assistant strong { color: #fff; font-weight: 700; }
.msg-assistant em { color: var(--accent2); font-style: italic; }

/* Lists */
.msg-assistant ul, .msg-assistant ol { padding-left: 24px; margin: 8px 0; }
.msg-assistant li { margin: 4px 0; line-height: 1.6; }
.msg-assistant ul > li::marker { color: var(--accent); }
.msg-assistant ol > li::marker { color: var(--accent); font-weight: 600; }

/* Links */
.msg-assistant a {
  color: var(--accent); text-decoration: none; word-break: break-all;
  border-bottom: 1px solid transparent; transition: border-color 0.2s;
}
.msg-assistant a:hover { border-bottom-color: var(--accent); }

/* Inline code */
.msg-assistant code:not(pre code) {
  background: rgba(124,108,240,0.1); padding: 2px 7px; border-radius: 6px;
  font-size: 0.88em; font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  color: #c4b5fd; border: 1px solid rgba(124,108,240,0.15);
}

/* Code blocks */
.msg-assistant pre {
  background: var(--code-bg, #0c0c1a); border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 0; overflow-x: auto; margin: 14px 0; font-size: 13px;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.msg-assistant pre code {
  background: none; padding: 16px; color: inherit; font-size: inherit;
  display: block;
}

/* Language label on code blocks */
.msg-assistant pre code[class]::before {
  content: attr(class);
  display: block;
  padding: 8px 16px;
  margin: 0 0 0 0;
  font-size: 11px; color: var(--text3); text-transform: uppercase;
  pointer-events: none;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.5px;
  font-weight: 600;
}
/* Strip hljs prefix from displayed language label */
.msg-assistant pre code[class*="language-"]::before {
  content: attr(data-lang);
}

/* Blockquotes */
.msg-assistant blockquote {
  border-left: 3px solid var(--accent); padding: 10px 18px;
  margin: 14px 0; background: var(--accent-dim); border-radius: 0 12px 12px 0;
  color: var(--text2); font-style: italic;
}

/* Headings — each level gets a distinct color for scanability */
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3, .msg-assistant h4 {
  font-weight: 700; margin: 18px 0 8px 0; letter-spacing: -0.02em;
}
.msg-assistant h1 { font-size: 20px; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.msg-assistant h2 { font-size: 17px; color: var(--accent2); }
.msg-assistant h3 { font-size: 15px; color: #56d4c4; }
.msg-assistant h4 { font-size: 15px; color: #c4b5fd; }

/* Horizontal rules */
.msg-assistant hr {
  border: none; height: 1px;
  background: linear-gradient(to right, transparent, var(--border), transparent);
  margin: 16px 0;
}

/* Tables */
.msg-assistant table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13px; margin: 8px 0;
  display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border-radius: 8px; border: 1px solid var(--border);
}
.msg-assistant thead { background: var(--surface2); }
.msg-assistant th, .msg-assistant td {
  padding: 6px 10px; border: 1px solid var(--border);
  white-space: nowrap; text-align: left;
}
.msg-assistant th { font-weight: 700; color: #8ab4f8; }

/* Copy button on code blocks */
.code-copy-btn {
  position: absolute; top: 6px; right: 8px;
  background: var(--surface2); color: var(--text3);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 10px; font-size: 11px; cursor: pointer;
  opacity: 0; transition: all var(--transition-normal);
  z-index: 1; font-family: inherit; font-weight: 500;
}
.code-copy-btn:hover {
  background: var(--surface3); color: var(--text2);
}
.code-copy-btn.copied {
  color: #4ade80; border-color: #4ade80;
  background: rgba(74,222,128,0.1);
}
pre:hover .code-copy-btn { opacity: 1; }

/* Speak button on assistant messages */
.msg-speak-btn {
  background: none; border: none; cursor: pointer;
  font-size: 14px; padding: 2px 6px; margin-left: 8px;
  opacity: 0.5; transition: opacity 0.2s;
  vertical-align: middle;
}
.msg-speak-btn:hover { opacity: 1; }
.msg-speak-btn.tts-playing {
  opacity: 1;
  animation: tts-pulse 1.2s ease-in-out infinite;
}
.msg-speak-btn.tts-paused {
  opacity: 0.8;
}
@keyframes tts-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.tts-progress {
  font-size: 11px; color: #888; margin-left: 4px;
  vertical-align: middle; font-variant-numeric: tabular-nums;
}

/* Mic button */
.mic-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-normal);
  -webkit-tap-highlight-color: transparent;
}
.mic-btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface2); }
.mic-btn:active, .mic-btn.recording {
  background: #c0392b;
  border-color: #c0392b;
  color: white;
}
.mic-btn.recording {
  animation: micPulse 1s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192,57,43,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(192,57,43,0); }
}

/* Load more messages button */
.load-more-btn {
  display: block;
  margin: 0 auto 12px;
  padding: 8px 20px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all var(--transition-normal);
}
.load-more-btn:hover { background: var(--surface2); border-color: var(--border-strong); }
.load-more-btn:active { background: var(--surface3); transform: scale(0.98); }

/* Streaming cursor */
.streaming::after {
  content: "";
  display: inline-block;
  width: 3px; height: 18px;
  background: var(--accent);
  border-radius: 2px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 1s steps(2, start) infinite;
}
@keyframes cursorBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }

/* Thinking timer (shown while waiting for first LLM chunk) */
.thinking-timer {
  color: var(--text3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.thinking-timer::before {
  content: "";
  display: inline-block;
  width: 80px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ===== Image Preview Strip ===== */
.image-preview-strip {
  display: flex;
  gap: 8px;
  padding: 8px 12px 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.image-preview-strip.hidden { display: none; }

.image-preview-item {
  position: relative;
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.image-preview-item .img-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

/* Images in chat messages */
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.msg-images img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 10px;
  object-fit: contain;
  cursor: pointer;
  border: 1px solid var(--border);
}

/* File (non-image) attachment chips */
.file-preview-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 12px;
}
.file-preview-strip.hidden { display: none; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  font-size: 0.78rem;
}
.file-chip-processing { opacity: 0.75; }
.file-chip-error { border-color: #d9534f; }
.file-chip-icon { flex-shrink: 0; font-size: 1rem; }
.file-chip-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.file-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.file-chip-sub {
  color: var(--text2);
  font-size: 0.7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-chip-error .file-chip-sub { color: #d9534f; }
.file-chip-remove {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.12);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.file-chip-remove:hover { background: rgba(0,0,0,0.25); }
.file-chip-remove:focus-visible { outline: 2px solid var(--accent); }

/* Sent attachments shown inside a chat bubble */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.msg-attachment {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text2);
  background: var(--surface2);
}

/* Failed-send notice in the chat transcript (not a .msg bubble on purpose —
   .msg nodes stay index-aligned with the persisted message list) */
.chat-error-notice {
  align-self: center;
  max-width: 90%;
  margin: 6px auto;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(242, 139, 130, 0.45);
  background: rgba(242, 139, 130, 0.12);
  color: #f28b82;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Note AI panel attach button */
.notes-ai-attach {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.notes-ai-attach:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface2); }

/* Upload button */
.img-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-normal);
  -webkit-tap-highlight-color: transparent;
}
.img-btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface2); }
.img-btn:active { background: var(--surface3); }

/* Drop zone highlight */
.input-area.drag-over .input-wrapper {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* ===== Input Area ===== */
.input-area {
  flex-shrink: 0;
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: transparent;
}

.input-form { display: flex; }

.input-wrapper {
  flex: 1;
  /* Without this the wrapper's automatic minimum size (textarea cols + send
     button) exceeds narrow screens and pushes the send button out of view. */
  min-width: 0;
  display: flex;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 4px 4px 4px 16px;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal), background var(--transition-normal);
  box-shadow: var(--shadow-sm);
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow-md);
  background: var(--input-focus-bg, rgba(26,26,46,0.95));
}

.input-wrapper textarea {
  flex: 1;
  /* A textarea's intrinsic width comes from its `cols` attribute (default 20),
     so it refuses to shrink inside flex layouts unless min-width is cleared. */
  min-width: 0;
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  outline: none;
  padding: 8px 0;
  max-height: 120px;
  font-family: inherit;
}
.input-wrapper textarea::placeholder { color: var(--text3); }

.send-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-normal);
  -webkit-tap-highlight-color: transparent;
}
.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 0 16px var(--accent-glow);
}
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn:not(:disabled):active { opacity: 0.8; transform: scale(0.95); }
.send-btn.stop-mode {
  background: #dc4444;
  color: #fff;
  animation: stop-btn-pulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 12px rgba(220,68,68,0.3);
}
.send-btn.stop-mode:active { opacity: 0.7; }
@keyframes stop-btn-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

/* ===== Drawer ===== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: 280px;
  background: var(--surface);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-top: var(--safe-top);
  border-right: 1px solid var(--border);
}
.drawer.open { transform: translateX(0); }

/* Sidebar collapse toggle button (desktop only, injected by JS) */
/* Sidebar collapse toggle button (desktop only, re-enabled in the >=768px
   block). The compound selector is required to outrank `.drawer-footer-btn`,
   which is declared later and would otherwise restore `display: flex`. */
.drawer-footer-btn.sidebar-collapse-btn {
  display: none;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.new-chat-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-dim); border: none; color: var(--accent);
  border-radius: 10px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all var(--transition-fast);
}
.new-chat-btn:hover { background: var(--accent-glow); }
.new-chat-btn:active { background: var(--surface3); transform: scale(0.95); }

/* Conversation search bar */
.drawer-search { padding: 12px 12px 0; flex-shrink: 0; }
.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 10px;
  gap: 8px;
  transition: border-color 0.2s, background 0.2s;
}
.search-input-wrap:focus-within {
  border-color: var(--border);
  background: var(--surface2);
}
.search-icon { color: var(--text3); flex-shrink: 0; }
.conversation-search-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 8px 0;
  outline: none;
  font-family: inherit;
}
.conversation-search-input::placeholder { color: var(--text3); }
.search-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface3);
  border: none;
  color: var(--text2);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.search-clear-btn:hover { background: var(--border); }
.search-clear-btn.hidden { display: none; }

/* Search results — shown inline in session list area */
.conversation-search-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
}
.conversation-search-results.hidden { display: none; }
.search-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s;
  animation: searchFadeIn 0.2s ease-out both;
}
.search-result-item:hover { background: var(--surface2); }
.search-result-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-excerpt {
  font-size: 12px;
  color: var(--text3);
  margin-top: 3px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.search-result-meta {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.search-result-date { opacity: 0.7; }
.search-no-results {
  padding: 20px 12px;
  text-align: center;
  color: var(--text3);
  font-size: 13px;
}

@keyframes searchFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.drawer-sessions {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
}

.session-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: background var(--transition-fast);
  position: relative;
}
.session-item:active { background: var(--surface2); }
.session-item.active {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}
.session-item .meta { font-size: 11px; color: var(--text3); margin-top: 2px; }
.session-item .delete-btn {
  opacity: 0; color: var(--text3); background: none; border: none;
  padding: 4px 8px; cursor: pointer; font-size: 14px;
  transition: opacity var(--transition-fast);
}
.session-item:hover .delete-btn, .session-item:active .delete-btn { opacity: 0.6; }

/* Streaming spinner badge on session list items */
.session-streaming-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin-badge 0.8s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}
@keyframes spin-badge {
  to { transform: rotate(360deg); }
}

.drawer-footer {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drawer-footer-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: none; border: none;
  color: var(--text2); font-size: 14px;
  cursor: pointer; width: 100%;
  -webkit-tap-highlight-color: transparent;
  transition: all var(--transition-fast);
}
.drawer-footer-btn:hover { background: var(--surface2); color: var(--text); }
.drawer-footer-btn:active { background: var(--surface3); }
/* Admin-only entries are gated by JS toggling `.hidden`; no global .hidden
   utility exists in this stylesheet, so scope the rule to these buttons. */
.drawer-footer-btn.hidden { display: none; }

.drawer-user {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text3);
}
.user-info { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn {
  color: var(--text3); text-decoration: none;
  padding: 4px; border-radius: 4px; display: flex;
}
.logout-btn:hover { color: var(--text1); background: var(--surface2); }

/* ===== Drawer — phone layout =====
   On phones the footer nav (up to 10 entries) stacked as full-width rows ate
   most of the drawer height, leaving the conversation list a few items tall
   with a correspondingly tiny scroll thumb. Collapsing the nav into an
   auto-fitting icon grid hands that space back to the list. Sizes are all
   relative so this holds from small phones to large flagships. */
@media (max-width: 767px) {
  .drawer {
    width: min(88vw, 360px);
    padding-bottom: var(--safe-bottom);
  }

  .drawer-sessions {
    min-height: 30vh;
    min-height: 30dvh;
    overscroll-behavior: contain;
  }

  /* Comfortable touch target (~44px) for picking a conversation. */
  .session-item { padding: 12px; font-size: 15px; }
  .session-item.active { padding-left: 9px; }

  .drawer-footer {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
    gap: 4px;
    /* Backstop so the nav can never starve the list on short viewports. */
    max-height: 38vh;
    max-height: 38dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .drawer-footer-btn {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 9px 2px;
    font-size: 11px;
    line-height: 1.15;
    text-align: center;
  }
  .drawer-footer-btn svg { flex-shrink: 0; }
}

/* ===== Search ===== */
.search-bar { padding: 8px 16px; flex-shrink: 0; }
.search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.search-input::placeholder { color: var(--text3); }

/* ===== Content scroll areas ===== */
.content-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

/* ===== Notes / Vault Editor ===== */

.notes-storage-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text3);
  font-size: 10px;
  font-weight: 600;
  vertical-align: middle;
}

.notes-storage-badge.local {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-dim);
}

.notes-local-setup {
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.notes-local-setup:not(.hidden) {
  display: flex;
}

.notes-local-setup-card {
  width: min(460px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.notes-local-setup-card svg {
  color: var(--accent);
  opacity: 0.85;
}

.notes-local-setup-card h2 {
  margin: 16px 0 8px;
  color: var(--text);
  font-size: 20px;
}

.notes-local-setup-card p {
  margin: 0;
  color: var(--text2);
  font-size: 14px;
  line-height: 1.6;
}

.notes-local-setup-card button {
  margin: 20px 0 14px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}

.notes-local-setup-card button:hover {
  filter: brightness(1.08);
}

.notes-local-setup-card .notes-local-privacy {
  color: var(--text3);
  font-size: 12px;
}

/* Notes tree panel — scrollable left panel */
.notes-tree-panel {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  max-height: 40vh; /* prevent tree from dominating on mobile */
}

@media (min-width: 768px) {
  .notes-tree-panel {
    max-height: none; /* no height limit on desktop — sidebar layout */
  }
}

.file-tree-item {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
  user-select: none;
  -webkit-user-select: none;
}
.file-tree-item:active { background: var(--surface2); }
.file-tree-item.dir { color: var(--text2); font-weight: 500; }
.file-tree-item .file-icon { color: var(--text3); flex-shrink: 0; font-size: 14px; }
.file-tree-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-tree-folder { padding-left: 8px; }

/* Chevron for expandable folders */
.file-tree-item .folder-chevron {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text3);
  transition: transform 0.15s;
}
.file-tree-item .folder-chevron.collapsed {
  transform: rotate(-90deg);
}

/* Drag & drop styles */
.file-tree-item.dragging {
  opacity: 0.4;
}
.file-tree-item.drag-over {
  background: var(--accent-dim) !important;
  border: 1px dashed var(--accent);
  border-radius: 8px;
}
.notes-drop-root {
  padding: 12px;
  margin-top: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
  color: var(--text3);
  font-size: 12px;
  transition: all 0.15s;
}
.notes-drop-root.drag-over {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Context menu */
.notes-context-menu {
  position: fixed;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 6px;
  min-width: 170px;
  box-shadow: var(--shadow-lg);
  animation: dropdownFadeIn 0.12s ease-out;
}
.notes-context-menu.hidden { display: none; }
.context-menu-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background 0.1s;
}
.context-menu-item:hover { background: var(--surface2); }
.context-menu-danger { color: #f28b82; }
.context-menu-danger:hover { background: rgba(242,139,130,0.1); }
.context-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

/* Inline rename input */
.file-tree-item .file-name-input {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 1px 4px;
  outline: none;
  width: 100%;
  font-family: inherit;
}

.edit-toolbar {
  display: flex;
  gap: 2px;
  padding: 6px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}
.edit-toolbar button {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text2);
  border-radius: 8px; cursor: pointer; font-size: 15px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.edit-toolbar button:active { background: var(--surface2); }

/* Monaco editor container fills the edit pane */
#monaco-container {
  flex: 1;
  min-height: 0;
  width: 100%;
}

.notes-status {
  padding: 6px 16px;
  font-size: 11px;
  color: var(--text3);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Auto-save indicator near filename */
.notes-save-indicator {
  font-size: 11px;
  margin-left: 8px;
  vertical-align: middle;
  transition: opacity 0.5s ease;
}.notes-save-indicator.saving { color: var(--text3); }
.notes-save-indicator.saved { color: var(--accent); }
.notes-save-indicator.error { color: var(--error, #f44); }

/* Overlay shown while the Monaco bundle is still downloading, so the edit pane
   never renders blank (which looks like the note lost its content). */
.notes-edit-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg);
  color: var(--text3);
  font-size: 13px;
  z-index: 5;
}
.notes-edit-loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--text3);
  border-top-color: transparent;
  border-radius: 50%;
  animation: notes-edit-loading-spin 0.8s linear infinite;
}
@keyframes notes-edit-loading-spin { to { transform: rotate(360deg); } }
.notes-save-indicator.fade-out { opacity: 0; }

.notes-ai-local-notice {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-dim);
  color: var(--text2);
  font-size: 11px;
  line-height: 1.4;
}

/* Split pane container (mobile: just flex column, desktop: side-by-side) */
.notes-split {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Placeholder shown when no file is open (desktop split layout) */
.notes-placeholder {
  display: none; /* hidden by default, shown via JS on desktop */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: 1;
  color: var(--text3);
  font-size: 15px;
}

/* Active file highlight in tree */
.file-tree-item.active { background: var(--accent-dim); color: var(--accent); }
.file-tree-item.dir.active-dir { background: var(--surface2); color: var(--accent); }

.markdown-body {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
}
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { margin-top: 22px; margin-bottom: 10px; font-weight: 700; letter-spacing: -0.02em; }
.markdown-body h1 { font-size: 24px; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.markdown-body h2 { font-size: 20px; color: var(--accent2); }
.markdown-body h3 { font-size: 17px; color: #56d4c4; }
.markdown-body h4 { font-size: 15px; color: #c4b5fd; }
.markdown-body strong { color: #fff; font-weight: 700; }
.markdown-body em { color: var(--accent2); font-style: italic; }
.markdown-body p { margin-bottom: 10px; }
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin-bottom: 10px; }
.markdown-body li { margin: 4px 0; line-height: 1.6; }
.markdown-body ul > li::marker { color: var(--accent); }
.markdown-body ol > li::marker { color: var(--accent); font-weight: 600; }
.markdown-body code:not(pre code) {
  background: rgba(124,108,240,0.1); padding: 2px 7px; border-radius: 6px;
  font-size: 13px; color: #c4b5fd; border: 1px solid rgba(124,108,240,0.15);
}
.markdown-body pre {
  background: var(--code-bg, #0c0c1a); border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 16px; overflow-x: auto; margin-bottom: 12px; position: relative;
  box-shadow: var(--shadow-sm);
}
.markdown-body pre code { background: none; padding: 0; color: inherit; }
.markdown-body pre code[class]::before {
  content: attr(class); position: absolute; top: 4px; right: 8px;
  font-size: 11px; color: var(--text3); text-transform: uppercase; pointer-events: none;
}
.markdown-body pre code[class*="language-"]::before { content: attr(data-lang); }
.markdown-body blockquote {
  border-left: 3px solid var(--accent); padding: 10px 18px;
  margin-bottom: 12px; background: var(--accent-dim); border-radius: 0 12px 12px 0;
  color: var(--text2); font-style: italic;
}
.markdown-body a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid transparent; transition: border-color 0.2s;
}
.markdown-body a:hover { border-bottom-color: var(--accent); }
.markdown-body table {
  border-collapse: separate; border-spacing: 0; width: 100%; margin-bottom: 10px;
  border-radius: 8px; overflow: hidden; border: 1px solid var(--border);
}
.markdown-body thead { background: var(--surface2); }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; font-size: 13px; }
.markdown-body th { background: var(--surface); font-weight: 700; color: #8ab4f8; }
.markdown-body hr {
  border: none; height: 1px;
  background: linear-gradient(to right, transparent, var(--border), transparent);
  margin: 16px 0;
}

/* ===== Knowledge Cards ===== */
.knowledge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}
.knowledge-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.knowledge-card p { font-size: 14px; line-height: 1.5; }
.knowledge-tag {
  display: inline-block; background: var(--surface2); color: var(--text2);
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
}
.knowledge-category {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  border-radius: 10px; font-weight: 500; text-transform: uppercase;
}
.cat-fact { background: rgba(124,108,240,0.15); color: var(--accent); }
.cat-concept { background: rgba(196,181,253,0.12); color: #c4b5fd; }
.cat-decision { background: rgba(253,230,138,0.12); color: #fde68a; }
.cat-opinion { background: rgba(110,231,183,0.1); color: #6ee7b7; }
.cat-reference { background: rgba(221,214,254,0.1); color: #ddd6fe; }

/* ===== Stats ===== */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}
.stat-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.2; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 6px; }

.budget-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.budget-section h3 { font-size: 13px; color: var(--text2); margin-bottom: 12px; font-weight: 500; }
.budget-bar-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text3); margin-bottom: 4px; }
.budget-bar-track { height: 6px; background: var(--surface3); border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
.budget-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.fill-green { background: #34a853; }
.fill-orange { background: #f4a261; }
.fill-purple { background: #a78bfa; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: modalBgFadeIn 0.2s ease-out;
}
@keyframes modalBgFadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 18px; letter-spacing: -0.01em; }
.modal-textarea, .modal-input, .modal-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.modal-textarea { resize: vertical; margin-bottom: 12px; }
.modal-textarea:focus, .modal-input:focus, .modal-select:focus { border-color: var(--accent); }
.modal-row { display: flex; gap: 8px; margin-bottom: 16px; }
.modal-row > * { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-cancel {
  padding: 10px 20px; border-radius: 20px;
  background: none; border: none; color: var(--text2);
  font-size: 14px; cursor: pointer;
  transition: color var(--transition-fast);
}
.modal-cancel:hover { color: var(--text); }
.modal-save {
  padding: 10px 22px; border-radius: 20px;
  background: var(--accent); border: none; color: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px rgba(124,108,240,0.3);
}
.modal-save:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(124,108,240,0.4); }

/* ===== Live Mode ===== */
.live-mode {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--safe-bottom) + env(safe-area-inset-bottom, 0px));
  opacity: 1;
  transition: opacity 0.3s ease;
}
.live-mode.hidden { display: none; opacity: 0; }
.live-mode.entering { opacity: 0; }
.live-mode.visible { opacity: 1; }

.live-topbar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  flex-shrink: 0;
}
.live-back-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text2);
  border-radius: 50%; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.live-back-btn:active { background: var(--surface2); }
.live-title { font-size: 16px; font-weight: 500; color: var(--text); flex: 1; }

.live-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 0;
}

/* Phase 2: frequency bars container replaces canvas */
.live-waveform-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 80%;
  max-width: 300px;
  height: 120px;
}
.live-waveform-bars .bar {
  width: 6px;
  min-height: 3px;
  border-radius: 3px;
  background: var(--text3);
  transition: height 0.08s ease, background 0.3s ease;
}
/* State-specific bar colors */
.live-waveform-bars.state-idle .bar { background: var(--text3); }
.live-waveform-bars.state-recording .bar { background: #ef4444; }
.live-waveform-bars.state-processing .bar { background: var(--accent); }
.live-waveform-bars.state-speaking .bar { background: #34a853; }
.live-waveform-bars.state-error .bar { background: #f59e0b; }

.live-status {
  font-size: 16px;
  color: var(--text2);
  font-weight: 500;
  transition: color 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.live-status.idle { color: var(--text2); }
.live-status.recording { color: #ef4444; }
.live-status.processing { color: var(--accent); }
.live-status.speaking { color: #34a853; }
.live-status.error { color: #f59e0b; }

/* Phase 2: live transcript with interim faded text */
.live-transcript {
  font-size: 18px;
  color: var(--text);
  text-align: center;
  padding: 0 24px;
  min-height: 28px;
  max-width: 90%;
}
.live-transcript-interim {
  font-size: 16px;
  color: var(--text3);
  text-align: center;
  padding: 0 24px;
  min-height: 20px;
  max-width: 90%;
  font-style: italic;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.live-response {
  max-height: 35%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 20px 12px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  flex-shrink: 0;
}
.live-response p { margin: 0 0 6px; }
.live-response strong { color: #e8eaed; }
.live-response a { color: var(--accent); }
.live-response ul, .live-response ol { padding-left: 18px; margin: 4px 0; }

.live-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 16px;
  flex-shrink: 0;
}

/* Phase 1: 5-state mic button with CSS transitions */
.live-mic-btn {
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface2);
  border: 2px solid var(--border);
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
  transform: scale(1.0);
}
/* IDLE state */
.live-mic-btn.state-idle {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
  transform: scale(1.0);
}
/* RECORDING state: red glow, scale up */
.live-mic-btn.state-recording {
  background: #c0392b;
  border-color: #e74c3c;
  color: white;
  transform: scale(1.2);
  animation: micRecordGlow 1.5s ease-in-out infinite;
}
/* PROCESSING state: blue pulse */
.live-mic-btn.state-processing {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.0);
  animation: micProcessPulse 2s ease-in-out infinite;
}
/* SPEAKING state: green pulse */
.live-mic-btn.state-speaking {
  background: #1a3d2e;
  border-color: #34a853;
  color: #34a853;
  transform: scale(1.0);
  animation: micSpeakPulse 2s ease-in-out infinite;
}
/* ERROR state: amber, shake */
.live-mic-btn.state-error {
  background: #3d2e0a;
  border-color: #f59e0b;
  color: #f59e0b;
  transform: scale(1.0);
  animation: micErrorShake 0.5s ease-in-out;
}

@keyframes micRecordGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192,57,43,0.4); }
  50% { box-shadow: 0 0 0 16px rgba(192,57,43,0); }
}
@keyframes micProcessPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(138,180,248,0.3); }
  50% { box-shadow: 0 0 0 12px rgba(138,180,248,0); }
}
@keyframes micSpeakPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52,168,83,0.3); }
  50% { box-shadow: 0 0 0 12px rgba(52,168,83,0); }
}
@keyframes micErrorShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Legacy compat */
.live-mic-btn:active, .live-mic-btn.recording {
  background: #c0392b;
  border-color: #e74c3c;
  color: white;
  transform: scale(1.2);
}
.live-mic-btn.recording {
  animation: micRecordGlow 1.5s ease-in-out infinite;
}

.live-stop-btn {
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.live-stop-btn.hidden { display: none; }
.live-stop-btn:active { background: var(--surface3); }

/* ===== VAD Mode Button ===== */
.vad-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface2);
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.vad-btn:active { background: var(--surface3); }
.vad-btn.active {
  background: #1a3d2e;
  border-color: #34a853;
  color: #34a853;
}
/* Green dot indicator when VAD is active */
.vad-btn.active::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #34a853;
  border-radius: 50%;
  margin-right: 5px;
  animation: vadPulse 1.5s ease-in-out infinite;
  vertical-align: middle;
}
@keyframes vadPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* VAD active: mic button shows listening state in idle */
.live-mic-btn.vad-idle {
  background: #1a3d2e;
  border-color: #34a853;
  color: #34a853;
  animation: vadListenPulse 3s ease-in-out infinite;
}
@keyframes vadListenPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52,168,83,0.2); }
  50% { box-shadow: 0 0 0 8px rgba(52,168,83,0); }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: 3px;
  transition: background 0.2s;
}
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ===== iOS standalone ===== */
@media (display-mode: standalone) {
  body { min-height: 100dvh; }
}

/* ===== Text selection ===== */
body { -webkit-user-select: none; user-select: none; }
.msg, .notes-ai-msg, .scratch-msg, textarea, input, select { -webkit-user-select: text; user-select: text; }

/* ===== Desktop Adaptation ===== */
/*
 * Breakpoints & sidebar widths:
 *   768px+  → sidebar 260px (tablet / small window)
 *   1024px+ → sidebar 270px (small laptop, 1024×768)
 *   1280px+ → sidebar 280px (13" laptop, 1280×800 / 1366×768)
 *   1440px+ → sidebar 290px (15" laptop / MacBook Pro)
 *   1920px+ → sidebar 300px (Full HD desktop, most common)
 *
 * Collapsed sidebar is always 48px at every breakpoint.
 * Content max-width uses min(Xpx, Y%) so it adapts to both
 * expanded and collapsed sidebar states naturally.
 */

/* --- 768px+: Tablet / small window (available ~508px with sidebar) --- */
@media (min-width: 768px) {
  /* Persistent sidebar: always visible, no overlay */
  .drawer {
    width: 260px;
    transform: translateX(0);
    position: fixed;
    border-right: 1px solid var(--border);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
  }
  .drawer-overlay {
    display: none !important;
  }

  /* Main content offset by sidebar width */
  .app {
    left: 260px;
    transition: left 0.25s ease;
  }
  .live-mode {
    left: 260px;
    align-items: center;
    transition: left 0.25s ease;
  }
  .modal-overlay {
    left: 260px;
    transition: left 0.25s ease;
  }

  /* Collapsed sidebar: narrow, icons only */
  .drawer.collapsed {
    width: 48px;
  }
  .drawer.collapsed .drawer-header {
    padding: 12px 4px;
    justify-content: center;
  }
  .drawer.collapsed .drawer-title { display: none; }
  .drawer.collapsed .new-chat-btn { display: none; }
  .drawer.collapsed .drawer-search { display: none; }
  .drawer.collapsed .drawer-sessions { display: none; }
  .drawer.collapsed .drawer-footer-btn {
    justify-content: center;
    padding: 12px 0;
    gap: 0;
  }
  .drawer.collapsed .drawer-footer-btn span,
  .drawer.collapsed .drawer-footer-btn:not(.sidebar-collapse-btn) {
    font-size: 0; /* hide text but keep element for icon */
  }
  .drawer.collapsed .drawer-footer-btn svg { flex-shrink: 0; }
  .drawer.collapsed .drawer-footer {
    padding: 4px;
    gap: 0;
  }
  .drawer.collapsed .drawer-footer > .drawer-footer-btn:not(.sidebar-collapse-btn) {
    display: none;
  }

  /* Collapsed: adjust main content left */
  .drawer.collapsed ~ .app { left: 48px; }
  .drawer.collapsed ~ #live-mode,
  .drawer.collapsed ~ .live-mode { left: 48px; }
  .drawer.collapsed ~ .app .modal-overlay,
  .drawer.collapsed ~ .modal-overlay { left: 48px; }

  /* Sidebar collapse/expand button */
  .sidebar-collapse-btn {
    display: flex !important;
    cursor: pointer;
  }
  .sidebar-collapse-btn svg {
    transition: transform 0.25s ease;
  }
  .drawer.collapsed .sidebar-collapse-btn svg {
    transform: rotate(180deg);
  }

  /* Center children horizontally in flex column layouts */
  .view {
    align-items: center;
  }

  /* Chat split must stretch full width for side-by-side artifact layout */
  .chat-split {
    align-self: stretch;
    width: 100%;
  }
  /* When artifact panel is hidden, center the chat content */
  .chat-main {
    align-items: center;
  }

  /* Topbar stays full-width */
  .topbar {
    align-self: stretch;
    padding: 0 16px;
  }

  /* Hide hamburger menu button on desktop — sidebar is always visible */
  .topbar-btn[aria-label="Menu"] {
    display: none;
  }

  /* Content areas: use 92% width on small screens to avoid cramped feel.
     Max 900px keeps text readable when sidebar is collapsed. */
  .messages {
    max-width: min(900px, 92%);
    width: 100%;
    padding: 14px 20px;
  }
  .input-area {
    max-width: min(900px, 92%);
    width: 100%;
    padding: 10px 20px;
    padding-bottom: calc(10px + var(--safe-bottom));
  }
  .content-scroll {
    max-width: min(900px, 92%);
    width: 100%;
    padding: 14px 20px;
  }
  .search-bar {
    max-width: min(900px, 92%);
    width: 100%;
    padding: 8px 20px;
  }
  /* --- Notes split-pane layout (desktop) --- */
  /* Override centered layout for notes view */
  #view-notes {
    align-items: stretch;
  }

  /* Split pane: side-by-side on desktop */
  .notes-split {
    flex-direction: row;
    flex: 1;
    min-height: 0;
  }

  /* File tree: fixed width sidebar in split layout */
  .notes-split .notes-tree-panel {
    max-width: none;
    width: 280px;
    min-width: 280px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    padding: 8px;
    overflow-y: auto;
  }

  /* Editor wrap: fill remaining space, no max-width constraint */
  .notes-split #notes-editor-wrap {
    max-width: none;
    width: auto;
    flex: 1;
    min-width: 0;
  }

  /* Preview area inside split: readable width but not globally constrained */
  .notes-split #notes-preview {
    max-width: none;
    width: 100%;
    padding: 20px 32px;
  }
  .notes-split #notes-preview > * {
    max-width: 900px;
  }

  /* Placeholder visible on desktop when no file open */
  .notes-placeholder {
    display: flex;
  }

  /* Edit toolbar stretches full width like topbar */
  .edit-toolbar {
    align-self: stretch;
  }

  /* Live mode: center content areas */
  .live-center { max-width: 600px; width: 100%; }
  .live-response { max-width: 600px; width: 100%; }
  .live-controls { max-width: 600px; width: 100%; }
  .live-topbar { align-self: stretch; }

  /* Wider scrollbar on desktop */
  ::-webkit-scrollbar { width: 7px; }

  /* Hover states for desktop */
  .topbar-btn:hover { background: var(--surface2); color: var(--text); }
  .session-item:hover { background: var(--surface2); }
  .drawer-footer-btn:hover { background: var(--surface2); color: var(--text); }
  .file-tree-item:hover { background: var(--surface2); }
  .rag-btn:hover, .council-btn:hover { background: var(--surface2); }
  .rag-btn.active:hover { background: rgba(124,108,240,0.2); }
  .council-btn.active:hover { background: rgba(196,181,253,0.16); }

  /* User message bubble: wider on small screens */
  .msg-user { max-width: 80%; }

  /* Stat grid: 2 columns on tablet */
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* --- 1024px+: Small laptop (1024×768, available ~754px with sidebar) --- */
@media (min-width: 1024px) {
  .drawer { width: 270px; }
  .app { left: 270px; }
  .live-mode { left: 270px; }
  .modal-overlay { left: 270px; }

  /* Collapsed overrides */
  .drawer.collapsed { width: 48px; }
  .drawer.collapsed ~ .app { left: 48px; }
  .drawer.collapsed ~ #live-mode,
  .drawer.collapsed ~ .live-mode { left: 48px; }
  .drawer.collapsed ~ .app .modal-overlay,
  .drawer.collapsed ~ .modal-overlay { left: 48px; }

  /* Content: still use most of available width */
  .messages { max-width: min(940px, 90%); padding: 16px 24px; }
  .input-area { max-width: min(940px, 90%); padding: 12px 24px; padding-bottom: calc(12px + var(--safe-bottom)); }
  .content-scroll { max-width: min(940px, 90%); padding: 16px 24px; }
  .search-bar { max-width: min(940px, 90%); padding: 8px 24px; }
  #notes-editor-wrap { max-width: min(940px, 90%); }
  /* Notes split overrides — tree and editor unconstrained */
  .notes-split .notes-tree-panel { max-width: none; }
  .notes-split #notes-editor-wrap { max-width: none; }

  /* User bubble slightly narrower */
  .msg-user { max-width: 75%; }

  /* Stat grid: 3 columns on small laptop */
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

/* --- 1280px+: Standard laptop / 13" (1280×800, 1366×768, available ~1000px) --- */
@media (min-width: 1280px) {
  .drawer { width: 280px; }
  .app { left: 280px; }
  .live-mode { left: 280px; }
  .modal-overlay { left: 280px; }

  /* Collapsed overrides */
  .drawer.collapsed { width: 48px; }
  .drawer.collapsed ~ .app { left: 48px; }
  .drawer.collapsed ~ #live-mode,
  .drawer.collapsed ~ .live-mode { left: 48px; }
  .drawer.collapsed ~ .app .modal-overlay,
  .drawer.collapsed ~ .modal-overlay { left: 48px; }

  /* Content: comfortable width, 85% of available space */
  .messages { max-width: min(1000px, 85%); padding: 18px 28px; }
  .input-area { max-width: min(1000px, 85%); padding: 12px 28px; padding-bottom: calc(12px + var(--safe-bottom)); }
  .content-scroll { max-width: min(1000px, 85%); padding: 16px 28px; }
  .search-bar { max-width: min(1000px, 85%); padding: 8px 28px; }
  #notes-editor-wrap { max-width: min(1000px, 85%); }
  .notes-split .notes-tree-panel { max-width: none; }
  .notes-split #notes-editor-wrap { max-width: none; }

  /* User bubble: 70% on standard laptop */
  .msg-user { max-width: 70%; }

  /* Stat grid: 4 columns */
  .stat-grid { grid-template-columns: repeat(4, 1fr); }

  /* Larger waveform on desktop */
  .live-waveform-bars { max-width: 400px; height: 150px; }

  /* Larger live mode mic button */
  .live-mic-btn { width: 80px; height: 80px; }
}

/* --- 1440px+: Large laptop / MacBook Pro / external monitor (available ~1140px) --- */
@media (min-width: 1440px) {
  .drawer { width: 290px; }
  .app { left: 290px; }
  .live-mode { left: 290px; }
  .modal-overlay { left: 290px; }

  /* Collapsed overrides */
  .drawer.collapsed { width: 48px; }
  .drawer.collapsed ~ .app { left: 48px; }
  .drawer.collapsed ~ #live-mode,
  .drawer.collapsed ~ .live-mode { left: 48px; }
  .drawer.collapsed ~ .app .modal-overlay,
  .drawer.collapsed ~ .modal-overlay { left: 48px; }

  /* Content: 90% of available on mid-size screens, keeps it wide on Surface/MacBook */
  .messages { max-width: min(1100px, 90%); padding: 20px 32px; }
  .input-area { max-width: min(1100px, 90%); padding: 12px 32px; padding-bottom: calc(12px + var(--safe-bottom)); }
  .content-scroll { max-width: min(1100px, 90%); padding: 18px 32px; }
  .search-bar { max-width: min(1100px, 90%); padding: 8px 32px; }
  #notes-editor-wrap { max-width: min(1100px, 90%); }
  .notes-split .notes-tree-panel { max-width: none; }
  .notes-split #notes-editor-wrap { max-width: none; }

  /* User bubble: 65% on large screens */
  .msg-user { max-width: 65%; }

  /* Live mode: slightly wider content */
  .live-center { max-width: 700px; }
  .live-response { max-width: 700px; }
  .live-controls { max-width: 700px; }
}

/* --- 1920px+: Full HD desktop and beyond (available ~1620px, most common) --- */
@media (min-width: 1920px) {
  .drawer { width: 300px; }
  .app { left: 300px; }
  .live-mode { left: 300px; }
  .modal-overlay { left: 300px; }

  /* Collapsed overrides */
  .drawer.collapsed { width: 48px; }
  .drawer.collapsed ~ .app { left: 48px; }
  .drawer.collapsed ~ #live-mode,
  .drawer.collapsed ~ .live-mode { left: 48px; }
  .drawer.collapsed ~ .app .modal-overlay,
  .drawer.collapsed ~ .modal-overlay { left: 48px; }

  /* Content: cap at 1200px for readability, 80% of space on FHD+ */
  .messages { max-width: min(1200px, 80%); padding: 24px 36px; }
  .input-area { max-width: min(1200px, 80%); padding: 14px 36px; padding-bottom: calc(14px + var(--safe-bottom)); }
  .content-scroll { max-width: min(1200px, 80%); padding: 20px 36px; }
  .search-bar { max-width: min(1200px, 80%); padding: 8px 36px; }
  #notes-editor-wrap { max-width: min(1200px, 80%); }
  .notes-split .notes-tree-panel { max-width: none; }
  .notes-split #notes-editor-wrap { max-width: none; }

  /* User bubble: 55% — plenty of space on FHD */
  .msg-user { max-width: 55%; }

  /* Live mode: generous width */
  .live-center { max-width: 800px; }
  .live-response { max-width: 800px; }
  .live-controls { max-width: 800px; }
  .live-waveform-bars { max-width: 500px; height: 160px; }

  /* Wider scrollbar on large screens */
  ::-webkit-scrollbar { width: 8px; }
}

/* ===== Note Edit Cards (AI-assisted editing) ===== */

.note-edit-card {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}

.note-edit-card.note-edit-applied {
  border-color: #2e7d32;
  opacity: 0.7;
}

.note-edit-card.note-edit-discarded {
  border-color: var(--text3);
  opacity: 0.5;
}

.note-edit-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.note-edit-action {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.note-edit-action-create { background: #1b5e20; color: #a5d6a7; }
.note-edit-action-edit { background: #e65100; color: #ffcc80; }
.note-edit-action-append { background: #0d47a1; color: #90caf9; }

.note-edit-path {
  color: var(--text2);
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-edit-diff {
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.note-edit-diff.expanded {
  max-height: 600px;
}

.diff-container {
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 4px 0;
}

.diff-line {
  padding: 1px 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.diff-line-add {
  background: rgba(46, 125, 50, 0.2);
  color: #a5d6a7;
}

.diff-line-remove {
  background: rgba(198, 40, 40, 0.2);
  color: #ef9a9a;
}

.diff-line-context {
  color: var(--text2);
}

.diff-line-header {
  color: var(--text3);
  font-weight: 600;
}

.diff-line-hunk {
  color: var(--accent);
  background: rgba(138, 180, 248, 0.1);
  font-weight: 500;
}

.note-edit-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

.note-edit-approve {
  padding: 5px 16px;
  background: #2e7d32;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.note-edit-approve:hover { background: #388e3c; }
.note-edit-approve:disabled { opacity: 0.5; cursor: not-allowed; }

.note-edit-discard {
  padding: 5px 16px;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.note-edit-discard:hover { background: var(--surface3); color: var(--text); }

.note-edit-toggle-diff {
  margin-left: auto;
  padding: 5px 12px;
  background: transparent;
  color: var(--accent);
  border: none;
  font-size: 12px;
  cursor: pointer;
}

.note-edit-toggle-diff:hover { text-decoration: underline; }

.note-edit-status-applied {
  color: #a5d6a7;
  font-size: 13px;
  font-weight: 500;
}

.note-edit-status-discarded {
  color: var(--text3);
  font-size: 13px;
  font-style: italic;
}

/* Mobile: note-edit cards take full width */
@media (max-width: 767px) {
  .note-edit-diff { max-height: 150px; }
  .note-edit-diff.expanded { max-height: 400px; }
}

/* ===== Edit Mode (Full-Screen Diff + Iteration) ===== */

.edit-mode {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.edit-mode.hidden { display: none; }

.edit-mode-topbar {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 8px;
  padding-top: var(--safe-top);
  min-height: calc(56px + var(--safe-top));
  background: var(--bg);
  flex-shrink: 0;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.edit-mode-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-mode-version {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 10px;
  border-radius: 12px;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}

.edit-mode-split {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.edit-mode-original,
.edit-mode-proposed {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
}

.edit-mode-original {
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.edit-mode-proposed {
  background: var(--surface);
}

/* Side-by-side diff line coloring */
.diff-side-line {
  padding: 1px 8px;
  min-height: 1.6em;
}
.diff-side-remove {
  background: rgba(248, 81, 73, 0.15);
  color: #f85149;
}
.diff-side-add {
  background: rgba(63, 185, 80, 0.15);
  color: #3fb950;
}
.diff-side-context {
  color: var(--text2);
}
.diff-side-empty {
  background: rgba(255, 255, 255, 0.02);
  min-height: 1.6em;
}

/* Line number gutter */
.diff-side-line .diff-ln {
  display: inline-block;
  width: 32px;
  text-align: right;
  margin-right: 8px;
  color: var(--text3);
  font-size: 11px;
  user-select: none;
}

/* Direct edit textarea (replaces right panel) */
.edit-direct-textarea {
  flex: 1;
  background: var(--surface);
  color: var(--text);
  border: none;
  padding: 16px;
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: none;
  outline: none;
  overflow-y: auto;
}
.edit-direct-textarea.hidden { display: none; }

/* Chat section */
.edit-mode-chat {
  height: 28%;
  min-height: 140px;
  max-height: 280px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.edit-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  scrollbar-width: thin;
}

.edit-chat-msg {
  padding: 6px 0;
  font-size: 13px;
  line-height: 1.5;
}
.edit-chat-msg-user {
  color: var(--accent);
}
.edit-chat-msg-user::before {
  content: "你: ";
  font-weight: 600;
}
.edit-chat-msg-ai {
  color: var(--text2);
}
.edit-chat-msg-ai::before {
  content: "AI: ";  /* keep "AI" as-is — recognized term */
  font-weight: 600;
  color: #a5d6a7;
}
.edit-chat-msg-system {
  color: var(--text3);
  font-style: italic;
  font-size: 12px;
}

.edit-chat-input {
  display: flex;
  padding: 8px 12px;
  gap: 8px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

.edit-chat-input textarea {
  flex: 1;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 80px;
}
.edit-chat-input textarea:focus {
  border-color: var(--accent);
}

.edit-chat-input .send-btn {
  flex-shrink: 0;
}

/* Action buttons */
.edit-mode-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.edit-approve-btn {
  padding: 8px 26px;
  background: #2e7d32;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px rgba(46,125,50,0.3);
}
.edit-approve-btn:hover { background: #388e3c; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(46,125,50,0.4); }
.edit-approve-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.edit-discard-btn {
  padding: 8px 26px;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.edit-discard-btn:hover { background: var(--surface2); color: var(--text); border-color: var(--border-strong); }

/* Streaming indicator in edit chat */
.edit-chat-thinking {
  color: var(--text3);
  font-size: 12px;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Mobile: stack vertically */
@media (max-width: 767px) {
  .edit-mode-split {
    flex-direction: column;
  }
  .edit-mode-original {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 35%;
    flex: none;
  }
  .edit-mode-proposed {
    flex: 1;
  }
  .edit-mode-chat {
    height: 25%;
    min-height: 120px;
    max-height: 200px;
  }
  .edit-mode-title {
    font-size: 12px;
  }
}

/* ===== AI Note Editor ===== */

/* --- File tree collapse/toggle --- */
.notes-tree-panel.collapsed {
  display: none !important;
}

/* AI button active state */
.notes-ai-btn.active {
  color: var(--accent) !important;
  background: var(--accent-dim);
}

/* --- AI panel resize handle --- */
.notes-ai-resize-handle {
  display: none;
}
.notes-split.ai-open .notes-ai-resize-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 6px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--border);
  transition: background 0.15s;
  position: relative;
}
.notes-split.ai-open .notes-ai-resize-handle::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -6px; right: -6px;
}
.notes-split.ai-open .notes-ai-resize-handle:hover,
.notes-split.ai-open .notes-ai-resize-handle.dragging {
  background: var(--accent);
}
.notes-split.ai-open .notes-ai-resize-handle::after {
  content: '··\A··\A··';
  white-space: pre;
  font-size: 9px;
  line-height: 6px;
  letter-spacing: 1px;
  color: var(--text3);
  opacity: 0.5;
}
.notes-split.ai-open .notes-ai-resize-handle:hover::after {
  opacity: 1;
  color: var(--accent);
}

/* --- AI Chat Panel (right side on desktop) --- */
.notes-ai-panel {
  width: var(--ai-panel-width, 380px);
  min-width: 200px;
  max-width: 70%;
  border-left: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  flex-shrink: 0;
  transition: width 0.2s ease;
}
.notes-ai-panel.hidden {
  display: none;
}

/* Drag handle — mobile only */
.notes-ai-drag-handle {
  display: none;
}

/* Panel header */
.notes-ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: linear-gradient(135deg, rgba(124,108,240,0.06), rgba(232,168,124,0.04));
}
.notes-ai-header-title {
  font-size: 14px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Selection context badge */
.notes-ai-context {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent-dim);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-ai-context.hidden {
  display: none;
}
.notes-ai-context-info {
  flex: 1;
  min-width: 0;
}
#notes-ai-context-text {
  display: block;
  font-size: 12px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notes-ai-context-meta {
  display: block;
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
}
.notes-ai-context-clear {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.notes-ai-context-clear:hover {
  background: var(--surface2);
  color: var(--text);
}

/* Chat messages area */
.notes-ai-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Individual chat messages */
.notes-ai-msg {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 95%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.notes-ai-msg-user {
  background: var(--user-bg);
  color: var(--text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.notes-ai-msg-assistant {
  background: var(--surface2);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.notes-ai-msg-assistant .markdown-body {
  font-size: 13px;
  line-height: 1.5;
}
.notes-ai-msg-system {
  background: transparent;
  color: var(--text3);
  font-size: 12px;
  text-align: center;
  align-self: center;
}
.notes-ai-msg-thinking {
  color: var(--text3);
  font-size: 12px;
  animation: pulse 1.5s ease-in-out infinite;
}

/* Queued messages in note AI (greyed out with accent border) */
.notes-ai-msg.msg-queued {
  opacity: 0.5;
  border-left: 2px solid var(--accent);
}

/* Streaming spinner badge on notes in the file tree */
.note-streaming-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin-badge 0.8s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}

/* Chat input area */
.notes-ai-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
#notes-ai-input {
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.4;
}
#notes-ai-input:focus {
  border-color: var(--accent);
}
#notes-ai-input::placeholder {
  color: var(--text3);
}
.notes-ai-send {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

/* Note AI image preview strip */
.note-ai-image-strip {
  display: flex;
  gap: 6px;
  padding: 6px 12px 2px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.note-ai-image-strip.hidden { display: none; }
.note-ai-image-strip .image-preview-item {
  width: 48px;
  height: 48px;
}

/* --- Inline edit diff card in chat --- */
.notes-ai-diff-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 8px;
}
.notes-ai-diff-card .diff-container {
  max-height: 200px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  font-size: 12px;
  padding: 8px;
}
.notes-ai-diff-card .diff-line {
  padding: 1px 4px;
  white-space: pre-wrap;
  word-break: break-all;
}
.notes-ai-diff-card .diff-line-add {
  background: rgba(80, 200, 80, 0.15);
  color: #6bcb77;
}
.notes-ai-diff-card .diff-line-remove {
  background: rgba(255, 80, 80, 0.15);
  color: #f28b82;
  text-decoration: line-through;
}
.notes-ai-diff-actions {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
}
.notes-ai-diff-apply {
  flex: 1;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: #2d8044;
  color: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.notes-ai-diff-apply:hover { background: #38a155; }
.notes-ai-diff-reject {
  flex: 1;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer;
  font-size: 12px;
}
.notes-ai-diff-reject:hover { background: var(--surface3); }

/* --- Insert-to-note button on AI messages --- */
.notes-ai-insert-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text3);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  transition: all 0.15s ease;
}
.notes-ai-insert-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}
.notes-ai-insert-btn.inserted {
  color: #6bcb77;
  border-color: #6bcb77;
  pointer-events: none;
}

/* --- Inline edit overlay on editor --- */
.notes-inline-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  font-size: 16px;
  line-height: 1.6;
  padding: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: transparent;
}
.notes-inline-overlay .inline-deleted {
  background: rgba(255, 80, 80, 0.15);
  color: #f28b82;
  text-decoration: line-through;
}
.notes-inline-overlay .inline-inserted {
  background: rgba(80, 200, 80, 0.15);
  color: #6bcb77;
}

/* Floating action bar for inline edits */
.notes-inline-actions {
  position: absolute;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 50;
}
.notes-inline-actions.hidden {
  display: none;
}
.notes-inline-apply {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  background: #2d8044;
  color: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.notes-inline-apply:hover { background: #38a155; }
.notes-inline-reject {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer;
  font-size: 12px;
}
.notes-inline-reject:hover { background: var(--surface3); }

/* Editor has proposal active */
#monaco-container.has-proposal {
  outline: 1px solid var(--accent);
}

/* Editor container needs position relative for overlay positioning */
#notes-edit {
  position: relative;
}

/* --- Mobile: bottom sheet --- */
@media (max-width: 767px) {
  .notes-ai-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60vh;
    width: 100% !important;
    min-width: unset;
    max-width: unset;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 100;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }
  .notes-ai-panel.open {
    display: flex;
    transform: translateY(0);
  }
  .notes-ai-panel.hidden {
    display: flex;
    transform: translateY(100%);
  }
  .notes-ai-drag-handle {
    display: flex;
    justify-content: center;
    padding: 8px 0 4px;
    cursor: grab;
    flex-shrink: 0;
  }
  .notes-ai-drag-bar {
    width: 36px;
    height: 4px;
    background: var(--surface3);
    border-radius: 2px;
  }
  /* No inline overlay on mobile — use diff cards in chat */
  .notes-inline-actions {
    display: none !important;
  }
  .notes-inline-overlay {
    display: none !important;
  }
}

/* Mobile: hide file tree entirely when AI panel is open (unless user toggled it) */
.notes-split.ai-open .notes-tree-panel:not(.tree-force-show) {
  display: none !important;
}

/* --- Desktop: three-panel layout adjustments --- */
@media (min-width: 768px) {
  /* Desktop: show tree but narrower when AI open (respect collapsed toggle) */
  .notes-split.ai-open .notes-tree-panel:not(.collapsed) {
    display: block !important;
    width: 200px;
    min-width: 200px;
  }
  .notes-split.ai-open #notes-editor-wrap {
    flex: 1;
    min-width: 350px;
  }

  /* Keyboard shortcut hint in status bar */
  .notes-status-shortcut {
    float: right;
    color: var(--text3);
    font-size: 11px;
  }
}

/* --- Voice Memo Recording Indicator --- */
.voice-memo-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg2, #1e1e1e);
  border-bottom: 1px solid var(--border, #333);
  font-size: 14px;
  color: var(--text1, #fff);
}
.voice-memo-indicator.hidden { display: none; }
.voice-memo-dot {
  width: 10px;
  height: 10px;
  background: #e53e3e;
  border-radius: 50%;
  animation: voice-memo-pulse 1s ease-in-out infinite;
}
@keyframes voice-memo-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.voice-memo-label {
  color: var(--text2, #aaa);
  font-size: 13px;
}
.voice-memo-btn-active {
  color: #e53e3e !important;
}
.voice-memo-btn-active svg {
  stroke: #e53e3e;
}
/* ===== Inline Chart Rendering ===== */

.inline-chart-container {
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface, #1e1f20);
  position: relative;
  border: 1px solid var(--border, #333);
}
.inline-chart-container iframe {
  width: 100%;
  border: none;
  display: block;
  border-radius: 8px;
  min-height: 60px;
  transition: height 0.15s ease;
}
.inline-chart-container iframe.hidden {
  display: none;
}
.inline-chart-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2;
}
.inline-chart-container:hover .inline-chart-actions {
  opacity: 1;
}
.inline-chart-btn {
  padding: 2px 8px;
  font-size: 11px;
  background: rgba(30, 31, 32, 0.85);
  color: var(--text2, #aaa);
  border: 1px solid var(--border, #444);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}
.inline-chart-btn:hover {
  background: var(--surface2, #2a2b2e);
  color: var(--text, #eee);
}
.inline-chart-code {
  margin: 0;
  max-height: 300px;
  overflow: auto;
}
.inline-chart-code.hidden {
  display: none;
}
.inline-chart-note-btn {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border-color: rgba(59, 130, 246, 0.3);
}
.inline-chart-note-btn:hover {
  background: rgba(59, 130, 246, 0.3);
  color: #93bbfc;
}

/* --- Infographic full-width rendering --- */
.inline-chart-container.infographic {
  width: 100%;
  max-width: none;
}
.inline-chart-container.infographic iframe {
  min-height: 400px;
}

/* ===== Artifact Preview Panel ===== */

/* Chat split container: wraps chat-main + artifact-panel */
.chat-split {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Chat main: the messages + input area */
.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Artifact panel: hidden by default, shown when artifacts detected */
.artifact-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  max-height: 50vh;
  min-height: 200px;
  overflow: hidden;
  animation: artifactSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}
.artifact-panel.hidden { display: none; }

@keyframes artifactSlideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Drag handle (mobile) */
.artifact-drag-handle {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
  cursor: grab;
}
.artifact-drag-bar {
  width: 36px;
  height: 4px;
  background: var(--text3);
  border-radius: 2px;
}

/* Panel header */
.artifact-header {
  display: flex;
  align-items: center;
  padding: 0 12px;
  min-height: 36px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.artifact-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  min-width: 0;
}

.artifact-tab {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text2);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.artifact-tab:hover { color: var(--text); }
.artifact-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.artifact-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.artifact-action-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text2);
  border-radius: 50%;
  cursor: pointer;
}
.artifact-action-btn:active { background: var(--surface2); }

/* Preview body */
.artifact-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.artifact-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

/* --- Desktop: side-by-side split --- */
@media (min-width: 768px) {
  .chat-split {
    flex-direction: row;
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }

  .chat-main {
    flex: 1;
    min-width: 0;
  }

  .artifact-panel {
    width: 45%;
    max-width: 560px;
    max-height: none;
    min-height: 0;
    border-top: none;
    border-left: 1px solid var(--border);
    animation: artifactSlideIn 0.25s ease-out;
  }

  @keyframes artifactSlideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
  }

  /* Hide drag handle on desktop */
  .artifact-drag-handle { display: none; }

  /* Hover state for action buttons */
  .artifact-action-btn:hover { background: var(--surface2); }
}

/* ===== Split View: Chat + Notes side by side (desktop only) ===== */

/* Insert-to-note button on assistant messages */
.msg-insert-note-btn {
  background: none; border: none; cursor: pointer;
  font-size: 14px; padding: 2px 6px; margin-left: 8px;
  opacity: 0.5; transition: opacity 0.2s, color 0.2s;
  vertical-align: middle;
  color: var(--text2);
}
.msg-insert-note-btn:hover { opacity: 1; color: var(--accent); }
.msg-insert-note-btn.inserted {
  opacity: 1; color: #4ade80;
}

/* Split-view toast notification */
.split-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--surface);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.split-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Split resize handle — hidden by default */
.split-resize-handle {
  display: none;
}

/* Split-view toggle button in topbar */
.split-view-btn {
  display: none; /* hidden on mobile */
}

/* Split-from-notes button — hidden on mobile, shown on desktop */
.split-from-notes-btn {
  display: none;
}

@media (min-width: 768px) {
  /* Show split-view button on desktop */
  .split-view-btn { display: flex; }
  .split-from-notes-btn { display: flex; }

  /* Split-view active: show chat and notes side by side */
  .app.split-active {
    flex-direction: row;
  }

  .app.split-active > #view-chat {
    flex: none;
    width: var(--split-chat-width, 55%);
    min-width: 0;
    display: flex !important;
    border-right: none; /* border replaced by resize handle */
  }
  .app.split-active > #view-chat .topbar {
    padding-right: 8px;
  }

  /* Draggable resize handle between chat and notes */
  .app.split-active > .split-resize-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 6px;
    flex-shrink: 0;
    cursor: col-resize;
    background: var(--border);
    transition: background var(--transition-normal);
    position: relative;
    z-index: 10;
  }
  /* Wider invisible hit area for easier grabbing */
  .app.split-active > .split-resize-handle::before {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    left: -6px; right: -6px;
    z-index: -1;
  }
  .app.split-active > .split-resize-handle:hover,
  .app.split-active > .split-resize-handle.dragging {
    background: var(--accent);
  }
  /* Grip dots indicator */
  .app.split-active > .split-resize-handle::after {
    content: '··\A··\A··';
    white-space: pre;
    font-size: 9px;
    line-height: 6px;
    letter-spacing: 1px;
    color: var(--text3);
    opacity: 0.5;
  }
  .app.split-active > .split-resize-handle:hover::after,
  .app.split-active > .split-resize-handle.dragging::after {
    opacity: 1;
    color: var(--accent);
  }
  /* Pulse animation to draw attention on first activation */
  @keyframes split-handle-pulse {
    0%, 100% { background: var(--border); }
    50% { background: var(--accent); }
  }
  .app.split-active > .split-resize-handle.attention {
    animation: split-handle-pulse 0.8s ease 2;
  }

  .app.split-active > #view-notes {
    flex: 1;
    min-width: 0;
    display: flex !important;
  }
  /* In split mode, notes topbar should not stretch beyond its panel */
  .app.split-active > #view-notes .topbar {
    padding-left: 8px;
  }

  /* Hide other views in split mode */
  .app.split-active > #view-knowledge,
  .app.split-active > #view-admin,
  .app.split-active > #view-stats {
    display: none !important;
  }

  /* In split mode, narrow the chat messages/input max-width */
  .app.split-active .messages {
    max-width: 100%;
    padding: 14px 16px;
  }
  .app.split-active .input-area {
    max-width: 100%;
    padding: 10px 16px;
  }

  /* In split mode, file tree starts hidden; toggle with .tree-visible */
  .app.split-active .notes-split .notes-tree-panel {
    display: none;
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
  }
  .app.split-active .notes-split .notes-tree-panel.tree-visible {
    display: block;
    overflow-y: auto;
  }

  /* Active indicator for split button */
  .split-view-btn.active {
    color: var(--accent);
    background: var(--accent-dim);
    border-radius: 8px;
  }

  /* Smooth transition for split */
  .app > .view {
    transition: flex 0.2s ease;
  }
}

/* Split-view file tree toggle button active state */
.app.split-active .notes-tree-toggle-btn-active {
  color: var(--accent) !important;
}

/* Monaco editor inline edit decorations */
.inline-deleted-decoration {
  background: rgba(255, 80, 80, 0.2);
}
.inline-deleted-text {
  text-decoration: line-through;
  color: #ff6b6b;
}
/* Green proposed text shown via Monaco ViewZone */
.inline-added-zone {
  background: rgba(80, 200, 100, 0.12);
  border-left: 3px solid #4caf50;
  padding: 2px 8px 2px 12px;
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
  font-size: 13px;
  line-height: 20px;
}
.inline-added-line {
  color: #4caf50;
  white-space: pre-wrap;
}

/* Prevent user-select during resize drag */
.app.split-dragging * {
  user-select: none !important;
}

/* ===== Admin Tab Switcher ===== */
.admin-tabs { overflow-x: auto; }
.admin-tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text3);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-normal);
  white-space: nowrap;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===== Ops Dashboard ===== */
.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.ops-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}
.ops-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.ops-card.ops-alert { border: 1px solid rgba(239,68,68,0.5); box-shadow: 0 0 16px rgba(239,68,68,0.1); }
.ops-card-wide { grid-column: 1 / -1; }
.ops-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.ops-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ops-card-body { flex: 1; }
.ops-big-num {
  font-size: 28px;
  font-weight: 700;
  color: var(--text1);
  line-height: 1.1;
}
.ops-label {
  font-size: 11px;
  color: var(--text3);
  margin-bottom: 8px;
  text-transform: uppercase;
}
.ops-stat-row {
  font-size: 13px;
  color: var(--text2);
  margin-top: 4px;
}
.ops-stat-row b { color: var(--text1); }
.ops-muted { color: var(--text3) !important; font-size: 12px !important; }
.ops-alert-text {
  color: #ef4444;
  font-weight: 600;
  font-size: 13px;
  margin-top: 8px;
}
.ops-meter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text3);
}
.ops-meter-row > span:first-child { width: 32px; text-align: right; flex-shrink: 0; }
.ops-meter-row > span:last-child { width: 60px; text-align: right; flex-shrink: 0; font-size: 12px; }
.ops-meter {
  flex: 1;
  height: 6px;
  background: var(--bg1, var(--bg));
  border-radius: 3px;
  overflow: hidden;
}
.ops-meter-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.ops-procs {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text3);
  max-height: 100px;
  overflow-y: auto;
}
.ops-proc-line {
  padding: 1px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ops-stats-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.ops-inline-stat {
  text-align: center;
  min-width: 64px;
}
.ops-chart-container { position: relative; width: 100%; max-width: 700px; }
.ops-vm-gauges { max-width: 360px; }
@media (max-width: 600px) {
  .ops-grid { grid-template-columns: 1fr; }
  .ops-stats-inline { gap: 10px; }
  .ops-big-num { font-size: 22px; }
  .ops-chart-container { max-width: 100%; }
}

/* Chat reference jump links */
.chat-ref-link {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  margin: 0 2px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  text-decoration: none;
  color: #3b82f6;
  transition: background 0.15s;
}
.chat-ref-link:hover {
  background: rgba(59, 130, 246, 0.2);
}
.chat-ref-icon {
  font-size: 0.9em;
  margin-right: 2px;
}

/* Note AI chat badge on AI button */
.note-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  border-radius: 8px;
  text-align: center;
  padding: 0 3px;
  pointer-events: none;
}

/* Notes AI conversations sidebar section */
.note-chats-section-header {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.note-chats-section-header:hover { color: var(--text2); }
.note-chats-toggle { font-size: 9px; }
.note-chats-count {
  background: var(--surface2);
  border-radius: 8px;
  padding: 1px 6px;
  font-size: 10px;
  margin-left: 4px;
}
#note-chats-section.collapsed { display: none; }
.session-type-icon { margin-right: 4px; font-size: 13px; }
.note-chat-item { padding-left: 16px; }

/* ===== Scratch Chat (Side Chat) ===== */
.scratch-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
}
.scratch-overlay.hidden { display: none; }

.scratch-chat {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, 90vw);
  min-width: 280px;
  min-height: 200px;
  max-height: min(600px, 80vh);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  overflow: hidden;
}
.scratch-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 1001;
}
.scratch-resize-handle::after {
  content: "";
  display: block;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text3);
  border-bottom: 2px solid var(--text3);
  opacity: 0.5;
  position: absolute;
  bottom: 4px;
  right: 4px;
}
.scratch-chat.hidden { display: none; }

.scratch-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: move;
  flex-shrink: 0;
  user-select: none;
}
.scratch-header svg { color: #f5a623; flex-shrink: 0; }
.scratch-title { font-size: 14px; font-weight: 600; color: var(--text); }
.scratch-context-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  cursor: pointer;
  font-size: 11px;
  color: var(--text2);
}
.scratch-context-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: #f5a623;
  cursor: pointer;
  margin: 0;
}
.scratch-context-label {
  font-size: 11px;
  color: var(--text2);
  user-select: none;
}
.scratch-shortcut {
  font-size: 11px;
  color: var(--text3);
  background: var(--surface3);
  padding: 1px 6px;
  border-radius: 4px;
}
.scratch-close-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
}
.scratch-close-btn:hover { color: var(--text); background: var(--surface3); }

.scratch-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  min-height: 120px;
  max-height: calc(80vh - 140px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scratch-msg {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 95%;
  word-break: break-word;
}
.scratch-msg-user {
  background: var(--user-bg);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.scratch-msg-assistant {
  background: var(--surface2);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.scratch-msg-assistant .markdown-body {
  font-size: 14px;
  line-height: 1.5;
}
.scratch-msg-system {
  background: transparent;
  color: var(--text3);
  font-size: 12px;
  text-align: center;
  align-self: center;
}

.scratch-promote-btn {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
}
.scratch-promote-btn:hover { background: var(--accent); color: #fff; }

.scratch-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.scratch-input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  min-height: 36px;
  max-height: 120px;
  line-height: 1.4;
}
.scratch-input-area textarea:focus { border-color: #f5a623; }
.scratch-send {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: #f5a623;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
}
.scratch-send:hover { background: #e09510; }

/* Scratch chat -- streaming state */
.scratch-msg-assistant.streaming {
  position: relative;
}
.scratch-msg-assistant.streaming::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--accent);
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
  vertical-align: text-bottom;
}

/* Mobile: full-screen scratch */
@media (max-width: 600px) {
  .scratch-chat {
    top: 0;
    left: 0;
    transform: none;
    width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
  }
  .scratch-messages {
    max-height: calc(100vh - 120px);
  }
}

/* ===== Scratch Selection Button ===== */
.scratch-sel-btn {
  position: absolute;
  transform: translateX(-50%);
  z-index: 1100;
  background: #f5a623;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  line-height: 1.4;
  pointer-events: auto;
}
.scratch-sel-btn:hover { background: #e09510; }

/* ===== Background Fact-Check ===== */

/* Verify toggle button in topbar */
.fact-check-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text3);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.fact-check-btn.active {
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.3);
  background: rgba(34, 197, 94, 0.08);
}
.fact-check-btn:hover {
  background: var(--surface2);
}

/* Verifying indicator */
.fact-check-indicator {
  font-size: 12px;
  color: var(--text3);
  padding: 6px 10px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.fact-check-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--text3);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Success badge (green checkmark) */
/* Fact-check results card — expandable */
.fact-check-card {
  border-radius: 10px;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.6;
  max-width: 720px;
  overflow: hidden;
}
.fact-check-card.has-corrections {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
}
.fact-check-card:not(.has-corrections) {
  background: rgba(34, 197, 94, 0.06);
  border: 1px solid rgba(34, 197, 94, 0.2);
}
.fact-check-header {
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  user-select: none;
}
.fact-check-header-ok { color: #22c55e; }
.fact-check-header-warn { color: #f59e0b; }
.fact-check-toggle {
  transition: transform 0.2s;
  font-size: 10px;
}
.fact-check-card.expanded .fact-check-toggle {
  transform: rotate(90deg);
}
.fact-check-details {
  display: none;
  padding: 0 14px 10px;
}
.fact-check-card.expanded .fact-check-details {
  display: block;
}
.fact-check-claim {
  padding: 4px 0;
  font-size: 12px;
  color: var(--text3);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.fact-check-claim:last-child { border-bottom: none; }
.fact-check-ok { color: var(--text3); }
.fact-check-warn { color: #f59e0b; }
.fact-check-source {
  color: var(--accent);
  text-decoration: none;
  font-size: 11px;
}
.fact-check-source:hover { text-decoration: underline; }

/* ===== Perplexity Mode — Search Progress, Citations, Sources ===== */

/* Perplexity toggle button (same style as fact-check-btn) */
.perplexity-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text3);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.perplexity-btn.active {
  color: #3b82f6;
  border-color: rgba(59, 130, 246, 0.3);
  background: rgba(59, 130, 246, 0.08);
}
.perplexity-btn:hover {
  background: var(--surface2);
}

/* Search progress indicator (shown during pre-search phase) */
.search-progress-indicator {
  font-size: 12px;
  color: var(--text3);
  padding: 8px 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.search-progress-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Citation links — inline [N] references */
.citation {
  color: #3b82f6;
  font-size: 0.75em;
  vertical-align: super;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  padding: 0 1px;
  border-radius: 2px;
  transition: background 0.15s;
}
.citation:hover {
  background: rgba(59, 130, 246, 0.15);
  text-decoration: none;
}
.citation-personal {
  color: #a78bfa;
}
.citation-personal:hover {
  background: rgba(167, 139, 250, 0.15);
}

/* Source panel — collapsible card below response */
.source-panel {
  margin-top: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface1);
  max-width: 720px;
  font-size: 13px;
  overflow: hidden;
}
.source-panel[open] {
  border-color: rgba(59, 130, 246, 0.3);
}
.source-panel-header {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  user-select: none;
  list-style: none;
}
.source-panel-header::-webkit-details-marker {
  display: none;
}
.source-panel-header::before {
  content: "\25B8 ";
  display: inline-block;
  transition: transform 0.2s;
  margin-right: 4px;
}
.source-panel[open] > .source-panel-header::before {
  transform: rotate(90deg);
}
.source-panel-content {
  padding: 4px 10px 10px;
}

/* Individual source card */
.source-card {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.15s;
  flex-wrap: wrap;
}
.source-card:hover {
  background: rgba(59, 130, 246, 0.06);
}
.source-personal:hover {
  background: rgba(167, 139, 250, 0.06);
}
.source-num {
  font-size: 11px;
  font-weight: 600;
  color: #3b82f6;
  min-width: 22px;
  flex-shrink: 0;
}
.source-personal .source-num {
  color: #a78bfa;
}
.source-icon {
  font-size: 13px;
  flex-shrink: 0;
}
.source-title-link {
  color: var(--text2);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  word-break: break-all;
}
.source-title-link:hover {
  color: #3b82f6;
  text-decoration: underline;
}
.source-title {
  color: var(--text2);
  font-size: 12px;
  font-weight: 500;
}
.source-excerpt {
  flex-basis: 100%;
  font-size: 11px;
  color: var(--text3);
  margin: 2px 0 0 28px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== Theme System ===== */

/* Smooth transition when switching themes */
html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease,
              box-shadow 0.3s ease, fill 0.3s ease, stroke 0.3s ease !important;
}

/* Theme picker panel — slides up from bottom */
.theme-picker {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  border-radius: 20px 20px 0 0;
  z-index: 200;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 24px;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.4);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.theme-picker.open {
  transform: translateY(0);
}

.theme-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 8px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.theme-picker-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.theme-picker-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text2);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.theme-picker-close:hover {
  background: var(--surface2);
  color: var(--text);
}

.theme-picker-section {
  margin-bottom: 16px;
}
.theme-picker-cat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  margin-bottom: 10px;
  padding-top: 4px;
}

.theme-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: none;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.theme-swatch:hover {
  background: var(--surface2);
  transform: scale(1.04);
}
.theme-swatch.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.swatch-preview {
  width: 60px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(128,128,128,0.2);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 6px 8px;
  gap: 3px;
  position: relative;
  overflow: hidden;
}
.swatch-accent {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  position: absolute;
  top: 5px;
  right: 5px;
}
.swatch-text-line {
  height: 3px;
  width: 70%;
  border-radius: 2px;
  opacity: 0.6;
}
.swatch-text-line.short {
  width: 45%;
}

.swatch-name {
  font-size: 11px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
  font-weight: 500;
}
.theme-swatch.active .swatch-name {
  color: var(--accent);
  font-weight: 600;
}

/* Desktop: side panel instead of bottom sheet */
@media (min-width: 768px) {
  .theme-picker {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    max-height: none;
    border-radius: 0;
    border-top: none;
    border-left: 1px solid var(--border-strong);
    transform: translateX(100%);
    box-shadow: -8px 0 32px rgba(0,0,0,0.3);
  }
  .theme-picker.open {
    transform: translateX(0);
  }
  .theme-picker-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ===== BRANCH CHAT ===== */

/* Fork button on user messages — appears on hover */
.branch-fork-btn {
  position: absolute;
  right: -28px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg2, #2a2a3e);
  border: 1px solid var(--border, #3a3a50);
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  color: var(--text3, #6b6b82);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg-user { position: relative; }
.msg-user:hover .branch-fork-btn { opacity: 1; }
.branch-fork-btn:hover {
  color: var(--accent, #8ab4f8);
  background: var(--bg3, #333350);
  border-color: var(--accent, #8ab4f8);
}

/* Branch navigation chevrons */
.branch-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 8px;
  vertical-align: middle;
  font-size: 12px;
  color: var(--text3, #6b6b82);
  user-select: none;
}
.branch-nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3, #6b6b82);
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.branch-nav-btn:hover:not(:disabled) {
  color: var(--accent, #8ab4f8);
  background: rgba(138, 180, 248, 0.1);
}
.branch-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}
.branch-nav-label {
  font-size: 11px;
  min-width: 24px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Branch indicator in topbar */
.branch-indicator {
  font-size: 11px;
  color: var(--accent, #8ab4f8);
  background: rgba(138, 180, 248, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  margin-left: 8px;
  white-space: nowrap;
  transition: background 0.15s;
}
.branch-indicator:hover {
  background: rgba(138, 180, 248, 0.2);
}

/* Branch list dropdown */
.branch-list-dropdown {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg2, #1e1f2e);
  border: 1px solid var(--border, #3a3a50);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  min-width: 240px;
  max-width: 340px;
  z-index: 200;
  overflow: hidden;
  margin-top: 4px;
}
.branch-list-header {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text3, #6b6b82);
  border-bottom: 1px solid var(--border, #3a3a50);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.branch-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.branch-list-item:hover {
  background: rgba(138, 180, 248, 0.08);
}
.branch-list-item.active {
  background: rgba(138, 180, 248, 0.12);
}
.branch-list-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--accent, #8ab4f8);
  border-radius: 0 3px 3px 0;
}
.branch-list-label {
  font-size: 13px;
  color: var(--text, #eaeaf0);
  font-weight: 500;
  flex-shrink: 0;
}
.branch-list-meta {
  font-size: 11px;
  color: var(--text3, #6b6b82);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.branch-list-delete {
  background: none;
  border: none;
  color: var(--text3, #6b6b82);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.branch-list-item:hover .branch-list-delete { opacity: 1; }
.branch-list-delete:hover { color: #f28b82; }

/* Mobile: position fork button below message instead of side */
@media (max-width: 767px) {
  .branch-fork-btn {
    position: static;
    transform: none;
    opacity: 1;
    margin-top: 4px;
    display: inline-flex;
  }
}

/* ===== TODO VIEW ===== */

.todo-form {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.todo-title-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 8px;
}
.todo-title-input:focus { border-color: var(--accent); }
.todo-form-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.todo-due-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  color-scheme: dark;
}
.todo-priority-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.todo-add-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.todo-add-btn:hover { opacity: 0.9; }

/* Notification banner */
.todo-notif-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--accent-dim);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text2);
}
.todo-notif-btn {
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  cursor: pointer;
  margin-left: auto;
}
.todo-notif-dismiss {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
}

/* Todo list */
.todo-list { padding: 8px 0; }
.todo-group-header {
  padding: 8px 16px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.todo-group-header.overdue { color: #ff6b6b; }

.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}
.todo-item:hover { background: var(--surface); }
.todo-item.done .todo-item-title { text-decoration: line-through; color: var(--text3); }

.todo-checkbox {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  transition: all var(--transition-fast);
}
.todo-checkbox:hover { border-color: var(--accent); }
.todo-checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
}
.todo-checkbox.checked::after {
  content: "";
  display: block;
  width: 6px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}

.todo-item-body { flex: 1; min-width: 0; }
.todo-item-title {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}
.todo-item-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text3);
}
.todo-priority-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.todo-priority-dot.high { background: #ff6b6b; }
.todo-priority-dot.medium { background: #ffa94d; }
.todo-priority-dot.low { background: #69db7c; }

.todo-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.todo-item:hover .todo-item-actions { opacity: 1; }
.todo-action-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.todo-action-btn:hover { color: var(--text); background: var(--surface2); }

.todo-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text3);
  font-size: 14px;
}
.todo-empty svg { margin-bottom: 12px; opacity: 0.3; }

@media (max-width: 767px) {
  .todo-item-actions { opacity: 1; }
}

/* ===== STUDY VIEW (Flashcards + Spaced Repetition) ===== */

/* --- Study Stats Bar (top bar below header) --- */
.study-stats-bar {
  display: none; /* hidden — stats now live in dashboard */
}

.study-content {
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* --- Card Review Area --- */
.study-card-area {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 32px;
  position: relative;
}

/* Progress bar at top */
.study-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  letter-spacing: 0.02em;
}
.study-progress-bar {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.study-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- The Card itself --- */
.study-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px 32px;
  min-height: 220px;
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease, opacity 0.25s ease;
  position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12), 0 0 0 1px rgba(255,255,255,0.03);
  overflow: hidden;
}
.study-card:hover {
  box-shadow: 0 8px 32px rgba(0,0,0,0.25), 0 0 0 1px rgba(124,108,240,0.1);
  transform: translateY(-1px);
}
.study-card:active { transform: translateY(0); }

/* Card slide animations */
.study-card.slide-out-left {
  animation: slideOutLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.study-card.slide-in-right {
  animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes slideOutLeft {
  0% { transform: translateX(0); opacity: 1; }
  100% { transform: translateX(-120px); opacity: 0; }
}
@keyframes slideInRight {
  0% { transform: translateX(80px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}

/* Front of card */
.study-card-front {
  font-size: 20px;
  line-height: 1.65;
  color: var(--text);
  text-align: center;
}
.study-card-front p { margin: 0 0 8px; }
.study-card-front p:last-child { margin-bottom: 0; }
.study-card-front code {
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* Tap to reveal hint */
.study-card-tap {
  text-align: center;
  color: var(--text3);
  font-size: 13px;
  margin-top: 24px;
  opacity: 0;
  animation: tapPulse 2.5s ease-in-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: 0.02em;
}
.study-card-tap::before {
  content: '';
  display: inline-block;
  width: 32px;
  height: 1px;
  background: var(--border);
}
.study-card-tap::after {
  content: '';
  display: inline-block;
  width: 32px;
  height: 1px;
  background: var(--border);
}
@keyframes tapPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.7; }
}

/* Back of card — revealed */
.study-card-back {
  font-size: 16px;
  line-height: 1.7;
  color: var(--text2);
  overflow: hidden;
}
.study-card-back.hidden {
  display: none;
}
.study-card-back p { margin: 0 0 8px; }
.study-card-back p:last-child { margin-bottom: 0; }
.study-card-back code {
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* Separator between front and back */
.study-card-back hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
  margin: 20px 0;
}

/* Reveal animation for back content */
.study-card-back.revealing {
  display: block;
  animation: revealSlideDown 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes revealSlideDown {
  0% { opacity: 0; transform: translateY(-12px); max-height: 0; }
  100% { opacity: 1; transform: translateY(0); max-height: 2000px; }
}

/* --- Card Meta (pills below card) --- */
.study-card-meta {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text3);
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}

.study-meta-phase {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.study-meta-phase.phase-new { background: rgba(124,108,240,0.2); color: #a78bfa; }
.study-meta-phase.phase-learning { background: rgba(245,158,11,0.15); color: #fbbf24; }
.study-meta-phase.phase-review { background: rgba(16,185,129,0.15); color: #34d399; }
.study-meta-phase.phase-relearning { background: rgba(239,68,68,0.15); color: #f87171; }

.study-meta-deck {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 500;
  background: var(--surface2);
  color: var(--text3);
  letter-spacing: 0.02em;
}

.study-meta-source {
  color: var(--accent);
  font-size: 11px;
  text-decoration: none;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--accent-dim);
  transition: background 0.15s;
}
.study-meta-source:hover { background: var(--accent-glow); text-decoration: none; }

.study-meta-bloom {
  font-size: 10px;
  font-weight: 500;
  color: var(--text2);
  background: var(--surface2);
  padding: 3px 8px;
  border-radius: 12px;
  letter-spacing: 0.02em;
}

/* Writing mode toggle */
.writing-toggle-btn {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  transition: all 0.15s;
}
.writing-toggle-btn:hover {
  background: var(--surface2);
  color: var(--text2);
}
.writing-toggle-btn.active {
  background: rgba(124,108,240,0.15);
  color: var(--accent);
  border-color: rgba(124,108,240,0.3);
}

/* --- Rating Buttons --- */
.study-rating-btns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 20px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.study-rating-btns:not(.hidden) {
  opacity: 1;
  transform: translateY(0);
}

.study-rate-btn {
  padding: 14px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}
.study-rate-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
}
.study-rate-btn .interval {
  font-size: 11px;
  color: var(--text3);
  font-weight: 400;
}
.study-rate-btn .key-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text3);
  margin-top: 2px;
}

.study-rate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.study-rate-btn:active {
  transform: translateY(0) scale(0.97);
}
.study-rate-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Again (red) */
.study-rate-btn.rate-again { border-color: rgba(239,68,68,0.3); }
.study-rate-btn.rate-again::before { background: #ef4444; }
.study-rate-btn.rate-again:hover { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.5); }

/* Hard (orange) */
.study-rate-btn.rate-hard { border-color: rgba(245,158,11,0.3); }
.study-rate-btn.rate-hard::before { background: #f59e0b; }
.study-rate-btn.rate-hard:hover { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.5); }

/* Good (green) */
.study-rate-btn.rate-good { border-color: rgba(16,185,129,0.3); }
.study-rate-btn.rate-good::before { background: #10b981; }
.study-rate-btn.rate-good:hover { background: rgba(16,185,129,0.1); border-color: rgba(16,185,129,0.5); }

/* Easy (bright green/blue) */
.study-rate-btn.rate-easy { border-color: rgba(59,130,246,0.3); }
.study-rate-btn.rate-easy::before { background: #3b82f6; }
.study-rate-btn.rate-easy:hover { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.5); }

/* --- Empty State --- */
.study-empty {
  text-align: center;
  padding: 80px 24px 48px;
  color: var(--text3);
  max-width: 400px;
  margin: 0 auto;
}
.study-empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
  line-height: 1;
  opacity: 0.9;
}
.study-empty-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.study-empty-subtitle {
  font-size: 14px;
  color: var(--text3);
  margin-bottom: 24px;
  line-height: 1.5;
}
.study-empty svg { display: none; } /* hide old icon */
.study-empty-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.study-create-cta {
  padding: 10px 28px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(124,108,240,0.25);
}
.study-create-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(124,108,240,0.35);
}
.study-empty-secondary {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.study-empty-secondary:hover {
  background: var(--surface2);
  border-color: var(--border-strong);
}

/* --- Create Card Form --- */
.study-create-form {
  max-width: 540px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}
.study-form-group {
  margin-bottom: 16px;
}
.study-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.study-form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
}
.study-form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.study-form-input::placeholder { color: var(--text3); }

/* Difficulty segmented control */
.study-difficulty-control {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.study-difficulty-option {
  flex: 1;
  padding: 10px 12px;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text3);
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  transition: all 0.15s;
}
.study-difficulty-option:last-child { border-right: none; }
.study-difficulty-option:hover { background: var(--surface2); color: var(--text2); }
.study-difficulty-option.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

/* Tags pill input */
.study-tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  min-height: 42px;
  align-items: center;
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.study-tags-container:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.study-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text2);
  font-size: 12px;
  font-weight: 500;
}
.study-tag-pill .tag-remove {
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  color: var(--text3);
  margin-left: 2px;
}
.study-tag-pill .tag-remove:hover { color: #f87171; }
.study-tags-input {
  flex: 1;
  min-width: 80px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  outline: none;
  padding: 2px 4px;
}
.study-tags-input::placeholder { color: var(--text3); }

/* Card preview */
.study-card-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-top: 16px;
}
.study-card-preview-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text3);
  margin-bottom: 8px;
}
.study-card-preview-front {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 12px;
  line-height: 1.5;
}
.study-card-preview-back {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.study-form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.study-form-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.study-form-select:focus {
  outline: none;
  border-color: var(--accent);
}
.study-form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}
.study-form-cancel {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.study-form-cancel:hover { background: var(--surface2); }
.study-form-submit {
  padding: 10px 24px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(124,108,240,0.25);
}
.study-form-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(124,108,240,0.35);
}

/* --- Study Dashboard --- */
.study-dashboard {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}

.study-dash-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  margin-top: 28px;
}
.study-dash-section-title:first-child { margin-top: 0; }

.study-dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.study-dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 12px;
  text-align: center;
  transition: all 0.15s;
}
.study-dash-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.study-dash-icon {
  font-size: 20px;
  margin-bottom: 6px;
  opacity: 0.7;
}
.study-dash-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.study-dash-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Deck list */
.study-deck-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.study-deck-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text2);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background 0.15s;
}
.study-deck-item:hover {
  background: var(--surface2);
}
.study-deck-name {
  font-weight: 500;
  color: var(--text);
}
.study-deck-stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text3);
}
.study-deck-progress {
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  align-self: center;
}
.study-deck-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* Heatmap */
.study-heatmap {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  padding: 8px 0;
}
.study-heatmap-day {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--surface2);
  transition: background 0.15s;
}
.study-heatmap-day.level-1 { background: rgba(124,108,240,0.2); }
.study-heatmap-day.level-2 { background: rgba(124,108,240,0.4); }
.study-heatmap-day.level-3 { background: rgba(124,108,240,0.6); }
.study-heatmap-day.level-4 { background: rgba(124,108,240,0.85); }
.study-heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text3);
  margin-top: 6px;
}

/* Dashboard action buttons */
.study-dash-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 28px;
}
.study-dash-btn {
  padding: 10px 22px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(124,108,240,0.25);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.study-dash-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(124,108,240,0.35);
}
.study-dash-btn.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  box-shadow: none;
  font-weight: 500;
}
.study-dash-btn.secondary:hover {
  background: var(--surface2);
  border-color: var(--border-strong);
  transform: none;
}
.study-dash-btn-icon {
  font-size: 16px;
  line-height: 1;
}

/* --- Study Note Modal (frosted glass) --- */
.study-note-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: overlayFadeIn 0.2s ease;
}
.study-note-overlay.hidden { display: none; }
@keyframes overlayFadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.study-note-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 520px;
  max-width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.05);
  animation: modalSlideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes modalSlideUp {
  0% { transform: translateY(16px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

.study-note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.study-note-header span { font-weight: 600; font-size: 16px; color: var(--text); }
.study-note-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text3);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}
.study-note-close:hover { background: var(--surface2); color: var(--text); }
.study-note-body { padding: 24px; overflow-y: auto; }
.study-note-body.hidden { display: none; }

/* Strategy toggle pills */
.study-strategies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.study-strategies label {
  font-size: 13px;
  color: var(--text2);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  transition: all 0.15s;
  user-select: none;
}
.study-strategies label:hover { background: var(--surface2); }
.study-strategies label:has(input:checked) {
  background: var(--accent-dim);
  border-color: rgba(124,108,240,0.3);
  color: var(--accent);
}
.study-strategies input[type=checkbox] {
  display: none;
}
.study-strategies label::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-radius: 4px;
  display: inline-block;
  transition: all 0.15s;
  flex-shrink: 0;
}
.study-strategies label:has(input:checked)::before {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px;
}

.study-note-count { margin-bottom: 20px; }
.study-note-count label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.study-note-count input {
  width: 64px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  text-align: center;
}
.study-note-count input:focus {
  outline: none;
  border-color: var(--accent);
}

.study-note-generate-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(124,108,240,0.25);
}
.study-note-generate-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(124,108,240,0.35);
}
.study-note-close-btn {
  width: 100%;
  padding: 10px;
  background: var(--surface2);
  color: var(--text2);
  border: none;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}
.study-note-close-btn:hover { background: var(--surface3); }

/* Loading: skeleton shimmer */
.study-note-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 24px auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.study-skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}
.study-skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.study-skeleton-line:nth-child(1) { width: 85%; }
.study-skeleton-line:nth-child(2) { width: 65%; }
.study-skeleton-line:nth-child(3) { width: 75%; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Results */
.study-note-summary {
  font-size: 14px;
  margin-bottom: 16px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
}
.study-note-summary strong {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

.study-kp-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.study-kp-item {
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  transition: background 0.15s;
  cursor: pointer;
}
.study-kp-item:hover { background: var(--surface3); }
.study-kp-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 8px;
  flex-shrink: 0;
  background: var(--surface2);
  color: var(--text2);
}
.study-kp-type.type-definition { background: rgba(59,130,246,0.15); color: #60a5fa; }
.study-kp-type.type-concept { background: rgba(139,92,246,0.15); color: #a78bfa; }
.study-kp-type.type-process { background: rgba(16,185,129,0.15); color: #34d399; }
.study-kp-type.type-relationship { background: rgba(245,158,11,0.15); color: #fbbf24; }
.study-kp-type.type-fact { background: rgba(148,163,184,0.15); color: #94a3b8; }
.study-kp-type.type-formula { background: rgba(236,72,153,0.15); color: #f472b6; }
.study-kp-content { color: var(--text2); flex: 1; }
.study-note-actions { display: flex; flex-direction: column; gap: 8px; }

/* --- Session Complete --- */
.study-complete {
  text-align: center;
  padding: 32px 20px;
}
.study-complete-icon {
  font-size: 56px;
  margin-bottom: 12px;
}
.study-complete-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.study-complete-subtitle {
  font-size: 14px;
  color: var(--text3);
  margin-bottom: 24px;
}
.study-complete-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}
.study-complete-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* --- Study Debrief --- */
.study-debrief {
  padding: 4px 0;
  text-align: left;
}
.study-debrief h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 16px 0 10px;
}
.study-debrief-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  margin: 3px 4px;
  gap: 4px;
}
.study-debrief-tag.weak {
  background: rgba(239,68,68,0.12);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.2);
}
.study-debrief-tag.strong {
  background: rgba(34,197,94,0.12);
  color: #4ade80;
  border: 1px solid rgba(34,197,94,0.2);
}
.study-debrief-recommendation {
  color: var(--text2);
  font-size: 13px;
  margin-bottom: 6px;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface2);
  border-radius: 0 8px 8px 0;
  line-height: 1.5;
}

/* --- Writing Mode --- */
.writing-review-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}
.writing-textarea {
  width: 100%;
  min-height: 100px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.writing-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.writing-submit-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-end;
  transition: all 0.2s;
}
.writing-submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124,108,240,0.3);
}
.writing-feedback {
  padding: 4px 0;
}
.writing-completeness { margin-bottom: 12px; }
.writing-bar-label {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 6px;
}
.writing-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.writing-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}
.writing-continue-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.writing-continue-btn:hover {
  transform: translateY(-1px);
}

/* Fail streak badge */
.fail-streak-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(239,68,68,0.15);
  color: #f87171;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Remediation panel */
.remediation-panel {
  padding: 4px 0;
}
.remediation-continue-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.remediation-continue-btn:hover {
  transform: translateY(-1px);
}

/* --- Study URL Modal --- */
.study-url-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: overlayFadeIn 0.2s ease;
}
.study-url-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.35);
  animation: modalSlideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Study toast notification --- */
.study-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  z-index: 10000;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.study-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.study-toast-icon { font-size: 16px; }

/* --- Focus indicators --- */
.study-card:focus-visible,
.study-rate-btn:focus-visible,
.study-dash-btn:focus-visible,
.study-form-submit:focus-visible,
.study-create-cta:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Mobile Responsive --- */
@media (max-width: 767px) {
  .study-card-area {
    padding: 12px 12px 24px;
  }
  .study-card {
    padding: 28px 20px 24px;
    border-radius: 14px;
  }
  .study-card-front {
    font-size: 18px;
  }
  .study-card-back {
    font-size: 15px;
  }
  .study-rating-btns {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .study-rate-btn {
    padding: 14px 8px 10px;
    border-radius: 10px;
  }
  .study-dash-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .study-card-meta {
    gap: 4px;
  }
  .study-create-form {
    padding: 16px 12px;
  }
  .study-dashboard {
    padding: 16px 12px;
  }
  .study-complete-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .study-dash-actions {
    flex-direction: column;
  }
  .study-dash-btn {
    justify-content: center;
  }
  /* Bottom safe area */
  .study-rating-btns,
  .study-form-actions,
  .study-complete-actions {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ===== DEEP RESEARCH PANEL ===== */

.research-panel {
  background: var(--surface1);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 720px;
  overflow: hidden;
  margin: 4px 0;
}
.research-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.research-panel-icon { font-size: 16px; }
.research-panel-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text1);
  flex: 1;
}
.research-panel-minimize {
  cursor: pointer;
  font-size: 14px;
  color: var(--text3);
  padding: 2px 6px;
  border-radius: 4px;
}
.research-panel-minimize:hover { background: var(--bg1); }
.research-panel-question {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text2);
  font-style: italic;
  border-bottom: 1px solid var(--border);
}
.research-panel-body { padding: 12px 14px; }
.research-stage {
  font-size: 13px;
  font-weight: 500;
  color: var(--text1);
  margin-bottom: 8px;
}
.research-progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--bg1);
  overflow: hidden;
  margin-bottom: 10px;
}
.research-progress-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  transition: width 0.5s ease;
}
.research-subtasks { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.research-subtask {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12px;
  color: var(--text2);
  line-height: 1.4;
}
.research-subtask-icon { flex-shrink: 0; width: 18px; text-align: center; }
.research-subtask-text { flex: 1; word-break: break-word; }
.research-stats {
  font-size: 11px;
  color: var(--text3);
  display: flex;
  gap: 12px;
}
.research-panel-actions {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.research-cancel-btn, .research-retry-btn {
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
}
.research-cancel-btn:hover { background: #ef4444; color: white; border-color: #ef4444; }
.research-retry-btn:hover { background: #3b82f6; color: white; border-color: #3b82f6; }

/* ===== RESEARCH REPORT ===== */

.research-report {
  background: var(--surface);
  color: var(--text);
  align-self: stretch;
  border-radius: 16px;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.75;
}
.research-report-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.research-report-title {
  font-weight: 700;
  font-size: 18px;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.research-report-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 13px;
  color: var(--text3);
  flex-wrap: wrap;
}
.research-confidence-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.conf-high { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.conf-medium { background: rgba(234, 179, 8, 0.15); color: #eab308; }
.conf-low { background: rgba(249, 115, 22, 0.15); color: #f97316; }
/* Key metrics dashboard */
.research-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.research-metric-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
}
.research-metric-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.research-metric-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 4px;
}
.research-metric-context {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
}

/* Mermaid diagram */
.research-diagram {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.research-diagram h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent2);
  margin: 0 0 12px;
}
.research-mermaid {
  background: var(--bg2);
  border-radius: 12px;
  padding: 16px;
  overflow-x: auto;
  text-align: center;
}
.research-mermaid svg {
  max-width: 100%;
  height: auto;
}
.mermaid-fallback {
  text-align: left;
  font-size: 12px;
}

.research-report-summary {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.research-report-summary h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent2);
  margin: 0 0 10px;
}
.research-report-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.research-report-section h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent2);
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}
.research-report-section p {
  font-size: 15px;
  color: var(--text);
  line-height: 1.75;
  margin: 0 0 10px;
}
/* Inherit assistant message markdown styles for richer rendering */
.research-report-section strong { color: #fff; font-weight: 700; }
.research-report-section em { color: var(--accent2); font-style: italic; }
.research-report-section ul, .research-report-section ol { padding-left: 24px; margin: 8px 0; }
.research-report-section li { margin: 4px 0; line-height: 1.6; }
.research-report-section ul > li::marker { color: var(--accent); }
.research-report-section a { color: var(--accent); text-decoration: none; }
.research-report-section a:hover { text-decoration: underline; }
.research-report-section table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; margin: 10px 0; border-radius: 8px; border: 1px solid var(--border); }
.research-report-section thead { background: var(--surface2); }
.research-report-section th, .research-report-section td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.research-report-section th { font-weight: 700; color: #8ab4f8; }
.citation-link {
  color: #3b82f6;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  vertical-align: super;
}
.citation-link:hover { text-decoration: underline; }
.source-highlight {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  border-radius: 6px;
  transition: outline 0.3s;
}

/* Contradictions */
.research-contradictions {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.research-contradictions summary {
  font-size: 13px;
  font-weight: 600;
  color: #ef4444;
  cursor: pointer;
  list-style: none;
}
.research-contradiction-item {
  font-size: 12px;
  color: var(--text2);
  padding: 4px 0;
}
.research-contradiction-severity {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
}
.severity-high { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.severity-medium { background: rgba(234, 179, 8, 0.15); color: #eab308; }
.severity-low { background: rgba(156, 163, 175, 0.15); color: #9ca3af; }

/* Limitations */
.research-report-limitations {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.research-report-limitations h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text3);
  margin: 0 0 8px;
}
.research-report-limitations ul {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  color: var(--text2);
  line-height: 1.6;
}

/* Methodology */
.research-methodology-note {
  padding: 12px 20px;
  font-size: 12px;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
}

/* Source panel inside report */
.research-source-panel { margin: 0; border: none; border-radius: 0; }

/* Action buttons */
.research-report-actions {
  padding: 10px 16px;
  display: flex;
  gap: 8px;
}
.research-action-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.research-action-btn:hover {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

/* Conversation escalation */
.research-escalation {
  padding: 4px 0 0;
}
.research-escalation-btn {
  font-size: 12px;
  color: #3b82f6;
  background: none;
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.research-escalation-btn:hover {
  background: rgba(59, 130, 246, 0.1);
}

/* Research history */
.research-history-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.research-history-item:hover { background: var(--bg2); }
.rh-question {
  font-size: 14px;
  color: var(--text1);
  font-weight: 500;
  margin-bottom: 4px;
}
.rh-meta {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--text3);
}
.rh-status {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
}
.rh-status-complete { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.rh-status-error { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.rh-status-running { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.rh-status-cancelled { background: rgba(156, 163, 175, 0.15); color: #9ca3af; }
.rh-status-pending { background: rgba(234, 179, 8, 0.15); color: #eab308; }

/* Research Dashboard overlay */
.research-dashboard-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.9);
  display: flex;
  flex-direction: column;
}
.research-dashboard-close {
  position: absolute;
  top: 16px; right: 24px;
  font-size: 32px;
  color: #fff;
  cursor: pointer;
  z-index: 10001;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
}
.research-dashboard-close:hover { background: rgba(255,255,255,0.2); }
.research-dashboard-iframe {
  flex: 1;
  border: none;
  width: 100%;
  background: #0d1117;
}
.research-dashboard-btn {
  background: rgba(88, 166, 255, 0.1) !important;
  color: #58a6ff !important;
  border-color: rgba(88, 166, 255, 0.3) !important;
}
.research-dashboard-btn:hover {
  background: #58a6ff !important;
  color: #fff !important;
  border-color: #58a6ff !important;
}
.research-dashboard-toggle {
  position: fixed;
  top: 12px;
  right: 56px;
  z-index: 10002;
  background: rgba(255,255,255,0.1);
  color: #e6edf3;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.research-dashboard-toggle:hover {
  background: rgba(255,255,255,0.2);
}
.research-action-btn.has-artifact {
  background: linear-gradient(135deg, #58a6ff, #3b82f6) !important;
  color: white !important;
}

/* ===== Deals View (admin-only Active Deals) ===== */
#deals-refresh-btn.spinning svg { animation: spin 0.8s linear infinite; }
.deals-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.deals-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}
.deals-filter-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.deals-filter-label {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.deals-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  min-height: 38px;
  cursor: pointer;
}
.deals-select:focus-visible,
.deals-search:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.deals-search {
  flex: 1 1 200px;
  min-width: 160px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  min-height: 38px;
}
.deals-search::placeholder { color: var(--text3); }
.deals-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--text2);
  align-items: center;
}
.deals-counts { font-weight: 600; color: var(--text); }
.deals-generated { color: var(--text3); }

.deals-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.deals-message {
  padding: 24px 16px;
  text-align: center;
  color: var(--text2);
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.deals-message-error {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
}
.deals-message-loading { color: var(--text3); }

.deal-card {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}
.deal-card:hover { border-color: var(--border-strong); }

.deal-detail > .deal-summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.deal-detail > .deal-summary::-webkit-details-marker { display: none; }
.deal-summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.deal-summary-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.deal-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.deal-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: capitalize;
  white-space: nowrap;
}
.deal-badge-active { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.deal-badge-dead { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.deal-badge-revived { background: rgba(232, 168, 124, 0.18); color: var(--accent2); }
.deal-badge-neutral { background: var(--surface3); color: var(--text2); }
.deal-badge-urgent { background: rgba(249, 115, 22, 0.18); color: #f97316; }
.deal-badge-daily { background: var(--accent-dim); color: var(--accent); }

.deal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.deal-submeta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
  color: var(--text2);
  align-items: center;
}
.deal-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 8px;
}
.deal-time { color: var(--text3); }
.deal-value-summary {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.deal-forum-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: underline;
  align-self: flex-start;
}
.deal-forum-link:hover { color: var(--text); }

.deal-chevron {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 4px;
  border-right: 2px solid var(--text3);
  border-bottom: 2px solid var(--text3);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  box-sizing: border-box;
}
.deal-detail[open] > .deal-summary .deal-chevron {
  transform: rotate(-135deg);
  margin-top: 8px;
}

.deal-tree {
  padding: 0 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
}
.deal-node {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  overflow: hidden;
}
.deal-node-summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  position: relative;
  padding-left: 26px;
}
.deal-node-summary::-webkit-details-marker { display: none; }
.deal-node-summary::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--text3);
  border-bottom: 2px solid var(--text3);
  transform: translateY(-50%) rotate(-45deg);
  transition: transform 0.15s ease;
}
.deal-node[open] > .deal-node-summary::before {
  transform: translateY(-50%) rotate(45deg);
}
.deal-node-summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.deal-node-body {
  padding: 4px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.deal-field { display: flex; flex-direction: column; gap: 2px; }
.deal-field-label {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.deal-field-val {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.deal-empty-note { color: var(--text3); font-size: 12px; }
.deal-structure-note {
  margin: 10px 14px 0;
  padding: 8px 10px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.08);
  color: var(--text2);
  font-size: 12px;
  line-height: 1.45;
}

.deal-list, .deal-kv {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.deal-kv { list-style: none; padding-left: 0; }
.deal-kv > li { display: flex; flex-wrap: wrap; gap: 4px 8px; }
.deal-kv-key {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
}
.deal-kv-val { color: var(--text); }
.deal-list ul, .deal-kv ul { margin-top: 3px; }

/* --- Topic-grouped cards: warning banner, extra badges, update tree --- */
.deals-warning {
  margin: 0 0 10px;
}
.deals-warning.hidden { display: none; }
.deals-warning-box {
  padding: 8px 12px;
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.1);
  color: var(--text2);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.deal-badge-nerfed { background: rgba(245, 158, 11, 0.18); color: #f59e0b; }
.deal-badge-updates { background: var(--surface3); color: var(--text2); }
.deal-badge-carried { background: rgba(56, 189, 248, 0.16); color: #38bdf8; }
.deal-badge-derived { background: rgba(168, 85, 247, 0.16); color: #a855f7; }
.deal-badge-missing { background: rgba(148, 163, 184, 0.2); color: var(--text2); }

.deal-updates-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.deal-update {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  overflow-wrap: anywhere;
}
.deal-update-head {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
}
.deal-update-meta { font-size: 12px; color: var(--text3); }
.deal-update-change {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  font-size: 12px;
  line-height: 1.45;
}
.deal-update-change-label { font-weight: 600; color: var(--text2); }
.deal-update-change-val { color: var(--text); }
.deal-update-ident {
  font-size: 11px;
  color: var(--text3);
  overflow-wrap: anywhere;
}

.deals-toolbar .deals-select,
.deals-toolbar .deals-search { max-width: 100%; }

@media (min-width: 768px) {
  .deals-list { max-width: min(1000px, 92%); margin: 0 auto; width: 100%; }
  .deals-warning { max-width: min(1000px, 92%); margin: 0 auto 10px; width: 100%; }
  .deals-toolbar { flex-direction: row; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
  .deals-meta { justify-content: flex-end; }
}

/* ===== Images View (admin-only AI image generation) ===== */
.img-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}
.img-warning {
  margin: 10px 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
}
.img-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.img-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.img-field-label {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.img-prompt {
  width: 100%;
  resize: vertical;
  min-height: 84px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.5;
  font-family: inherit;
}
.img-prompt::placeholder { color: var(--text3); }
.img-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}
.img-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  min-height: 38px;
  cursor: pointer;
}
.img-prompt:focus-visible,
.img-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.img-generate-btn {
  margin-left: auto;
  min-height: 38px;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.img-generate-btn:hover:not(:disabled) { filter: brightness(1.1); }
.img-generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.img-status {
  font-size: 12px;
  color: var(--text2);
  min-height: 18px;
}
.img-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}
.img-preview {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface2);
}
.img-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.img-download-btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}
.img-download-btn:hover { border-color: var(--accent); color: var(--accent); }
.img-prompt-echo {
  font-size: 12px;
  color: var(--text3);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* ---- Source image + mask painting (edit mode) ---- */
.img-source {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface2);
}
.img-source-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.img-source-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.img-brush {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text2);
}
.img-brush-range { width: 90px; accent-color: var(--accent); }
.img-mini-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
}
.img-mini-btn:hover { border-color: var(--accent); color: var(--accent); }
/* The canvas is absolutely positioned over the preview, so the wrapper must
   shrink to the image's rendered box rather than fill the column. */
.img-canvas-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  align-self: flex-start;
}
.img-source-preview {
  display: block;
  max-width: 100%;
  max-height: 46vh;
  height: auto;
  border-radius: 10px;
}
.img-mask-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  opacity: 0.45;
  cursor: crosshair;
  /* Without this a drag scrolls the page on touch instead of painting. */
  touch-action: none;
}
.img-source-hint {
  font-size: 11px;
  color: var(--text3);
  line-height: 1.5;
}
.img-upload-btn {
  min-height: 38px;
  padding: 8px 14px;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.img-upload-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.img-upload-btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* Only one element may claim the auto margin, or the pair splits apart. */
.img-upload-btn + .img-generate-btn { margin-left: 0; }

@media (min-width: 768px) {
  .img-body { max-width: min(1000px, 92%); margin: 0 auto; width: 100%; }
  .img-warning { max-width: min(1000px, 92%); margin: 10px auto 0; width: 100%; }
}
