:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 20px 50px rgba(15, 23, 42, .35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  color: var(--text);
  background: radial-gradient(circle at 20% 10%, #312e81 0, transparent 45%),
              radial-gradient(circle at 80% 90%, #0e7490 0, transparent 40%),
              var(--bg);
  font-size: 16px;
  line-height: 1.5;
}
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ===== Views ===== */
.view { min-height: 100%; }
.view--login {
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}

/* ===== Card ===== */
.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
  animation: pop .35s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }

.brand { text-align: center; margin-bottom: 24px; }
.brand__logo {
  width: 56px; height: 56px; margin: 0 auto 12px;
  border-radius: 16px; display: grid; place-items: center;
  color: #fff; background: linear-gradient(135deg, var(--primary), #06b6d4);
}
.brand__name { margin: 0; font-size: 1.6rem; }
.brand__tagline { margin: 4px 0 0; color: var(--muted); }

/* ===== Form ===== */
.form { display: flex; flex-direction: column; gap: 14px; }
.field__label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field__input {
  width: 100%; padding: 11px 14px; font: inherit;
  border: 1px solid var(--border); border-radius: 10px;
  background: #f8fafc; color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field__input:focus {
  outline: none; background: #fff; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .18);
}
.field--invalid .field__input { border-color: var(--danger); }
.field__error { margin: 4px 0 0; min-height: 1em; font-size: .8rem; color: var(--danger); }

.field__group { position: relative; }
.field__group .field__input { padding-right: 70px; }
.field__addon {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--primary);
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  padding: 6px 8px; border-radius: 6px;
}
.field__addon:hover { background: #eef2ff; }

.form__row {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px; font-size: .9rem;
}
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox input { accent-color: var(--primary); width: 16px; height: 16px; }
.link { color: var(--primary); text-decoration: none; }
.link:hover { text-decoration: underline; }

.alert {
  padding: 10px 12px; border-radius: 10px; font-size: .9rem;
  background: #fef2f2; color: var(--danger); border: 1px solid #fecaca;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; font: inherit; font-weight: 600;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); }
.btn--ghost { background: transparent; color: #e2e8f0; border-color: #334155; padding: 7px 12px; }
.btn--ghost:hover { background: #334155; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .7; cursor: progress; }

.spinner {
  display: none; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.btn.is-loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }


/* ===== Chat ===== */
.view--chat {
  display: flex; flex-direction: column; height: 100vh;
  max-width: 900px; margin: 0 auto; background: var(--bg-2); color: #e2e8f0;
}
.chat-header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid #334155;
}
.chat-header__title, .chat-header__user { display: flex; align-items: center; gap: 8px; }
.muted { color: #94a3b8; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot--online { background: #22c55e; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 700; font-size: .85rem;
  text-transform: uppercase; flex-shrink: 0;
}

.messages {
  list-style: none; margin: 0; padding: 16px; flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.msg { display: flex; gap: 10px; max-width: 80%; }
.msg__bubble { background: #334155; padding: 8px 12px; border-radius: 12px; word-break: break-word; }
.msg__meta { font-size: .75rem; color: #94a3b8; margin-bottom: 2px; }
.msg--own { align-self: flex-end; flex-direction: row-reverse; }
.msg--own .msg__bubble { background: var(--primary); }
.msg--own .msg__meta { color: #c7d2fe; text-align: right; }
.msg--system { align-self: center; font-size: .8rem; color: #94a3b8; }

.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid #334155; }
.composer__input { background: #0f172a; border-color: #334155; color: #e2e8f0; }
.composer__input:focus { background: #0f172a; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: .9rem; max-width: calc(100% - 32px);
}

@media (max-width: 420px) {
  .card { padding: 24px 18px; }
  .chat-header__name { display: none; }
  .msg { max-width: 92%; }
}
