:root {
  color-scheme: dark;
  --bg-app: #0b1118;
  --bg-panel: #111a24;
  --bg-panel-hover: #182433;
  --bg-panel-active: #1f2f42;
  --bg-input: #192533;
  --bg-chat: #090e14;
  --bg-bubble-me: #026ca8;
  --bg-bubble-me-hover: #0378ba;
  --bg-bubble-them: #1e293b;
  --fg: #f1f5f9;
  --fg-muted: #94a3b8;
  --fg-subtle: #64748b;
  --accent-blue: #0284c7;
  --accent-gold: #f59e0b;
  --accent-grey: #475569;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --border: #202d3d;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --header-height: 60px;
  --tabbar-height: 56px;
}

[data-theme="light"] {
  --bg-app: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-panel-hover: #f5f7fb;
  --bg-panel-active: #e8ecf4;
  --bg-input: #eef2f7;
  --bg-chat: #e5ddd5;
  --bg-bubble-me: #0284c7;
  --bg-bubble-them: #ffffff;
  --fg: #0f172a;
  --fg-muted: #64748b;
  --fg-subtle: #94a3b8;
  --border: #e2e8f0;
  --border-subtle: rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body, #root {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg-app);
  color: var(--fg);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

/* =========================================================
   AUTH SCREEN (Sign up / Login required before app opens)
   ========================================================= */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  width: 100%;
  background: radial-gradient(circle at 50% 20%, #162436 0%, #090e15 100%);
  padding: 20px;
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: rgba(17, 26, 36, 0.94);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: authFadeIn 0.3s ease-out;
}

@keyframes authFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}

.auth-logo-box {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #182635, #0d151e);
  border-radius: 24px;
  border: 1px solid rgba(2, 132, 199, 0.3);
  box-shadow: 0 8px 24px rgba(2, 132, 199, 0.25);
  padding: 8px;
}

.auth-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 40%, #93c5fd 80%, #fbbf24 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-subtitle {
  font-size: 13.5px;
  color: var(--fg-muted);
  line-height: 1.45;
  max-width: 320px;
}

.auth-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(2, 132, 199, 0.15);
  border: 1px solid rgba(2, 132, 199, 0.35);
  color: #38bdf8;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  margin-top: 2px;
}

.auth-tabs {
  display: flex;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 4px;
  border: 1px solid var(--border);
}

.auth-tab-btn {
  flex: 1;
  padding: 10px;
  font-size: 13.5px;
  font-weight: 600;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 3px);
  color: var(--fg-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.auth-tab-btn.active {
  background: var(--accent-blue);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-muted);
}

.auth-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
  color: var(--fg);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.auth-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
}

.auth-submit-btn {
  margin-top: 6px;
  width: 100%;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, filter 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
}

.auth-submit-btn:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.auth-submit-btn:active:not(:disabled) {
  transform: translateY(0);
}

.auth-submit-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.auth-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-notice {
  font-size: 11.5px;
  color: var(--fg-subtle);
  text-align: center;
  line-height: 1.5;
  border-top: 1px solid var(--border-subtle);
  padding-top: 14px;
}

/* =========================================================
   APP LAYOUT
   ========================================================= */
.elite-app {
  display: flex;
  height: 100%;
  width: 100%;
  background: var(--bg-app);
  position: relative;
  overflow: hidden;
}

.elite-sidebar {
  width: 400px;
  min-width: 340px;
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  position: relative;
}

.elite-main {
  flex: 1;
  height: 100%;
  background: var(--bg-chat);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

@media (max-width: 768px) {
  .elite-sidebar {
    width: 100%;
    min-width: 100%;
  }
  .elite-sidebar.hidden-mobile {
    display: none;
  }
  .elite-main.hidden-mobile {
    display: none;
  }
}

/* Sidebar Header */
.sidebar-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-logo-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-tag {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #000000;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-panel-hover);
  color: var(--fg);
}

.icon-btn.active {
  background: var(--bg-panel-active);
  color: var(--accent-blue);
}

.icon-btn.admin-glow {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

/* Tab Bar */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  padding: 4px 8px;
  gap: 4px;
}

.nav-tab {
  flex: 1;
  padding: 8px 4px;
  font-size: 12.5px;
  font-weight: 600;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: all 0.15s ease;
  position: relative;
}

.nav-tab:hover {
  color: var(--fg);
  background: var(--bg-panel-hover);
}

.nav-tab.active {
  color: var(--accent-blue);
  background: var(--bg-panel-active);
}

.nav-tab.admin-tab.active {
  color: #fbbf24;
}

.tab-badge {
  position: absolute;
  top: 4px;
  right: 18%;
  background: var(--accent-blue);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-full);
}

/* Search Bar */
.search-wrapper {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 12px;
  gap: 8px;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 13.5px;
  outline: none;
  color: var(--fg);
}

.search-input::placeholder {
  color: var(--fg-subtle);
}

/* Chat & Contacts List */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.15s ease;
}

.chat-item:hover {
  background: var(--bg-panel-hover);
}

.chat-item.active {
  background: var(--bg-panel-active);
  border-left: 3px solid var(--accent-blue);
}

.avatar-wrap {
  position: relative;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
}

.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background: var(--accent-green);
  border: 2px solid var(--bg-panel);
  border-radius: var(--radius-full);
}

.chat-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-name {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.verified-icon {
  color: #38bdf8;
  font-size: 13px;
}

.chat-time {
  font-size: 11px;
  color: var(--fg-subtle);
  flex-shrink: 0;
}

.chat-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-preview {
  font-size: 12.5px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.unread-count {
  background: var(--accent-blue);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* =========================================================
   CHAT WINDOW
   ========================================================= */
.chat-window {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
  background-color: var(--bg-chat);
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 0);
  background-size: 24px 24px;
}

.chat-header {
  height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
}

.contact-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  min-width: 0;
}

.contact-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-sub {
  font-size: 11.5px;
  color: var(--accent-green);
}

.contact-sub.offline {
  color: var(--fg-subtle);
}

.message-stream {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.enc-notice {
  align-self: center;
  background: rgba(2, 132, 199, 0.1);
  border: 1px solid rgba(2, 132, 199, 0.25);
  color: #7dd3fc;
  font-size: 11.5px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: 75%;
}

.msg-row.me {
  align-self: flex-end;
}

.msg-row.them {
  align-self: flex-start;
}

.msg-bubble {
  padding: 9px 13px;
  border-radius: var(--radius);
  position: relative;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: var(--shadow-sm);
}

.msg-row.me .msg-bubble {
  background: var(--bg-bubble-me);
  color: #ffffff;
  border-bottom-right-radius: 3px;
}

.msg-row.them .msg-bubble {
  background: var(--bg-bubble-them);
  color: var(--fg);
  border-bottom-left-radius: 3px;
  border: 1px solid var(--border-subtle);
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 4px;
}

.msg-row.them .msg-meta {
  color: var(--fg-subtle);
}

.ticks {
  color: #38bdf8;
  font-size: 12px;
}

/* Audio Waveform */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  min-width: 200px;
}

.audio-play-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: #ffffff;
  color: #0284c7;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.waveform-bars {
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 24px;
  flex: 1;
}

.wave-bar {
  width: 3px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 2px;
  transition: height 0.1s ease;
}

.wave-bar.active {
  background: #fbbf24;
}

/* Reactions */
.reaction-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.reaction-pill {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 1px 6px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

/* Chat Input Bar */
.chat-input-bar {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  z-index: 5;
}

.chat-textarea {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--fg);
  outline: none;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  line-height: 1.4;
}

.chat-textarea:focus {
  border-color: var(--accent-blue);
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  background: var(--accent-blue);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.send-btn:hover {
  filter: brightness(1.1);
  transform: scale(1.05);
}

/* =========================================================
   ADMIN CENTER / ADMINISTRATOR USE ONLY
   ========================================================= */
.admin-view {
  flex: 1;
  height: 100%;
  overflow-y: auto;
  padding: 24px;
  background: radial-gradient(circle at 80% 10%, #162436 0%, #0c1219 100%);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.admin-header-card {
  background: rgba(17, 26, 36, 0.9);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.admin-title-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-main-title {
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-subtitle {
  font-size: 13px;
  color: var(--fg-muted);
}

.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.admin-stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-stat-label {
  font-size: 12px;
  color: var(--fg-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-stat-val {
  font-size: 26px;
  font-weight: 700;
  color: #ffffff;
}

.admin-stat-sub {
  font-size: 11px;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 4px;
}

.admin-panel-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.admin-panel-title {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--fg-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--fg);
}

.admin-table tr:hover td {
  background: var(--bg-panel-hover);
}

.admin-badge-member {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.admin-badge-admin {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 80vh;
  overflow-y: auto;
}

/* Status Story Overlay */
.story-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.story-container {
  width: 100%;
  max-width: 420px;
  height: 90vh;
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
}

.story-progress-bar {
  display: flex;
  gap: 4px;
  width: 100%;
  z-index: 10;
}

.story-bar-segment {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.story-bar-fill {
  height: 100%;
  background: #ffffff;
  width: 0%;
}

.story-bar-fill.done {
  width: 100%;
}
