/* Modern UI Styling for TN Education Heatmap Dashboard */
:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(31, 41, 55, 0.9);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(224, 68, 167, 0.5);
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --pbi-magenta: #e044a7;
  --pbi-pink-light: #fce7f3;
  --pbi-pink-mid: #f472b6;
  --pbi-purple: #8b5cf6;
  --pbi-cyan: #06b6d4;
  --pbi-blue: #3b82f6;
  --pbi-emerald: #10b981;
  --pbi-amber: #f59e0b;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 25px rgba(224, 68, 167, 0.25);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

[data-theme="light"] {
  --bg-primary: #f3f4f6;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.95);
  --bg-card-hover: #ffffff;
  --border-color: #e5e7eb;
  --border-active: rgba(224, 68, 167, 0.6);
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 20px rgba(224, 68, 167, 0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Glassmorphism Classes */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: all 0.2s ease-in-out;
}

.glass-panel:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

/* App Header */
.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(12px);
}

.header-container {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #e044a7 0%, #8b5cf6 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(224, 68, 167, 0.4);
  color: white;
  font-size: 1.4rem;
}

.brand-title h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .brand-title h1 {
  background: linear-gradient(90deg, #111827 0%, #374151 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-title p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Tab Navigation */
.tab-navigation {
  display: flex;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

[data-theme="light"] .tab-navigation {
  background: rgba(0, 0, 0, 0.05);
}

.nav-tab {
  padding: 0.6rem 1.2rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  background: linear-gradient(135deg, #e044a7 0%, #c026d3 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(224, 68, 167, 0.35);
}

/* Action Controls in Header */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-action {
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-action:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-action.btn-export {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.3);
}

.btn-action.btn-export:hover {
  background: rgba(16, 185, 129, 0.25);
}

/* Dashboard Content */
.main-container {
  max-width: 1600px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  flex: 1;
}

.page-view {
  display: none;
  animation: fadeIn 0.3s ease forwards;
}

.page-view.active {
  display: block;
}

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

/* Control Filter Bar */
.filter-bar {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) 160px;
  gap: 1.25rem;
  align-items: center;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.filter-select, .filter-input {
  padding: 0.65rem 0.9rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  outline: none;
  transition: all 0.2s ease;
  width: 100%;
}

.filter-select:focus, .filter-input:focus {
  border-color: var(--pbi-magenta);
  box-shadow: 0 0 0 3px rgba(224, 68, 167, 0.2);
}

/* KPI Summary Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--pbi-magenta);
}

.kpi-card.kpi-avg::before { background: var(--pbi-magenta); }
.kpi-card.kpi-high::before { background: var(--pbi-emerald); }
.kpi-card.kpi-low::before { background: #ef4444; }
.kpi-card.kpi-spread::before { background: var(--pbi-purple); }

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.kpi-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.kpi-icon {
  font-size: 1.2rem;
  opacity: 0.7;
}

.kpi-value {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Main Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (max-width: 1100px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* Map Container */
.map-panel {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  height: 640px;
  position: relative;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.panel-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.map-wrapper {
  flex: 1;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
}

#map-page1, #map-page2, #map-page3 {
  width: 100%;
  height: 100%;
  background: transparent !important;
}

/* Map Custom Tooltip & Legend */
.map-legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(8px);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  box-shadow: var(--shadow-md);
}

[data-theme="light"] .map-legend {
  background: rgba(255, 255, 255, 0.95);
}

.legend-scale {
  display: flex;
  height: 10px;
  width: 160px;
  border-radius: 4px;
  margin: 6px 0;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Custom Leaflet Tooltip */
.custom-district-tooltip {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-active) !important;
  border-radius: 10px !important;
  padding: 10px 14px !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5) !important;
  font-family: var(--font-family) !important;
  font-size: 0.85rem !important;
}

.custom-district-tooltip::before {
  border-top-color: var(--bg-secondary) !important;
}

/* Table Panel & Ranked Districts */
.table-panel {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  height: 640px;
}

.table-search-bar {
  margin-bottom: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.table-container {
  flex: 1;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.data-table th {
  background: var(--bg-primary);
  color: var(--text-secondary);
  padding: 0.75rem 1rem;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  user-select: none;
}

.data-table th:hover {
  color: var(--text-primary);
}

.data-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s;
}

.data-table tr:hover td {
  background: var(--bg-card-hover);
}

.data-table tr.selected td {
  background: rgba(224, 68, 167, 0.15);
  border-color: rgba(224, 68, 167, 0.3);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.rank-1 { background: #fbbf24; color: #78350f; }
.rank-2 { background: #94a3b8; color: #0f172a; }
.rank-3 { background: #d97706; color: #fff; }

.val-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.val-bar-bg {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}

.val-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #f472b6 0%, #e044a7 100%);
  border-radius: 4px;
  transition: width 0.4s ease-out;
}

/* Page 2: Longitudinal Charts & Layout */
.chart-panel {
  padding: 1.5rem;
  height: 480px;
  display: flex;
  flex-direction: column;
}

.chart-wrapper {
  flex: 1;
  width: 100%;
  position: relative;
}

.udise-split-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (max-width: 1100px) {
  .udise-split-grid {
    grid-template-columns: 1fr;
  }
}

/* Badges & Tags */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-magenta {
  background: rgba(224, 68, 167, 0.15);
  color: #f472b6;
  border: 1px solid rgba(224, 68, 167, 0.3);
}

.badge-purple {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.badge-emerald {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Footer */
.app-footer {
  padding: 1.5rem 2rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: auto;
}

.app-footer a {
  color: var(--pbi-magenta);
  text-decoration: none;
  font-weight: 600;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}
