/* ═══════════════════════════════════════════════════════════
   ShivaChat — Apple style
   iOS/Messages dark mode · true black + elevated grays
   systemBlue accent · systemGreen memory · systemIndigo reasoning
   San Francisco (system) typography · vibrancy · iMessage bubbles
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg: #000000;
  --bg-1: #1c1c1e;   /* secondary system background */
  --bg-2: #2c2c2e;   /* tertiary */
  --bg-3: #3a3a3c;   /* elevated */
  --bg-hover: #48484a;
  --line: #38383a;
  --line-soft: #262628;
  --text: #f5f5f7;
  --dim: rgba(235, 235, 245, 0.6);      /* secondaryLabel */
  --faint: rgba(235, 235, 245, 0.32);   /* tertiaryLabel */

  --accent: #0a84ff;                    /* systemBlue (dark) */
  --accent-hi: #409cff;
  --accent-ink: #ffffff;
  --accent-glow: rgba(10, 132, 255, 0.55);
  --teal: #30d158;                      /* systemGreen — memory */
  --teal-dim: #1f5a33;
  --violet: #5e5ce6;                    /* systemIndigo — reasoning */
  --purple: #bf5af2;                    /* systemPurple — vision */
  --danger: #ff453a;                    /* systemRed (dark) */

  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 22px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --shadow: 0 12px 40px -12px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 30px 80px -20px rgba(0, 0, 0, 0.85);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

/* subtle ambient depth (kept very restrained — Apple is clean) */
body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(1000px 520px at 72% -16%, rgba(10, 132, 255, 0.10), transparent 60%),
    radial-gradient(720px 520px at -8% 110%, rgba(94, 92, 230, 0.06), transparent 58%);
  pointer-events: none; z-index: 0;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font-family: inherit; font-size: inherit; color: var(--text); }
::selection { background: rgba(10, 132, 255, 0.32); }

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #48484a; border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #5a5a5c; background-clip: padding-box; border: 3px solid transparent; }
*::-webkit-scrollbar-track { background: transparent; }

/* ═══════ layout ═══════ */
#app { position: relative; z-index: 1; display: grid; grid-template-columns: 288px 1fr; height: 100vh; }
#app[hidden], #login-screen[hidden], #memory-page[hidden] { display: none; }

/* ═══════ sidebar ═══════ */
#sidebar {
  display: flex; flex-direction: column;
  background: rgba(28, 28, 30, 0.6);
  backdrop-filter: blur(20px) saturate(180%);
  border-right: 1px solid var(--line-soft);
  padding: 20px 14px 14px; gap: 14px; min-height: 0;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 8px; }
.brand-mark { color: var(--accent); display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: rgba(10, 132, 255, 0.14); border: 1px solid rgba(10, 132, 255, 0.24); }
.brand-tile { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); }
.brand-tile img { width: 22px; height: 22px; object-fit: contain; display: block; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: -0.02em; }
.brand-name em { font-style: normal; color: var(--accent); }
.logo-tile-lg { display: inline-grid; place-items: center; padding: 14px 20px; border-radius: 20px; background: #fff; box-shadow: 0 8px 30px -8px rgba(0, 0, 0, 0.6); }
.logo-tile-lg img { height: 32px; display: block; }
.logo-tile-xl { display: inline-grid; place-items: center; width: 92px; height: 92px; border-radius: 24px; background: #fff; box-shadow: 0 16px 50px -12px rgba(0, 0, 0, 0.7); }
.logo-tile-xl img { width: 56px; height: 56px; object-fit: contain; display: block; }

.new-chat {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 12px; border-radius: 980px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: 14px; letter-spacing: -0.01em;
  transition: background 0.2s var(--ease), transform 0.12s var(--ease);
}
.new-chat:hover { background: var(--accent-hi); }
.new-chat:active { transform: scale(0.97); }

.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid transparent; border-radius: 10px;
  padding: 8px 11px; color: var(--faint); transition: background 0.15s;
}
.search-wrap input { flex: 1; background: none; border: 0; outline: none; font-size: 13.5px; color: var(--text); }
.search-wrap input::placeholder { color: var(--faint); }
.search-wrap:focus-within { background: var(--bg-3); }

#chat-list { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -6px; padding: 0 6px; }
.chat-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); font-weight: 600; padding: 15px 8px 6px; }
.chat-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 11px; border-radius: 9px; font-size: 14px; color: var(--dim);
  text-align: left; position: relative; transition: background 0.12s, color 0.12s;
}
.chat-item:hover { background: var(--bg-2); color: var(--text); }
.chat-item.active { background: var(--accent); color: #fff; }
.chat-item.active .chat-del { color: rgba(255, 255, 255, 0.7); }
.chat-item .chat-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item .chat-del { opacity: 0; color: var(--faint); padding: 2px 5px; border-radius: 6px; font-size: 12px; transition: opacity 0.12s, color 0.12s; }
.chat-item:hover .chat-del { opacity: 1; }
.chat-item .chat-del:hover { color: #fff; }
.chat-list-empty { color: var(--faint); font-size: 13px; padding: 16px 10px; }

.sidebar-footer { border-top: 1px solid var(--line-soft); padding-top: 12px; display: flex; flex-direction: column; gap: 3px; }
.footer-btn { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px; font-size: 14px; color: var(--dim); transition: background 0.12s, color 0.12s; }
.footer-btn:hover { background: var(--bg-2); color: var(--text); }
.count-pill { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; background: rgba(48, 209, 88, 0.16); color: var(--teal); border-radius: 20px; padding: 1px 9px; }
.count-pill:empty { display: none; }

/* ═══════ main / topbar ═══════ */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
#topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 22px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(28, 28, 30, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  z-index: 20;
}
.model-picker { position: relative; }
.model-btn {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-2); border: 1px solid transparent; border-radius: 980px;
  padding: 8px 15px; font-size: 13.5px; font-weight: 500; max-width: 440px;
  transition: background 0.15s;
}
.model-btn:hover { background: var(--bg-3); }
.model-btn svg { color: var(--faint); flex: none; }
#model-btn-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.model-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--faint); }
.model-dot.on { background: var(--teal); box-shadow: 0 0 8px rgba(48, 209, 88, 0.8); }

.model-menu {
  position: absolute; top: calc(100% + 8px); left: 0; width: 480px; max-width: 74vw;
  background: rgba(44, 44, 46, 0.82); backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  padding: 10px; z-index: 50; animation: pop 0.2s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-8px) scale(0.97); } }
.model-menu[hidden] { display: none; }
.model-menu input { width: 100%; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 9px; padding: 9px 13px; outline: none; font-size: 13.5px; margin-bottom: 8px; }
.model-menu input:focus { border-color: var(--accent); }
.model-list { max-height: 46vh; overflow-y: auto; }
.model-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 11px; border-radius: 9px; transition: background 0.1s; }
.model-row:hover { background: rgba(255, 255, 255, 0.06); }
.model-row.selected { background: var(--accent); }
.model-row .m-name { font-size: 13.5px; flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.model-row.selected .m-name, .model-row.selected .m-meta, .model-row.selected .m-meta * { color: #fff !important; }
.m-vision { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--purple); border: 1px solid rgba(191, 90, 242, 0.45); border-radius: 5px; padding: 1px 5px; flex: none; }
.model-row .m-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--faint); flex: none; display: flex; gap: 10px; }
.model-row .m-free { color: var(--teal); }
.model-empty { color: var(--faint); padding: 14px; font-size: 13px; text-align: center; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.pill-toggle { display: flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.02em; color: var(--faint); background: var(--bg-2); border-radius: 980px; padding: 6px 13px; transition: color 0.15s, background 0.15s; }
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); transition: background 0.15s, box-shadow 0.15s; }
.pill-toggle.on { color: var(--teal); background: rgba(48, 209, 88, 0.14); }
.pill-toggle.on .pill-dot { background: var(--teal); box-shadow: 0 0 7px rgba(48, 209, 88, 0.9); }

.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: var(--dim); transition: background 0.12s, color 0.12s; }
.icon-btn:hover { background: var(--bg-2); color: var(--text); }

/* ═══════ chat area ═══════ */
#chat-scroll { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: smooth; }
#messages { max-width: 800px; margin: 0 auto; padding: 30px 24px 12px; }
#messages[hidden], #empty-state[hidden], #recall-strip[hidden] { display: none; }

.msg { margin-bottom: 26px; animation: rise 0.32s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* iMessage-style sent bubble */
.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.msg-user .bubble {
  max-width: 80%;
  background: linear-gradient(180deg, #0a84ff, #0a6fe0);
  color: #fff; border-radius: 20px 20px 6px 20px;
  padding: 10px 16px; white-space: pre-wrap; word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.msg-assistant .msg-head { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.msg-assistant .role-chip { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(180deg, #0a84ff, #0a6fe0); color: #fff; }
.msg-assistant .model-chip { font-family: var(--font-mono); font-size: 11px; color: var(--faint); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.msg-assistant .msg-body { color: var(--text); }
.msg-error .msg-body { color: #ff9d97; font-size: 13.5px; background: rgba(255, 69, 58, 0.12); border: 1px solid rgba(255, 69, 58, 0.3); padding: 11px 15px; border-radius: var(--r); }

.msg-stats { margin-top: 10px; font-family: var(--font-mono); font-size: 10.5px; color: var(--faint); display: flex; gap: 15px; }
.caret { display: inline-block; width: 8px; height: 16px; background: var(--accent); border-radius: 2px; vertical-align: -3px; margin-left: 2px; animation: blink 0.9s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* attachments in messages */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 9px; justify-content: flex-end; }
.msg-user .msg-attachments { max-width: 80%; margin-left: auto; }
.att-image { border-radius: var(--r-lg); border: 1px solid var(--line); max-width: 240px; max-height: 240px; object-fit: cover; cursor: pointer; transition: transform 0.15s var(--ease); display: block; }
.att-image:hover { transform: scale(1.02); }
.att-file { display: flex; align-items: center; gap: 10px; padding: 9px 13px; background: var(--bg-2); border-radius: var(--r); font-size: 12.5px; max-width: 260px; }
.att-file .att-ico { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 8px; background: var(--accent); color: #fff; }
.att-file .att-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.att-file .att-size { color: var(--faint); font-family: var(--font-mono); font-size: 10px; }

/* markdown */
.msg-body > *:first-child { margin-top: 0; }
.msg-body > *:last-child { margin-bottom: 0; }
.msg-body h1, .msg-body h2, .msg-body h3 { font-family: var(--font-display); line-height: 1.25; letter-spacing: -0.02em; margin: 1.2em 0 0.5em; }
.msg-body h1 { font-size: 1.45em; } .msg-body h2 { font-size: 1.25em; } .msg-body h3 { font-size: 1.1em; }
.msg-body p { margin: 0.65em 0; }
.msg-body a { color: var(--accent); text-decoration: none; }
.msg-body a:hover { text-decoration: underline; }
.msg-body ul, .msg-body ol { padding-left: 1.4em; margin: 0.6em 0; }
.msg-body li { margin: 0.25em 0; }
.msg-body blockquote { margin: 0.8em 0; padding: 4px 16px; border-left: 3px solid var(--accent); color: var(--dim); }
.msg-body code { font-family: var(--font-mono); font-size: 0.85em; background: var(--bg-2); border-radius: 6px; padding: 0.14em 0.4em; }
.msg-body pre { position: relative; background: #161618 !important; border: 1px solid var(--line); border-radius: 14px; padding: 15px 16px; overflow-x: auto; margin: 0.9em 0; }
.msg-body pre code { background: none; border: 0; padding: 0; font-size: 12.8px; line-height: 1.6; display: block; }
.msg-body pre .hljs { background: transparent; padding: 0; }
.msg-body table { border-collapse: collapse; margin: 0.8em 0; font-size: 0.92em; display: block; overflow-x: auto; }
.msg-body th, .msg-body td { border: 1px solid var(--line); padding: 6px 12px; }
.msg-body th { background: var(--bg-2); font-weight: 600; }
.msg-body hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.copy-code { position: absolute; top: 9px; right: 9px; font-family: var(--font-mono); font-size: 10px; color: var(--faint); background: var(--bg-3); border-radius: 6px; padding: 3px 9px; opacity: 0; transition: opacity 0.15s, color 0.15s; }
.msg-body pre:hover .copy-code { opacity: 1; }
.copy-code:hover { color: var(--accent); }

.thinking { margin: 0 0 12px; border: 1px solid var(--line); border-left: 3px solid var(--violet); border-radius: var(--r); background: var(--bg-1); overflow: hidden; }
.thinking summary { cursor: pointer; padding: 8px 14px; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); user-select: none; list-style: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before { content: "▸ "; }
.thinking[open] summary::before { content: "▾ "; }
.thinking-body { padding: 4px 16px 13px; font-size: 13px; line-height: 1.6; color: var(--dim); white-space: pre-wrap; word-wrap: break-word; max-height: 280px; overflow-y: auto; }

/* ═══════ empty state ═══════ */
#empty-state { height: 100%; display: grid; place-items: center; padding: 24px; }
.empty-inner { text-align: center; max-width: 640px; }
.empty-glyph { color: var(--accent); margin-bottom: 20px; animation: rise 0.6s var(--ease) both; filter: drop-shadow(0 0 30px var(--accent-glow)); }
.empty-title { font-family: var(--font-display); font-size: clamp(40px, 6vw, 60px); font-weight: 700; letter-spacing: -0.035em; margin: 0 0 12px; background: linear-gradient(120deg, #fff 30%, var(--accent) 95%); -webkit-background-clip: text; background-clip: text; color: transparent; animation: rise 0.6s 0.08s var(--ease) both; }
.empty-sub { color: var(--dim); margin: 0 0 32px; animation: rise 0.6s 0.16s var(--ease) both; }
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; }
.suggestion { text-align: left; background: var(--bg-1); border: 1px solid var(--line-soft); border-radius: var(--r-lg); padding: 15px 16px; display: flex; flex-direction: column; gap: 5px; transition: background 0.18s var(--ease), transform 0.18s var(--ease); animation: rise 0.6s var(--ease) both; }
.suggestion:nth-child(1) { animation-delay: 0.24s; } .suggestion:nth-child(2) { animation-delay: 0.3s; } .suggestion:nth-child(3) { animation-delay: 0.36s; }
.suggestion .s-title { font-weight: 600; font-size: 13.5px; }
.suggestion .s-sub { font-size: 12px; color: var(--faint); }
.suggestion:hover { background: var(--bg-2); transform: translateY(-3px); }

/* ═══════ composer ═══════ */
#composer-wrap { padding: 6px 24px 16px; max-width: 848px; margin: 0 auto; width: 100%; }
#recall-strip { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 8px; }
.recall-chip { font-size: 11.5px; color: var(--teal); background: rgba(48, 209, 88, 0.1); border-radius: 980px; padding: 3px 12px; max-width: 340px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; animation: rise 0.25s ease both; }
.recall-label { font-family: var(--font-mono); font-size: 10px; color: var(--faint); align-self: center; letter-spacing: 0.06em; }

#composer { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 8px 8px 8px 6px; transition: border-color 0.2s, box-shadow 0.2s; }
#composer:focus-within { border-color: rgba(10, 132, 255, 0.6); box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.12); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
#input { flex: 1; resize: none; background: none; border: 0; outline: none; font-size: 15px; line-height: 1.45; max-height: 220px; padding: 9px 2px; }
#input::placeholder { color: var(--faint); }

.attach-btn, .send-btn, .stop-btn { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; transition: background 0.15s, transform 0.1s, color 0.15s; }
.attach-btn { color: var(--dim); }
.attach-btn:hover { background: var(--bg-3); color: var(--accent); }
.attach-btn.busy { color: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.send-btn { background: var(--accent); color: #fff; }
.send-btn:hover { background: var(--accent-hi); }
.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.35; cursor: default; }
.stop-btn { background: var(--bg-3); color: var(--danger); }
.stop-btn:hover { background: var(--bg-hover); }
.stop-btn[hidden], .send-btn[hidden] { display: none; }

#attach-tray { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 6px 10px; }
#attach-tray[hidden] { display: none; }
.tray-item { position: relative; display: flex; align-items: center; gap: 8px; background: var(--bg-3); border-radius: var(--r); padding: 7px 10px; font-size: 12px; max-width: 220px; animation: pop 0.2s var(--ease) both; }
.tray-item.thumb { padding: 0; overflow: hidden; width: 58px; height: 58px; border-radius: 14px; }
.tray-item.thumb img { width: 100%; height: 100%; object-fit: cover; }
.tray-ico { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 7px; background: var(--accent); color: #fff; }
.tray-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tray-x { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%; background: var(--bg-hover); color: var(--text); display: grid; place-items: center; font-size: 11px; opacity: 0; transition: opacity 0.12s, background 0.12s; }
.tray-item:hover .tray-x { opacity: 1; }
.tray-x:hover { background: var(--danger); color: #fff; }

.composer-hint { text-align: center; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.04em; color: var(--faint); padding-top: 9px; }

#drop-overlay { position: absolute; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(10px); animation: fade 0.15s ease; }
#drop-overlay[hidden] { display: none; }
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--accent); font-family: var(--font-display); font-size: 20px; font-weight: 600; padding: 50px 70px; border: 2px dashed rgba(10, 132, 255, 0.55); border-radius: var(--r-xl); background: rgba(10, 132, 255, 0.06); }

/* ═══════ drawer ═══════ */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 400px; max-width: 92vw; background: rgba(28, 28, 30, 0.9); backdrop-filter: blur(30px) saturate(180%); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); padding: 22px 24px; z-index: 90; overflow-y: auto; animation: slide-in 0.3s var(--ease); }
@keyframes slide-in { from { transform: translateX(44px); opacity: 0; } }
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.drawer-head h2 { font-family: var(--font-display); font-size: 20px; letter-spacing: -0.02em; margin: 0; }
.drawer-actions { display: flex; gap: 10px; margin-top: 22px; }

/* ═══════ forms ═══════ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 17px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--dim); }
.field > span em { font-style: normal; color: var(--faint); font-weight: 400; font-family: var(--font-mono); font-size: 11px; }
.field input[type="text"], .field input[type="password"], .field input[type="number"], .field textarea { background: var(--bg-2); border: 1px solid transparent; border-radius: 10px; padding: 10px 13px; outline: none; font-size: 13.5px; transition: border-color 0.15s, background 0.15s; }
.field input:focus, .field textarea:focus { border-color: var(--accent); background: var(--bg-1); }
.field textarea { resize: vertical; line-height: 1.5; }
.field input[type="range"] { accent-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-note { font-size: 12px; color: var(--faint); margin: -8px 0 16px; line-height: 1.5; }
.mono { font-family: var(--font-mono) !important; font-size: 12.5px !important; }
.check-field { display: flex; align-items: center; gap: 10px; font-size: 13.5px; margin-bottom: 17px; cursor: pointer; }
.check-field input { accent-color: var(--accent); width: 16px; height: 16px; }

.btn-primary { background: var(--accent); color: #fff; font-weight: 600; font-size: 13.5px; border-radius: 980px; padding: 10px 20px; transition: background 0.15s; }
.btn-primary:hover { background: var(--accent-hi); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-danger { color: var(--danger); background: rgba(255, 69, 58, 0.12); border-radius: 980px; padding: 10px 18px; font-size: 13.5px; transition: background 0.15s; }
.btn-danger:hover { background: rgba(255, 69, 58, 0.2); }
.ghost-btn { color: var(--accent); background: var(--bg-2); border-radius: 980px; padding: 7px 15px; font-size: 12.5px; font-weight: 500; transition: background 0.15s; }
.ghost-btn:hover { background: var(--bg-3); }

/* ═══════ modals ═══════ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(10px); display: grid; place-items: center; z-index: 100; animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; } }
.modal-backdrop[hidden] { display: none; }
.modal { width: 570px; max-width: 94vw; max-height: 88vh; overflow-y: auto; background: rgba(44, 44, 46, 0.85); backdrop-filter: blur(30px) saturate(180%); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 24px 28px; box-shadow: var(--shadow-lg); animation: modal-in 0.3s var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: scale(0.96); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { font-family: var(--font-display); font-size: 22px; letter-spacing: -0.02em; margin: 0; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 6px; padding-top: 18px; border-top: 1px solid var(--line); }
.status-msg { font-size: 12.5px; color: var(--teal); }
.tabs { display: flex; gap: 4px; background: var(--bg-2); border-radius: 10px; padding: 3px; margin-bottom: 22px; }
.tab { flex: 1; padding: 7px 16px; font-size: 13px; font-weight: 600; color: var(--dim); border-radius: 8px; transition: color 0.15s, background 0.15s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--bg-hover); }
.tab-page { display: none; }
.tab-page.active { display: block; }

/* ═══════════════════════════════════════════════════════════
   MEMORY GRAPH PAGE
   ═══════════════════════════════════════════════════════════ */
#memory-page { position: fixed; inset: 0; z-index: 120; display: flex; flex-direction: column; background: radial-gradient(1200px 700px at 50% -10%, #101012, #000 72%); animation: mem-in 0.35s var(--ease); }
@keyframes mem-in { from { opacity: 0; transform: scale(0.99); } }
.mem-page-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 24px; border-bottom: 1px solid var(--line-soft); flex: none; }
.mem-page-title { display: flex; align-items: center; gap: 12px; }
.mem-page-title .brand-mark { color: var(--teal); background: rgba(48, 209, 88, 0.14); border-color: rgba(48, 209, 88, 0.24); }
.mem-page-title h1 { font-family: var(--font-display); font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.mem-stats { font-family: var(--font-mono); font-size: 11px; color: var(--dim); background: var(--bg-2); border-radius: 20px; padding: 3px 11px; }
.mem-page-tools { display: flex; align-items: center; gap: 10px; }
.mem-search-wrap { display: flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid transparent; border-radius: 980px; padding: 8px 14px; color: var(--faint); width: 280px; transition: border-color 0.15s, background 0.15s; }
.mem-search-wrap:focus-within { border-color: var(--teal); background: var(--bg-1); }
.mem-search-wrap input { flex: 1; background: none; border: 0; outline: none; font-size: 13.5px; color: var(--text); }
.mem-search-wrap input::placeholder { color: var(--faint); }

.mem-page-body { flex: 1; position: relative; min-height: 0; overflow: hidden; }
#mem-graph-stage { position: absolute; inset: 0; }
#mem-canvas { width: 100%; height: 100%; display: block; cursor: grab; }
#mem-canvas:active { cursor: grabbing; }
.mem-graph-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--faint); }
.mem-graph-empty[hidden] { display: none; }
.mem-graph-empty p { font-family: var(--font-display); font-size: 22px; color: var(--dim); margin: 0; }
.mem-graph-empty span { font-size: 13px; }
.mem-legend { position: absolute; left: 22px; bottom: 20px; display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: var(--dim); pointer-events: none; }
.mem-legend span { display: flex; align-items: center; gap: 8px; }
.mem-legend i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.mem-legend .dot-auto { background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.mem-legend .dot-manual { background: var(--teal); box-shadow: 0 0 8px rgba(48, 209, 88, 0.7); }
.mem-legend .mem-hint { font-family: var(--font-mono); font-size: 10px; color: var(--faint); margin-top: 4px; }

.mem-list-view { position: absolute; inset: 0; overflow-y: auto; padding: 24px; max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.mem-list-view[hidden] { display: none; }
.memory-item { display: flex; align-items: flex-start; gap: 12px; background: var(--bg-1); border-left: 3px solid var(--teal); border-radius: var(--r); padding: 12px 16px; font-size: 13.5px; animation: rise 0.25s ease both; }
.memory-item.src-manual { border-left-color: var(--accent); }
.memory-item .mem-text { flex: 1; }
.memory-item .mem-body { display: block; }
.memory-item mark { background: rgba(10, 132, 255, 0.32); color: #fff; border-radius: 4px; padding: 0 2px; }
.memory-item .mem-meta { font-family: var(--font-mono); font-size: 10px; color: var(--faint); display: block; margin-top: 5px; }
.memory-item .mem-del { color: var(--faint); font-size: 13px; padding: 2px 7px; border-radius: 6px; }
.memory-item .mem-del:hover { color: var(--danger); }
.memory-none { color: var(--faint); text-align: center; padding: 40px 0; font-size: 14px; }

.mem-detail { position: absolute; top: 20px; right: 20px; width: 320px; max-width: calc(100% - 40px); background: rgba(44, 44, 46, 0.85); backdrop-filter: blur(30px) saturate(180%); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 20px; z-index: 5; animation: slide-in 0.25s var(--ease); }
.mem-detail[hidden] { display: none; }
.mem-detail-close { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; }
.mem-detail-source { font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--teal); margin-bottom: 10px; }
.mem-detail-source.src-manual { color: var(--accent); }
.mem-detail-text { font-size: 14.5px; line-height: 1.5; margin: 0 0 14px; }
.mem-detail-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--faint); margin-bottom: 14px; }
.mem-detail-links { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; max-height: 200px; overflow-y: auto; }
.mem-detail-links:empty { display: none; }
.mem-link-item { font-size: 12px; color: var(--dim); background: var(--bg-2); border-radius: 8px; padding: 7px 10px; cursor: pointer; transition: background 0.12s, color 0.12s; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mem-link-item:hover { background: var(--bg-3); color: var(--text); }
.mem-link-item .lw { font-family: var(--font-mono); font-size: 10px; color: var(--teal); margin-right: 6px; }
.mem-page-foot { flex: none; display: flex; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line-soft); max-width: 900px; margin: 0 auto; width: 100%; }
.mem-page-foot input { flex: 1; background: var(--bg-2); border: 1px solid transparent; border-radius: 980px; padding: 11px 17px; outline: none; font-size: 13.5px; }
.mem-page-foot input:focus { border-color: var(--teal); background: var(--bg-1); }

/* ═══════ login ═══════ */
#login-screen { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: radial-gradient(900px 600px at 50% 30%, #101012, #000); }
.login-card { width: 372px; max-width: 92vw; text-align: center; background: rgba(44, 44, 46, 0.7); backdrop-filter: blur(30px) saturate(180%); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 42px 36px; box-shadow: var(--shadow-lg); animation: modal-in 0.4s var(--ease); }
.login-mark { color: var(--accent); margin-bottom: 16px; filter: drop-shadow(0 0 22px var(--accent-glow)); }
.login-card h1 { font-family: var(--font-display); font-size: 28px; letter-spacing: -0.03em; margin: 0 0 6px; }
.login-card p { color: var(--faint); font-size: 13.5px; margin: 0 0 24px; }
.login-card input { width: 100%; background: var(--bg-2); border: 1px solid transparent; border-radius: 11px; padding: 12px 15px; outline: none; font-size: 14px; margin-bottom: 12px; text-align: center; }
.login-card input:focus { border-color: var(--accent); }
.login-card button { width: 100%; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; border-radius: 980px; padding: 12px; transition: background 0.15s; }
.login-card button:hover { background: var(--accent-hi); }
.login-error { color: var(--danger); font-size: 12.5px; min-height: 18px; padding-top: 8px; }

/* ═══════ toast ═══════ */
#toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); background: rgba(44, 44, 46, 0.9); backdrop-filter: blur(20px) saturate(180%); border: 1px solid var(--line); border-radius: 980px; padding: 11px 20px; font-size: 13.5px; box-shadow: var(--shadow); z-index: 300; animation: toast-in 0.3s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }
#toast[hidden] { display: none; }
#toast.error { color: #ff9d97; }

/* lightbox */
#lightbox { position: fixed; inset: 0; z-index: 400; background: rgba(0, 0, 0, 0.9); backdrop-filter: blur(10px); display: grid; place-items: center; animation: fade 0.15s ease; cursor: zoom-out; }
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 92vw; max-height: 92vh; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); }

/* ═══════ responsive ═══════ */
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { display: none; }
  .suggestions { grid-template-columns: 1fr; }
  .mem-search-wrap { width: 160px; }
  .mem-detail { width: calc(100% - 40px); }
}
