:root {
  color-scheme: dark;
  --bg: #0b0f19;
  --bg-soft: #111827;
  --panel: #151c2b;
  --panel-2: #1b2436;
  --line: rgba(148, 163, 184, 0.16);
  --text: #e8edf7;
  --muted: #94a3b8;
  --accent: #6d8cff;
  --accent-2: #9d7bff;
  --danger: #ff7b7b;
  --ok: #4ade80;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1000px 600px at 15% -10%, rgba(109, 140, 255, 0.16), transparent 60%),
    radial-gradient(800px 500px at 110% 10%, rgba(157, 123, 255, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

/* ---------- Auth ---------- */
.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}

.auth-card {
  width: min(100%, 420px);
  background: linear-gradient(180deg, rgba(27, 36, 54, 0.96), rgba(17, 24, 39, 0.96));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 30px 26px 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-card h1 {
  font-size: 22px;
  line-height: 1.25;
  margin: 26px 0 8px;
  letter-spacing: -0.02em;
}

.auth-desc {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}

.auth-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
  margin: 0 0 8px;
}

.auth-card input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(11, 15, 25, 0.7);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.auth-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 140, 255, 0.18);
}

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

.brand--center { justify-content: center; }

.brand__mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(109, 140, 255, 0.28);
}

.brand__mark svg { width: 23px; height: 23px; }

.brand__copy { min-width: 0; }

.brand__title {
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand__sub {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.dot--ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.14); }
.dot--bad { background: var(--danger); }

.btn {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 650;
}

.btn--primary {
  width: 100%;
  margin-top: 18px;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 26px rgba(109, 140, 255, 0.25);
  transition: transform .12s, opacity .12s;
}

.btn--primary:active { transform: scale(0.985); }
.btn--primary:disabled { opacity: .6; cursor: wait; }

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 12px 0 0;
}

.auth-foot {
  color: #64748b;
  font-size: 11px;
  text-align: center;
  margin: 22px 0 0;
}

/* ---------- Chat shell ---------- */
.app {
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.55), rgba(11, 15, 25, 0.2));
  border-inline: 1px solid var(--line);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 25, 0.72);
  backdrop-filter: blur(16px);
  position: relative;
  z-index: 2;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.model-pill {
  font-size: 11px;
  font-weight: 650;
  color: #c7d2fe;
  border: 1px solid rgba(109, 140, 255, 0.32);
  background: rgba(109, 140, 255, 0.1);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(27, 36, 54, 0.7);
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:active { background: var(--panel-2); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Messages ---------- */
.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 22px 16px 18px;
  scroll-behavior: smooth;
}

.empty-state {
  height: 100%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 20px;
}

.empty-state__icon {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 24px;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  margin-bottom: 16px;
}

.empty-state h2 {
  color: var(--text);
  font-size: 18px;
  margin: 0 0 6px;
}

.empty-state p { margin: 0; font-size: 14px; }

.msg {
  display: flex;
  gap: 10px;
  margin: 0 0 18px;
  animation: rise .18s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg__avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  margin-top: 2px;
}

.msg--user { flex-direction: row-reverse; }
.msg--user .msg__avatar { background: linear-gradient(135deg, #334155, #475569); }

.msg__body { min-width: 0; max-width: min(82%, 640px); }

.msg--user .msg__body { display: flex; flex-direction: column; align-items: flex-end; }

.bubble {
  padding: 12px 14px;
  border-radius: 16px 16px 16px 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 14.5px;
}

.msg--user .bubble {
  border-radius: 16px 16px 5px 16px;
  background: linear-gradient(135deg, rgba(109, 140, 255, 0.92), rgba(123, 104, 238, 0.92));
  border-color: transparent;
  color: white;
}

.msg__meta {
  color: #64748b;
  font-size: 11px;
  margin: 5px 4px 0;
}

.typing { display: flex; gap: 4px; padding: 14px; }
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- Composer ---------- */
.composer-wrap {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(11, 15, 25, 0.86);
  backdrop-filter: blur(16px);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 8px 8px 8px 14px;
  transition: border-color .15s, box-shadow .15s;
}

.composer:focus-within {
  border-color: rgba(109, 140, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(109, 140, 255, 0.12);
}

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 140px;
  min-height: 38px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 0;
  line-height: 1.45;
}

.composer textarea::placeholder { color: #64748b; }

.send-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 13px;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  transition: transform .12s, opacity .12s;
}

.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: .45; cursor: wait; }
.send-btn svg { width: 21px; height: 21px; }

.composer-hint {
  color: #526077;
  font-size: 10.5px;
  text-align: center;
  margin-top: 7px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  padding: 11px 16px;
  border-radius: 12px;
  background: #2a1620;
  border: 1px solid rgba(255, 123, 123, 0.35);
  color: #ffd7d7;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 10;
}

/* ---------- Desktop polish ---------- */
@media (min-width: 768px) {
  .messages { padding: 30px 32px 24px; }
  .composer-wrap { padding-inline: 32px; }
  .app {
    margin: 18px auto;
    height: calc(100dvh - 36px);
    border: 1px solid var(--line);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }
  .body-holder { padding: 18px; }
}

@media (max-width: 380px) {
  .model-pill { display: none; }
  .brand__mark { width: 38px; height: 38px; }
  .msg__body { max-width: 86%; }
}
