:root {
  color-scheme: dark;
  --bg: #07111f;
  --panel: #0d1a2b;
  --panel-strong: #12233a;
  --line: rgba(163, 190, 229, 0.16);
  --text: #eef6ff;
  --muted: #91a5bf;
  --cyan: #5de1d2;
  --blue: #78a7ff;
  --danger: #ff8b8b;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 8%, rgba(54, 133, 196, 0.22), transparent 32rem),
    radial-gradient(circle at 90% 88%, rgba(36, 192, 172, 0.14), transparent 28rem),
    var(--bg);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand { display: flex; align-items: center; gap: 13px; }
.mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: #07111f;
  font-weight: 800;
  background: linear-gradient(145deg, var(--cyan), var(--blue));
  box-shadow: 0 10px 30px rgba(93, 225, 210, 0.18);
}
.brand h1 { margin: 0; font-size: 1.08rem; letter-spacing: 0.01em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 0.84rem; }
.account-actions { display: flex; align-items: center; gap: 10px; }
.user-name { color: var(--muted); font-size: 0.9rem; }

.button {
  border: 1px solid transparent;
  border-radius: 12px;
  min-height: 42px;
  padding: 0 17px;
  color: var(--text);
  font-weight: 700;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(93, 225, 210, 0.32);
  outline-offset: 2px;
}
.button.primary { color: #06121d; background: linear-gradient(135deg, var(--cyan), #7fb6ff); }
.button.primary:disabled { opacity: 0.55; cursor: wait; transform: none; }
.button.ghost { border-color: var(--line); background: rgba(255, 255, 255, 0.035); }

.login-panel {
  align-self: center;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: clamp(28px, 6vw, 64px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(18, 35, 58, 0.94), rgba(10, 25, 42, 0.94));
  box-shadow: var(--shadow);
}
.login-copy h2 { max-width: 600px; margin: 12px 0 16px; font-size: clamp(2rem, 5vw, 3.8rem); line-height: 1.04; letter-spacing: -0.045em; }
.login-copy p { max-width: 570px; margin: 0 0 34px; color: var(--muted); font-size: 1.05rem; line-height: 1.65; }
.eyebrow { color: var(--cyan); font-size: 0.76rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
}
.controls, .conversation {
  border: 1px solid var(--line);
  background: rgba(13, 26, 43, 0.9);
  box-shadow: var(--shadow);
}
.controls { border-radius: 20px; padding: 22px; }
.control-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 18px; }
.mode-badge { padding: 5px 9px; border: 1px solid rgba(93, 225, 210, 0.28); border-radius: 999px; color: var(--cyan); font-size: 0.76rem; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 0; border-top: 1px solid var(--line); }
.switch-row strong, .switch-row small { display: block; }
.switch-row strong { font-size: 0.95rem; }
.switch-row small { margin-top: 4px; color: var(--muted); font-size: 0.78rem; }
.switch-row input { width: 42px; height: 22px; accent-color: var(--cyan); }
.field { display: grid; gap: 8px; margin-top: 16px; }
.field span { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.field input, textarea {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(4, 12, 23, 0.72);
}
.field input { height: 43px; border-radius: 10px; padding: 0 12px; }
.privacy-note { margin-top: 26px; padding: 15px; border-radius: 14px; background: rgba(93, 225, 210, 0.07); border: 1px solid rgba(93, 225, 210, 0.14); }
.privacy-note strong { font-size: 0.84rem; color: var(--cyan); }
.privacy-note p { margin: 7px 0 0; color: var(--muted); font-size: 0.8rem; line-height: 1.55; }

.conversation { min-height: calc(100vh - 96px); border-radius: 20px; overflow: hidden; display: grid; grid-template-rows: 1fr auto; }
.messages { min-height: 0; overflow-y: auto; padding: clamp(20px, 4vw, 48px); display: flex; flex-direction: column; gap: 18px; }
.empty-state { margin: auto; max-width: 520px; text-align: center; }
.empty-state h2 { margin: 18px 0 9px; font-size: clamp(1.6rem, 4vw, 2.6rem); letter-spacing: -0.035em; }
.empty-state p { margin: 0; color: var(--muted); line-height: 1.6; }
.pulse { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 0 10px rgba(93, 225, 210, 0.08), 0 0 34px rgba(93, 225, 210, 0.55); }
.message { width: min(760px, 92%); padding: 16px 18px; border-radius: 17px; line-height: 1.62; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { align-self: flex-end; background: linear-gradient(135deg, rgba(75, 127, 205, 0.34), rgba(62, 164, 164, 0.23)); border: 1px solid rgba(120, 167, 255, 0.2); }
.message.assistant { align-self: flex-start; background: var(--panel-strong); border: 1px solid var(--line); }
.message-meta { margin-top: 9px; color: var(--muted); font-size: 0.76rem; }
.composer { padding: 16px; border-top: 1px solid var(--line); background: rgba(7, 17, 31, 0.75); }
.composer textarea { min-height: 88px; max-height: 260px; resize: vertical; border-radius: 14px; padding: 14px 15px; line-height: 1.5; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 11px; }
.route-info { color: var(--muted); font-size: 0.8rem; }

.dialog { width: min(520px, calc(100% - 28px)); color: var(--text); border: 1px solid var(--line); border-radius: 20px; background: var(--panel); box-shadow: var(--shadow); padding: 0; }
.dialog::backdrop { background: rgba(0, 5, 13, 0.72); backdrop-filter: blur(5px); }
.dialog form { padding: 26px; }
.dialog h2 { margin: 10px 0; }
.dialog p { color: var(--muted); line-height: 1.55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(420px, calc(100% - 44px)); padding: 13px 16px; border-radius: 12px; color: var(--text); background: #17304a; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: 180ms ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #572d38; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 820px) {
  .shell { padding: 14px; gap: 14px; }
  .topbar { align-items: flex-start; }
  .account-actions { flex-wrap: wrap; justify-content: flex-end; }
  .user-name { width: 100%; text-align: right; }
  .workspace { grid-template-columns: 1fr; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
  .control-heading, .privacy-note, .field { grid-column: 1 / -1; }
  .conversation { min-height: 70vh; }
}

@media (max-width: 560px) {
  .topbar { display: grid; }
  .account-actions { justify-content: flex-start; }
  .user-name { text-align: left; }
  .controls { grid-template-columns: 1fr; }
  .control-heading, .privacy-note, .field { grid-column: auto; }
  .message { width: 96%; }
  .button { padding-inline: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
