:root {
  /* Dark Theme (Default) */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-panel: rgba(18, 18, 26, 0.7);
  --bg-card: rgba(25, 25, 35, 0.6);
  --bg-card-hover: rgba(35, 35, 50, 0.8);
  
  --text-primary: #ffffff;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #6366f1; /* Indigo */
  --accent-secondary: #8b5cf6; /* Violet */
  --accent-glow: rgba(99, 102, 241, 0.2);
  
  --status-success: #10b981;
  --status-warning: #f59e0b;
  --status-danger: #ef4444;
  --status-info: #3b82f6;

  --border-color: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.03);
  
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
  
  --glass-blur: blur(12px);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --border-radius: 16px;
  --border-radius-sm: 8px;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-panel: rgba(255, 255, 255, 0.8);
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: rgba(248, 250, 252, 1);
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --border-color: rgba(0, 0, 0, 0.08);
  --border-light: rgba(0, 0, 0, 0.03);
  
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.1);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}

/* Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  z-index: 100;
}

.sidebar-header {
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo i {
  font-size: 28px;
  -webkit-text-fill-color: var(--accent-primary);
}

.sidebar-menu {
  flex: 1;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.menu-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 16px 0 8px 12px;
  font-weight: 600;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  transition: var(--transition);
  font-weight: 500;
}

.menu-item i {
  font-size: 20px;
}

.menu-item:hover, .menu-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

.menu-item.active {
  background: var(--accent-glow);
  color: var(--accent-primary);
  border-right: 3px solid var(--accent-primary);
}

.sidebar-footer {
  padding: 20px 16px;
  border-top: 1px solid var(--border-color);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--border-radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  transition: var(--transition);
}

.user-profile:hover {
  background: var(--bg-card-hover);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: white;
  font-size: 14px;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-info .name {
  font-size: 14px;
  font-weight: 600;
}

.user-info .role {
  font-size: 12px;
  color: var(--text-muted);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  background: radial-gradient(circle at top right, var(--accent-glow) 0%, transparent 40%),
              radial-gradient(circle at bottom left, rgba(139, 92, 246, 0.1) 0%, transparent 40%);
}

.topbar {
  height: 72px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 8px 16px;
  width: 100%;
  max-width: 400px;
  transition: var(--transition);
}

.search-bar:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.search-bar i {
  color: var(--text-muted);
}

.search-bar input {
  border: none;
  background: none;
  outline: none;
  color: var(--text-primary);
  width: 100%;
  font-family: inherit;
  font-size: 14px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  font-size: 20px;
  color: var(--text-secondary);
  transition: var(--transition);
  position: relative;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.icon-btn .badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--status-danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-secondary);
}

.mobile-toggle {
  display: none;
  font-size: 24px;
  color: var(--text-primary);
}

/* View Container */
.view-container {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
  position: relative;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 16px;
}

.loading-state i {
  font-size: 32px;
  color: var(--accent-primary);
}

/* Common UI Components */
.page-header {
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Grid Layouts */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

/* KPI Card */
.kpi-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 24px;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-glow);
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  color: var(--text-secondary);
  font-weight: 500;
}

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent-primary);
}

.kpi-value {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.kpi-trend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
}

.trend-up { color: var(--status-success); }
.trend-down { color: var(--status-danger); }

/* Glass Panel */
.glass-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 24px;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.panel-title {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
}

.data-table tr:last-child td {
  border-bottom: none;
}

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

.student-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Badges */
.badge-status {
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  display: inline-block;
}

.badge-low { background: rgba(16, 185, 129, 0.1); color: var(--status-success); }
.badge-medium { background: rgba(245, 158, 11, 0.1); color: var(--status-warning); }
.badge-high { background: rgba(239, 68, 68, 0.1); color: var(--status-danger); }

/* AI Insights List */
.insight-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.insight-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  transition: var(--transition);
}

.insight-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-glow);
}

.insight-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.insight-content h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.insight-content p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.insight-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* SVG Chart Container */
.chart-container {
  width: 100%;
  height: 250px;
  position: relative;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fadeIn 0.4s ease forwards;
}

/* Responsive */
@media (max-width: 1024px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -260px;
    height: 100vh;
  }
  
  .sidebar.open {
    left: 0;
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
  }
  
  .mobile-toggle {
    display: block;
  }
  
  .topbar {
    padding: 0 16px;
  }
  
  .view-container {
    padding: 16px;
  }
  
  .search-bar {
    display: none; /* Hide on small screens for simplicity */
  }
}

/* Mode Switcher UI */
.mode-switcher {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: var(--border-radius-sm);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
  padding-right: 32px;
}
.mode-switcher:focus {
  border-color: var(--accent-primary);
}

/* AI Assistant Panel */
.ai-assistant-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  z-index: 1000;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.3);
}
.ai-assistant-panel.open {
  transform: translateX(-420px);
}
.assistant-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
}
.assistant-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 16px;
}
.assistant-chat {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.assistant-input-area {
  padding: 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
}
.assistant-suggestions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 4px;
}
.assistant-suggestions::-webkit-scrollbar { height: 4px; }
.suggestion-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: var(--transition);
}
.suggestion-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--accent-glow);
}
.input-wrapper {
  display: flex;
  align-items: center;
  position: relative;
}
.input-wrapper input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 12px 48px 12px 16px;
  border-radius: 24px;
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
  transition: var(--transition);
}
.input-wrapper input:focus {
  border-color: var(--accent-primary);
}
.send-btn {
  position: absolute;
  right: 4px;
  width: 36px;
  height: 36px;
  background: var(--accent-primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn:hover { background: var(--accent-secondary); color: white; }

/* Chat Bubbles */
.chat-msg {
  display: flex;
  gap: 12px;
  max-width: 90%;
  animation: fadeIn 0.3s ease-out forwards;
}
.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg .avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  font-size: 14px;
}
.chat-msg.ai .avatar {
  background: var(--accent-primary);
}
.chat-msg.user .avatar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
}
.chat-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  border-radius: 16px;
  border-top-left-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
}
.chat-msg.user .chat-bubble {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
  border-radius: 16px;
  border-top-right-radius: 4px;
}
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

@media (max-width: 768px) {
  .ai-assistant-panel {
    width: 100%;
    height: 80vh;
    right: 0;
    top: auto;
    bottom: -85vh;
    border-left: none;
    border-top: 1px solid var(--border-color);
    border-radius: 24px 24px 0 0;
    transform: translateY(0);
  }
  .ai-assistant-panel.open {
    transform: translateY(-85vh);
  }
}

/* Global Mode Density Variables */
:root {
  --mode-spacing-md: 24px;
  --mode-border-radius: 16px;
}
html[data-mode="teacher"] {
  --mode-spacing-md: 20px;
  --mode-border-radius: 12px;
}
html[data-mode="parent"] {
  --mode-spacing-md: 32px;
  --mode-border-radius: 24px;
}
html[data-mode="institute"] {
  --mode-spacing-md: 16px;
  --mode-border-radius: 8px;
}

html[data-mode] {
  --border-radius: var(--mode-border-radius);
}
.glass-panel { padding: var(--mode-spacing-md); }
.kpi-card { padding: var(--mode-spacing-md); }
