/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: #f4f6fb;
  color: #0f1e3d;
  -webkit-font-smoothing: antialiased;
}
a { color: #1d4ed8; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { color: #0b1a3a; margin: 0 0 12px; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
.muted { color: #64748b; }
.small { font-size: .85rem; }
.inline { display: inline; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .95rem;
  cursor: pointer;
  background: #e2e8f0;
  color: #0f1e3d;
  transition: .15s ease;
}
.btn:hover { filter: brightness(.96); }
.btn.primary { background: #1d4ed8; color: #fff; }
.btn.primary:hover { background: #1a44c0; }
.btn.ghost { background: transparent; border-color: #cbd5e1; color: #0f1e3d; }
.btn.small { padding: 6px 10px; font-size: .82rem; border-radius: 8px; }
.btn.danger { background: #dc2626; color: #fff; }
.btn.ok { background: #16a34a; color: #fff; }

/* ---------- Forms ---------- */
label { display: block; margin-bottom: 12px; font-size: .9rem; color: #334155; }
input[type="text"], input[type="password"], input[type="email"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  margin-top: 6px;
  outline: none;
}
input:focus { border-color: #1d4ed8; box-shadow: 0 0 0 3px rgba(29,78,216,.15); }

/* ---------- Alerts ---------- */
.alert {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: .9rem;
}

/* ---------- Centered auth pages ---------- */
.center-page {
  display: flex;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 100%);
}
.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 6px 24px rgba(15,30,61,.06);
  margin-bottom: 16px;
}
.auth-card { width: 100%; max-width: 380px; }

/* ---------- Chat layout ---------- */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #eef2ff;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: #0b1a3a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}
.chat-title { display: flex; align-items: center; gap: 8px; }
.chat-title .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.25);
}
.chat-actions { display: flex; align-items: center; gap: 8px; }
.chat-actions .who { font-size: .85rem; opacity: .85; }
.chat-header .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.chat-header .btn.ghost:hover { background: rgba(255,255,255,.1); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty {
  text-align: center;
  color: #64748b;
  margin-top: 40px;
  font-size: .95rem;
}

.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 9px 12px 7px;
  border-radius: 16px;
  line-height: 1.35;
  box-shadow: 0 2px 8px rgba(15,30,61,.05);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg-row.theirs .bubble {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 6px;
}
.msg-row.mine .bubble {
  background: #1d4ed8;
  color: #fff;
  border-bottom-right-radius: 6px;
}
.sender {
  font-size: .75rem;
  font-weight: 600;
  color: #1d4ed8;
  margin-bottom: 3px;
}
.msg-row.mine .sender { color: #c7d2fe; }
.text { font-size: .96rem; }
.time {
  font-size: .68rem;
  opacity: .7;
  margin-top: 4px;
  text-align: right;
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  position: sticky;
  bottom: 0;
}
.composer input {
  flex: 1;
  margin-top: 0;
  border-radius: 24px;
  padding: 12px 16px;
}
.composer .btn.primary { border-radius: 24px; padding: 12px 18px; }

/* ---------- Admin ---------- */
.admin-page { background: #f4f6fb; }
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.card.stat { text-align: center; margin: 0; }
.stat-num { font-size: 1.8rem; font-weight: 700; color: #1d4ed8; }
.stat-label { font-size: .8rem; color: #64748b; text-transform: uppercase; letter-spacing: .05em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #eef2f7; white-space: nowrap; }
th { background: #f8fafc; font-weight: 600; color: #334155; }
tr:hover td { background: #f8fafc; }
.msg-cell { max-width: 320px; white-space: normal; }
.ua { max-width: 200px; white-space: normal; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
}
.pill.active { background: #dcfce7; color: #166534; }
.pill.disabled { background: #fee2e2; color: #991b1b; }

/* ---------- Mobile tweaks ---------- */
@media (max-width: 480px) {
  .chat-actions .who { display: none; }
  .bubble { max-width: 85%; }
  .admin-wrap { padding: 10px; }
  th, td { padding: 6px 8px; font-size: .8rem; }
}