/* ════════════════════════════════════════
   BASE & RESET
════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:      #4f46e5;
  --primary-dk:   #4338ca;
  --primary-lt:   #ede9fe;
  --accent:       #7c3aed;
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --text:         #0f172a;
  --text2:        #64748b;
  --text3:        #94a3b8;
  --border:       #e2e8f0;
  --green:        #22c55e;
  --red:          #dc2626;
  --radius:       14px;
  --shadow-card:  0 4px 32px rgba(15,23,42,.10), 0 1px 4px rgba(15,23,42,.06);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

svg { display: block; }
button { font-family: inherit; cursor: pointer; }
input  { font-family: inherit; }

.hidden { display: none !important; }


/* ════════════════════════════════════════
   LOGIN SCREEN
════════════════════════════════════════ */
#login-screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: #f8fafc;
  transition: opacity .28s ease;
}
#login-screen.fade-out { opacity: 0; pointer-events: none; }

/* decorative blobs */
.blobs { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.blob  { position: absolute; border-radius: 50%; filter: blur(90px); opacity: .13; }
.b1 { width: 520px; height: 520px; background: var(--primary); top: -180px; right: -120px; }
.b2 { width: 420px; height: 420px; background: var(--accent);  bottom: -160px; left: -100px; }
.b3 { width: 280px; height: 280px; background: #0ea5e9; bottom: 80px; right: 180px; }

/* Card */
.login-card {
  position: relative; z-index: 1;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow-card);
  padding: 44px 40px 40px;
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center;
}

/* ── LOGO ── */
.logo {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 28px;
}
.logo-icon {
  width: 46px; height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-size: 26px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: -1px;
  box-shadow: 0 6px 20px rgba(79,70,229,.35);
}
.logo-text {
  font-size: 30px; font-weight: 800; letter-spacing: -1px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-title {
  font-size: 22px; font-weight: 700;
  color: var(--text); margin-bottom: 6px; text-align: center;
}
.login-sub {
  font-size: 14px; color: var(--text2);
  margin-bottom: 28px; text-align: center;
}

/* ── FIELDS ── */
.field-group { width: 100%; margin-bottom: 14px; }
.field-label {
  display: block; font-size: 12px; font-weight: 600;
  color: #475569; margin-bottom: 6px; letter-spacing: .02em;
}
.field-wrap { position: relative; display: flex; align-items: center; }

/* SVG field icon */
.fi {
  position: absolute; left: 13px; width: 18px; height: 18px;
  color: var(--text3); pointer-events: none; flex-shrink: 0;
}

.field-input {
  width: 100%; height: 46px;
  border: 1.5px solid var(--border); border-radius: 12px;
  padding: 0 14px 0 44px;
  font-size: 14px; color: var(--text);
  background: #f8fafc;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.field-input.no-icon  { padding-left: 14px; }
.field-input.has-right { padding-right: 44px; }
.field-input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79,70,229,.14);
}
.field-input::placeholder { color: var(--text3); }

/* Eye toggle */
.eye-btn {
  position: absolute; right: 10px;
  background: none; border: none;
  color: var(--text3); padding: 5px;
  display: flex; align-items: center;
  transition: color .2s;
}
.eye-btn:hover { color: var(--text2); }
.eye-btn svg { width: 18px; height: 18px; }

/* Error message */
.error-msg {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--red);
  background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 10px; padding: 10px 14px;
  width: 100%; margin-bottom: 14px;
  opacity: 0; transform: translateY(-4px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.error-msg svg { width: 16px; height: 16px; flex-shrink: 0; }
.error-msg.show { opacity: 1; transform: none; pointer-events: auto; }

/* ── BUTTONS ── */
.btn-primary {
  width: 100%; height: 46px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-size: 15px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(79,70,229,.32);
  transition: opacity .2s, transform .1s, box-shadow .2s;
  margin-top: 2px;
}
.btn-primary:hover  { opacity: .91; box-shadow: 0 6px 22px rgba(79,70,229,.42); }
.btn-primary:active { transform: scale(.98); }

.btn-secondary {
  width: 100%; height: 46px; border: 1.5px solid var(--border);
  border-radius: 12px; background: transparent;
  color: var(--primary); font-size: 15px; font-weight: 600;
  transition: background .2s, border-color .2s;
}
.btn-secondary:hover { background: var(--primary-lt); border-color: #c4b5fd; }

/* Divider */
.divider {
  width: 100%; display: flex; align-items: center; gap: 12px;
  color: var(--text3); font-size: 13px; margin: 16px 0;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}


/* ════════════════════════════════════════
   REGISTRATION MODAL
════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15,23,42,.48);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal-card {
  background: var(--surface); border-radius: 24px;
  box-shadow: 0 20px 60px rgba(15,23,42,.22);
  padding: 40px 36px 36px;
  width: 100%; max-width: 400px;
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  transform: translateY(14px) scale(.97);
  transition: transform .3s cubic-bezier(.34,1.3,.64,1);
}
.modal-overlay.open .modal-card { transform: none; }

.modal-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; border: none;
  background: #f1f5f9; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: background .2s, color .2s;
}
.modal-close svg { width: 16px; height: 16px; }
.modal-close:hover { background: var(--border); color: var(--text); }

/* Steps */
.reg-step { width: 100%; display: flex; flex-direction: column; align-items: center; }

.step-ico {
  width: 64px; height: 64px; border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
}
.step-ico svg { width: 30px; height: 30px; }

.modal-title {
  font-size: 20px; font-weight: 700; color: var(--text);
  margin-bottom: 8px; text-align: center;
}
.modal-sub {
  font-size: 14px; color: var(--text2); line-height: 1.55;
  margin-bottom: 22px; text-align: center;
}

.w100 { width: 100%; }

.form-error {
  font-size: 12px; color: var(--red);
  margin-top: -10px; margin-bottom: 10px;
  text-align: center;
}

/* Code boxes */
.code-wrap { display: flex; gap: 8px; margin-bottom: 14px; }
.code-box {
  width: 44px; height: 52px; text-align: center;
  font-size: 22px; font-weight: 700;
  border: 2px solid var(--border); border-radius: 12px;
  background: #f8fafc; color: var(--text);
  outline: none; caret-color: transparent;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.code-box:focus  { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(79,70,229,.14); }
.code-box.filled { border-color: var(--primary); background: var(--primary-lt); }

.btn-link {
  background: none; border: none;
  color: var(--primary); font-size: 13px; font-weight: 500;
  text-decoration: underline; text-underline-offset: 2px;
  padding: 8px 4px; margin-top: 2px;
  transition: color .2s;
}
.btn-link:hover { color: var(--primary-dk); }

/* Success */
.success-circle {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(34,197,94,.3);
  margin-bottom: 20px;
  animation: popIn .4s cubic-bezier(.34,1.56,.64,1);
}
.success-circle svg { width: 36px; height: 36px; }
@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}


/* ════════════════════════════════════════
   CHAT SCREEN
════════════════════════════════════════ */
#chat-screen {
  position: fixed; inset: 0; z-index: 5;
  display: flex;
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease;
}
#chat-screen.visible { opacity: 1; pointer-events: auto; }


/* ════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════ */
.sidebar {
  width: 320px; height: 100vh; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 2;
}

/* Header */
.sb-header {
  padding: 14px 14px 10px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid #f1f5f9;
}
.me-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-size: 17px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.me-info { flex: 1; min-width: 0; }
.me-name  { font-size: 14px; font-weight: 700; color: var(--text); }
.me-status {
  font-size: 12px; color: var(--green);
  display: flex; align-items: center; gap: 4px; margin-top: 1px;
}
.dot-online {
  width: 7px; height: 7px; border-radius: 50%; background: var(--green);
  display: inline-block; flex-shrink: 0;
}

/* Icon button */
.icon-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  border: none; background: transparent; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: background .18s, color .18s;
}
.icon-btn svg  { width: 18px; height: 18px; }
.icon-btn:hover { background: #f1f5f9; color: var(--text); }

/* Search */
.sb-search {
  padding: 9px 10px;
  display: flex; align-items: center;
  gap: 8px; background: #f1f5f9;
  border-radius: 12px; margin: 10px 12px;
}
.search-ico { width: 16px; height: 16px; color: var(--text3); flex-shrink: 0; }
.search-field {
  flex: 1; border: none; background: transparent;
  outline: none; font-size: 14px; color: var(--text);
}
.search-field::placeholder { color: var(--text3); }

/* Chats list */
.chats-list {
  flex: 1; overflow-y: auto; padding: 4px 0;
}
.chats-list::-webkit-scrollbar { width: 4px; }
.chats-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Chat item */
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; cursor: pointer;
  transition: background .15s;
  position: relative;
}
.chat-item:hover  { background: #f8fafc; }
.chat-item.active { background: #f5f3ff; }
.chat-item.active .ci-name { color: var(--primary); }

/* Avatar */
.ci-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff; flex-shrink: 0;
  position: relative;
}
.ci-online {
  position: absolute; bottom: 1px; right: 1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--green); border: 2px solid #fff;
}
.ci-content  { flex: 1; min-width: 0; }
.ci-top      { display: flex; align-items: center; justify-content: space-between; margin-bottom: 3px; }
.ci-name     { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time     { font-size: 11px; color: var(--text3); flex-shrink: 0; margin-left: 6px; }
.ci-bottom   { display: flex; align-items: center; justify-content: space-between; }
.ci-last     { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ci-badge {
  background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px; margin-left: 8px; flex-shrink: 0;
}


/* ════════════════════════════════════════
   CHAT MAIN
════════════════════════════════════════ */
.chat-main {
  flex: 1; display: flex; flex-direction: column;
  background: #eef2f8; height: 100vh; overflow: hidden;
  /* subtle dot pattern */
  background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
  background-size: 24px 24px;
  background-color: #eef2f8;
}

/* Empty state */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 40px;
}
.empty-ico {
  width: 96px; height: 96px; background: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(15,23,42,.07); margin-bottom: 6px;
}
.empty-ico svg { width: 48px; height: 48px; }
.empty-title { font-size: 20px; font-weight: 700; color: var(--text); }
.empty-sub   { font-size: 14px; color: var(--text2); text-align: center; line-height: 1.6; }

/* Chat view */
.chat-view {
  flex: 1; display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}

/* Chat header */
.chat-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(15,23,42,.04);
  z-index: 1;
}
.ch-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.ch-info { flex: 1; }
.ch-name   { font-size: 15px; font-weight: 700; color: var(--text); }
.ch-status { font-size: 12px; color: var(--text2); margin-top: 1px; }
.ch-status.online { color: var(--green); }
.ch-actions { display: flex; gap: 2px; }

/* Messages */
.messages-area {
  flex: 1; overflow-y: auto;
  padding: 20px 80px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.messages-area::-webkit-scrollbar       { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* Date separator */
.date-sep { text-align: center; margin: 12px 0 10px; }
.date-sep span {
  background: rgba(15,23,42,.07); color: var(--text2);
  font-size: 12px; padding: 4px 14px; border-radius: 12px;
}

/* Message bubbles */
.msg { display: flex; flex-direction: column; max-width: 68%; margin-bottom: 1px; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in  { align-self: flex-start; align-items: flex-start; }

.msg-sender {
  font-size: 12px; font-weight: 600; color: var(--primary);
  margin-bottom: 3px; padding-left: 12px;
}
.msg-bubble {
  padding: 10px 14px; border-radius: 18px;
  font-size: 14px; line-height: 1.55; word-break: break-word;
  position: relative;
}
.msg.out .msg-bubble {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; border-bottom-right-radius: 4px;
}
.msg.in .msg-bubble {
  background: #fff; color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(15,23,42,.07);
}
.msg-meta { display: flex; align-items: center; gap: 4px; padding: 3px 4px 0; }
.msg-time  { font-size: 11px; color: var(--text3); }
.msg-check { font-size: 13px; color: var(--primary); line-height: 1; }

/* Input bar */
.input-bar {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.attach-btn { color: var(--text3); }
.attach-btn:hover { color: var(--primary); }
.msg-input {
  flex: 1; height: 42px;
  border: 1.5px solid var(--border); border-radius: 22px;
  padding: 0 18px; font-size: 14px; color: var(--text);
  background: #f8fafc; outline: none;
  transition: border-color .2s, background .2s;
}
.msg-input:focus { border-color: #c4b5fd; background: #fff; }
.msg-input::placeholder { color: var(--text3); }
.send-btn {
  width: 42px; height: 42px; border: none; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(79,70,229,.32); flex-shrink: 0;
  transition: opacity .2s, transform .1s;
}
.send-btn svg   { width: 18px; height: 18px; margin-left: 2px; }
.send-btn:hover  { opacity: .9; }
.send-btn:active { transform: scale(.93); }


/* ════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════ */
@media (max-width: 700px) {
  .sidebar { width: 260px; }
  .messages-area { padding: 16px 16px 8px; }
}
@media (max-width: 520px) {
  .sidebar { display: none; }
  #chat-screen { flex-direction: column; }
  .chat-main { height: 100vh; }
  .login-card { padding: 32px 22px; }
}
