:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --border: #e3e8f0;
  --text: #172033;
  --muted: #7b8496;
  --accent: #5b5cf0;
  --accent-2: #7778ff;
  --bubble: #f0f2f6;
  --shadow: 0 20px 60px rgba(26, 37, 63, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, #e9eef7, #f7f9fc);
}

button, input { font: inherit; }

button { cursor: pointer; }

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  height: min(900px, calc(100vh - 32px));
  min-height: 620px;
  margin: 16px auto;
  display: grid;
  grid-template-columns: 285px minmax(420px, 1fr) 275px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 22px 16px 14px;
  background: var(--panel-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand { display:flex; align-items:center; gap:11px; padding: 2px 8px 24px; }
.brand-icon {
  width: 40px; height: 40px; border-radius: 13px;
  display:grid; place-items:center; color:white; font-size:21px;
  background: linear-gradient(135deg, var(--accent), #9a7cff);
}
.brand strong { display:block; font-size:17px; }
.brand span { display:block; color:var(--muted); font-size:11px; margin-top:2px; }

.profile-card {
  display:flex; align-items:center; gap:10px;
  padding: 11px; border:1px solid var(--border);
  border-radius:15px; background:white;
}
.avatar {
  width: 42px; height:42px; border-radius:50%;
  display:grid; place-items:center; flex:0 0 auto;
  color:white; font-weight:800;
  background: linear-gradient(135deg,#5f67ef,#a276ff);
}
.avatar.me { background: linear-gradient(135deg,#1d9b76,#42c9a0); }
.profile-info { min-width:0; flex:1; }
.profile-info strong { display:block; font-size:13px; }
.profile-info span { display:block; color:var(--muted); font-size:11px; margin-top:3px; }

.online-dot {
  display:inline-block; width:7px; height:7px; border-radius:50%;
  background:#31c58b; margin-right:5px;
}

.icon-btn, .circle-btn, .attach-btn, .emoji-btn, .new-chat {
  border:0; background:transparent; color:var(--muted);
}
.icon-btn { font-weight:800; }

.sidebar-title {
  display:flex; align-items:center; justify-content:space-between;
  padding: 23px 7px 10px; font-weight:750; font-size:13px;
}
.new-chat {
  width:28px; height:28px; border-radius:9px; background:white;
  border:1px solid var(--border); color:var(--accent); font-size:19px;
}

.search-box {
  height:38px; display:flex; align-items:center; gap:8px;
  padding:0 11px; background:white; border:1px solid var(--border);
  border-radius:11px; color:var(--muted);
}
.search-box input { width:100%; border:0; outline:0; background:transparent; font-size:12px; color:var(--text); }

.conversation-list { overflow:auto; margin-top:10px; padding-right:3px; }
.conversation {
  display:flex; align-items:center; gap:10px; padding:10px;
  border-radius:13px; margin-bottom:3px; transition:.15s;
}
.conversation:hover { background:#eceff5; }
.conversation.active { background:#e7e7ff; }
.conversation .avatar { width:40px; height:40px; font-size:13px; }
.conversation-info { min-width:0; flex:1; }
.conversation-top { display:flex; justify-content:space-between; gap:5px; }
.conversation-name { font-size:13px; font-weight:750; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.conversation-time { font-size:10px; color:var(--muted); white-space:nowrap; }
.preview { margin-top:3px; color:var(--muted); font-size:11px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.unread { min-width:18px; height:18px; padding:0 5px; border-radius:9px; display:grid; place-items:center; background:var(--accent); color:white; font-size:10px; }

.sidebar-footer { margin-top:auto; display:grid; gap:3px; padding-top:12px; border-top:1px solid var(--border); }
.footer-btn { border:0; background:transparent; text-align:left; padding:9px; color:var(--muted); border-radius:9px; font-size:12px; }
.footer-btn:hover { background:#e9edf4; color:var(--text); }
.footer-btn span { margin-left:8px; }

.chat { display:flex; flex-direction:column; min-width:0; background:white; }
.chat-header {
  min-height:76px; padding:15px 22px; border-bottom:1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between;
}
.chat-person { display:flex; align-items:center; gap:11px; }
.chat-person h1 { font-size:15px; margin:0; }
.chat-person p { font-size:11px; color:var(--muted); margin:4px 0 0; }
.header-actions { display:flex; gap:5px; }
.circle-btn { width:35px; height:35px; border-radius:10px; font-size:17px; }
.circle-btn:hover { background:var(--panel-2); color:var(--text); }

.messages {
  flex:1; overflow:auto; padding:26px clamp(20px, 5vw, 70px);
  background: radial-gradient(circle at 50% 0%, #fafbff 0%, white 55%);
}
.day-divider { display:flex; align-items:center; gap:10px; color:#a0a7b5; font-size:10px; margin:4px 0 23px; }
.day-divider::before, .day-divider::after { content:""; height:1px; background:var(--border); flex:1; }

.message-row { display:flex; margin:7px 0; }
.message-row.mine { justify-content:flex-end; }
.message {
  max-width:min(70%, 510px); padding:10px 13px; border-radius:16px;
  background:var(--bubble); font-size:13px; line-height:1.45;
}
.message-row.mine .message {
  color:white; background:linear-gradient(135deg,var(--accent),var(--accent-2));
  border-bottom-right-radius:5px;
}
.message-row:not(.mine) .message { border-bottom-left-radius:5px; }
.message-time { display:block; margin-top:4px; font-size:9px; opacity:.55; text-align:right; }
.system-message { text-align:center; color:var(--muted); font-size:10px; margin:17px 0; }

.typing { padding:0 0 8px 32px; color:var(--muted); font-size:10px; }
.typing span { display:inline-block; width:4px; height:4px; background:#9aa2b2; border-radius:50%; margin:0 1px; animation:bounce 1s infinite; }
.typing span:nth-child(2) { animation-delay:.15s; }
.typing span:nth-child(3) { animation-delay:.3s; }
@keyframes bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-4px)} }

.composer {
  display:flex; align-items:center; gap:8px; margin:0 20px 18px;
  padding:7px 8px; border:1px solid var(--border); border-radius:16px;
  background:#fafbfc;
}
.composer input { flex:1; border:0; outline:0; background:transparent; padding:9px 4px; color:var(--text); font-size:13px; }
.attach-btn, .emoji-btn { width:32px; height:32px; border-radius:9px; font-size:19px; }
.attach-btn:hover, .emoji-btn:hover { background:#eef0f5; }
.send-btn { width:36px; height:36px; border:0; border-radius:11px; color:white; background:var(--accent); font-size:16px; }
.send-btn:hover { filter:brightness(1.06); transform:translateY(-1px); }

.details {
  padding:32px 20px; text-align:center; border-left:1px solid var(--border);
  background:var(--panel-2); overflow:auto;
}
.details-avatar { width:72px; height:72px; margin:0 auto 13px; font-size:22px; }
.details h2 { margin:0; font-size:16px; }
.details > p { color:var(--muted); font-size:11px; margin:5px 0 10px; }
.status-pill { display:inline-block; padding:5px 9px; border-radius:20px; background:#e9f8f2; color:#23946d; font-size:10px; }
.details-actions { display:grid; grid-template-columns:repeat(3,1fr); gap:5px; margin:24px 0; }
.details-actions button { border:0; background:white; border-radius:10px; padding:9px 4px; font-size:14px; color:var(--text); }
.details-actions span { display:block; color:var(--muted); font-size:9px; margin-top:4px; }
.details-section { text-align:left; border-top:1px solid var(--border); padding:13px 0; }
.section-row { width:100%; border:0; background:transparent; display:flex; justify-content:space-between; padding:3px 0; font-size:11px; color:var(--text); }
.section-row b { color:var(--muted); }
.danger { color:#c95868; }
.media-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:5px; margin-top:10px; }
.media-grid div { height:55px; display:grid; place-items:center; background:white; border-radius:8px; font-size:21px; }

.toast {
  position:fixed; left:50%; bottom:28px; transform:translate(-50%,20px);
  opacity:0; pointer-events:none; background:#172033; color:white; padding:10px 14px;
  border-radius:10px; font-size:12px; transition:.25s; box-shadow:var(--shadow);
}
.toast.show { opacity:1; transform:translate(-50%,0); }

body.dark {
  --bg:#0d111a; --panel:#151b27; --panel-2:#111722; --border:#283142;
  --text:#edf1f8; --muted:#8f99aa; --bubble:#232b39;
}
body.dark .app-shell, body.dark .profile-card, body.dark .search-box, body.dark .composer,
body.dark .details-actions button, body.dark .media-grid div { background:var(--panel); }
body.dark .conversation:hover { background:#1b2330; }
body.dark .conversation.active { background:#292a52; }
body.dark .brand-icon { color:white; }
body.dark .messages { background:var(--panel); }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns:245px minmax(420px,1fr); }
  .details { display:none; }
}
@media (max-width: 700px) {
  body { background:var(--panel); }
  .app-shell { width:100vw; height:100vh; min-height:0; margin:0; border-radius:0; grid-template-columns:1fr; }
  .sidebar { display:none; }
  .chat-header { padding:12px 15px; }
  .messages { padding:20px 14px; }
  .message { max-width:82%; }
  .composer { margin:0 10px 10px; }
}


.auth-screen { min-height:100vh; display:grid; place-items:center; padding:20px; }
.auth-card { width:min(420px,100%); background:var(--panel); border:1px solid var(--border); border-radius:24px; padding:30px; box-shadow:var(--shadow); }
.auth-brand { display:flex; align-items:center; gap:11px; margin-bottom:28px; }
.auth-brand strong { display:block; font-size:20px; }.auth-brand span { display:block; color:var(--muted); font-size:11px; margin-top:3px; }
.auth-tabs { display:grid; grid-template-columns:1fr 1fr; background:var(--panel-2); padding:4px; border-radius:12px; margin-bottom:22px; }
.auth-tab { border:0; background:transparent; padding:9px; border-radius:9px; color:var(--muted); font-size:12px; font-weight:700; }
.auth-tab.active { background:var(--panel); color:var(--text); box-shadow:0 2px 8px rgba(0,0,0,.06); }
.auth-label { display:block; font-size:11px; font-weight:700; margin:13px 0; color:var(--text); }
.auth-label input { width:100%; margin-top:7px; padding:12px; border:1px solid var(--border); border-radius:11px; outline:0; background:var(--panel-2); color:var(--text); }
.auth-label input:focus { border-color:var(--accent); }
.auth-submit { width:100%; border:0; border-radius:12px; padding:12px; color:#fff; background:var(--accent); font-weight:750; margin-top:8px; }
.auth-message { font-size:10px; color:var(--muted); line-height:1.5; text-align:center; margin:15px 0 0; }

/* Pulse opening screen */
.intro-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, rgba(105, 99, 255, .12), transparent 32%),
    #f7f9fc;
  animation: introFadeOut .8s ease 2.9s forwards;
}
.intro-content {
  text-align: center;
  transform-style: preserve-3d;
  perspective: 900px;
}
.intro-logo {
  color: #5b5cf0;
  font-size: clamp(52px, 9vw, 92px);
  line-height: 1;
  font-weight: 850;
  letter-spacing: .16em;
  margin-right: -.16em;
  opacity: 0;
  filter: blur(8px);
  transform: scale(.35) rotate(-22deg) translateY(14px);
  animation: pulseLogoIn 1.65s cubic-bezier(.18,.86,.22,1) .18s forwards;
}
.intro-slogan {
  margin-top: 18px;
  color: #7b8496;
  font-size: clamp(12px, 2vw, 15px);
  letter-spacing: .12em;
  opacity: 0;
  transform: translateY(12px);
  animation: sloganIn .9s ease 1.45s forwards;
}
@keyframes pulseLogoIn {
  0% { opacity:0; filter:blur(8px); transform:scale(.35) rotate(-22deg) translateY(14px); }
  35% { opacity:.8; filter:blur(2px); }
  65% { transform:scale(1.08) rotate(7deg); }
  82% { transform:scale(.98) rotate(-2deg); }
  100% { opacity:1; filter:blur(0); transform:scale(1) rotate(0) translateY(0); }
}
@keyframes sloganIn {
  to { opacity:1; transform:translateY(0); }
}
@keyframes introFadeOut {
  0% { opacity:1; visibility:visible; }
  99% { opacity:0; visibility:visible; }
  100% { opacity:0; visibility:hidden; pointer-events:none; }
}
@media (prefers-reduced-motion: reduce) {
  .intro-logo, .intro-slogan { animation:none; opacity:1; transform:none; filter:none; }
  .intro-screen { animation:introFadeOut .4s ease 1.2s forwards; }
}
