/* CSS Custom Design System - Dual Role & Excel Import/Export Version */
:root {
  --font-primary: 'Noto Sans TC', 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Color Palette - Vibrant Modern Dashboard */
  --bg-main: #f4f6f9;
  --bg-sidebar: #1e293b;
  --sidebar-hover: #334155;
  --sidebar-active: #2563eb;
  
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  /* Primary Actions */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  
  /* Role Themes */
  --teacher-badge-bg: #8b5cf6;
  --parent-badge-bg: #10b981;

  /* Emerald Green / Success */
  --success: #10b981;
  --success-bg: #d1fae5;
  --success-text: #065f46;
  
  /* Amber / Warning */
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  
  /* Rose / Danger */
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  
  /* Shadows & Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.05);
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-primary);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* App Container Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Styles */
.sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  flex-shrink: 0;
  box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 1.5rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.brand-text h2 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand-text span {
  font-size: 0.75rem;
  color: #94a3b8;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: transparent;
  border: none;
  color: #cbd5e1;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  width: 100%;
}

.nav-item i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

.nav-item:hover {
  background-color: var(--sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background-color: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding: 2rem;
  overflow-x: hidden;
  max-width: 100%;
}

/* Topbar Header */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  background: var(--card-bg);
  padding: 1.25rem 1.75rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.page-title h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-title p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Role Badges & Switch Role Button */
.role-badge-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.role-badge {
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: white;
}

.role-badge-teacher {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.role-badge-parent {
  background: linear-gradient(135deg, #10b981, #047857);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-role-switch {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
  padding: 0.5rem 0.85rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-role-switch:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* Tab Panels */
.tab-panel {
  display: none;
  animation: fadeIn 0.3s ease-in-out;
}

.tab-panel.active {
  display: block;
}

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

/* Toolbar Controls */
.panel-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.left-tools, .right-tools {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.toolbar-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box i {
  position: absolute;
  left: 1rem;
  color: var(--text-light);
}

.search-box input {
  padding: 0.6rem 1rem 0.6rem 2.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  width: 220px;
  transition: var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  width: 260px;
}

/* Buttons */
.btn-primary {
  background-color: var(--primary);
  color: white;
  border: none;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background-color: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.btn-secondary:hover {
  background-color: #e2e8f0;
  color: #0f172a;
}

.btn-danger-outline {
  background-color: transparent;
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.4);
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-danger-outline:hover {
  background-color: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* Template Download Button (Amber/Indigo) */
.btn-template {
  background: #f8fafc;
  color: #475569;
  border: 1px solid #cbd5e1;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
}

.btn-template:hover {
  background: #e2e8f0;
  color: #1e293b;
  border-color: #94a3b8;
}

/* Import Button (Indigo Accent) */
.btn-import {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  border: none;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.25);
}

.btn-import:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.35);
}

/* Export Button (Emerald Accent) */
.btn-export {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.25);
}

.btn-export:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(16, 185, 129, 0.35);
}

.btn-sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
}

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

.stat-card {
  background: var(--card-bg);
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  color: white;
  flex-shrink: 0;
}

.bg-blue { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.bg-emerald { background: linear-gradient(135deg, #10b981, #047857); }
.bg-purple { background: linear-gradient(135deg, #a855f7, #7e22ce); }
.bg-amber { background: linear-gradient(135deg, #f59e0b, #b45309); }
.bg-rose { background: linear-gradient(135deg, #f43f5e, #be123c); }

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

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-info h3 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 0.1rem;
}

/* Data Table Container */
.shadow-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.table-container {
  overflow-x: auto;
  max-width: 100%;
  position: relative;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
  text-align: left;
}

.data-table th, .data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table th {
  background-color: #f8fafc;
  color: #475569;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  z-index: 10;
  border-top: 1px solid var(--border-color);
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* Fixed Columns Styling */
.col-fixed {
  position: sticky;
  background-color: var(--card-bg);
  z-index: 5;
}

.data-table tbody tr:hover .col-fixed {
  background-color: #f8fafc;
}

.col-id { left: 0; min-width: 60px; text-align: center; }
.col-name { left: 60px; min-width: 110px; font-weight: 600; border-right: 2px solid #e2e8f0; }

.col-calc {
  font-weight: 600;
  background-color: #f8fafc;
}

.col-total { color: var(--primary); }
.col-avg { color: #0284c7; }
.col-rank { color: #d97706; text-align: center; }

/* Table Input Styling */
.input-score {
  width: 70px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  text-align: center;
  font-family: inherit;
  transition: var(--transition);
}

.input-score:focus {
  outline: none;
  border-color: var(--border-focus);
  background-color: #eff6ff;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Status Badges & Buttons */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.status-badge:hover {
  transform: scale(1.05);
}

.status-done {
  background-color: var(--success-bg);
  color: var(--success-text);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-none {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.status-warn {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.status-exempt {
  background-color: #f1f5f9;
  color: #64748b;
  border: 1px solid #cbd5e1;
}

/* Parent Portal Dashboard Specific Styling */
.parent-welcome-card {
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: white;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.parent-welcome-avatar {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #10b981, #059669);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.parent-welcome-info h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.parent-welcome-info p {
  color: #94a3b8;
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.parent-section {
  margin-bottom: 2rem;
}

.parent-section-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: #f8fafc;
}

.parent-section-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

/* Modals & Auth Tabs */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--card-bg);
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(0.95);
  transition: all 0.25s ease;
}

.modal-backdrop.active .modal-card {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 1.5rem;
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  background: #f1f5f9;
  padding: 0.35rem;
  border-radius: var(--radius-md);
}

.auth-tab-btn {
  flex: 1;
  padding: 0.65rem;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.auth-tab-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 0.4rem;
}

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-family: inherit;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.modal-footer {
  padding: 1rem 1.5rem;
  background: #f8fafc;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 2000;
}

.toast {
  background: var(--bg-sidebar);
  color: #fff;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 4px solid var(--primary);
}

.toast.success { border-left-color: var(--success); }
.toast.danger { border-left-color: var(--danger); }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Responsive Adjustments */
@media (max-width: 900px) {
  .app-container {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
  }
  .main-content {
    padding: 1rem;
  }
}
