/* === W-Stream Design System === */

:root {
  /* Brand */
  --brand-50: #EFF6FF;
  --brand-100: #DBEAFE;
  --brand-200: #BFDBFE;
  --brand-300: #93C5FD;
  --brand-400: #60A5FA;
  --brand-500: #3B82F6;
  --brand-600: #2563EB;
  --brand-700: #1D4ED8;
  --brand-800: #1E40AF;
  --brand-900: #1E3A8A;

  /* Dark mode (default) */
  --bg-primary: #0B1121;
  --bg-secondary: #111827;
  --bg-surface: #1A2332;
  --bg-surface-hover: #1F2A3D;
  --bg-elevated: #243247;
  --border-default: #1E2D4A;
  --border-subtle: #162033;
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-tertiary: #64748B;
  --text-inverse: #0F172A;

  /* Semantic */
  --success: #10B981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --danger: #EF4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --info: #3B82F6;
  --info-bg: rgba(59, 130, 246, 0.1);

  /* Spacing (8pt grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.4);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand-400); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--brand-300); }

/* === Typography === */
.display { font-size: 3.5rem; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: 2.25rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.75rem; line-height: 1.3; font-weight: 600; }
h3 { font-size: 1.375rem; line-height: 1.4; font-weight: 600; }
h4 { font-size: 1.125rem; line-height: 1.5; font-weight: 600; }

/* === Layout Utilities === */
.container { max-width: 1280px; margin: 0 auto; padding: 0 var(--space-6); }

/* === Button System === */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-size: 0.875rem; font-weight: 600; font-family: inherit;
  border: 1px solid transparent; border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--transition-fast);
  white-space: nowrap; text-decoration: none;
  line-height: 1;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: var(--space-2) var(--space-3); font-size: 0.8125rem; }
.btn-lg { padding: var(--space-4) var(--space-8); font-size: 1rem; }

.btn-primary { background: var(--brand-600); color: #fff; border-color: var(--brand-600); }
.btn-primary:hover { background: var(--brand-500); border-color: var(--brand-500); }
.btn-primary:active { background: var(--brand-700); }

.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-default); }
.btn-secondary:hover { background: var(--bg-surface-hover); border-color: var(--brand-600); }
.btn-secondary:active { background: var(--bg-elevated); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-surface); color: var(--text-primary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

/* === Form Elements === */
.form-group { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.form-label { font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); }
.form-input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem; font-family: inherit;
  transition: all var(--transition-fast);
  outline: none;
}
.form-input::placeholder { color: var(--text-tertiary); }
.form-input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }
.form-input:disabled { opacity: 0.5; cursor: not-allowed; }
.form-error { font-size: 0.8125rem; color: var(--danger); }
.form-hint { font-size: 0.8125rem; color: var(--text-tertiary); }

/* === Card / Box Component === */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.card:hover { border-color: var(--border-subtle); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.card-title { font-size: 1rem; font-weight: 600; }

/* === Badge === */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: 0.75rem; font-weight: 600;
  border-radius: var(--radius-full);
  line-height: 1.4;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* === DataTable === */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
  text-align: left; padding: var(--space-3) var(--space-4);
  color: var(--text-tertiary); font-weight: 600; font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-default);
  cursor: pointer; user-select: none;
}
.data-table th:hover { color: var(--text-secondary); }
.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}
.data-table tr:hover td { background: var(--bg-surface-hover); }

/* === Toast === */
.toast-container { position: fixed; top: var(--space-6); right: var(--space-6); z-index: 9999; display: flex; flex-direction: column; gap: var(--space-2); }
.toast {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: 0.875rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  min-width: 280px; max-width: 400px;
}
.toast-success { background: #065F46; color: #D1FAE5; border: 1px solid #059669; }
.toast-danger { background: #7F1D1D; color: #FEE2E2; border: 1px solid #DC2626; }
.toast-info { background: #1E3A5F; color: #DBEAFE; border: 1px solid #2563EB; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === Modal === */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fadeIn 0.2s ease; }
.modal {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-xl); padding: var(--space-8);
  max-width: 500px; width: 90%; max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-xl);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-6); }
.modal-title { font-size: 1.25rem; font-weight: 600; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* === Navbar === */
.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: rgba(11, 17, 33, 0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-default);
  padding: 0 var(--space-6); height: 64px;
  display: flex; align-items: center; justify-content: space-between;
}

/* === Sidebar === */
.sidebar {
  position: fixed; top: 64px; left: 0; bottom: 0;
  width: 240px; background: var(--bg-secondary);
  border-right: 1px solid var(--border-default);
  padding: var(--space-6) var(--space-4);
  overflow-y: auto;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.875rem; font-weight: 500;
  transition: all var(--transition-fast);
}
.sidebar-link:hover { background: var(--bg-surface); color: var(--text-primary); }
.sidebar-link.active { background: var(--brand-600); color: #fff; }
.sidebar-section { font-size: 0.6875rem; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.08em; padding: var(--space-4) var(--space-3) var(--space-2); }

/* === Charts === */
.chart-container { position: relative; width: 100%; }
.chart-legend { display: flex; gap: var(--space-4); margin-top: var(--space-3); justify-content: center; }
.chart-legend-item { display: flex; align-items: center; gap: var(--space-2); font-size: 0.75rem; color: var(--text-tertiary); }
.chart-legend-dot { width: 8px; height: 8px; border-radius: 2px; }

/* === Tabs === */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border-default); margin-bottom: var(--space-6); }
.tab {
  padding: var(--space-3) var(--space-4); font-size: 0.875rem; font-weight: 500;
  color: var(--text-tertiary); cursor: pointer; border-bottom: 2px solid transparent;
  transition: all var(--transition-fast); background: none; border-top: none; border-left: none; border-right: none;
  font-family: inherit;
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--brand-400); border-bottom-color: var(--brand-500); }

/* === Stream Status Dot === */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.live { background: var(--danger); box-shadow: 0 0 6px var(--danger); animation: pulse 2s infinite; }
.status-dot.offline { background: var(--text-tertiary); }
.status-dot.connecting { background: var(--warning); animation: pulse 1s infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* === Utility === */
.text-mono { font-family: 'JetBrains Mono', 'IBM Plex Mono', monospace; }
.text-muted { color: var(--text-tertiary); }
.text-sm { font-size: 0.875rem; }
.divider { border: none; border-top: 1px solid var(--border-default); margin: var(--space-6) 0; }
.empty-state { text-align: center; padding: var(--space-12) var(--space-6); color: var(--text-tertiary); }
.empty-state i { font-size: 2.5rem; margin-bottom: var(--space-3); display: block; }

/* === Responsive === */
@media (max-width: 768px) {
  .display { font-size: 2.25rem; }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.375rem; }
  .container { padding: 0 var(--space-4); }
  .nav-links { display: none !important; flex-direction: column; position: absolute; top: 64px; left: 0; right: 0; background: var(--bg-secondary); border-bottom: 1px solid var(--border-default); padding: var(--space-4); gap: var(--space-2); z-index: 45; }
  .nav-links.show { display: flex !important; }
  .sidebar { transform: translateX(-100%); transition: transform var(--transition-slow); z-index: 40; }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: flex !important; }
  .form-input { font-size: 0.8125rem !important; padding: var(--space-2) var(--space-3) !important; }
  .card { padding: var(--space-4) !important; }
}

@media (min-width: 769px) {
  .mobile-menu-btn { display: none !important; }
  .main-with-sidebar { margin-left: 240px; }
}
