/* ═══════════════════════════════════════════
   DESIGN TOKENS
   ═══════════════════════════════════════════ */
:root {
  --bg-base: #0a0a12;
  --bg-card: #131322;
  --bg-hover: rgba(79, 143, 247, 0.05);
  --bg-input: #1a1a30;
  --bg-skeleton: #1e1e38;
  --border: #1e2044;
  --text: #e8e5f0;
  --text-muted: #8892b0;
  --text-dim: #5a6280;
  --accent-start: #4f8ff7;
  --accent-end: #8c5ffb;
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.15);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.15);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.15);
  --teal: #0d3b3b;
  --teal-accent: #14b8a6;
  --val-white: #e8e5f0;
  --val-yellow: #f0c040;
  --val-purple: #a855f7;
  --val-red: #ef4444;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
}

/* ═══════════════════════════════════════════
   RESET
   ═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg-base);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   SHARED — BUTTONS
   ═══════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 20px; border: none; border-radius: var(--radius);
  font-family: var(--font-ui); font-size: 0.875rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition); text-decoration: none;
  line-height: 1;
}
.btn:focus-visible { outline: 2px solid var(--accent-end); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
}
.btn-secondary:hover { border-color: var(--accent-start); background: var(--bg-hover); }
.btn-secondary.active { border-color: var(--accent-start); color: var(--accent-start); }

.btn-danger { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-sm { padding: 6px 12px; font-size: 0.75rem; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border: 1px solid var(--border); border-radius: var(--radius);
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: all var(--transition); font-size: 1rem; line-height: 1;
}
.btn-icon:hover, .btn-icon.active { color: var(--accent-start); border-color: var(--accent-start); }

/* ═══════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════ */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: radial-gradient(ellipse at top, #111128 0%, var(--bg-base) 60%);
}
.login-brand { text-align: center; margin-bottom: 36px; }
.login-brand-icon {
  font-size: 3rem;
  filter: drop-shadow(0 0 20px rgba(79, 143, 247, 0.4));
  margin-bottom: 4px;
}
.login-brand-name {
  font-size: 2.25rem; font-weight: 800;
  background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; letter-spacing: -0.5px;
}
.login-brand-sub { font-size: 1rem; color: var(--text-muted); margin-top: 2px; }

.login-card {
  width: 100%; max-width: 400px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px; box-shadow: var(--shadow);
}
.login-card h2 {
  font-size: 1.5rem; font-weight: 700; margin-bottom: 24px; text-align: center;
}
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block; font-size: 0.8rem; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-input {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font-ui); font-size: 0.9rem;
  transition: border-color var(--transition);
}
.form-input:focus {
  outline: none; border-color: var(--accent-start);
  box-shadow: 0 0 0 3px rgba(79, 143, 247, 0.15);
}
.form-input::placeholder { color: var(--text-dim); }
.login-error {
  color: var(--red); font-size: 0.8rem; margin-top: 12px;
  text-align: center; min-height: 20px;
}
.login-card .btn-primary { width: 100%; padding: 12px; font-size: 0.95rem; }

@media (max-width: 480px) {
  .login-card { padding: 24px; }
  .login-brand-name { font-size: 1.75rem; }
}

/* ═══════════════════════════════════════════
   APP — TOP BAR
   ═══════════════════════════════════════════ */
body.app-page { overflow: hidden; }

.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  height: 48px; padding: 0 16px;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  gap: 12px; flex-shrink: 0;
}
.top-bar-left {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.top-bar-logo { font-size: 1.4rem; line-height: 1; }
.top-bar-brand {
  font-size: 1rem; font-weight: 700;
  background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.top-bar-tag {
  font-size: 0.75rem; color: var(--text-muted); padding: 2px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
}

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 14px; border-radius: var(--radius-pill);
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.status-pill.live { background: var(--green-dim); color: var(--green); }
.status-pill.reconnecting { background: var(--amber-dim); color: var(--amber); }
.status-pill.offline { background: var(--red-dim); color: var(--red); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.top-bar-right {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.top-bar-user { font-size: 0.85rem; color: var(--text-muted); }

/* ═══════════════════════════════════════════
   APP — MAIN LAYOUT + SPLITTER
   ═══════════════════════════════════════════ */
.app-main {
  display: flex; flex-direction: column;
  height: calc(100vh - 48px);
}
.top-panel { overflow: hidden; display: flex; flex-direction: column; }
.splitter {
  height: 6px; flex-shrink: 0;
  background: var(--border); cursor: ns-resize;
  position: relative; transition: background 0.15s;
}
.splitter::after {
  content: ''; position: absolute; inset: 0 -2px;
}
.splitter:hover, .splitter.dragging {
  background: linear-gradient(90deg, var(--accent-start), var(--accent-end));
}
.bottom-panel { overflow: hidden; display: flex; flex-direction: column; flex: 1; }

/* ═══════════════════════════════════════════
   TOOLBAR
   ═══════════════════════════════════════════ */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; flex-shrink: 0;
  align-items: stretch;
}
.toolbar-group { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; }
.toolbar-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; flex-shrink: 0; align-self: center; }

.ticker-wrap {
  position: relative; flex-shrink: 0; width: 130px;
}
.ticker-input {
  padding: 6px 10px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-family: var(--font-mono);
  font-size: 0.85rem; width: 100%; text-transform: uppercase;
  transition: border-color var(--transition);
}
.ticker-input:focus { outline: none; border-color: var(--accent-start); }
.ticker-input::placeholder { color: var(--text-dim); text-transform: none; }

.ticker-dropdown {
  display: none; position: absolute; top: 100%; left: 0; width: 100%;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-top: 4px; z-index: 1000;
  max-height: 200px; overflow-y: auto;
  box-shadow: var(--shadow);
}
.ticker-dropdown.open { display: block; }
.ticker-option {
  padding: 6px 10px; cursor: pointer; font-family: var(--font-mono);
  font-size: 0.8rem; color: var(--text); transition: background 0.1s;
}
.ticker-option:hover { background: var(--bg-hover); }

.share-select, .ba-select {
  padding: 6px 8px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-family: var(--font-ui);
  font-size: 0.8rem; cursor: pointer;
}
.share-select:focus, .ba-select:focus { outline: none; border-color: var(--accent-start); }
.share-select option, .ba-select option { background: var(--bg-card); }

.session-tabs { display: inline-flex; gap: 0; flex-shrink: 0; height: fit-content; align-self: center; }
.session-tab {
  padding: 6px 12px; background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.75rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition); line-height: 1;
}
.session-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.session-tab:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.session-tab:not(:first-child) { border-left-width: 0; }
.session-tab:hover { color: var(--text); background: var(--bg-hover); }
.session-tab.active { background: var(--accent-start); color: #fff; border-color: var(--accent-start); }

.conditions-trigger {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.8rem;
  cursor: pointer; transition: all var(--transition); white-space: nowrap;
  position: relative; height: fit-content; align-self: center;
}
.conditions-trigger:hover, .conditions-trigger.active {
  border-color: var(--accent-start); color: var(--accent-start);
}
.conditions-trigger .count {
  background: var(--accent-start); color: #fff;
  font-size: 0.7rem; padding: 1px 6px; border-radius: var(--radius-pill);
  font-weight: 700;
}

.conditions-panel {
  display: none; position: absolute; top: calc(100% + 6px); left: 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; z-index: 1000;
  min-width: 260px; box-shadow: var(--shadow);
  max-height: 320px; overflow-y: auto;
}
.conditions-panel.open { display: block; }
.cond-item {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px;
  cursor: pointer; border-radius: 4px; transition: background 0.1s;
}
.cond-item:hover { background: var(--bg-hover); }
.cond-item input[type="checkbox"] {
  accent-color: var(--accent-start); width: 14px; height: 14px; cursor: pointer;
}
.cond-item label { cursor: pointer; font-size: 0.8rem; color: var(--text); }

/* ═══════════════════════════════════════════
   TABLES (SHARED)
   ═══════════════════════════════════════════ */
.table-wrap { flex: 1; overflow-y: auto; overflow-x: hidden; }
.table-wrap::-webkit-scrollbar { width: 6px; }
.table-wrap::-webkit-scrollbar-track { background: var(--bg-base); }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

table.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.8rem;
}
table.data-table thead { position: sticky; top: 0; z-index: 10; }
table.data-table th {
  background: var(--bg-card); border-bottom: 2px solid var(--border);
  padding: 8px 12px; text-align: left; font-weight: 600;
  color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.5px; white-space: nowrap;
}
table.data-table td {
  padding: 6px 12px; border-bottom: 1px solid rgba(30, 32, 68, 0.4);
  white-space: nowrap; transition: background 0.15s;
}
table.data-table tbody tr:hover td { background: var(--bg-hover); }
table.data-table .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
table.data-table .ticker-cell { font-weight: 700; color: var(--accent-start); }

/* Value color classes */
.val-low { color: var(--val-white); }
.val-med { color: var(--val-yellow); }
.val-high { color: var(--val-purple); }
.val-ultra { color: var(--val-red); }

/* Row flash animation */
@keyframes rowFlash {
  0% { background: rgba(79, 143, 247, 0.15); }
  100% { background: transparent; }
}
.row-new { animation: rowFlash 0.6s ease-out; }

/* ═══════════════════════════════════════════
   SKELETON LOADING
   ═══════════════════════════════════════════ */
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.skeleton {
  background: var(--bg-skeleton);
  background: linear-gradient(90deg, var(--bg-skeleton) 25%, #252545 50%, var(--bg-skeleton) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: 4px;
  height: 16px;
}
.skeleton td { background: none; border: none; padding: 8px 12px; }
.skeleton td > div { border-radius: 4px; }

/* ═══════════════════════════════════════════
   PANEL HEADERS / CONTROLS
   ═══════════════════════════════════════════ */
.panel-header {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--bg-card);
  border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap;
}
.panel-title { font-size: 0.85rem; font-weight: 700; color: var(--text); }

.tabs-row { display: inline-flex; gap: 0; }
.tab-btn {
  padding: 6px 16px; background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition); line-height: 1;
}
.tab-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.tab-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.tab-btn:not(:first-child) { border-left-width: 0; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--accent-start); color: #fff; border-color: var(--accent-start); }

.date-group {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: auto;
}
.date-group label { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.date-group .form-input {
  padding: 5px 8px; font-size: 0.75rem; width: 120px;
  color-scheme: dark;
}

/* ═══════════════════════════════════════════
   PANEL FILTERS ROW
   ═══════════════════════════════════════════ */
.panel-filters {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
}

/* ═══════════════════════════════════════════
   PANEL TAB CONTENT
   ═══════════════════════════════════════════ */
.panel-tab-content { flex: 1; display: none; overflow: hidden; flex-direction: column; }
.panel-tab-content.active { display: flex; }

/* ═══════════════════════════════════════════
   AGGREGATE HIGHLIGHT
   ═══════════════════════════════════════════ */
.highlight-row { background: var(--teal) !important; }
.highlight-row:hover td { background: rgba(13, 59, 59, 0.8) !important; }

/* ═══════════════════════════════════════════
   EMPTY / ERROR / STATES
   ═══════════════════════════════════════════ */
.state-overlay {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center; color: var(--text-muted); gap: 12px;
}
.state-overlay.visible { display: flex; }
.state-overlay svg, .state-overlay .state-icon { font-size: 2.5rem; opacity: 0.4; }
.state-overlay .state-text { font-size: 0.9rem; }
.state-overlay .state-hint { font-size: 0.8rem; color: var(--text-dim); }
.state-overlay .btn { margin-top: 8px; }

/* ═══════════════════════════════════════════
   LIVE COUNT BADGE
   ═══════════════════════════════════════════ */
.live-badge {
  font-size: 0.7rem; color: var(--text-muted); padding: 2px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  margin-left: auto;
}
.live-badge span { color: var(--green); font-weight: 700; }

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { font-size: 13px; }
  .toolbar { gap: 6px; padding: 6px 8px; }
  .toolbar-sep { display: none; }
  .ticker-wrap { width: 100px; }
  table.data-table th,
  table.data-table td { padding: 6px 8px; font-size: 0.7rem; }
  .top-bar { padding: 0 8px; gap: 6px; }
  .top-bar-user { display: none; }
  .date-group { margin-left: 0; }
  .panel-filters { gap: 4px; }
}
