/* My AI — dark, mobile-first chat UI. No frameworks, no tracking. */
:root {
  --bg: #0a0e18;
  --bg-soft: #101623;
  --surface: #161e2e;
  --surface-2: #1c2639;
  --border: #26314a;
  --text: #eef2f8;
  --muted: #93a1b8;
  --accent: #7df0ff;
  --accent-dim: #3fa9c4;
  --user-bubble: #1d4e63;
  --danger: #ff6b6b;
  --radius: 18px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
#app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- Header ---------- */
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
#titleWrap { flex: 1; min-width: 0; }
#appTitle { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
#brainLine { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot-idle { background: #55627e; }
.dot-busy { background: var(--accent); animation: pulse 1s infinite; }
.dot-ok { background: #4ade80; }
.dot-err { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.icon-btn {
  background: transparent; border: none; color: var(--text);
  font-size: 20px; width: 40px; height: 40px; border-radius: 12px;
  cursor: pointer; flex: 0 0 auto; line-height: 1;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.listening { color: var(--danger); animation: pulse 1s infinite; }

/* ---------- Drawer ---------- */
#drawerScrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40;
}
#drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(320px, 85vw);
  background: var(--bg-soft); border-right: 1px solid var(--border);
  transform: translateX(-105%); transition: transform .22s ease;
  z-index: 50; overflow-y: auto; padding: calc(12px + env(safe-area-inset-top)) 14px calc(20px + env(safe-area-inset-bottom));
}
#drawer.open { transform: translateX(0); }
#drawerScrim.show { opacity: 1; pointer-events: auto; }
.drawer-section { margin-bottom: 22px; }
.drawer-heading { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 8px; }
.drawer-btn {
  width: 100%; padding: 10px 12px; border-radius: 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); font-size: 15px; cursor: pointer; text-align: left;
}
.drawer-btn:active { background: var(--surface-2); }
.drawer-btn.danger { color: var(--danger); border-color: #4a2b2b; }
.drawer-hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.45; }
#memoryInput, #providerSelect {
  width: 100%; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 10px;
  font-size: 14.5px; font-family: inherit; outline: none;
}
#memoryInput:focus, #providerSelect:focus { border-color: var(--accent-dim); }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14.5px; padding: 7px 0; cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent-dim); }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item:active, .chat-item.active { background: var(--surface-2); }
.chat-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chat-item .del { color: var(--muted); background: none; border: none; font-size: 15px; cursor: pointer; padding: 2px 6px; }
.empty-list { font-size: 13.5px; color: var(--muted); padding: 4px 2px; }

/* ---------- Chat ---------- */
#chat { flex: 1; overflow-y: auto; padding: 14px 12px; scroll-behavior: smooth; }
#messages { display: flex; flex-direction: column; gap: 12px; max-width: 760px; margin: 0 auto; }
.msg { max-width: 88%; padding: 11px 14px; border-radius: var(--radius); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user-bubble); border-bottom-right-radius: 6px; }
.msg.ai { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 6px; }
.msg.ai.streaming::after { content: "▍"; color: var(--accent); animation: pulse 1s infinite; }
.msg .meta { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.msg .meta .censored-tag { color: #f5c542; }
.msg pre {
  background: #0b101c; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; overflow-x: auto; font-size: 13.5px; margin: 8px 0; white-space: pre;
}
.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; background: #0b101c; padding: 1px 5px; border-radius: 6px; }
.msg pre code { background: none; padding: 0; }
.msg p { margin: 6px 0; }
.msg p:first-child { margin-top: 0; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 6px 0 6px 20px; }
.msg a { color: var(--accent); }
.msg .file-note { font-size: 13px; color: var(--muted); border-left: 3px solid var(--accent-dim); padding-left: 8px; margin-bottom: 6px; }
.msg.error { background: #3a1d1d; border: 1px solid #5a2b2b; }

/* ---------- Empty state ---------- */
#emptyState { max-width: 560px; margin: 8vh auto 0; text-align: center; padding: 0 16px; }
#emptyState.hidden { display: none; }
.empty-icon { font-size: 44px; margin-bottom: 10px; }
#emptyState h1 { font-size: 24px; margin-bottom: 8px; }
#emptyState p { color: var(--muted); font-size: 15px; margin-bottom: 18px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggestions button {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: 9px 14px; font-size: 14px; cursor: pointer;
}
.suggestions button:active { background: var(--surface-2); }

/* ---------- Composer ---------- */
#composer {
  flex: 0 0 auto; padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-soft); border-top: 1px solid var(--border);
}
.composer-row { display: flex; align-items: flex-end; gap: 6px; max-width: 760px; margin: 0 auto; }
#input {
  flex: 1; resize: none; max-height: 140px; min-height: 44px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 22px;
  padding: 11px 14px; font-size: 16px; font-family: inherit; outline: none; line-height: 1.4;
}
#input:focus { border-color: var(--accent-dim); }
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; flex: 0 0 auto;
  background: var(--accent-dim); color: #06121a; font-size: 18px; cursor: pointer;
}
.send-btn:disabled { opacity: .4; }
#composerHint { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
#fileChip {
  max-width: 760px; margin: 0 auto 8px; display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 10px; font-size: 13.5px;
}
#fileChip[hidden] { display: none; }
#fileChipName { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#fileChipRemove { background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer; }

/* ---------- Modal / toast ---------- */
#passwordModal {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#passwordModal[hidden] { display: none; }
.modal-card { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: 100%; max-width: 340px; }
.modal-card h2 { font-size: 18px; margin-bottom: 6px; }
.modal-card p { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.modal-card input {
  width: 100%; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px;
  font-size: 16px; margin-bottom: 12px; outline: none;
}
.primary-btn {
  width: 100%; padding: 12px; border: none; border-radius: 12px;
  background: var(--accent-dim); color: #06121a; font-size: 16px; font-weight: 600; cursor: pointer;
}
.error-text { color: var(--danger); font-size: 13.5px; margin-top: 8px; }
#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 90;
  max-width: 90vw; text-align: center;
}
#toast[hidden] { display: none; }

@media (min-width: 700px) {
  .msg { max-width: 75%; }
  #chat { padding: 20px; }
}
