:root {
  --bg: #0b0d12;
  --bg2: #11141b;
  --panel: #161a22;
  --text: #d7dae0;
  --bright: #ffffff;
  --muted: #8b93a3;
  --accent: #5eb0ff;
  --accent-dark: #2f7fd1;
  --accent-soft: rgba(94, 176, 255, .12);
  --border: #23262e;
  --user: #1a5a9e;
  --ok: #4ade80;
  --err: #f87171;
  --shadow: 0 16px 40px rgba(0, 0, 0, .35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 58px;
  --composer-h: 84px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  background:
    radial-gradient(1100px 420px at 50% -120px, var(--accent-soft), transparent),
    var(--bg);
}

a { color: var(--accent); text-decoration: none; }

.input, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  outline: none;
}
.input:focus, .textarea:focus { border-color: var(--accent); }

.label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.field { margin-bottom: 1rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fff;
}
.btn-icon {
  background: transparent;
  color: var(--text);
  width: 44px;
  padding: 0;
  font-size: 1.15rem;
}
.btn-send {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fff;
  min-width: 76px;
  flex-shrink: 0;
}
.btn-send:disabled { opacity: .4; cursor: not-allowed; }

.alert.err {
  background: rgba(248, 113, 113, .12);
  border: 1px solid rgba(248, 113, 113, .35);
  color: #fecaca;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 1rem;
}

.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 1.5rem; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fff; font-weight: 700;
}
.brand-name { font-weight: 700; color: var(--bright); }
.brand-tag { color: var(--muted); font-size: .85rem; }
.login-note { color: var(--muted); font-size: .8rem; line-height: 1.45; margin: 14px 0 0; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--composer-h);
}

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  padding-top: var(--safe-top);
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 18, .85);
  backdrop-filter: blur(10px);
}
.header-center { flex: 1; text-align: center; min-width: 0; }
.header-title { font-weight: 700; color: var(--bright); }
.header-sub { font-size: .75rem; color: var(--muted); }
.header-actions { display: flex; }

.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 20;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(360px, 92vw);
  background: var(--bg2); border-right: 1px solid var(--border);
  transform: translateX(-105%); transition: transform .18s ease; z-index: 30;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { padding: 18px 16px 8px; }
.drawer-title { font-weight: 700; color: var(--bright); }
.drawer-hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.drawer-search { margin: 8px 12px 12px; width: calc(100% - 24px); }
.drawer-list { flex: 1; overflow: auto; padding: 0 8px 12px; }
.drawer-empty { color: var(--muted); padding: 20px 12px; font-size: .9rem; }
.drawer-foot {
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + var(--safe-bottom));
  font-size: .8rem; color: var(--muted);
}

.session-item {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0; color: inherit;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
}
.session-item:hover, .session-item.active { background: var(--accent-soft); }
.session-item-title { font-weight: 600; color: var(--bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item-meta { font-size: .75rem; color: var(--muted); margin-top: 2px; }

.messages-wrap { overflow: hidden; display: flex; flex-direction: column; }
.status-bar {
  min-height: 0;
  font-size: .8rem;
  color: var(--accent);
  padding: 0 20px;
}
.status-bar:not(:empty) { padding: 8px 20px 0; }
.status-bar.error { color: var(--err); }
.messages {
  flex: 1;
  overflow: auto;
  padding: 16px 18px 12px;
}

.welcome {
  max-width: 720px;
  margin: 8vh auto 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}
.welcome-kicker { color: var(--accent); font-size: .8rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.welcome h2 { margin: 8px 0 10px; color: var(--bright); font-size: 1.45rem; }
.welcome p { margin: 0 0 16px; color: var(--muted); line-height: 1.5; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #2a3b50;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.chips button:hover { border-color: var(--accent); }

.msg {
  max-width: 820px;
  margin: 0 auto 14px;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user {
  background: linear-gradient(135deg, #1a5a9e, var(--accent-dark));
  color: #fff;
  margin-left: auto;
  white-space: pre-wrap;
}
.msg.assistant {
  background: var(--panel);
  border: 1px solid var(--border);
  white-space: normal;
}
.msg.assistant pre, .msg.assistant code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .85em;
}
.msg.assistant pre {
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
}
.msg.assistant p { margin: 0 0 .75em; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 .75em; padding-left: 1.2em; }
.msg.assistant .ask {
  color: #facc15;
  font-weight: 700;
}
.msg.typing { color: var(--muted); font-style: italic; }
.msg-meta { font-size: .72rem; color: var(--muted); margin-top: 8px; }

.msg.assistant {
  padding: 0;
  overflow: hidden;
}
.msg.assistant .answer {
  padding: 12px 14px;
}
.think {
  border-bottom: 1px solid var(--border);
  background: #10141c;
}
.think-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 0;
  color: var(--accent);
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
}
.think-toggle .label { flex: 1; }
.think-toggle .secs { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid #2a3b50;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.think:not(.working) .spinner { display: none; }
.think-body {
  display: none;
  margin: 0;
  padding: 0 14px 12px;
  color: #9aa8b5;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 240px;
  overflow: auto;
}
.think.open .think-body { display: block; }
.tool-line {
  margin: 0 14px 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .75rem;
  overflow-wrap: anywhere;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-bar.live {
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-bar.live::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(94, 176, 255, .7);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(94, 176, 255, .55); }
  70% { box-shadow: 0 0 0 8px rgba(94, 176, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(94, 176, 255, 0); }
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg2);
}
.composer .textarea {
  min-height: 44px;
  max-height: 140px;
  resize: none;
}

.prompts {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(340px, 92vw);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  transform: translateX(105%);
  transition: transform .18s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.prompts.open { transform: none; }
.prompts-head { padding: 18px 16px 10px; }
.prompts-kicker {
  color: var(--accent);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.prompts-title { font-weight: 700; color: var(--bright); margin-top: 4px; }
.prompts-group { padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.prompts-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 4px 4px 2px;
}
.prompts button {
  text-align: left;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  font-size: .85rem;
  line-height: 1.35;
  cursor: pointer;
}
.prompts button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--bright);
}
.prompts button.pulse-gold {
  border-color: #eab308;
  box-shadow: 0 0 0 1px rgba(234, 179, 8, .35), 0 0 12px rgba(250, 204, 21, .25);
  animation: goldPulse 2.8s ease-in-out infinite;
}
.prompts button.pulse-gold:hover {
  border-color: #facc15;
  animation: none;
  box-shadow: 0 0 0 1px rgba(250, 204, 21, .7), 0 0 14px rgba(250, 204, 21, .4);
}
@keyframes goldPulse {
  0%, 100% {
    border-color: rgba(234, 179, 8, .28);
    box-shadow: 0 0 0 1px rgba(234, 179, 8, .12), 0 0 6px rgba(250, 204, 21, 0);
  }
  50% {
    border-color: #facc15;
    box-shadow: 0 0 0 1px rgba(250, 204, 21, .8), 0 0 16px rgba(250, 204, 21, .45);
  }
}

@media (min-width: 980px) {
  .drawer { transform: none; position: static; width: auto; }
  .drawer-backdrop { display: none; }
  .app {
    grid-template-columns: 280px minmax(0, 1fr) 300px;
    grid-template-rows: var(--header-h) 1fr var(--composer-h);
  }
  .header { grid-column: 1 / -1; }
  .drawer { grid-column: 1; grid-row: 2 / -1; }
  .messages-wrap { grid-column: 2; grid-row: 2; }
  .composer { grid-column: 2; grid-row: 3; }
  .prompts {
    position: static;
    transform: none;
    width: auto;
    grid-column: 3;
    grid-row: 2 / -1;
  }
  #menuBtn, #promptsBtn { visibility: hidden; }
}
