:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #12161c;
  --panel-2: #171c24;
  --border: #242b36;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #7dd3fc;
  --green: #4ade80;
  --amber: #f5b942;
  --red: #f87171;
  --blue: #1d4ed8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.4em; }

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 9px 13px;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }

input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #0f1319;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

/* Login */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(92vw, 380px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px 22px;
}
.login-card h1 { margin: 0 0 4px; font-size: 30px; letter-spacing: -1px; }
.login-card form { display: grid; gap: 10px; margin-top: 18px; }
.login-card button { background: var(--accent); color: #071018; border-color: transparent; font-weight: 650; }

/* App shell */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 920px;
  margin: 0 auto;
  position: relative;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: rgba(11, 13, 16, .88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar .title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar .title strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon {
  width: 38px;
  height: 38px;
  padding: 0;
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
  background: transparent;
}
.status { color: var(--muted); font-size: 11px; }
.status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  margin-right: 6px;
  vertical-align: middle;
}
.status.online::before { background: var(--green); }
.status.running::before { background: var(--amber); animation: pulse 1.1s infinite ease-in-out; }
.status.offline::before { background: var(--red); }
@keyframes pulse { 50% { opacity: .25; } }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 128px;
  scrollbar-width: thin;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 56px 18px;
  font-size: 14px;
}

/* Messages */
.msg {
  max-width: 90%;
  margin: 0 0 11px;
  padding: 10px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user {
  margin-left: auto;
  background: var(--blue);
  border-bottom-right-radius: 6px;
}
.msg.assistant {
  margin-right: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg.streaming::after {
  content: "▍";
  color: var(--accent);
  animation: blink .9s infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.tool-chip {
  display: inline-block;
  margin: 6px 6px 0 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: #0d2533;
  border: 1px solid #174257;
  color: var(--accent);
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Tool cards */
.tool {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 8px 0;
  font-size: 13px;
}
.tool summary {
  padding: 9px 12px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "▸ "; color: var(--accent); }
.tool[open] summary::before { content: "▾ "; }
.tool pre {
  margin: 0;
  padding: 0 12px 12px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #b8c4d4;
}

/* Approval */
.approval {
  border: 1px solid rgba(245, 185, 66, .65);
  background: rgba(245, 185, 66, .07);
  border-radius: 14px;
  padding: 12px;
  margin: 12px 0;
}
.approval-title { font-weight: 650; }
.approval-detail { color: var(--muted); font-size: 12px; margin-top: 3px; overflow-wrap: anywhere; }
.approval pre {
  background: #0f1319;
  border-radius: 8px;
  padding: 8px;
  max-height: 180px;
  overflow: auto;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #b8c4d4;
}
.approval .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.approval .allow { border-color: var(--green); color: var(--green); }
.approval .always { border-color: var(--accent); color: var(--accent); }
.approval .deny { border-color: var(--red); color: var(--red); }
.approval.resolved { opacity: .65; }
.approval-result { margin-top: 8px; font-size: 12px; color: var(--muted); }

/* Composer */
.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, rgba(11, 13, 16, 0));
}
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  border-radius: 15px;
  padding: 11px 13px;
  line-height: 1.4;
}
.send {
  height: 44px;
  padding: 0 17px;
  background: var(--accent);
  color: #071018;
  border-color: transparent;
  font-weight: 650;
}
.cancel {
  height: 44px;
  color: var(--red);
  border-color: rgba(248, 113, 113, .45);
  background: transparent;
}

/* Drawer */
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  width: min(86vw, 360px);
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-right: 1px solid var(--border);
  transform: translateX(-105%);
  transition: transform .2s ease;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.session-list { display: grid; gap: 8px; }
.session-item {
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border-color: transparent;
  padding: 10px 11px;
}
.session-item.active { border-color: var(--accent); }
.session-title { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.session-title span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot.running { background: var(--amber); animation: pulse 1.1s infinite; }
.session-meta { color: var(--muted); font-size: 11px; margin-top: 3px; overflow-wrap: anywhere; }
.new-session { margin-top: 22px; display: grid; gap: 8px; }
.new-session h3 { margin: 0 0 2px; font-size: 13px; color: var(--muted); font-weight: 600; }
.new-session button { background: var(--accent); color: #071018; border-color: transparent; font-weight: 650; }
.logout { width: 100%; margin-top: 24px; background: transparent; color: var(--muted); }
.overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(2px);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(90vw, 520px);
  padding: 9px 13px;
  border-radius: 10px;
  background: #2a1114;
  border: 1px solid rgba(248, 113, 113, .5);
  color: #fecaca;
  font-size: 13px;
}

@media (min-width: 720px) {
  .messages { padding-left: 22px; padding-right: 22px; }
  .msg { max-width: 78%; }
}
