/* ============================================================
   STRM Admin — Analytics Dashboard  ·  Premium Dark Theme
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  --bg-primary: #0a0a0f;
  --bg-card: #12121a;
  --bg-glass: rgba(18, 18, 26, 0.85);
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.35);
  --live-red: #ff4757;
  --success: #2ed573;
  --warning: #ffa502;
  --text-primary: #f1f1f5;
  --text-secondary: #9ca3af;
  --border: rgba(255, 255, 255, 0.06);
  --font: 'Inter', sans-serif;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(108, 92, 231, 0.3); border-radius: 3px; }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  /* Dark purple mesh gradient */
  background:
    radial-gradient(ellipse at 20% 50%, rgba(108, 92, 231, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(255, 71, 87, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(46, 213, 115, 0.06) 0%, transparent 50%),
    var(--bg-primary);
}

/* Hide dashboard when login is visible */
.login-screen ~ .dashboard { display: none; }
.login-screen.hidden { display: none; }
.login-screen.hidden ~ .dashboard { display: block; }

.login-card {
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 60px var(--accent-glow);
}

.login-card .logo {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.login-card .subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 32px;
}

.login-card input {
  width: 100%;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.login-card input::placeholder { color: var(--text-secondary); }

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-btn {
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.25s, transform 0.15s, box-shadow 0.25s;
}

.login-btn:hover {
  background: #7c6ef0;
  box-shadow: 0 4px 20px var(--accent-glow);
  transform: translateY(-1px);
}

.login-btn:active { transform: translateY(0); }

.login-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(255, 71, 87, 0.12);
  border: 1px solid rgba(255, 71, 87, 0.25);
  border-radius: 10px;
  color: var(--live-red);
  font-size: 0.85rem;
  display: none;
}

.login-error.visible { display: block; }

/* Shake animation for bad login */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%, 45%, 75% { transform: translateX(-6px); }
  30%, 60%, 90% { transform: translateX(6px); }
}

.shake { animation: shake 0.5s ease; }

/* ============================================================
   DASHBOARD LAYOUT
   ============================================================ */
.dashboard { display: none; }
.dashboard.visible { display: block; animation: fadeIn 0.6s ease-out; }

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

/* ---------- Top Bar ---------- */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 60px;
  background: var(--bg-glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

.top-bar .brand {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--success);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.live-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 213, 115, 0.5); }
  50%      { box-shadow: 0 0 0 8px rgba(46, 213, 115, 0); }
}

.logout-btn {
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.logout-btn:hover {
  color: var(--live-red);
  border-color: rgba(255, 71, 87, 0.3);
  background: rgba(255, 71, 87, 0.06);
}

/* ---------- Main Content ---------- */
.main-content {
  max-width: 1360px;
  margin: 0 auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ============================================================
   GLASS CARD  (shared)
   ============================================================ */
.glass-card {
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.glass-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.stat-card {
  position: relative;
  padding-left: 20px;
}

/* Colored left-border accent */
.stat-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 18px;
  bottom: 18px;
  width: 3px;
  border-radius: 3px;
}

.stat-card.viewers::before  { background: var(--success); }
.stat-card.requests::before { background: #3b82f6; }
.stat-card.bandwidth::before { background: var(--accent); }
.stat-card.uptime::before   { background: var(--warning); }

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.stat-unit {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 4px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* Count-up animation helper */
.count-up {
  transition: opacity 0.2s;
}

/* ============================================================
   CHARTS SECTION
   ============================================================ */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.chart-card { display: flex; flex-direction: column; }

.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 220px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* ============================================================
   SECTION HEADERS
   ============================================================ */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-accent {
  background: var(--accent-glow);
  color: var(--accent);
}

.badge-red {
  background: rgba(255, 71, 87, 0.15);
  color: var(--live-red);
}

/* ============================================================
   SESSIONS TABLE
   ============================================================ */
.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  transition: background 0.15s;
}

/* Zebra striping */
tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
tbody tr:hover { background: rgba(108, 92, 231, 0.06); }

tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.masked-ip {
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.status-playing {
  background: rgba(46, 213, 115, 0.14);
  color: var(--success);
}

.status-paused {
  background: rgba(255, 165, 2, 0.14);
  color: var(--warning);
}

.status-buffering {
  background: rgba(255, 165, 2, 0.14);
  color: #ff9f43;
}

/* Kick button */
.kick-btn {
  padding: 5px 12px;
  background: rgba(255, 71, 87, 0.1);
  border: 1px solid rgba(255, 71, 87, 0.2);
  border-radius: 8px;
  color: var(--live-red);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.kick-btn:hover {
  background: rgba(255, 71, 87, 0.22);
  border-color: var(--live-red);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* ============================================================
   SERVER HEALTH
   ============================================================ */
.server-health-row {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.server-card {
  min-width: 200px;
  flex: 1;
}

.server-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green  { background: var(--success); box-shadow: 0 0 6px rgba(46, 213, 115, 0.5); }
.dot-yellow { background: var(--warning); box-shadow: 0 0 6px rgba(255, 165, 2, 0.5); }
.dot-red    { background: var(--live-red); box-shadow: 0 0 6px rgba(255, 71, 87, 0.5); }

.server-metric {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  padding: 4px 0;
  color: var(--text-secondary);
}

.server-metric span:last-child {
  color: var(--text-primary);
  font-weight: 500;
}

/* ============================================================
   ERROR LOG
   ============================================================ */
.error-log-card {
  overflow: hidden;
}

.error-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.toggle-btn {
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-btn:hover { background: rgba(255, 255, 255, 0.08); }

.error-log-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease;
}

.error-log-body.expanded {
  max-height: 400px;
  overflow-y: auto;
  margin-top: 16px;
}

.error-msg {
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--live-red);
  font-size: 0.8rem;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* Tablet — 2 column */
@media (max-width: 1024px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .server-health-row { flex-wrap: wrap; }
  .server-card { min-width: calc(50% - 8px); }
}

/* Mobile — 1 column */
@media (max-width: 640px) {
  .stats-row { grid-template-columns: 1fr; }
  .top-bar { padding: 0 16px; }
  .main-content { padding: 16px; gap: 16px; }
  .glass-card { padding: 18px; }
  .stat-value { font-size: 1.6rem; }
  .server-card { min-width: 100%; }
  .login-card { margin: 16px; padding: 32px 24px; }
}
