:root {
  --bg: #101418;
  --card: #1a2128;
  --text: #e7edf2;
  --muted: #93a1ad;
  --line: #2c3640;
  --input: #0d1216;
  --accent: #7dcea0;
  --danger: #f0a8a0;
  --mine: #2b6a4a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f5f7;
    --card: #ffffff;
    --text: #16202a;
    --muted: #5c6b78;
    --line: #d6dee5;
    --input: #eef2f5;
    --accent: #2f8f5b;
    --danger: #c23b3b;
    --mine: #cdebd8;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; }

.screen { height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login { align-items: center; justify-content: center; padding: 1.5rem; }
.login-card {
  width: min(100%, 22rem);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.brand { font-size: 1.4rem; font-weight: 700; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 0; }
.field {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--text);
  font-size: 1rem;
}
.field:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }
.error { color: var(--danger); font-size: 0.88rem; margin: 0; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--input);
  color: var(--text);
}
.btn.primary { background: var(--accent); color: #06210f; }

/* ---------- chat ---------- */
.chat { padding-top: var(--safe-top); }
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 80%, transparent);
  backdrop-filter: blur(10px);
}
.chat-title { display: flex; align-items: center; gap: 0.5rem; font-weight: 650; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 transparent;
}
.dot.busy { background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.2rem; height: 2.2rem;
  border-radius: 10px; border: 1px solid var(--line);
  background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  -webkit-overflow-scrolling: touch;
}

.msg { max-width: 86%; border-radius: 14px; padding: 0.55rem 0.75rem; font-size: 0.95rem; word-wrap: break-word; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--mine); color: var(--text); border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.thinking, .msg.tool { align-self: flex-start; background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 0.85rem; padding: 0.4rem 0.65rem; }
.msg.status { align-self: center; background: transparent; color: var(--muted); font-size: 0.8rem; }
.msg.error { align-self: flex-start; background: color-mix(in srgb, var(--danger) 16%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.msg.tool details { margin: 0; }
.msg.tool summary { cursor: pointer; }

.msg code { background: color-mix(in srgb, var(--input) 80%, transparent); padding: 0.05rem 0.3rem; border-radius: 5px; font-size: 0.85em; }

/* ---------- composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.6rem 0.7rem calc(0.6rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 85%, transparent);
  backdrop-filter: blur(10px);
}
.draft {
  flex: 1;
  resize: none;
  max-height: 9rem;
  min-height: 2.6rem;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--text);
  font: inherit;
}
.draft:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.send {
  width: 2.7rem; height: 2.7rem; flex: none;
  border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #06210f;
  display: inline-flex; align-items: center; justify-content: center;
}
.send svg { width: 20px; height: 20px; }
.send .ico-stop { display: none; }
.send.is-stop { background: color-mix(in srgb, var(--danger) 80%, transparent); color: #2a0808; }
.send.is-stop .ico-send { display: none; }
.send.is-stop .ico-stop { display: block; }

@media (min-width: 720px) {
  .messages { max-width: 46rem; width: 100%; margin: 0 auto; }
  .composer { max-width: 46rem; width: 100%; margin: 0 auto; }
}
