:root, [data-theme="hacker"] {
  --bg:          #020b02;
  --bg-sidebar:  #010801;
  --bg-card:     #040f04;
  --bg-input:    #030c03;
  --bg-hover:    rgba(var(--accent-rgb),0.04);
  --bg-active:   rgba(var(--accent-rgb),0.09);
  --border:      #091509;
  --border-mid:  #0f2e0f;
  --border-hi:   #1a4d1a;
  --accent:      #00ff41;
  --accent-rgb:  0,255,65;
  --accent-dim:  #00cc34;
  --purple:      #00ffcc;
  --purple-rgb:  0,255,204;
  --teal:        #00e676;
  --teal-rgb:    0,230,118;
  --amber:       #ffb300;
  --amber-rgb:   255,179,0;
  --red:         #ff4444;
  --red-rgb:     217,88,88;
  --text:        #b8ffb8;
  --text2:       #3d8040;
  --text3:       #1a3d1a;
  --glow:        0 0 8px rgba(var(--accent-rgb),0.55);
  --glow-sm:     0 0 5px rgba(var(--accent-rgb),0.35);
  --r:           3px;
  --rs:          2px;
  --t:           0.14s ease;
  --font:        'Fira Code','JetBrains Mono','Cascadia Code','Courier New',monospace;
}

/* ══ Modern theme ═══════════════════════════════════════════════════════════ */
[data-theme="modern"] {
  --bg:          #15171d;
  --bg-sidebar:  #111318;
  --bg-card:     #1d2129;
  --bg-input:    #1a1d24;
  --bg-hover:    rgba(255,255,255,0.04);
  --bg-active:   rgba(110,142,251,0.13);
  --border:      #262a33;
  --border-mid:  #323744;
  --border-hi:   #454c5e;
  --accent:      #6e8efb;
  --accent-rgb:  110,142,251;
  --accent-dim:  #5570d8;
  --purple:      #b389f9;
  --purple-rgb:  179,137,249;
  --teal:        #4fd1c5;
  --teal-rgb:    79,209,197;
  --amber:       #f6ad55;
  --amber-rgb:   246,173,85;
  --red:         #f56565;
  --red-rgb:     245,101,101;
  --text:        #e6e8ef;
  --text2:       #9aa0ad;
  --text3:       #5c6270;
  --glow:        0 0 0 transparent;
  --glow-sm:     0 0 0 transparent;
  --r:           10px;
  --rs:          6px;
  --t:           0.14s ease;
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ══ Classic theme ══════════════════════════════════════════════════════════ */
[data-theme="classic"] {
  --bg:          #1a1b1e;
  --bg-sidebar:  #141517;
  --bg-card:     #212328;
  --bg-input:    #1c1e22;
  --bg-hover:    rgba(255,255,255,0.04);
  --bg-active:   rgba(201,163,92,0.12);
  --border:      #2a2c31;
  --border-mid:  #383b42;
  --border-hi:   #50535c;
  --accent:      #c9a35c;
  --accent-rgb:  201,163,92;
  --accent-dim:  #a8854a;
  --purple:      #9b8bc4;
  --purple-rgb:  155,139,196;
  --teal:        #6fae9e;
  --teal-rgb:    111,174,158;
  --amber:       #d4a24e;
  --amber-rgb:   212,162,78;
  --red:         #c1574a;
  --red-rgb:     193,87,74;
  --text:        #e4e2dd;
  --text2:       #9a9a9c;
  --text3:       #62646a;
  --glow:        0 0 0 transparent;
  --glow-sm:     0 0 0 transparent;
  --r:           4px;
  --rs:          3px;
  --t:           0.14s ease;
  --font:        Georgia, 'Times New Roman', 'Liberation Serif', serif;
}

/* ══ Archie theme ════════════════════════════════════════════════════════════ */
[data-theme="archie"] {
  --bg:          #202124;
  --bg-sidebar:  #1a1c1f;
  --bg-card:     #2c2d30;
  --bg-input:    #252628;
  --bg-hover:    rgba(80,250,123,0.06);
  --bg-active:   rgba(80,250,123,0.13);
  --border:      #2a2b2f;
  --border-mid:  #3a3b3f;
  --border-hi:   #0066ff;
  --accent:      #50fa7b;
  --accent-rgb:  80,250,123;
  --accent-dim:  #3dd458;
  --purple:      #bd93f9;
  --purple-rgb:  189,147,249;
  --teal:        #8be9fd;
  --teal-rgb:    139,233,253;
  --amber:       #f1fa8c;
  --amber-rgb:   241,250,140;
  --red:         #ff5555;
  --red-rgb:     255,85,85;
  --text:        #f8f8f2;
  --text2:       #adadad;
  --text3:       #6272a4;
  --glow:        0 0 0 transparent;
  --glow-sm:     0 0 0 transparent;
  --r:           5px;
  --rs:          3px;
  --t:           0.14s ease;
  --font:        'Roboto Mono', 'Courier New', monospace;
}

/* Dotted hr separators (Archie signature) */
[data-theme="archie"] hr {
  border-color: var(--border-hi);
  border-style: dotted;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: var(--user-font-size, 14px); line-height: 1.5; transition: background var(--t), color var(--t); }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }
button { font-family: inherit; }

/* CRT scanlines overlay (hacker theme only) */
[data-theme="hacker"] #app::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 9999;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px, transparent 3px,
    rgba(0,0,0,0.13) 3px, rgba(0,0,0,0.13) 4px
  );
}
/* Phosphor vignette (hacker theme only) */
[data-theme="hacker"] #app::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 9998;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.45) 100%);
}

/* ══ Layout ═══════════════════════════════════════════════════════════════ */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; position: relative; }
#app-body { display: flex; flex: 1; overflow: hidden; min-height: 0; }

/* ══ Fallback banner ═════════════════════════════════════════════════════ */
#fallback-banner {
  flex-shrink: 0; display: flex; flex-wrap: wrap; gap: 4px 16px;
  align-items: center; padding: 6px 14px; font-size: 0.78rem;
  color: var(--amber, #c9a227);
  background: rgba(201,162,39,0.1); border-bottom: 1px solid rgba(201,162,39,0.3);
}
#fallback-banner[hidden] { display: none; }
#fallback-banner .fb-item strong { font-weight: 600; }

/* ══ Sidebar ══════════════════════════════════════════════════════════════ */
#sidebar {
  width: 248px; min-width: 180px;
  position: relative;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.22s cubic-bezier(.4,0,.2,1), min-width 0.22s cubic-bezier(.4,0,.2,1);
}
#sidebar.collapsed { width: 0 !important; min-width: 0 !important; }
#sidebar.resizing { transition: none; }
#sb-resize {
  position: absolute; top: 0; right: -3px; width: 6px; height: 100%;
  cursor: col-resize; z-index: 25; background: transparent;
}
#sb-resize:hover, #sidebar.resizing #sb-resize { background: var(--accent); opacity: 0.35; }
#sb-close {
  margin-left: auto; width: 22px; height: 22px; border-radius: var(--rs);
  background: none; border: none; color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 1rem; line-height: 1;
  transition: all var(--t); flex-shrink: 0;
}
#sb-close:hover { background: var(--bg-hover); color: var(--text); }
#sb-open {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 16px; height: 48px; z-index: 20;
  background: var(--bg-sidebar); border: 1px solid var(--border); border-left: none;
  border-radius: 0 8px 8px 0; color: var(--text2); cursor: pointer;
  display: none; align-items: center; justify-content: center;
  font-size: 0.75rem; line-height: 1; transition: color var(--t), background var(--t);
}
#sb-open:hover { color: var(--text); background: var(--bg-card); }
.sb-collapsed #sb-open { display: flex; }

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 15px 13px;
  flex-shrink: 0;
}
.brand-gem {
  width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--accent); letter-spacing: 0;
  box-shadow: var(--glow-sm), inset 0 0 8px rgba(var(--accent-rgb),0.08);
  text-shadow: var(--glow);
}
.brand-name { font-weight: 700; font-size: 1rem; color: var(--accent); letter-spacing: 0.15em; text-shadow: var(--glow-sm); }
#model-tag { font-size: 0.9rem; font-weight: 700; color: var(--accent); margin-left: auto; white-space: nowrap; text-align: right; text-shadow: var(--glow-sm); }

.view-tabs {
  display: flex; padding: 8px 10px; gap: 3px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.vtab {
  flex: 1; padding: 7px 4px; border: none; border-radius: var(--rs);
  background: transparent; color: var(--text2); font-size: 0.8rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  gap: 5px; transition: all var(--t); font-weight: 500;
}
.vtab svg { opacity: 0.6; transition: opacity var(--t); }
.vtab:hover { background: var(--bg-hover); color: var(--text); }
.vtab:hover svg { opacity: 1; }
.vtab.active { background: var(--bg-active); color: var(--accent); text-shadow: var(--glow-sm); }
.vtab.active svg { opacity: 1; filter: drop-shadow(0 0 3px rgba(var(--accent-rgb),0.6)); }

#session-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.panel-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px 7px; flex-shrink: 0;
}
.panel-label {
  font-size: 0.68rem; font-weight: 700; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.1em;
}
#new-btn {
  width: 22px; height: 22px; border-radius: 0;
  background: transparent; border: 1px solid var(--border-hi);
  color: var(--accent); font-size: 1.15rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; line-height: 1;
  transition: all var(--t);
}
#new-btn:hover { background: var(--bg-active); border-color: var(--accent); box-shadow: var(--glow-sm); }

#session-list { flex: 1; overflow-y: auto; padding: 3px 8px 10px; }
.sess {
  display: flex; align-items: center; padding: 7px 8px 7px 10px;
  border-radius: var(--rs); cursor: pointer; gap: 8px;
  transition: background var(--t); position: relative;
}
.sess:hover { background: var(--bg-hover); }
.sess.active { background: var(--bg-active); }
.sess-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text3); flex-shrink: 0; transition: background var(--t);
}
.sess.active .sess-dot { background: var(--accent); box-shadow: var(--glow); border-radius: 0; }
.sess-name {
  flex: 1; font-size: 0.84rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
  color: var(--text2); transition: color var(--t);
}
.sess.active .sess-name { color: var(--text); font-weight: 500; }
.sess-del, .sess-ren, .sess-merge {
  width: 20px; height: 20px; border-radius: 5px;
  background: none; border: none; color: transparent; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.1s; flex-shrink: 0; line-height: 1;
}
.sess-ren { font-size: 0.8rem; }
.sess:hover .sess-del, .sess:hover .sess-ren, .sess:hover .sess-merge { color: var(--text2); }
.sess-del:hover { background: rgba(var(--red-rgb),0.16) !important; color: var(--red) !important; }
.sess-ren:hover { background: var(--bg-hover); color: var(--text) !important; }
.sess-merge { font-size: 0.85rem; }
.sess-merge:hover { background: var(--bg-hover); color: var(--text) !important; }

/* ══ Main ══════════════════════════════════════════════════════════════════ */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.view.on { display: flex; }

/* ══ Chat header ══════════════════════════════════════════════════════════ */
#chat-hdr {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 22px 10px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg-sidebar);
}
#chat-title { font-size: 0.88rem; font-weight: 600; color: var(--text2); }
#chat-title.live { color: var(--text); }
#chat-model { font-size: 0.72rem; color: var(--text3); margin-left: auto;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 9px; cursor: pointer; }
#chat-model:disabled { opacity: 0.5; cursor: default; }
#chat-model option.opt-featured { font-weight: 700; color: var(--accent); background: var(--bg-card); }
#proof-model, #lecture-model { font-size: 0.72rem; color: var(--text3); margin-left: auto;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 9px; cursor: pointer; }
#proof-model:disabled, #lecture-model:disabled { opacity: 0.5; cursor: default; }
#ctx-meter {
  display: none; align-items: center; gap: 6px; font-size: 0.7rem;
  color: var(--text3);
}
#ctx-meter.show { display: inline-flex; }
#ctx-bar {
  width: 60px; height: 6px; border-radius: 3px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  overflow: hidden;
}
#ctx-fill {
  height: 100%; width: 0%; background: var(--accent);
  transition: width .3s, background-color .3s;
}
#ctx-fill.warn { background: var(--orange, #d9822b); }
#ctx-fill.crit { background: var(--red); }
#project-badge {
  display: none; align-items: center; gap: 6px; font-size: 0.74rem;
  padding: 2px 9px; border-radius: 20px; color: var(--teal);
  border: 1px solid rgba(var(--teal-rgb),0.3); background: rgba(var(--teal-rgb),0.06);
}
#project-badge.show { display: inline-flex; }
#project-badge .pclear { cursor: pointer; opacity: 0.6; transition: opacity var(--t); }
#project-badge .pclear:hover { opacity: 1; }

/* ══ Messages ══════════════════════════════════════════════════════════════ */
#msgs {
  flex: 1; overflow-y: auto; padding: 22px 28px 14px;
  display: flex; flex-direction: column; gap: 18px;
}
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  pointer-events: none;
}
.empty-ascii {
  font-family: 'Fira Code','JetBrains Mono','Cascadia Code','Courier New',monospace; font-size: 0.72rem; color: var(--border-hi);
  line-height: 1.4; text-align: center; white-space: pre;
  text-shadow: 0 0 6px rgba(var(--accent-rgb),0.2);
}
.empty-text {
  font-size: 0.82rem; color: var(--text3);
}
.empty-text::before { content: '$ '; color: var(--accent); }
.empty-cursor { display: inline-block; width: 0.55em; height: 1em; background: var(--text3); vertical-align: text-bottom; animation: blink 1.1s step-end infinite; }

/* Message row */
.mrow { display: flex; align-items: flex-start; gap: 10px; }
.mrow.user { flex-direction: row-reverse; }
.bubble {
  max-width: 76%; padding: 11px 16px; border-radius: var(--r);
  line-height: 1.7; font-size: 0.875rem; word-break: break-word;
}
.mrow.user .bubble {
  background: rgba(var(--accent-rgb),0.05);
  color: var(--text); border: 1px solid rgba(var(--accent-rgb),0.2);
  border-bottom-right-radius: 0; white-space: pre-wrap;
}
.mrow.assistant .bubble {
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-bottom-left-radius: 0;
}

/* Turn wrapper + delete button */
.turn { position: relative; display: flex; flex-direction: column; gap: 18px; }
.turn-delete {
  position: absolute; top: -6px; right: -6px; z-index: 2;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text3); display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; line-height: 1; cursor: pointer; padding: 0;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.turn:hover .turn-delete, .turn:hover .split-btn { opacity: 1; }
.turn-delete:hover { color: var(--red); border-color: var(--red); }
.turn-delete:disabled, .split-btn:disabled { opacity: 0.4; cursor: default; }
.split-btn {
  position: absolute; top: -6px; right: 20px; z-index: 2;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text3); display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; line-height: 1; cursor: pointer; padding: 0;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.split-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ══ Thinking block ════════════════════════════════════════════════════════ */
.think-wrap { margin-bottom: 10px; }
.think-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.72rem; color: var(--text2); padding: 3px 10px 3px 8px;
  background: rgba(var(--purple-rgb),0.04); border: 1px solid rgba(var(--purple-rgb),0.18);
  border-radius: 0; cursor: pointer; user-select: none; transition: all var(--t);
}
.think-toggle:hover { background: rgba(var(--purple-rgb),0.09); color: var(--purple); border-color: rgba(var(--purple-rgb),0.4); }
.think-pulse { width: 5px; height: 5px; border-radius: 0; background: var(--purple); animation: pulse 1.3s ease-in-out infinite; flex-shrink: 0; }
@keyframes pulse { 0%,100%{opacity:.2;transform:scale(.75)} 50%{opacity:1;transform:scale(1)} }
.think-body {
  margin-top: 6px; padding: 10px 13px;
  background: rgba(var(--purple-rgb),0.03); border: 1px solid rgba(var(--purple-rgb),0.1);
  border-radius: 0; font-size: 0.72rem; color: var(--text2);
  white-space: pre-wrap; max-height: 240px; overflow-y: auto; line-height: 1.65;
  display: none;
}
.think-body.open { display: block; }

/* ══ Markdown ══════════════════════════════════════════════════════════════ */
.md p { margin: 5px 0; }
.md p:first-child { margin-top: 0; }
.md p:last-child  { margin-bottom: 0; }
.md code {
  font-family: 'Fira Code','JetBrains Mono','Cascadia Code','Courier New',monospace;
  font-size: 0.82em; background: rgba(var(--accent-rgb),0.06);
  padding: 1px 5px; border-radius: 0; color: var(--accent); border: 1px solid rgba(var(--accent-rgb),0.15);
}
.md pre {
  background: #000; border: 1px solid var(--border-mid);
  border-radius: 0; padding: 13px 15px; overflow-x: auto; margin: 10px 0;
  border-left: 2px solid var(--accent);
}
.md pre code { background: none; padding: 0; border: none; font-size: 0.79rem; color: var(--text); line-height: 1.55; font-family: 'Fira Code','JetBrains Mono','Cascadia Code','Courier New',monospace; }
.md strong { color: var(--accent); font-weight: 700; text-shadow: var(--glow-sm); }
.md em { color: var(--purple); font-style: italic; }
.md a { color: var(--accent); text-decoration: none; text-shadow: var(--glow-sm); }
.md a:hover { text-decoration: underline; }
.md ul, .md ol { padding-left: 22px; margin: 4px 0; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--accent); }
.md blockquote { border-left: 2px solid var(--accent); padding: 2px 0 2px 12px; color: var(--text2); margin: 6px 0; opacity: 0.75; }
.md h1, .md h2, .md h3, .md h4 { color: var(--accent); font-weight: 700; margin: 12px 0 5px; text-shadow: var(--glow-sm); }
.md h1 { font-size: 1.1em; } .md h2 { font-size: 1em; } .md h3 { font-size: 0.94em; } .md h4 { font-size: 0.9em; }
.md hr { border: none; border-top: 1px dashed var(--border-hi); margin: 10px 0; }
.tbl-wrap { overflow-x: auto; margin: 10px 0; border-radius: var(--r); border: 1px solid var(--border); }
.md table { border-collapse: collapse; width: 100%; font-size: 0.83rem; }
.md th { background: rgba(255,255,255,0.04); color: var(--text); font-weight: 600; padding: 7px 13px; text-align: left; border-bottom: 1px solid var(--border-mid); white-space: nowrap; }
.md td { padding: 6px 13px; border-bottom: 1px solid var(--border); color: var(--text2); vertical-align: top; }
.md tr:last-child td { border-bottom: none; }
.md tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
/* ══ Tool pills ════════════════════════════════════════════════════════════ */
.tool-pills { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.tool-pill {
  display: inline-flex; align-items: center; gap: 5px; align-self: flex-start;
  font-size: 0.72rem; padding: 3px 9px 3px 6px; border-radius: 12px;
  border: 1px solid; line-height: 1.4; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-pill.running {
  color: var(--amber); border-color: rgba(232,163,72,0.28);
  background: rgba(232,163,72,0.07);
}
.tool-pill.done {
  color: var(--teal); border-color: rgba(62,201,160,0.25);
  background: rgba(62,201,160,0.06);
}
.tool-dot {
  width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
  background: currentColor; animation: pulse 1.1s ease-in-out infinite;
}
.tool-pill.done .tool-dot { animation: none; }

.cursor {
  display: inline-block; width: 0.55em; height: 1em;
  background: var(--accent); vertical-align: text-bottom;
  animation: blink 1s step-end infinite; margin-left: 2px;
  box-shadow: var(--glow);
}
@keyframes blink { 50%{opacity:0} }

/* ══ Input area ════════════════════════════════════════════════════════════ */
#input-area {
  padding: 12px 20px 15px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; flex-shrink: 0;
  background: rgba(5,6,14,0.8);
}
#input-row { display: flex; gap: 10px; align-items: flex-end; }
#attach-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
}
#attach-bar:empty { display: none; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; font-size: 0.75rem; color: var(--text2);
  border: 1px solid var(--border-mid); background: var(--bg-input);
  max-width: 220px;
}
.attach-chip .ac-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .ac-remove {
  cursor: pointer; color: var(--text3); flex-shrink: 0; line-height: 1;
}
.attach-chip .ac-remove:hover { color: var(--red); }
.attach-btn {
  width: 42px; height: 42px; border-radius: 0;
  background: transparent; border: 1px solid var(--border-mid);
  color: var(--text2); font-size: 1.1rem; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all var(--t);
}
.attach-btn:not(:disabled):hover { background: var(--bg-active); color: var(--accent); border-color: var(--accent); }
.attach-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.msg-attachments {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px;
}
.msg-attach-img {
  max-width: 200px; max-height: 200px; border: 1px solid var(--border-mid);
  cursor: pointer; display: block;
}
.msg-attach-file {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; font-size: 0.78rem; color: var(--text2);
  border: 1px solid var(--border-mid); background: var(--bg-input);
}
#inp {
  flex: 1; background: var(--bg-input); border: 1px solid var(--border-mid);
  color: var(--text); border-radius: 0; padding: 10px 12px;
  font-size: 0.875rem; font-family: inherit; resize: none;
  min-height: 42px; max-height: 190px; overflow-y: auto; line-height: 1.55;
  transition: border-color var(--t), box-shadow var(--t);
}
#inp:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow-sm); }
#inp::placeholder { color: var(--text3); }
#inp:disabled { opacity: 0.45; }
#send {
  width: 42px; height: 42px; border-radius: 0;
  background: transparent; border: 1px solid var(--accent);
  color: var(--accent); font-size: 1.1rem; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all var(--t);
  box-shadow: var(--glow-sm);
}
#send:not(:disabled):hover { background: var(--bg-active); box-shadow: var(--glow); }
#send:not(:disabled):active { transform: scale(0.96); }
#send:disabled { border-color: var(--border-mid); color: var(--border-mid); box-shadow: none; cursor: not-allowed; }
#send.stop { border-color: var(--red); color: var(--red); box-shadow: none; }
#send.stop:hover { background: rgba(var(--red-rgb),0.12); }

/* ══ Cancel notice ═════════════════════════════════════════════════════════ */
.cancel-notice {
  text-align: center; font-size: 0.78rem; color: var(--text3);
  padding: 6px 0; font-style: italic;
}

/* ══ Turn notice (non-fatal warnings) ═════════════════════════════════════ */
.turn-notice {
  font-size: 0.75rem; color: var(--amber, #c9a227);
  border: 1px solid rgba(201,162,39,0.3); background: rgba(201,162,39,0.08);
  border-radius: 6px; padding: 4px 8px; margin-bottom: 6px; align-self: flex-start;
}

/* ══ Tools-used summary ════════════════════════════════════════════════════ */
.tools-used {
  font-size: 0.7rem; color: var(--text3); margin-top: 4px;
}

/* ══ Pending review in-progress indicator ══════════════════════════════════ */
.pending-spinner {
  font-size: 0.75rem; color: var(--text3); margin-top: 6px;
  animation: pulse-opacity 1.4s ease-in-out infinite;
}
@keyframes pulse-opacity { 0%,100%{opacity:.4} 50%{opacity:1} }

/* ══ Skill autocomplete ════════════════════════════════════════════════════ */
#input-area { position: relative; }
#skill-popup {
  display: none; position: absolute; bottom: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border-mid); border-radius: var(--r);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6); z-index: 100;
  max-height: 280px; overflow-x: hidden; overflow-y: auto;
}
#skill-popup.open { display: block; }
.skill-item {
  display: flex; align-items: baseline; gap: 10px; padding: 8px 14px;
  cursor: pointer; transition: background var(--t);
}
.skill-item:hover, .skill-item.active { background: var(--bg-active); }
.skill-item.active .skill-cmd { text-shadow: var(--glow-sm); }
.skill-cmd { color: var(--accent); font-family: inherit; font-size: 0.82rem; white-space: nowrap; }
.skill-desc { color: var(--text2); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skill-badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem;
  padding: 2px 8px; border-radius: 0; margin-bottom: 5px; align-self: flex-start;
  color: var(--accent); border: 1px solid rgba(var(--accent-rgb),0.3); background: rgba(var(--accent-rgb),0.06);
  text-shadow: var(--glow-sm);
}
.skill-badge.project {
  color: var(--teal); border-color: rgba(var(--teal-rgb),0.3); background: rgba(var(--teal-rgb),0.06);
}
.skill-item.project .skill-cmd { color: var(--teal); }

/* ══ File autocomplete ═════════════════════════════════════════════════════ */
#file-popup {
  display: none; position: absolute; bottom: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border-mid);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6); z-index: 101;
  max-height: 280px; overflow-x: hidden; overflow-y: auto;
}
#file-popup.open { display: block; }
.file-item {
  display: flex; align-items: baseline; gap: 10px; padding: 6px 14px;
  cursor: pointer; transition: background var(--t); font-family: inherit;
}
.file-item:hover, .file-item.active { background: var(--bg-active); }
.file-item.active .file-name { text-shadow: var(--glow-sm); }
.file-kind {
  font-size: 0.68rem; padding: 1px 5px; border: 1px solid;
  flex-shrink: 0; font-family: inherit;
}
.file-kind.dir  { color: var(--accent); border-color: rgba(var(--accent-rgb),0.3); background: rgba(var(--accent-rgb),0.06); }
.file-kind.file { color: var(--text2);  border-color: var(--border-mid);  background: transparent; }
.file-name { color: var(--text); font-size: 0.83rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.file-name.is-dir { color: var(--accent); }
.file-popup-path {
  font-size: 0.68rem; color: var(--text3); padding: 5px 14px 3px;
  border-bottom: 1px solid var(--border); font-family: inherit;
}

/* ══ Memory view ═══════════════════════════════════════════════════════════ */
#mem-view { background: var(--bg); }
.mem-hdr {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 24px 13px; border-bottom: 1px solid var(--border); flex-shrink: 0;
  background: var(--bg-sidebar);
}
.mem-hdr h2 { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.mem-filters { display: flex; gap: 5px; flex: 1; }
.fpill {
  padding: 4px 11px; border-radius: 20px; border: 1px solid var(--border);
  background: transparent; color: var(--text2); font-size: 0.75rem;
  cursor: pointer; transition: all var(--t); font-family: inherit;
}
.fpill:hover { border-color: var(--border-hi); color: var(--text); }
.fpill.on { font-weight: 500; }
.fpill[data-cat=all].on    { border-color: var(--accent);  background: rgba(var(--accent-rgb),0.08);   color: var(--accent); text-shadow: var(--glow-sm); }
.fpill[data-cat=fact].on   { border-color: var(--accent);  background: rgba(var(--accent-rgb),0.08);   color: var(--accent); text-shadow: var(--glow-sm); }
.fpill[data-cat=preference].on { border-color: var(--purple); background: rgba(var(--purple-rgb),0.08); color: var(--purple); }
.fpill[data-cat=task].on   { border-color: var(--amber);   background: rgba(var(--amber-rgb),0.08);  color: var(--amber); }
.fpill[data-cat=context].on { border-color: var(--teal);   background: rgba(var(--teal-rgb),0.08);  color: var(--teal); }
.fpill[data-tfilter].on { border-color: var(--accent); background: rgba(var(--accent-rgb),0.08); color: var(--accent); text-shadow: var(--glow-sm); }

.mem-search {
  padding: 5px 12px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 0.78rem; font-family: inherit;
  width: 180px; transition: all var(--t);
}
.mem-search:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow-sm); }
.mem-search::placeholder { color: var(--text3); }

.add-btn {
  padding: 6px 14px; border-radius: 0; cursor: pointer;
  border: 1px solid rgba(var(--accent-rgb),0.25); background: rgba(var(--accent-rgb),0.05);
  color: var(--accent); font-size: 0.78rem; font-family: inherit;
  transition: all var(--t); white-space: nowrap;
}
.add-btn:hover { background: rgba(var(--accent-rgb),0.12); border-color: var(--accent); box-shadow: var(--glow-sm); }

#mem-scroll { flex: 1; overflow-y: auto; padding: 18px 24px; }
#mem-form-slot { margin-bottom: 16px; }

/* ══ Tasks view ════════════════════════════════════════════════════════════ */
#tasks-view { background: var(--bg); }
#tasks-scroll { flex: 1; overflow-y: auto; padding: 18px 24px; }
#task-form-slot { margin-bottom: 16px; }
.tcheck { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; accent-color: var(--accent); cursor: pointer; }
.tcard-title { font-size: 0.85rem; color: var(--text); line-height: 1.5; }
.tcard.done .tcard-title { color: var(--text3); text-decoration: line-through; }
.tcard-desc { font-size: 0.78rem; color: var(--text2); line-height: 1.5; margin-top: 3px; }
.tdate {
  font-size: 0.69rem; padding: 2px 8px; border-radius: 12px;
  border: 1px solid var(--border-hi); color: var(--text2); font-weight: 600;
}
.tdate.overdue { border-color: rgba(var(--red-rgb),0.28); color: var(--red); background: rgba(var(--red-rgb),0.06); }
.tdate.anxiety-medium { border-color: rgba(var(--amber-rgb),0.28); color: var(--amber); background: rgba(var(--amber-rgb),0.06); }
.tdate.anxiety-high { border-color: rgba(var(--red-rgb),0.28); color: var(--red); background: rgba(var(--red-rgb),0.06); }
.tf-datelabel { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text2); }
.bulk-resched {
  display: flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--red);
  border: 1px solid rgba(var(--red-rgb),0.28); background: rgba(var(--red-rgb),0.06);
  padding: 4px 8px; border-radius: 12px; white-space: nowrap;
}
.bulk-resched-btn {
  padding: 2px 8px; border-radius: 10px; cursor: pointer; font-family: inherit;
  border: 1px solid rgba(var(--red-rgb),0.28); background: transparent; color: var(--red); font-size: 0.7rem;
  transition: all var(--t);
}
.bulk-resched-btn:hover { background: rgba(var(--red-rgb),0.14); border-color: var(--red); }

.agent-status-line {
  font-size: 0.76rem; font-style: italic; color: var(--text2);
  padding: 8px 24px; margin: 0; border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar); flex-shrink: 0;
}
.agent-status-line[hidden] { display: none; }

.vtoggle { display: flex; border: 1px solid var(--border-mid); border-radius: 4px; overflow: hidden; }
.vtoggle button {
  padding: 5px 12px; border: none; background: transparent; color: var(--text2); cursor: pointer;
  font-size: 0.76rem; font-family: inherit; transition: all var(--t);
}
.vtoggle button + button { border-left: 1px solid var(--border-mid); }
.vtoggle button.on { background: rgba(var(--accent-rgb),0.1); color: var(--accent); }
.vtoggle button:hover:not(.on) { color: var(--text); }

#tasks-day-view { display: none; flex-direction: column; flex: 1; overflow: hidden; }
#tasks-view.day-mode #tasks-scroll { display: none; }
#tasks-view.day-mode #tasks-day-view { display: flex; }

.day-cal-nav { display: flex; align-items: center; gap: 10px; padding: 10px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.day-cal-nav button {
  padding: 4px 10px; border-radius: 4px; border: 1px solid var(--border-mid); background: transparent;
  color: var(--text2); cursor: pointer; font-family: inherit; font-size: 0.78rem; transition: all var(--t);
}
.day-cal-nav button:hover { border-color: var(--accent); color: var(--accent); }
#day-label { font-size: 0.85rem; color: var(--text); font-weight: 500; min-width: 160px; }
#day-sidebar-toggle { margin-left: auto; }

.day-cal-body { flex: 1; display: flex; overflow: hidden; }
.day-cal-sidebar {
  position: relative; width: 220px; min-width: 140px; max-width: 420px; flex-shrink: 0;
  overflow-y: auto; padding: 14px; border-left: 1px solid var(--border);
  transition: width 0.2s cubic-bezier(.4,0,.2,1), min-width 0.2s cubic-bezier(.4,0,.2,1), padding 0.2s;
}
.day-cal-sidebar.collapsed { width: 0 !important; min-width: 0 !important; padding-left: 0; padding-right: 0; overflow: hidden; }
.day-cal-sidebar.resizing { transition: none; }
#day-sidebar-resize {
  position: absolute; top: 0; left: -3px; width: 6px; height: 100%;
  cursor: col-resize; z-index: 25; background: transparent;
}
#day-sidebar-resize:hover, .day-cal-sidebar.resizing #day-sidebar-resize { background: var(--accent); opacity: 0.35; }
.day-cal-sidebar h3 { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text3); margin: 14px 0 8px; white-space: nowrap; }
.day-cal-sidebar h3:first-child { margin-top: 0; }
.unsched-item {
  font-size: 0.78rem; color: var(--text); padding: 6px 8px; margin-bottom: 5px; border-radius: 4px;
  border: 1px solid var(--border-mid); background: var(--bg-card); cursor: grab; transition: all var(--t);
}
.unsched-item:hover { border-color: var(--accent); }
.unsched-item.done { color: var(--text3); text-decoration: line-through; }

.day-cal-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.day-cal-grid-wrap { flex: 1; overflow-y: auto; position: relative; }
.day-cal-hours { position: absolute; left: 0; top: 0; width: 52px; }
.day-hour-label { position: absolute; left: 0; width: 52px; font-size: 0.65rem; color: var(--text3); transform: translateY(-6px); text-align: right; padding-right: 8px; }
.day-cal-grid {
  position: relative; margin-left: 52px;
  background-image: repeating-linear-gradient(to bottom, var(--border) 0 1px, transparent 1px 60px);
}
.day-block {
  position: absolute; left: 4px; right: 4px; min-height: 15px; overflow: hidden;
  border-radius: 4px; border: 1px solid rgba(var(--accent-rgb),0.35); background: rgba(var(--accent-rgb),0.1);
  padding: 3px 6px; cursor: grab; font-size: 0.72rem; color: var(--text); box-sizing: border-box;
}
.day-block.dragging { cursor: grabbing; box-shadow: var(--glow-sm); z-index: 5; }
.day-block.done { opacity: 0.55; }
.day-block.done .day-block-title { text-decoration: line-through; }
.day-block-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 50px; }
.day-block-time { color: var(--text3); font-size: 0.65rem; }
.day-block-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; }
.day-block-acts {
  position: absolute; top: 1px; right: 2px; display: flex; gap: 1px; z-index: 2;
  opacity: 0; transition: opacity var(--t);
}
.day-block:hover .day-block-acts { opacity: 1; }
.day-block-acts .ibt {
  width: 15px; height: 15px; font-size: 0.6rem; border-radius: 3px; cursor: pointer;
  background: var(--bg-card); color: var(--text2); border: none;
  display: flex; align-items: center; justify-content: center; transition: all 0.1s;
}
.day-block-acts .ibt:hover { background: var(--bg-hover); color: var(--text); }
.day-block-acts .ibt.done:hover { background: rgba(var(--accent-rgb),0.14); color: var(--accent); }
.day-block-acts .ibt.remove:hover { background: rgba(var(--red-rgb),0.14); color: var(--red); }

/* Bigger, easier-to-hit buttons in the Tasks view specifically (filter pills, Add task, List/Day
   toggle, calendar nav, per-task actions) — scoped to #tasks-view so shared classes like .fpill/
   .add-btn/.ibt keep their normal size in Memory/Jobs. */
#tasks-view .fpill { padding: 6px 15px; font-size: 0.85rem; }
#tasks-view .add-btn { padding: 9px 20px; font-size: 0.88rem; }
#tasks-view .vtoggle button { padding: 8px 16px; font-size: 0.86rem; }
#tasks-view .day-cal-nav button { padding: 7px 14px; font-size: 0.86rem; }
#tasks-view .mcard-acts .ibt { width: 32px; height: 32px; font-size: 1rem; }

#day-cal-bg { position: absolute; left: 52px; right: 0; top: 0; z-index: 0; }
.cal-event-bg {
  position: absolute; left: 4px; right: 4px; overflow: hidden; pointer-events: none; box-sizing: border-box;
  border-left: 2px solid var(--text3); border-radius: 2px; padding: 2px 6px; font-size: 0.68rem; color: var(--text2);
  background-image: repeating-linear-gradient(45deg, rgba(var(--accent-rgb),0.06) 0 6px, transparent 6px 12px);
}
.day-cal-grid > .day-block { z-index: 1; }
.day-cal-allday { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; min-height: 14px; }
.day-cal-allday .cal-event-pill {
  font-size: 0.68rem; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--border-hi); color: var(--text2);
}

/* ══ Jobs view ═════════════════════════════════════════════════════════════ */
#jobs-view { background: var(--bg); }
#jobs-scroll { flex: 1; overflow-y: auto; padding: 18px 24px; }
.jobcard { gap: 11px; }
.job-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.82rem; color: var(--text2); }
.job-label { color: var(--text3); font-size: 0.78rem; }
.job-time, .job-model {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--rs);
  color: var(--text); font-family: inherit; font-size: 0.82rem; padding: 4px 8px;
}
.job-time:focus, .job-model:focus { outline: none; border-color: var(--accent); }
.job-toggle { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text2); cursor: pointer; }
.job-message { font-size: 0.8rem; color: var(--text2); background: var(--bg-hover); border-radius: var(--rs); padding: 6px 10px; line-height: 1.5; }
.job-status { font-size: 0.69rem; padding: 2px 8px; border-radius: 12px; border: 1px solid; font-weight: 600; text-transform: capitalize; }
.job-status.ok  { color: var(--accent); border-color: rgba(var(--accent-rgb),0.28); background: rgba(var(--accent-rgb),0.06); }
.job-status.err { color: var(--red);    border-color: rgba(var(--red-rgb),0.28);   background: rgba(var(--red-rgb),0.06); }

.job-changes { display: flex; flex-direction: column; gap: 8px; }
.job-change { background: var(--bg-hover); border-radius: var(--rs); padding: 8px 10px; display: flex; flex-direction: column; gap: 5px; }
.job-change-hd { display: flex; align-items: center; gap: 6px; }
.job-change-action { font-size: 0.69rem; padding: 2px 8px; border-radius: 12px; border: 1px solid var(--border-hi); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text2); }
.job-change-action.delete { color: var(--red); border-color: rgba(var(--red-rgb),0.28); background: rgba(var(--red-rgb),0.06); }
.job-change-action.merge, .job-change-action.rewrite { color: var(--accent); border-color: rgba(var(--accent-rgb),0.28); background: rgba(var(--accent-rgb),0.06); }
.job-change-before { font-size: 0.8rem; color: var(--text3); text-decoration: line-through; line-height: 1.5; }
.job-change-after { font-size: 0.84rem; color: var(--text); line-height: 1.5; }

/* ══ Settings view ═════════════════════════════════════════════════════════ */
#settings-view { background: var(--bg); }
#settings-scroll { flex: 1; overflow-y: auto; padding: 18px 24px; }
.settings-section { max-width: 360px; margin-bottom: 22px; }
.settings-label {
  font-size: 0.78rem; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px;
}
.settings-section select {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border-mid); color: var(--text);
  font-family: inherit; font-size: 0.85rem; border-radius: var(--rs);
  padding: 8px 10px; cursor: pointer; transition: all var(--t);
}
.settings-section select:hover { border-color: var(--border-hi); }
.settings-section select:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow-sm); }
.account-username { font-size: 0.85rem; color: var(--text); margin-bottom: 10px; }
.change-password-form { display: flex; flex-direction: column; gap: 8px; }
.change-password-form input {
  background: var(--bg-input); border: 1px solid var(--border-mid); color: var(--text);
  border-radius: var(--rs); padding: 7px 9px; font-family: inherit; font-size: 0.85rem;
  outline: none; transition: border-color var(--t); width: 100%; box-sizing: border-box;
}
.change-password-form input:focus { border-color: var(--border-hi); }
.change-password-form .btn-save { align-self: flex-start; }
.change-password-msg { font-size: 0.8rem; margin: 0; }
.change-password-msg.error { color: var(--red); }
.change-password-msg.success { color: var(--teal); }
.settings-section select option { background: var(--bg-card); color: var(--text); }

.mem-form {
  background: var(--bg-card); border: 1px solid var(--border-hi);
  border-radius: var(--r); padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  animation: slide-in 0.15s ease;
}
@keyframes slide-in { from { opacity: 0; transform: translateY(-8px); } }
.mem-form textarea {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border-mid);
  color: var(--text); border-radius: var(--rs); padding: 9px 11px;
  font-family: inherit; font-size: 0.86rem; resize: none;
  min-height: 76px; line-height: 1.55;
}
.mem-form textarea:focus { outline: none; border-color: var(--border-hi); }
.mem-form-row { display: flex; align-items: center; gap: 8px; }
.mem-form select {
  background: var(--bg-input); border: 1px solid var(--border-mid);
  color: var(--text); border-radius: var(--rs); padding: 6px 9px;
  font-family: inherit; font-size: 0.82rem;
}
.mem-form select:focus { outline: none; border-color: var(--border-hi); }
.mem-form input[type=text], .mem-form input[type=number], .mem-form input[type=time], .mem-form input[type=datetime-local], .mem-form input[type=date] {
  background: var(--bg-input); border: 1px solid var(--border-mid);
  color: var(--text); border-radius: var(--rs); padding: 6px 9px;
  font-family: inherit; font-size: 0.82rem;
}
.mem-form input[type=text] { flex: 1; }
.mem-form input[type=number] { width: 64px; }
.mem-form input:focus { outline: none; border-color: var(--border-hi); }
.mem-form label.chk { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--text2); cursor: pointer; }
.btn-save {
  padding: 6px 16px; border-radius: 0;
  border: 1px solid var(--accent); background: rgba(var(--accent-rgb),0.1);
  color: var(--accent); font-size: 0.82rem;
  font-family: inherit; cursor: pointer; transition: all var(--t);
}
.btn-save:hover { background: rgba(var(--accent-rgb),0.2); box-shadow: var(--glow-sm); }
.btn-cancel {
  padding: 6px 12px; border-radius: 0;
  border: 1px solid var(--border); background: transparent;
  color: var(--text2); font-size: 0.82rem; font-family: inherit; cursor: pointer;
  transition: all var(--t);
}
.btn-cancel:hover { border-color: var(--border-hi); color: var(--text); }

.mem-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 11px;
}
.mcard {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px 15px 12px;
  display: flex; flex-direction: column; gap: 9px;
  transition: border-color var(--t), transform 0.12s;
}
.mcard:hover { border-color: var(--border-mid); transform: translateY(-1px); }
.mcard-body {
  display: flex; align-items: flex-start; gap: 8px;
}
.mcard-text { flex: 1; font-size: 0.85rem; color: var(--text); line-height: 1.65; }
.mcard-acts { display: flex; gap: 2px; flex-shrink: 0; opacity: 0; transition: opacity var(--t); }
.mcard:hover .mcard-acts { opacity: 1; }
.ibt {
  width: 26px; height: 26px; border-radius: var(--rs); border: none;
  background: none; cursor: pointer; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2); transition: all 0.1s;
}
.ibt:hover { background: var(--bg-hover); color: var(--text); }
.ibt.del:hover { background: rgba(var(--red-rgb),0.14); color: var(--red); }
.mcard-foot { display: flex; align-items: center; justify-content: space-between; }
.cbadge {
  font-size: 0.69rem; padding: 2px 8px; border-radius: 12px;
  border: 1px solid; font-weight: 600; letter-spacing: 0.04em; text-transform: capitalize;
}
.cbadge.fact       { color: var(--accent); border-color: rgba(var(--accent-rgb),0.28);   background: rgba(var(--accent-rgb),0.06); }
.cbadge.preference { color: var(--purple); border-color: rgba(var(--purple-rgb),0.28);  background: rgba(var(--purple-rgb),0.06); }
.cbadge.task       { color: var(--amber);  border-color: rgba(var(--amber-rgb),0.28);  background: rgba(var(--amber-rgb),0.06); }
.cbadge.context    { color: var(--teal);   border-color: rgba(var(--teal-rgb),0.28);  background: rgba(var(--teal-rgb),0.06); }
.cbadge.observation{ color: var(--red);    border-color: rgba(var(--red-rgb),0.28);   background: rgba(var(--red-rgb),0.06); }
.cbadge.concept    { color: var(--text);   border-color: var(--border-hi);            background: var(--bg-hover); }
.mdate { font-size: 0.69rem; color: var(--text3); }
.msource {
  font-size: 0.69rem; color: var(--text3); text-decoration: none;
  border: 1px solid var(--border); border-radius: 12px; padding: 1px 8px;
  max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msource:hover { color: var(--accent); border-color: var(--accent); }

.mem-empty { color: var(--text3); font-size: 0.88rem; text-align: center; margin-top: 70px; line-height: 1.8; }

/* ══ Proofreader ═══════════════════════════════════════════════════════════ */
#proof-prompt-panel {
  display: none; flex-shrink: 0; flex-direction: column; gap: 6px;
  padding: 0 16px 12px; border-bottom: 1px solid var(--border-mid);
}
#proof-prompt-panel.open { display: flex; }
#proof-prompt-text {
  resize: vertical; width: 100%; box-sizing: border-box; min-height: 60px;
  background: var(--bg-input); border: 1px solid var(--border-mid);
  border-radius: var(--r); color: var(--text); font-family: var(--font);
  font-size: 0.82rem; line-height: 1.55; padding: 8px 10px;
  transition: border-color var(--t); outline: none;
}
#proof-prompt-text:focus { border-color: var(--border-hi); }
.proof-prompt-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
#proof-prompt-badge {
  font-size: 0.72rem; color: var(--accent); border: 1px solid rgba(var(--accent-rgb),0.4);
  border-radius: var(--rs); padding: 1px 7px; text-transform: uppercase; letter-spacing: 0.07em;
}
#proof-body {
  flex: 1; display: flex; min-height: 0;
}
.proof-left {
  flex: 1; display: flex; flex-direction: column; gap: 10px;
  padding: 16px; border-right: 1px solid var(--border-mid); min-width: 0;
}
.proof-right {
  flex: 1; display: flex; flex-direction: column; gap: 10px;
  padding: 16px; overflow-y: auto; min-width: 0;
}
.proof-pane-hdr { display: flex; align-items: center; justify-content: space-between; }
.proof-pane-label {
  font-size: 0.68rem; font-weight: 700; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.1em;
}
#proof-input {
  flex: 1; resize: none; width: 100%; box-sizing: border-box;
  background: var(--bg-input); border: 1px solid var(--border-mid);
  border-radius: var(--r); color: var(--text); font-family: var(--font);
  font-size: 0.88rem; line-height: 1.6; padding: 10px 12px;
  transition: border-color var(--t); outline: none;
}
#proof-input:focus { border-color: var(--border-hi); }
.proof-controls { display: flex; gap: 8px; flex-shrink: 0; }
.proof-summary-text {
  font-size: 0.84rem; color: var(--text2); margin: 0 0 4px;
  padding: 8px 12px; background: var(--bg-card); border-radius: var(--r);
  border-left: 3px solid var(--border-hi);
}
.proof-no-changes {
  font-size: 0.84rem; color: var(--teal); margin: 0;
  padding: 8px 12px; background: rgba(var(--teal-rgb),0.06);
  border-radius: var(--r); border-left: 3px solid var(--teal);
}
.proof-error {
  font-size: 0.82rem; color: var(--red); padding: 10px 12px;
  background: rgba(var(--red-rgb),0.07); border-radius: var(--r);
  border-left: 3px solid var(--red);
}
.proof-error pre { margin: 6px 0 0; font-size: 0.78rem; white-space: pre-wrap; word-break: break-all; }
.proof-card {
  background: var(--bg-card); border: 1px solid var(--border-mid);
  border-radius: var(--r); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
  transition: border-color var(--t), opacity var(--t);
}
.proof-card.is-accepted { border-color: rgba(var(--teal-rgb),0.4); opacity: 0.7; }
.proof-card.is-rejected { border-color: rgba(var(--red-rgb),0.3); opacity: 0.5; }
.proof-card-body { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.proof-orig {
  text-decoration: line-through; color: var(--red); font-size: 0.85rem;
  background: rgba(var(--red-rgb),0.08); padding: 1px 5px; border-radius: var(--rs);
  white-space: pre-wrap; word-break: break-word;
}
.proof-arrow { color: var(--text3); flex-shrink: 0; }
.proof-sugg {
  flex: 1; min-width: 120px; background: rgba(var(--teal-rgb),0.07);
  border: 1px solid rgba(var(--teal-rgb),0.3); border-radius: var(--rs);
  color: var(--teal); font-family: var(--font); font-size: 0.85rem;
  padding: 2px 7px; outline: none; transition: border-color var(--t);
}
.proof-sugg:focus { border-color: var(--teal); }
.proof-card-reason { font-size: 0.75rem; color: var(--text3); font-style: italic; }
.proof-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.proof-card-acts { display: flex; gap: 6px; }
.proof-locate {
  font-size: 0.76rem; padding: 3px 10px; border-radius: var(--rs);
  border: 1px solid var(--border-mid); background: none; color: var(--text3);
  cursor: pointer; font-family: var(--font); transition: all var(--t);
}
.proof-locate:hover { color: var(--text2); border-color: var(--border-hi); background: var(--bg-hover); }
.proof-accept, .proof-reject {
  font-size: 0.76rem; padding: 3px 10px; border-radius: var(--rs);
  border: 1px solid; cursor: pointer; font-family: var(--font);
  transition: all var(--t); background: none;
}
.proof-accept { color: var(--teal); border-color: rgba(var(--teal-rgb),0.4); }
.proof-accept:hover { background: rgba(var(--teal-rgb),0.12); }
.proof-reject { color: var(--red); border-color: rgba(var(--red-rgb),0.35); }
.proof-reject:hover { background: rgba(var(--red-rgb),0.10); }
.proof-resolved { font-size: 0.75rem; padding: 3px 10px; border-radius: var(--rs); border: 1px solid; }
.proof-resolved.accept { color: var(--teal); border-color: rgba(var(--teal-rgb),0.3); }
.proof-resolved.reject { color: var(--text3); border-color: var(--border); }

/* ══ Lecture Builder ════════════════════════════════════════════════════════ */
#lecture-prompt-panel {
  display: none; flex-shrink: 0; flex-direction: column; gap: 6px;
  padding: 0 16px 12px; border-bottom: 1px solid var(--border-mid);
}
#lecture-prompt-panel.open { display: flex; }
#lecture-prompt-text {
  resize: vertical; width: 100%; box-sizing: border-box; min-height: 60px;
  background: var(--bg-input); border: 1px solid var(--border-mid);
  border-radius: var(--r); color: var(--text); font-family: var(--font);
  font-size: 0.82rem; line-height: 1.55; padding: 8px 10px;
  transition: border-color var(--t); outline: none;
}
#lecture-prompt-text:focus { border-color: var(--border-hi); }
#lecture-prompt-badge {
  font-size: 0.72rem; color: var(--accent); border: 1px solid rgba(var(--accent-rgb),0.4);
  border-radius: var(--rs); padding: 1px 7px; text-transform: uppercase; letter-spacing: 0.07em;
}
#lecture-body { flex: 1; display: flex; min-height: 0; }
.lecture-left {
  flex: 1; display: flex; flex-direction: column; gap: 10px;
  padding: 16px; border-right: 1px solid var(--border-mid); min-width: 0;
}
.lecture-right {
  flex: 1; display: flex; flex-direction: column; gap: 10px;
  padding: 16px; min-width: 0;
}
#lecture-input {
  flex: 1; resize: none; width: 100%; box-sizing: border-box;
  background: var(--bg-input); border: 1px solid var(--border-mid);
  border-radius: var(--r); color: var(--text); font-family: var(--font);
  font-size: 0.88rem; line-height: 1.6; padding: 10px 12px;
  transition: border-color var(--t); outline: none;
}
#lecture-input:focus { border-color: var(--border-hi); }
#lecture-editor {
  flex: 1; resize: none; width: 100%; box-sizing: border-box;
  background: var(--bg-input); border: 1px solid var(--border-mid);
  border-radius: var(--r); color: var(--text); font-family: monospace;
  font-size: 0.82rem; line-height: 1.55; padding: 10px 12px;
  transition: border-color var(--t); outline: none;
}
#lecture-editor:focus { border-color: var(--border-hi); }
.lecture-status { font-size: 0.82rem; color: var(--red); min-height: 1.2em; }

/* ── Login page ─────────────────────────────────────────────────────────── */
#login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-card {
  display: flex; flex-direction: column; align-items: stretch; gap: 14px;
  width: 280px; padding: 28px 26px; box-sizing: border-box;
  background: var(--bg-card); border: 1px solid var(--border-mid); border-radius: var(--r);
}
.login-card .brand-gem { align-self: center; margin-bottom: 4px; }
.login-card h1 {
  margin: 0 0 6px; text-align: center; font-size: 1rem; font-weight: 700;
  color: var(--accent); letter-spacing: 0.15em; text-shadow: var(--glow-sm);
}
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 0.8rem; color: var(--text2); }
.login-card input {
  background: var(--bg-input); border: 1px solid var(--border-mid); color: var(--text);
  border-radius: var(--rs); padding: 7px 9px; font-family: inherit; font-size: 0.85rem;
  outline: none; transition: border-color var(--t);
}
.login-card input:focus { border-color: var(--border-hi); }
.login-error { color: var(--red); font-size: 0.8rem; margin: 0; }
.login-submit { margin-top: 4px; text-align: center; }
