@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;500;600;700&family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ===================== CSS VARIABLES ===================== */
:root {
  --bg: #0D0D0F;
  --bg2: #161618;
  --bg3: #1E1E22;
  --card: #1A1A1F;
  --border: #2A2A2E;
  --primary: #FF5C1A;
  --primary-hover: #FF7A40;
  --primary-glow: rgba(255, 92, 26, 0.25);
  --gold: #D4A847;
  --gold-dim: rgba(212, 168, 71, 0.15);
  --text: #F0EEE9;
  --text-sec: #8A8A94;
  --text-dim: #555560;
  --success: #22C55E;
  --danger: #EF4444;
  --warning: #F59E0B;
  --info: #3B82F6;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
  --font-display: 'Rajdhani', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --header-h: 60px;
  --sidebar-w: 260px;
  --bottom-nav-h: 64px;
}

:root[data-theme="light"] {
  --bg: #F7F6F3;
  --bg2: #EFEFEB;
  --bg3: #E8E6E1;
  --card: #FFFFFF;
  --border: #E2E0DC;
  --primary: #FF5C1A;
  --primary-hover: #E04800;
  --primary-glow: rgba(255, 92, 26, 0.15);
  --gold: #B8902E;
  --gold-dim: rgba(184, 144, 46, 0.1);
  --text: #1A1A1F;
  --text-sec: #6B6B75;
  --text-dim: #9A9AA4;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
}

/* ===================== RESET ===================== */
*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html { font-size: 16px; scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
button, a, [role="button"], .btn,
input[type="button"], input[type="submit"], input[type="reset"],
.sidebar-item, .bottom-nav-item, .action-btn,
.chat-send-btn, .chat-media-btn, .chat-mic-btn, .chat-emoji-btn,
.msg-audio-play, .msg-audio-wave-wrap, .msg-reply,
.profile-ff-id, .profile-avatar-wrap, .theme-toggle, .notif-bell,
.user-card-ff-id {
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
button:focus, button:focus-visible,
a:focus, a:focus-visible,
[role="button"]:focus, [role="button"]:focus-visible,
.btn:focus, .btn:focus-visible,
.sidebar-item:focus, .sidebar-item:focus-visible,
.bottom-nav-item:focus, .bottom-nav-item:focus-visible,
.action-btn:focus, .action-btn:focus-visible {
  outline: none;
}
button::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner, input[type="reset"]::-moz-focus-inner {
  border: 0; padding: 0;
}
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
input, textarea, select, [contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
}
img, video { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; }
input, textarea, select, button { font-family: inherit; }

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===================== TYPOGRAPHY ===================== */
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: 0.02em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
.mono { font-family: var(--font-mono); }

/* ===================== LAYOUT ===================== */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden; }

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.view { display: none; }
.view.active { display: flex; flex: 1; overflow: hidden; }
.view.active.app-layout { flex-direction: row; }

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: var(--radius-sm);
  font-family: var(--font-display); font-weight: 600; font-size: 0.95rem;
  letter-spacing: 0.04em; cursor: pointer; transition: all var(--transition);
  text-transform: uppercase; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 0 20px var(--primary-glow); transform: translateY(-1px); }
.btn-gold { background: var(--gold); color: #0D0D0F; }
.btn-gold:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg3); border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ===================== INPUTS ===================== */
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label { font-size: 0.8rem; font-weight: 500; color: var(--text-sec); text-transform: uppercase; letter-spacing: 0.06em; }
.input {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); padding: 11px 14px; border-radius: var(--radius-sm);
  font-size: 0.95rem; transition: all var(--transition); width: 100%;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); background: var(--bg3); }
.input::placeholder { color: var(--text-dim); }
select.input option { background: var(--bg2); }

/* ===================== CARD ===================== */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm);
}

/* ===================== BADGE / RANK ===================== */
.badge {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 3px 10px; border-radius: 99px;
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500;
  white-space: nowrap; flex-shrink: 0;
}
.badge-admin { background: var(--gold-dim); color: var(--gold); border: 1px solid var(--gold); }
.badge-member { background: var(--primary-glow); color: var(--primary); border: 1px solid var(--primary); }

.rank-bar {
  display: flex; align-items: center; gap: 8px; margin-top: 4px;
}
.rank-bar-track {
  flex: 1; height: 3px; background: var(--border); border-radius: 99px; overflow: hidden;
}
.rank-bar-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  animation: rankPulse 2.5s ease-in-out infinite;
}
@keyframes rankPulse {
  0%, 100% { opacity: 1; filter: brightness(1); }
  50% { opacity: 0.75; filter: brightness(1.3); }
}
.rank-label { font-family: var(--font-mono); font-size: 0.7rem; color: var(--gold); }

/* ===================== AVATAR ===================== */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
  background: var(--bg3); border: 2px solid var(--border);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem; color: var(--primary);
  overflow: hidden; background-size: cover; background-position: center;
}
.avatar.lg { width: 72px; height: 72px; font-size: 1.6rem; }
.avatar.sm { width: 30px; height: 30px; font-size: 0.75rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-online { position: relative; }
.avatar-online::after {
  content: ''; position: absolute; bottom: 0; right: 0;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--card);
}

/* ===================== HEADER ===================== */
.header {
  height: var(--header-h); background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 12px;
  position: sticky; top: 0; z-index: 100; flex-shrink: 0;
}
.header-brand {
  display: flex; align-items: center; gap: 10px;
}
.header-logo-img {
  width: 36px; height: 36px; border-radius: 8px; object-fit: cover;
  flex-shrink: 0;
}
.header-logo {
  font-family: var(--font-display); font-weight: 700; font-size: 1.3rem;
  letter-spacing: 0.04em; color: var(--primary);
}
.header-logo span { color: var(--gold); }
.header-spacer { flex: 1; }

.push-permission-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.85); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.push-permission-overlay.hidden { display: none; }
.push-permission-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 24px; max-width: 380px;
  text-align: center; box-shadow: var(--shadow-lg);
}
.push-permission-icon {
  width: 80px; height: 80px; border-radius: 18px; margin-bottom: 16px;
}
.push-permission-card h2 {
  font-family: var(--font-display); font-size: 1.2rem; margin-bottom: 8px;
}
.push-permission-card p { color: var(--text-sec); font-size: 0.9rem; margin-bottom: 20px; line-height: 1.5; }
.push-permission-hint { font-size: 0.75rem; color: var(--text-dim); margin-top: 12px; }

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-w); background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  overflow-y: auto; overflow-x: hidden;
}
.sidebar-section { padding: 12px 8px; }
.sidebar-section-title {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-dim); font-weight: 600; margin-bottom: 10px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition);
  font-size: 0.9rem;
}
.sidebar-item:hover { background: var(--bg3); }
.sidebar-item.active { background: var(--primary-glow); color: var(--primary); }

/* ===================== BOTTOM NAV (mobile) ===================== */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h); background: var(--card); border-top: 1px solid var(--border);
  z-index: 200; padding: 0 8px; gap: 4px;
  align-items: center; justify-content: space-around;
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer;
  transition: all var(--transition); color: var(--text-sec); font-size: 0.65rem;
  font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; flex: 1;
}
.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item:hover { background: var(--bg3); }

/* ===================== TOAST ===================== */
.toast-container { position: fixed; top: 80px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow); animation: toastIn 0.3s ease; min-width: 260px; max-width: 340px;
  font-size: 0.88rem;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.danger  { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--info); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 500;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 28px; width: 100%; max-width: 480px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 12px; color: var(--primary); }
.modal-desc { font-size: 0.95rem; color: var(--text-sec); margin-bottom: 24px; line-height: 1.5; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; }
.modal-actions .btn { min-width: 100px; }

/* ===================== LOADING ===================== */
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== THEME TOGGLE ===================== */
.theme-toggle, .toggle-switch {
  width: 44px; height: 24px; background: var(--border); border-radius: 99px;
  cursor: pointer; position: relative; transition: background var(--transition);
  border: none; flex-shrink: 0;
}
.theme-toggle::after, .toggle-switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--text-sec);
  transition: transform var(--transition), background var(--transition);
}
:root[data-theme="light"] .theme-toggle { background: var(--primary); }
:root[data-theme="light"] .theme-toggle::after { transform: translateX(20px); background: #fff; }

/* ===================== NOTIFICATION BELL ===================== */
.notif-bell { position: relative; cursor: pointer; }
.notif-count {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); color: #fff; border-radius: 99px;
  font-size: 0.65rem; font-weight: 700; min-width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.notif-count.hidden { display: none; }
.notif-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 320px; max-height: 400px; overflow-y: auto; box-shadow: var(--shadow);
  z-index: 300;
}
.notif-dropdown.hidden { display: none; }
.notif-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-size: 0.85rem; cursor: pointer; transition: background var(--transition);
}
.notif-item:hover { background: var(--bg3); }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--primary-glow); }
.notif-item-time { font-size: 0.72rem; color: var(--text-dim); margin-top: 3px; font-family: var(--font-mono); }

/* ===================== DIVIDER ===================== */
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ===================== EMPTY STATE ===================== */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 60px 20px; color: var(--text-sec); text-align: center;
}
.empty-state svg { opacity: 0.3; }
.empty-state h3 { font-size: 1.1rem; color: var(--text); }
.empty-state p { font-size: 0.85rem; max-width: 260px; }

/* ===================== UTILITY ===================== */
.text-primary { color: var(--primary); }
.text-gold { color: var(--gold); }
.text-sec { color: var(--text-sec); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .app-layout { padding-bottom: var(--bottom-nav-h); }
  .modal { padding: 20px; }
}
