/* ============================================================
   LAYER 1: DESIGN TOKENS — PM1 Dong Huong Map (Financial Dashboard Dark)
   ============================================================ */
:root {
  /* Background */
  --bg-base: #020617;
  --bg-surface: #0a1628;
  --bg-card: #0e1a2e;
  --bg-elevated: #132240;

  /* Text */
  --text-primary: #f0f6ff;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Accent — cyan glow */
  --accent: #38bdf8;
  --accent-bright: #7dd3fc;
  --accent-dim: rgba(56, 189, 248, 0.15);
  --accent-glow: rgba(56, 189, 248, 0.4);

  /* Semantic */
  --success: #22c55e;
  --destructive: #ef4444;
  --warning: #f59e0b;

  /* Border */
  --border: rgba(56, 189, 248, 0.12);
  --border-hover: rgba(56, 189, 248, 0.3);

  /* Typography */
  --font-sans: 'Be Vietnam Pro', system-ui, sans-serif;
  --font-mono: 'Fira Code', 'Cascadia Code', monospace;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  /* Spacing - 4px system */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Typography scale */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 20px;
  --text-xl: 28px;
  --text-2xl: 36px;

  --leading-normal: 1.5;
  --leading-tight: 1.2;

  /* Shadows — cyan glow */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4), 0 0 20px rgba(56, 189, 248, 0.06);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.5), 0 0 30px rgba(56, 189, 248, 0.08);
  --shadow-glow: 0 0 20px rgba(56, 189, 248, 0.1);

  /* Transitions */
  --transition-fast: 150ms ease-out;
  --transition-normal: 200ms ease-out;

  /* Backward-compat aliases used by inline styles & JS */
  --color-primary: var(--accent);
  --color-primary-light: var(--accent-dim);
  --color-primary-dark: #0c4a6e;
  --color-primary-hover: var(--accent-bright);
  --text-inverse: #020617;

  --color-blue-50: rgba(56, 189, 248, 0.06);
  --color-blue-100: rgba(56, 189, 248, 0.1);
  --color-blue-200: rgba(56, 189, 248, 0.2);
  --color-blue-600: var(--accent);
  --color-blue-700: #0ea5e9;
  --color-blue-800: #0c4a6e;

  --color-green-50: rgba(34, 197, 94, 0.06);
  --color-green-100: rgba(34, 197, 94, 0.12);
  --color-green-200: rgba(34, 197, 94, 0.2);
  --color-green-500: #22c55e;
  --color-green-600: #22c55e;
  --color-green-700: #16a34a;

  --color-amber-50: rgba(245, 158, 11, 0.06);
  --color-amber-100: rgba(245, 158, 11, 0.12);
  --color-amber-500: #f59e0b;
  --color-amber-600: #d97706;

  --color-red-50: rgba(239, 68, 68, 0.06);
  --color-red-100: rgba(239, 68, 68, 0.12);
  --color-red-500: #ef4444;
  --color-red-600: #ef4444;

  --color-purple-50: rgba(167, 139, 250, 0.06);
  --color-purple-100: rgba(167, 139, 250, 0.12);
  --color-purple-200: rgba(167, 139, 250, 0.2);
  --color-purple-500: #a78bfa;
  --color-purple-600: #a78bfa;

  --color-teal-50: rgba(45, 212, 191, 0.06);
  --color-teal-100: rgba(45, 212, 191, 0.12);
  --color-teal-500: #2dd4bf;
  --color-teal-600: #2dd4bf;

  --color-pink-100: rgba(244, 114, 182, 0.12);
  --color-pink-600: #f472b6;

  --color-sky-100: rgba(125, 211, 252, 0.12);
  --color-sky-600: #7dd3fc;

  --color-gray-50: rgba(56, 189, 248, 0.04);
  --color-gray-100: rgba(56, 189, 248, 0.06);
  --color-gray-200: var(--border);
  --color-gray-300: var(--border-hover);
  --color-gray-400: #64748b;
  --color-gray-500: #64748b;
  --color-gray-600: #94a3b8;

  --color-success: var(--success);
  --color-success-light: rgba(34, 197, 94, 0.12);
  --color-warning: var(--warning);
  --color-warning-light: rgba(245, 158, 11, 0.12);
  --color-error: var(--destructive);
  --color-error-light: rgba(239, 68, 68, 0.12);
  --color-info: var(--color-purple-600);
  --color-info-light: var(--color-purple-100);

  --bg-page: var(--bg-base);
  --border-default: var(--border);
  --border-subtle: var(--border);
}

/* ============================================================
   LIGHT THEME OVERRIDE
   ============================================================ */
html.light {
  --bg-base: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-elevated: #f8fafc;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent: #0284c7;
  --accent-bright: #0ea5e9;
  --accent-dim: rgba(2, 132, 199, 0.1);
  --accent-glow: rgba(2, 132, 199, 0.2);

  --border: rgba(2, 132, 199, 0.15);
  --border-hover: rgba(2, 132, 199, 0.3);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.1);
  --shadow-glow: 0 0 20px rgba(2, 132, 199, 0.06);

  --text-inverse: #ffffff;
  --color-primary: var(--accent);
  --color-primary-light: var(--accent-dim);
  --color-primary-dark: #0c4a6e;
  --color-primary-hover: var(--accent-bright);
}
html.light .page-header {
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
}
html.light .page-header::after {
  background: linear-gradient(90deg, var(--accent), #0ea5e9) !important;
}
html.light .stat-box {
  background: var(--bg-card);
  border-color: #e2e8f0;
}
html.light .main-tab.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
html.light table thead th {
  background: #f1f5f9;
  color: #475569;
  border-bottom-color: #e2e8f0;
}
html.light td {
  border-bottom-color: #f1f5f9;
}
html.light tbody tr:hover td {
  background: rgba(2, 132, 199, 0.04) !important;
}
html.light .person-chip {
  background: #f1f5f9;
  border-color: #e2e8f0;
}
html.light .pill {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #475569;
}
html.light .pill.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
html.light .chart-card {
  background: var(--bg-card);
  border-color: #e2e8f0;
}
html.light .legend {
  background: var(--bg-card);
  border-color: #e2e8f0;
}
html.light .table-wrap {
  border-color: #e2e8f0;
}
html.light .domain-card {
  background: var(--bg-card) !important;
}
html.light .btn {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #475569;
}
html.light .btn:hover {
  background: #e2e8f0;
}
html.light .btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
html.light .btn-primary:hover {
  background: var(--accent-bright);
}
html.light .search-wrap .search-input {
  background: #ffffff;
  border-color: #e2e8f0;
  color: #0f172a;
}
html.light .btn-search-inside {
  background: var(--accent);
  color: #ffffff;
}
html.light .load-badge.over { background: rgba(239,68,68,0.1); color: #dc2626; border-color: rgba(239,68,68,0.3); }
html.light .load-badge.under { background: rgba(245,158,11,0.1); color: #d97706; border-color: rgba(245,158,11,0.3); }
html.light .load-badge.ok { background: rgba(34,197,94,0.1); color: #16a34a; border-color: rgba(34,197,94,0.3); }
html.light .error-banner { background: rgba(239,68,68,0.05); }
html.light #login-gate { background: var(--bg-base) !important; }
html.light #login-gate > div { background: var(--bg-card) !important; border-color: #e2e8f0 !important; }
html.light #login-email { background: #f8fafc !important; border-color: #e2e8f0 !important; color: #0f172a !important; }
html.light .section-header { background: #f1f5f9; }
html.light .domain-block { border-color: #e2e8f0; }
html.light .sp-table { background: #f8fafc; }
html.light .btn-search-clear { background: #e2e8f0; color: #64748b; }
html.light .btn-search-clear:hover { background: rgba(239,68,68,0.1); color: #ef4444; }

/* ============================================================
   LAYER 2: COMPONENT STYLES — Dark Financial Dashboard
   ============================================================ */

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

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Page layout */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
}

/* ---- Header ---- */
.page-header {
  background: rgba(2, 6, 23, 0.92);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-8);
  margin-bottom: var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.page-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56,189,248,0.3), transparent);
}
.page-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--accent-bright);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  letter-spacing: -0.01em;
  text-shadow: 0 0 20px var(--accent-glow);
}
.page-title svg { flex-shrink: 0; color: var(--accent); }
.page-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}
.header-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

/* ---- Buttons (Ghost style with cyan border) ---- */
.btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  min-width: 44px;
  justify-content: center;
  line-height: 1;
}
.btn:hover {
  border-color: var(--border-hover);
  color: var(--accent-bright);
  background: rgba(56, 189, 248, 0.08);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.1);
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--accent);
}
.btn svg { flex-shrink: 0; }
.btn-primary {
  background: var(--accent);
  color: #020617;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-bright);
  color: #020617;
  box-shadow: 0 0 16px var(--accent-glow);
}

/* Header button overrides */
.page-header .btn {
  background: rgba(56, 189, 248, 0.06);
  border-color: var(--border);
  color: var(--text-secondary);
  backdrop-filter: blur(4px);
}
.page-header .btn:hover {
  background: rgba(56, 189, 248, 0.12);
  border-color: var(--border-hover);
  color: var(--accent-bright);
}
.page-header .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #020617;
}
.page-header .btn-primary:hover {
  background: var(--accent-bright);
}

/* ---- Stats cards ---- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.stat-box {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-5) var(--space-5);
  text-align: left;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  transition: all var(--transition-normal);
  position: relative;
  backdrop-filter: blur(8px);
}
.stat-box:hover {
  box-shadow: var(--shadow-glow);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}
.stat-box:nth-child(2) { border-left-color: var(--success); }
.stat-box:nth-child(2):hover { border-left-color: #16a34a; }
.stat-box:nth-child(3) { border-left-color: var(--color-purple-500); }
.stat-box:nth-child(3):hover { border-left-color: #8b5cf6; }
.stat-box:nth-child(4) { border-left-color: var(--destructive); }
.stat-box:nth-child(4):hover { border-left-color: #dc2626; }
.stat-box:nth-child(5) { border-left-color: var(--warning); }
.stat-box:nth-child(5):hover { border-left-color: #d97706; }
.stat-box:nth-child(6) { border-left-color: #2dd4bf; }
.stat-box:nth-child(6):hover { border-left-color: #14b8a6; }
.stat-box:nth-child(7) { border-left-color: var(--color-pink-600); }
.stat-box:nth-child(8) { border-left-color: var(--color-sky-600); }
.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}
.stat-num {
  font-size: var(--text-xl);
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
}
.stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  font-weight: 500;
}

/* ---- Legend (Dark theme) ---- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-6);
  align-items: center;
}
.legend-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.legend-sep {
  width: 1px;
  height: 14px;
  background: rgba(56, 189, 248, 0.15);
}

/* ---- Tabs (Pill style, dark) ---- */
.main-tabs {
  display: inline-flex;
  gap: 4px;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  border-bottom: none;
  padding: 4px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.main-tab {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--text-muted);
  transition: all var(--transition-normal);
  user-select: none;
  margin-bottom: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
}
.main-tab:hover {
  color: var(--text-primary);
  background: rgba(56, 189, 248, 0.06);
}
.main-tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--accent);
}
.main-tab.active {
  background: var(--accent-dim);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--accent-bright);
  font-weight: 600;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}
.main-tab svg { flex-shrink: 0; }

.tab-content {
  display: none;
  animation: fadeIn var(--transition-normal);
}
.tab-content.active { display: block; }

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

/* ---- Filter bar ---- */
.filter-bar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar .search-input {
  padding: var(--space-2) 90px var(--space-2) 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  width: 340px;
  outline: none;
  min-height: 44px;
  transition: all var(--transition-normal);
  background: var(--bg-surface);
  color: var(--text-primary);
}
.filter-bar .search-input::placeholder {
  color: var(--text-muted);
}
.filter-bar .search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}
.search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search-wrap svg {
  position: absolute;
  left: 13px;
  pointer-events: none;
  color: var(--text-muted);
}
.btn-search-clear {
  position: absolute;
  right: 90px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  padding: 0;
}
.btn-search-clear:hover {
  background: rgba(239,68,68,0.2);
  color: #ef4444;
}
.btn-search-inside {
  position: absolute;
  right: 4px;
  padding: 6px 16px;
  border-radius: 20px;
  border: none;
  background: var(--accent);
  color: var(--bg-base);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  letter-spacing: 0.3px;
}
.btn-search-inside:hover {
  background: var(--accent-bright);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.3);
}
.btn-search-inside:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}
.filter-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 500;
}
.pills { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.pill {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--text-secondary);
  transition: all var(--transition-normal);
  user-select: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.pill:hover {
  border-color: var(--border-hover);
  color: var(--accent-bright);
  background: rgba(56, 189, 248, 0.08);
}
.pill:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--accent);
}
.pill.active {
  background: var(--accent-dim);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--accent-bright);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}
.pill svg { width: 14px; height: 14px; }

/* ---- Section headers ---- */
.section-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.section-header.north {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.1), rgba(56, 189, 248, 0.04));
}
.section-header.south {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(245, 158, 11, 0.04));
}
.section-label {
  font-size: var(--text-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.section-label.north { color: var(--accent-bright); }
.section-label.south { color: var(--warning); }
.section-count {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-left: auto;
  font-weight: 500;
}

/* ---- Tables (Dark rows, subtle cyan hover) ---- */
.table-wrap {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--space-6);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
}
/* Custom scrollbar */
.table-wrap::-webkit-scrollbar { height: 6px; }
.table-wrap::-webkit-scrollbar-track { background: var(--bg-surface); border-radius: 3px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--accent); }
table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  background: var(--bg-card);
}
thead tr { background: rgba(56, 189, 248, 0.04); }
th {
  padding: 10px 10px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 10px;
  border-bottom: 1px solid rgba(56, 189, 248, 0.06);
  vertical-align: top;
  font-size: var(--text-sm);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}
tr:last-child td { border-bottom: none; }
tbody tr {
  transition: all var(--transition-fast);
}
tbody tr:hover td {
  background: rgba(56, 189, 248, 0.06) !important;
}
tbody tr:hover td:first-child {
  box-shadow: inset 3px 0 0 0 var(--accent);
}
.col-id {
  width: 75px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}
.col-name { min-width: 140px; font-weight: 500; }
.col-score { width: 50px; text-align: center; }
.col-status { width: 100px; }
.col-lead { min-width: 140px; max-width: 260px; }
.col-lead .person-chip { margin-bottom: 4px; }

/* ---- Theme toggle ---- */
.theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ---- Sortable table headers ---- */
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
}
th.sortable:hover {
  color: var(--accent-bright);
}
th.sortable::after {
  content: ' ⇅';
  font-size: 10px;
  opacity: 0.3;
}
th.sortable.sort-asc::after {
  content: ' ▲';
  opacity: 0.8;
  color: var(--accent);
}
th.sortable.sort-desc::after {
  content: ' ▼';
  opacity: 0.8;
  color: var(--accent);
}

/* ---- Person badges (Avatar-initial style, dark theme) ---- */
.person-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 3px;
  font-size: 12px;
  border-radius: var(--radius-full);
  font-size: 13px;
  margin: 3px 2px;
  white-space: nowrap;
  transition: all var(--transition-fast);
  font-weight: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: default;
  position: relative;
}
.person-chip:hover {
  border-color: var(--border-hover);
  background: rgba(56, 189, 248, 0.08);
}
/* Avatar circle */
.person-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: -0.5px;
}
/* Lead = cyan accent avatar */
.person-chip.is-lead .person-avatar {
  background: var(--accent);
  color: #020617;
}
/* Member = green avatar */
.person-chip.is-member .person-avatar {
  background: var(--success);
  color: #020617;
}
/* External = purple avatar */
.person-chip.is-ext .person-avatar {
  background: #a78bfa;
  color: #020617;
}
/* Load count - small number badge top-right of avatar */
.person-load-dot {
  position: absolute;
  top: -2px;
  left: 20px;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-full);
  line-height: 1.3;
  border: 2px solid var(--bg-card);
  z-index: 1;
}
.person-load-dot.over {
  background: var(--destructive);
  color: white;
}
.person-load-dot.under {
  background: var(--warning);
  color: #020617;
}
/* Overload/underload chip border glow */
.person-chip.load-over {
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
}
.person-chip.load-under {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
}
/* External indicator - subtle text */
.person-ext-label {
  font-size: 10px;
  color: #a78bfa;
  font-weight: 600;
  margin-left: -2px;
}
/* Legacy classes kept for compatibility */
span.lead, span.member { display: none; }
span.overload, span.underload { display: none; }
.badge, .area-tag, .ext-tag, .ext-dept-flag { display: none; }
.north-dot, .south-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin: 1px;
}
.north-dot { background: var(--accent); }
.south-dot { background: var(--warning); }

.status-active {
  color: var(--success);
  font-size: var(--text-xs);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.status-research {
  color: var(--warning);
  font-size: var(--text-xs);
  font-weight: 500;
}
.status-other {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

/* ---- Domain cards (Dark glass, glow hover) ---- */
.domain-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.domain-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-4);
  cursor: pointer;
  transition: all var(--transition-normal);
  text-align: center;
  border: 1px solid var(--border);
  min-height: 44px;
  position: relative;
  overflow: hidden;
}
.domain-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(56,189,248,0.04), rgba(167,139,250,0.04));
  opacity: 0;
  transition: opacity var(--transition-normal);
  border-radius: inherit;
}
.domain-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px) scale(1.02);
  border-color: var(--border-hover);
}
.domain-card:hover::before {
  opacity: 1;
}
.domain-card:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--accent);
}
.dc-icon {
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dc-icon svg { width: 28px; height: 28px; }
.dc-name {
  font-size: var(--text-xs);
  font-weight: 600;
  margin-bottom: var(--space-1);
  color: var(--text-primary);
}
.dc-count {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ---- Domain blocks ---- */
.domain-block {
  margin-bottom: var(--space-4);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: all var(--transition-normal);
}
.domain-block:hover { box-shadow: var(--shadow-md); border-color: var(--border-hover); }
.domain-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  cursor: pointer;
  user-select: none;
  flex-wrap: wrap;
  min-height: 44px;
  transition: all var(--transition-fast);
}
.domain-header:hover { background: rgba(56, 189, 248, 0.04); }
.domain-header svg { flex-shrink: 0; }
.domain-icon { display: inline-flex; align-items: center; }
.domain-icon svg { width: 20px; height: 20px; }
.domain-name { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); }
.domain-count {
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  font-weight: 500;
  border: 1px solid var(--border);
}
.domain-warning {
  font-size: var(--text-xs);
  color: var(--destructive);
  font-weight: 600;
  background: rgba(239, 68, 68, 0.1);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.domain-toggle {
  margin-left: auto;
  color: var(--text-muted);
  transition: transform var(--transition-normal);
  display: inline-flex;
  align-items: center;
}
.domain-toggle.collapsed { transform: rotate(-90deg); }
.domain-body { border-top: 1px solid var(--border); }
.domain-body.collapsed { display: none; }

/* ---- Load table ---- */
.load-table { width: 100%; border-collapse: collapse; }
.load-table th, .load-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}
.load-table th {
  background: rgba(56, 189, 248, 0.04);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.load-num {
  text-align: center;
  font-weight: 700;
  font-size: var(--text-base);
  font-family: var(--font-mono);
}
.load-over .load-num { color: var(--destructive); text-shadow: 0 0 8px rgba(239, 68, 68, 0.3); }
.load-under .load-num { color: var(--warning); text-shadow: 0 0 8px rgba(245, 158, 11, 0.3); }
.load-ok .load-num { color: var(--success); text-shadow: 0 0 8px rgba(34, 197, 94, 0.3); }

.load-badge {
  font-size: var(--text-xs);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.load-badge.over { background: rgba(239, 68, 68, 0.12); color: var(--destructive); }
.load-badge.under { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.load-badge.ok { background: rgba(34, 197, 94, 0.12); color: var(--success); }

.load-over td { background: rgba(239, 68, 68, 0.04); }
.load-under td { background: rgba(245, 158, 11, 0.04); }
.load-table tbody tr:hover td { background: rgba(56, 189, 248, 0.06) !important; }

.person-row {
  cursor: pointer;
  transition: background var(--transition-fast);
  min-height: 44px;
}
.expand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  margin-right: var(--space-1);
  transition: transform var(--transition-normal);
}
.expand-icon.open { transform: rotate(90deg); }
.expand-icon svg { width: 12px; height: 12px; }

.person-detail td {
  padding: 0 !important;
  border-bottom: 2px solid rgba(56, 189, 248, 0.15) !important;
}
.sp-table { width: 100%; border-collapse: collapse; margin: 0; }
.sp-table th {
  padding: var(--space-2) var(--space-3);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  background: rgba(56, 189, 248, 0.06);
  border-bottom: 1px solid var(--border);
}
.sp-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid rgba(56, 189, 248, 0.04);
  font-size: var(--text-xs);
  background: var(--bg-surface);
  color: var(--text-primary);
}
.sp-table tr:last-child td { border-bottom: none; }
.sp-id {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.sp-name { font-weight: 500; }
.sp-type-ih {
  font-size: 10px; padding: 1px 6px; border-radius: var(--radius-full);
  background: rgba(56, 189, 248, 0.12); color: var(--accent-bright); font-weight: 600;
}
.sp-type-os {
  font-size: 10px; padding: 1px 6px; border-radius: var(--radius-full);
  background: rgba(167, 139, 250, 0.12); color: #a78bfa; font-weight: 600;
}
.sp-type-pt {
  font-size: 10px; padding: 1px 6px; border-radius: var(--radius-full);
  background: rgba(244, 114, 182, 0.12); color: #f472b6; font-weight: 600;
}
.sp-role-lead {
  font-size: 10px; padding: 1px 6px; border-radius: var(--radius-full);
  background: rgba(56, 189, 248, 0.12); color: var(--accent-bright);
}
.sp-role-mem {
  font-size: 10px; padding: 1px 6px; border-radius: var(--radius-full);
  background: rgba(34, 197, 94, 0.12); color: var(--success);
}

/* ---- Charts ---- */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}
.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  height: 380px;
  position: relative;
  border: 1px solid var(--border);
  transition: all var(--transition-normal);
  overflow: hidden;
}
.chart-card:hover {
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.08);
  border-color: var(--border-hover);
}
.chart-title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-4);
  color: var(--accent-bright);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}
.chart-title svg { flex-shrink: 0; color: var(--accent); }
.chart-card canvas { max-height: 300px !important; }

/* ---- Loading (Dark) ---- */
.loading-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(2, 6, 23, 0.95);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; flex-direction: column; gap: var(--space-4);
}
.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 500;
}

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-card) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-card {
  height: 80px;
  border-radius: var(--radius-md);
}
.skeleton-row {
  height: 16px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
}

.error-banner {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--destructive);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  display: none;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}
.error-banner svg { flex-shrink: 0; }
.empty-state {
  text-align: center;
  padding: var(--space-10);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ---- Print ---- */
@media print {
  .header-actions, .filter-bar, .main-tabs, .legend, .charts-grid { display: none !important; }
  .tab-content { display: block !important; }
  .page { padding: 0; }
  .page-header { background: #020617 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .page-header, .stat-box, .table-wrap, .domain-block { box-shadow: none !important; }
}

@media (max-width: 1024px) {
  .charts-grid { grid-template-columns: 1fr; }
  .page { padding: var(--space-4); }
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .page-header { padding: var(--space-5) var(--space-5); }
}
@media (max-width: 640px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .filter-bar { flex-direction: column; gap: var(--space-2); }
  .filter-bar .search-input { width: 100%; }
  .search-wrap { width: 100%; }
  .pills { width: 100%; overflow-x: auto; flex-wrap: nowrap; gap: var(--space-1); -webkit-overflow-scrolling: touch; }
  .pill { white-space: nowrap; font-size: 11px; padding: 6px 10px; }
  .page-header { flex-direction: column; align-items: flex-start; padding: var(--space-4); }
  .page-title { font-size: var(--text-lg); }
  .page-sub { font-size: 11px; }
  .header-actions { width: 100%; justify-content: flex-end; }
  .main-tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; gap: 0; }
  .main-tab { white-space: nowrap; font-size: 12px; padding: var(--space-2) var(--space-3); }
  .legend { flex-wrap: wrap; gap: var(--space-1) var(--space-3); font-size: 11px; padding: var(--space-3); }
  .legend-sep { display: none; }
  table { min-width: 600px; }
  .stat-box { padding: var(--space-3); }
  .stat-num { font-size: var(--text-lg); }
  .stat-label { font-size: 10px; }
  .domain-cards { grid-template-columns: repeat(2, 1fr); }
  .chart-card { min-height: 250px; }
}
