:root {
  --bg1: #0f0c29; --bg2: #302b63; --bg3: #24243e;
  --glass: rgba(255,255,255,0.08);
  --glass-strong: rgba(255,255,255,0.14);
  --accent: #7c5cff; --accent2: #00d4ff; --gold: #ffd700; --diamond: #4fd1ff;
  --text: #f5f5ff; --muted: #b9b6d6; --danger: #ff5470;
  --radius: 18px; --shadow: 0 8px 32px rgba(0,0,0,0.37);
}
[data-theme="light"] {
  --bg1: #e0e7ff; --bg2: #f5f3ff; --bg3: #ffffff;
  --glass: rgba(255,255,255,0.55); --glass-strong: rgba(255,255,255,0.8);
  --text: #1a1730; --muted: #5b5872; --shadow: 0 8px 32px rgba(80,60,180,0.15);
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, sans-serif; }
body {
  min-height: 100vh; color: var(--text);
  background: linear-gradient(135deg, var(--bg1), var(--bg2), var(--bg3));
  background-attachment: fixed; transition: background .5s;
}
.glass {
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.12); border-radius: var(--radius); box-shadow: var(--shadow);
}
.btn {
  border: none; padding: 12px 18px; border-radius: 12px; cursor: pointer; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; transition: transform .15s, filter .2s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--glass-strong); color: var(--text); }
input, textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.15);
  background: var(--glass); color: var(--text); font-size: 15px; outline: none; transition: border .2s;
}
input:focus, textarea:focus { border-color: var(--accent); }
label { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: block; }
a { color: var(--accent2); text-decoration: none; }
.hidden { display: none !important; }
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; padding: 32px; }
.auth-card h1 { font-size: 28px; margin-bottom: 6px; background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.auth-card .sub { color: var(--muted); margin-bottom: 22px; font-size: 14px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 10px; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 16px; }
.switch { margin-top: 14px; text-align: center; font-size: 14px; }

@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.pop { animation: pop .3s ease; }
.slidein { animation: slidein .35s ease; }

/* ===== Chat layout ===== */
.app { display: grid; grid-template-columns: 320px 1fr; height: 100vh; }
.sidebar { display: flex; flex-direction: column; border-right: 1px solid rgba(255,255,255,0.08); overflow: hidden; }
.sidebar .top { position: relative; padding: 16px; display: flex; align-items: center; gap: 10px; }
.brand { font-size: 20px; font-weight: 700; background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.tabs { display: flex; gap: 6px; padding: 0 12px; }
.tab { flex: 1; text-align: center; padding: 8px; border-radius: 10px; cursor: pointer; font-size: 13px; color: var(--muted); }
.tab.active { background: var(--glass-strong); color: var(--text); }
.search { padding: 12px; }
.list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.item { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; cursor: pointer; transition: background .15s; }
.item:hover { background: var(--glass); }
.item.active { background: var(--glass-strong); }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: linear-gradient(135deg, #7c3aed, #db2777); display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; position: relative; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.dot { position: absolute; bottom: 0; right: 0; width: 12px; height: 12px; border-radius: 50%; background: #2ecc71; border: 2px solid var(--bg1); }
.dot.off { background: #777; }
.item .meta { flex: 1; min-width: 0; }
.item .name { font-weight: 600; display: flex; align-items: center; gap: 5px; }
.item .last { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.item .last .unread { background: var(--accent); color: #fff; border-radius: 12px; font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; flex-shrink: 0; }
.item .time { font-size: 11px; color: var(--muted); margin-left: 4px; flex-shrink: 0; }
.icon-btn.rec { background: #e74c3c; color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.badge-ico { font-size: 13px; }
.badge-blue { color: #1da1f2; } .badge-gold { color: var(--gold); } .badge-diamond { color: var(--diamond); }

.chat-pane { display: flex; flex-direction: column; background: var(--glass); min-width: 0; }
.chat-header { padding: 14px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.chat-header .actions { margin-left: auto; display: flex; gap: 8px; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 70%; padding: 10px 14px; border-radius: 16px; background: var(--glass-strong); animation: slidein .2s ease; position: relative; }
.msg.me { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.msg .sender { font-size: 12px; color: var(--accent2); font-weight: 600; margin-bottom: 2px; }
.msg .time { font-size: 10px; opacity: .6; margin-top: 4px; text-align: right; }
.msg .time .ticks { color: var(--accent); margin-left: 3px; }
.msg .reactions { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.msg .reactions span { background: rgba(0,0,0,0.2); border-radius: 10px; padding: 1px 6px; font-size: 12px; cursor: pointer; }
.reply-prev { border-left: 3px solid var(--accent); padding: 4px 8px; font-size: 12px; opacity: .85; margin-bottom: 4px; background: rgba(255,255,255,.05); border-radius: 6px; cursor: pointer; max-width: 90%; }
.reply-bar { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.08); border-left: 3px solid var(--accent); padding: 6px 10px; border-radius: 8px; margin-bottom: 6px; font-size: 12px; }
.composer { padding: 14px; display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid rgba(255,255,255,0.08); }
.composer textarea { resize: none; height: 46px; max-height: 120px; }
.empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); flex-direction: column; gap: 10px; }
.typing-ind { font-size: 12px; color: var(--muted); padding: 0 18px 8px; font-style: italic; min-height: 18px; }

/* premium frame */
.premium-frame { border: 2px solid var(--gold); box-shadow: 0 0 12px rgba(255,215,0,.4); }

/* modals */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { width: 100%; max-width: 460px; padding: 24px; max-height: 86vh; overflow-y: auto; }
.modal h3 { margin-bottom: 14px; }

/* call UI */
#callUI { z-index: 90; }
#callUI video { border-radius: 12px; }
#callUI .modal { position: relative; }

/* verification + badges */
/* verification starburst — shown after the name, only for verified users */
.verified-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 5px; vertical-align: middle;
  background: #1da1f2; color: #fff; font-size: 9px; font-weight: 900;
  /* blue multi-pointed starburst */
  clip-path: polygon(50% 0%, 61% 23%, 86% 14%, 78% 39%, 100% 50%, 78% 61%, 86% 86%, 61% 77%, 50% 100%, 39% 77%, 14% 86%, 22% 61%, 0% 50%, 22% 39%, 14% 14%, 39% 23%);
  filter: drop-shadow(0 0 3px rgba(29,161,242,0.5));
}
.verified-ico::after { content: "✓"; line-height: 1; }
.badge-ico { position: absolute; top: -2px; left: -2px; font-size: 11px; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg, #0f1020); }
.badge-blue { background: #1da1f2; color: #fff; }
.badge-gold { background: linear-gradient(135deg,#ffd700,#ffaa00); color: #5a3b00; }
.badge-diamond { background: linear-gradient(135deg,#7df9ff,#a0f); color: #fff; }
.avatar.premium-frame { box-shadow: 0 0 0 2px #ffd700, 0 0 12px rgba(255,215,0,.5); }

/* admin */
.admin-wrap { padding: 24px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.1); font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { padding: 18px; text-align: center; }
.stat .n { font-size: 26px; font-weight: 700; color: var(--accent2); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 8px; background: var(--glass-strong); }
.tag.prem { background: var(--gold); color: #000; }
.icon-btn { background: var(--glass-strong); border: none; color: var(--text); width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 16px; }
.icon-btn:hover { background: var(--accent); }

/* inline SVG icons */
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.ic.sm { width: 16px; height: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .3px; }
.brand-logo { height: 28px; width: 28px; border-radius: 8px; object-fit: cover; }
.empty-logo img { height: 64px; width: 64px; border-radius: 16px; opacity: .5; margin-bottom: 14px; }
/* overflow menu (⋮) */
.top-menu { position: absolute; top: 56px; right: 12px; z-index: 50; min-width: 200px; background: var(--glass-strong); backdrop-filter: blur(16px); border: 1px solid rgba(255,255,255,.12); border-radius: 14px; padding: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.menu-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; background: none; border: none; color: var(--text); font-size: 14px; cursor: pointer; border-radius: 10px; text-align: left; }
.menu-row:hover { background: var(--accent); color: #fff; }
.menu-row .ic { color: var(--accent); }
.menu-row:hover .ic { color: #fff; }
#bellBtn { position: relative; }
.badge-count { position: absolute; top: -3px; right: -3px; background: #e74c3c; color: #fff; font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.bell-panel { position: fixed; z-index: 95; width: 340px; max-width: 90vw; background: var(--glass-strong); backdrop-filter: blur(16px); border: 1px solid rgba(255,255,255,.12); border-radius: 14px; padding: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.45); max-height: 60vh; overflow: auto; }
.bell-item { padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,.06); }
.bell-item:last-child { border-bottom: none; }
.bell-text { font-size: 14px; line-height: 1.4; }
.bell-time { font-size: 11px; opacity: .6; margin-top: 4px; }
.bell-empty { padding: 18px; text-align: center; opacity: .6; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu-grid .btn { display: flex; align-items: center; justify-content: center; gap: 6px; }

/* emoji */
.emoji-bar { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 0; }
.emoji-bar span { font-size: 20px; cursor: pointer; padding: 2px 4px; border-radius: 8px; }
.emoji-bar span:hover { background: var(--glass); }

/* ===== Mobile polish ===== */
@media (max-width: 760px) {
  /* sidebar becomes a full-screen slide-in panel */
  .app { display: block; height: 100vh; overflow: hidden; }
  .sidebar {
    position: fixed; inset: 0; z-index: 40; width: 100%; height: 100%;
    background: linear-gradient(135deg, var(--bg1), var(--bg2)); backdrop-filter: none;
  }
  .app.show-chat .sidebar { transform: translateX(-100%); transition: transform .28s ease; }
  .app:not(.show-chat) .chat-pane { display: none; }
  .sidebar .top { padding: 16px 16px 10px; }
  .brand { font-size: 24px; }
  .top > div[style] { gap: 4px; }
  .moreBtn, #moreBtn { width: 42px; height: 42px; }
  .top-menu { top: 60px; right: 14px; min-width: 210px; }
  .list { padding: 4px 8px; }
  .item { padding: 14px 12px; border-radius: 14px; margin-bottom: 4px; }
  .item:hover { background: rgba(255,255,255,.05); }
  .icon-btn { width: 40px; height: 40px; font-size: 17px; }
  .tabs { padding: 6px 10px; gap: 4px; overflow-x: auto; }
  .tab { flex: 0 0 auto; padding: 8px 14px; white-space: nowrap; }
  .search { padding: 8px 12px; }
  .search input { padding: 12px 14px; font-size: 16px; }
  .item { padding: 12px; }
  .avatar { width: 50px; height: 50px; }
  .item .name { font-size: 15px; }
  .item .last { font-size: 13px; }
  .sidebar > div:last-child { padding: 10px 12px 16px; }
  .sidebar > div:last-child .btn { padding: 12px; font-size: 14px; }

  /* chat pane fills screen */
  .chat-pane { position: fixed; inset: 0; z-index: 30; }
  .chat-header {
    position: sticky; top: 0; padding: 12px 12px; gap: 10px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: var(--glass); backdrop-filter: blur(14px);
  }
  #chName { font-size: 16px; font-weight: 700; }
  .chat-header .actions { gap: 6px; }
  .messages { padding: 14px 12px; gap: 8px; }
  .msg { max-width: 82%; padding: 10px 13px; font-size: 15px; border-radius: 16px; }
  .msg .time { font-size: 10px; }
  .typing-ind { padding: 0 12px 6px; }

  .reply-bar { padding: 10px 12px; font-size: 13px; margin-bottom: 8px; }
  #replyBar .ic { width: 18px; height: 18px; }
  /* composer: thumb-friendly, safe-area aware */
  .composer {
    position: sticky; bottom: 0; padding: 12px 10px; gap: 8px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--glass); backdrop-filter: blur(14px);
    align-items: flex-end;
  }
  .composer textarea { height: 48px; min-height: 48px; font-size: 16px; border-radius: 24px; padding: 12px 16px; flex: 1; }
  #micBtn, #emojiBtn, #attachBtn { width: 46px; height: 46px; font-size: 20px; border-radius: 50%; flex-shrink: 0; }
  #sendBtn { padding: 13px 20px; border-radius: 24px; flex-shrink: 0; font-size: 15px; }
  .emoji-bar { position: fixed; left: 0; right: 0; bottom: 78px; background: var(--glass-strong); padding: 10px; justify-content: center; z-index: 60; }

  /* full-screen modals & calls on mobile */
  .modal-bg { padding: 0; align-items: stretch; }
  .modal { max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; padding: 22px 18px; padding-top: max(22px, env(safe-area-inset-top)); overflow-y: auto; }
  #callUI .modal, #callOverlay .modal { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
  #callUI video { width: 100%; max-height: 40vh; }
  .center-screen { padding: 16px; }
  .auth-card { padding: 26px 22px; border-radius: 22px; }
  .auth-card h1 { font-size: 30px; }

  /* admin table: horizontal scroll, larger taps */
  .admin-wrap { padding: 14px; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  th, td { padding: 12px 10px; font-size: 13px; }
  .icon-btn { width: 42px; height: 42px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .stat .n { font-size: 22px; }
}

/* very small phones */
@media (max-width: 380px) {
  .brand { font-size: 19px; }
  .msg { max-width: 90%; }
  .top > div[style] .icon-btn { width: 36px; height: 36px; font-size: 15px; }
}
