:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #070b14;
  --panel: rgba(17, 24, 39, 0.86);
  --panel-solid: #111827;
  --border: rgba(148, 163, 184, 0.18);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --danger: #f87171;
  --user: #312e81;
  --assistant: #182334;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(139, 92, 246, 0.18), transparent 34rem),
    radial-gradient(circle at 90% 15%, rgba(34, 211, 238, 0.12), transparent 30rem),
    var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(100%, 920px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(7, 11, 20, 0.5);
  border-inline: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.topbar {
  min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 20, 0.78);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark,
.login-icon {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 900;
  box-shadow: 0 0 24px rgba(139, 92, 246, 0.45);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
}

.brand h1 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 35vw;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ghost-button,
.primary-button,
.send-button {
  border: 0;
  color: white;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.ghost-button {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.7);
  font-size: 0.78rem;
}

.primary-button {
  width: 100%;
  margin-top: 16px;
  padding: 13px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #6d5dfc);
  font-weight: 750;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 390px);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.login-icon {
  width: 54px;
  height: 54px;
  border-radius: 17px;
  margin-bottom: 20px;
  font-size: 1.3rem;
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.login-card > p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.login-card label {
  display: block;
  margin-bottom: 8px;
  color: #cbd5e1;
  font-size: 0.86rem;
  font-weight: 650;
}

.login-card input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: rgba(2, 6, 23, 0.72);
  color: var(--text);
}

.login-card input:focus,
.composer textarea:focus {
  border-color: rgba(139, 92, 246, 0.72);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.13);
}

.error-text {
  min-height: 1.2em;
  margin: 14px 0 0 !important;
  color: var(--danger) !important;
  font-size: 0.84rem;
}

.chat-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 18px 14px 28px;
  scroll-behavior: smooth;
}

.empty-state {
  width: min(100%, 580px);
  margin: 12vh auto 0;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 1.35rem;
}

.message {
  width: fit-content;
  max-width: min(86%, 720px);
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 17px;
  line-height: 1.52;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}

.message.user {
  margin-left: auto;
  background: linear-gradient(145deg, var(--user), #272361);
  border-bottom-right-radius: 5px;
}

.message.assistant {
  margin-right: auto;
  background: var(--assistant);
  border-bottom-left-radius: 5px;
}

.message .label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.working {
  margin: 0 14px 10px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.82rem;
}

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent-2);
  box-shadow: 0 0 0 rgba(34, 211, 238, 0.4);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.44); }
  70% { box-shadow: 0 0 0 10px rgba(34, 211, 238, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
}

.composer {
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 48px;
  align-items: end;
  gap: 9px;
  border-top: 1px solid var(--border);
  background: rgba(7, 11, 20, 0.9);
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 15px;
  outline: none;
  background: rgba(15, 23, 42, 0.86);
  color: var(--text);
  line-height: 1.4;
}

.send-button {
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 1.18rem;
  font-weight: 900;
}

@media (max-width: 640px) {
  .app-shell {
    border-inline: 0;
  }

  .brand p {
    max-width: 38vw;
  }

  .ghost-button {
    padding: 8px;
    font-size: 0.72rem;
  }

  .message {
    max-width: 92%;
  }
}
