/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --red: #e8002d;
  --red-dark: #b50024;
  --bg: #0f0f0f;
  --bg2: #1a1a1a;
  --bg3: #242424;
  --border: #2e2e2e;
  --text: #f0f0f0;
  --text2: #999;
  --text3: #666;
  --accent: #e8002d;
  --chat-bg: #111;
  --bubble-me: #e8002d;
  --bubble-them: #2a2a2a;
  --nav-h: 60px;
  --topnav-h: 56px;
  --cats-h: 44px;
  --radius: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input { outline: none; border: none; font: inherit; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }

/* ─── Screens ───────────────────────────────────────────────── */
.screen { position: fixed; inset: 0; background: var(--bg); overflow: hidden; }

/* ─── Auth ──────────────────────────────────────────────────── */
.auth-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.auth-logo { font-size: 2.5rem; font-weight: 700; letter-spacing: -1px; margin-bottom: 4px; }
.logo-vn { color: var(--red); }
.logo-express { color: var(--text); }
.auth-subtitle { color: var(--text2); font-size: 0.9rem; margin-bottom: 32px; }
.tab-bar {
  display: flex; background: var(--bg2); border-radius: 8px; padding: 4px;
  margin-bottom: 24px; width: 100%; max-width: 360px;
}
.tab { flex: 1; padding: 8px 16px; border-radius: 6px; font-size: 0.9rem; color: var(--text2); transition: all .2s; }
.tab.active { background: var(--red); color: #fff; font-weight: 600; }
.auth-form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; font-size: 1rem; transition: border .2s;
}
.auth-form input:focus { border-color: var(--red); }
.btn-primary {
  background: var(--red); color: #fff; border-radius: 8px;
  padding: 14px; font-size: 1rem; font-weight: 600;
  transition: background .2s, transform .1s;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:hover { background: var(--red-dark); }
.form-error { color: #ff6b6b; font-size: 0.85rem; text-align: center; min-height: 20px; }

/* ─── Top Nav ───────────────────────────────────────────────── */
.topnav {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topnav-h); padding: 0 16px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
}
.topnav-logo { font-size: 1.5rem; font-weight: 700; }
.topnav-actions { display: flex; gap: 8px; }

/* ─── Category tabs ─────────────────────────────────────────── */
.cat-tabs {
  display: flex; overflow-x: auto; gap: 0;
  background: var(--bg); border-bottom: 1px solid var(--border);
  position: fixed; top: var(--topnav-h); left: 0; right: 0; z-index: 99;
  scrollbar-width: none;
}
.cat-tabs::-webkit-scrollbar { display: none; }
.cat {
  flex-shrink: 0; padding: 12px 16px; font-size: 0.85rem; color: var(--text2);
  border-bottom: 2px solid transparent; transition: all .2s; white-space: nowrap;
}
.cat.active { color: var(--red); border-color: var(--red); font-weight: 600; }

/* ─── News Feed ─────────────────────────────────────────────── */
.news-feed {
  position: fixed;
  top: calc(var(--topnav-h) + var(--cats-h));
  bottom: var(--nav-h);
  left: 0; right: 0;
  overflow-y: auto;
  background: var(--bg);
  padding-bottom: 8px;
}

/* Skeleton */
.skeleton-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.skeleton-card {
  height: 90px; background: var(--bg2);
  border-radius: var(--radius); animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0%,100% { opacity: 1; } 50% { opacity: 0.4; }
}

/* News cards */
.news-card {
  display: flex; gap: 12px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background .15s;
}
.news-card:active { background: var(--bg2); }
.news-card-thumb {
  width: 90px; height: 70px; border-radius: 8px; object-fit: cover;
  flex-shrink: 0; background: var(--bg3);
}
.news-card-thumb-placeholder {
  width: 90px; height: 70px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--bg3), var(--border));
  display: flex; align-items: center; justify-content: center; color: var(--text3);
}
.news-card-body { flex: 1; min-width: 0; }
.news-card-title {
  font-size: 0.9rem; line-height: 1.4; font-weight: 500; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.news-card-meta { font-size: 0.75rem; color: var(--text3); margin-top: 6px; }
.news-feed-empty { text-align: center; color: var(--text2); padding: 40px 16px; }

/* ─── Bottom Nav ────────────────────────────────────────────── */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
  display: flex; background: var(--bg2); border-top: 1px solid var(--border); z-index: 100;
}
.bnav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; color: var(--text3); font-size: 0.65rem;
  transition: color .2s;
}
.bnav-btn svg { width: 22px; height: 22px; }
.bnav-btn.active { color: var(--red); }
.premium-trigger { color: var(--text2); position: relative; }
.premium-trigger.holding { color: var(--red); }

/* Long-press ring */
.premium-ring {
  position: fixed; bottom: calc(var(--nav-h) + 10px);
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none;
}
.premium-ring svg { width: 80px; height: 80px; filter: drop-shadow(0 0 12px #e8002d80); }
.ring-bg { fill: none; stroke: #e8002d30; stroke-width: 8; }
.ring-fill {
  fill: none; stroke: var(--red); stroke-width: 8;
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dashoffset 0.05s linear;
}
.premium-ring span { font-size: 0.75rem; color: var(--red); font-weight: 600; }

/* ─── Icon button ───────────────────────────────────────────── */
.icon-btn {
  width: 40px; height: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--bg3); }

/* ─── Chat Screen ───────────────────────────────────────────── */
#chat-screen {
  display: flex; flex-direction: row;
  background: var(--chat-bg);
}

/* Sidebar */
.chat-sidebar {
  width: 320px; min-width: 280px; max-width: 100%;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg2);
  overflow: hidden;
}
@media (max-width: 640px) {
  .chat-sidebar { width: 100%; }
  .chat-main { display: none; }
  .chat-sidebar.mobile-hidden { display: none; }
  .chat-main.mobile-visible { display: flex; }
}
.chat-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
  padding-top: max(16px, env(safe-area-inset-top));
}
.chat-sidebar-header h2 { font-size: 1.1rem; font-weight: 700; }

/* Online bar */
.online-bar {
  display: flex; gap: 12px; padding: 10px 16px; overflow-x: auto;
  border-bottom: 1px solid var(--border); flex-shrink: 0; scrollbar-width: none;
}
.online-bar::-webkit-scrollbar { display: none; }
.online-avatar {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  flex-shrink: 0;
}
.avatar-circle {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--red); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.95rem; position: relative;
}
.avatar-circle.online::after {
  content: ''; position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px; background: #22c55e;
  border-radius: 50%; border: 2px solid var(--bg2);
}
.avatar-name { font-size: 0.65rem; color: var(--text2); max-width: 42px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Rooms list */
.rooms-list { flex: 1; overflow-y: auto; }
.room-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  cursor: pointer; border-bottom: 1px solid var(--border); transition: background .15s;
}
.room-item:hover, .room-item.active { background: var(--bg3); }
.room-avatar {
  width: 46px; height: 46px; border-radius: 50%; background: var(--red);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem; flex-shrink: 0;
}
.room-info { flex: 1; min-width: 0; }
.room-name { font-size: 0.9rem; font-weight: 600; }
.room-last { font-size: 0.8rem; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.room-badge {
  background: var(--red); color: #fff;
  font-size: 0.7rem; font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

/* ─── Chat Main ─────────────────────────────────────────────── */
.chat-main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; color: var(--text3);
}
.chat-empty svg { width: 64px; height: 64px; }
.chat-empty p { font-size: 0.95rem; }
.chat-room { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-header {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); flex-shrink: 0; background: var(--bg2);
  padding-top: max(12px, env(safe-area-inset-top));
}
.chat-header-info { flex: 1; }
.chat-room-name { font-weight: 700; display: block; }
.chat-room-members { font-size: 0.75rem; color: var(--text2); }
.messages-container { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; }
.load-more-wrap { text-align: center; padding: 8px 0; }
.btn-ghost { background: var(--bg3); color: var(--text2); border-radius: 20px; padding: 6px 16px; font-size: 0.8rem; }
.messages-list { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }

/* Message bubbles */
.msg-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.msg-group.mine { align-items: flex-end; }
.msg-group.theirs { align-items: flex-start; }
.msg-sender { font-size: 0.72rem; color: var(--text3); padding: 0 4px; margin-bottom: 2px; }
.msg-bubble {
  max-width: 72%; padding: 10px 14px; border-radius: 18px;
  font-size: 0.9rem; line-height: 1.5; word-break: break-word;
  position: relative;
}
.msg-group.mine .msg-bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 4px; }
.msg-group.theirs .msg-bubble { background: var(--bubble-them); color: var(--text); border-bottom-left-radius: 4px; }
.msg-time { font-size: 0.65rem; color: var(--text3); padding: 0 4px; margin-top: 2px; }
.msg-media { max-width: 240px; border-radius: 12px; cursor: pointer; }
.msg-media-video { max-width: 240px; border-radius: 12px; }

/* Chat input */
.chat-input-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--bg2); border-top: 1px solid var(--border); flex-shrink: 0;
}
#msg-input {
  flex: 1; background: var(--bg3); border-radius: 24px;
  padding: 10px 16px; font-size: 0.92rem; color: var(--text);
}
.btn-send {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--red); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .2s, transform .1s;
}
.btn-send:active { transform: scale(0.9); }
.btn-send svg { width: 18px; height: 18px; stroke: #fff; }

/* ─── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: #222; color: var(--text); padding: 10px 20px; border-radius: 20px;
  font-size: 0.88rem; z-index: 9999; white-space: nowrap;
  animation: toastIn .3s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }
