/* Black, Purple, and Gold Color System */
:root {
  /* Primary Colors - Purple palette */
  --primary: #7C3AED;
  --primary-light: #A855F7;
  --primary-dark: #5B21B6;
  --primary-50: #F3F0FF;
  --primary-100: #E9E5FF;
  --primary-200: #D4CDFF;
  
  /* Accent Colors - Gold */
  --accent: #F59E0B;
  --accent-light: #FCD34D;
  --accent-dark: #D97706;
  
  /* Neutral Colors - Black/White system */
  --bg: #FAFBFC;
  --surface: #FFFFFF;
  --surface-secondary: #F8F9FA;
  --text: #000000;
  --text-secondary: #1F2937;
  --text-muted: #6B7280;
  --border: #E5E7EB;
  --border-hover: #D1D5DB;
  
  /* Semantic Colors */
  --success: #10B981;
  --warning: #F59E0B;
  --error: #EF4444;
  
  /* Shadow System */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  
  /* Spacing Scale */
  --space-1: 0.25rem; /* 4px */
  --space-2: 0.5rem;  /* 8px */
  --space-3: 0.75rem; /* 12px */
  --space-4: 1rem;    /* 16px */
  --space-5: 1.25rem; /* 20px */
  --space-6: 1.5rem;  /* 24px */
  --space-8: 2rem;    /* 32px */
  --space-12: 3rem;   /* 48px */
  --space-16: 4rem;   /* 64px */
  
  /* Typography Scale */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px */
  --text-lg: 1.125rem;   /* 18px */
  --text-xl: 1.25rem;    /* 20px */
  --text-2xl: 1.5rem;    /* 24px */
  --text-3xl: 1.875rem;  /* 30px */
  --text-4xl: 2.25rem;   /* 36px */
  
  /* Border Radius */
  --radius-sm: 0.375rem; /* 6px */
  --radius-md: 0.5rem;   /* 8px */
  --radius-lg: 0.75rem;  /* 12px */
  --radius-xl: 1rem;     /* 16px */
}

/* Improved Typography with Modern System Font Stack */
* {
  box-sizing: border-box;
}

*::before, *::after {
  box-sizing: inherit;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
  position: relative;
  min-height: 100vh;
  font-size: var(--text-base);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -60px;
  background: var(--primary);
  color: white;
  padding: var(--space-3) var(--space-5);
  z-index: 1000;
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  font-size: var(--text-base);
}

.skip-link:focus {
  top: var(--space-4);
}

/* Header - Simplified Design */
header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: var(--space-8) 0;
  text-align: center;
  position: relative;
  border-bottom: 2px solid var(--primary-dark);
}

header h1 {
  margin: 0;
  font-size: clamp(var(--text-2xl), 5vw, var(--text-4xl));
  font-weight: 700;
  color: white;
  position: relative;
  z-index: 1;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

/* Main container */
main {
  padding: var(--space-8) var(--space-6);
  max-width: none;
  width: 100%;
  margin: 0 auto;
  background: var(--bg);
  min-height: calc(100vh - 120px);
}

.intro {
  text-align: center;
  margin-bottom: var(--space-8);
  padding: var(--space-6);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.intro p {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  margin: 0;
  font-weight: 500;
}

/* Simplified Button System */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--text);
  padding: var(--space-3) var(--space-6);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  border: 1px solid var(--accent-dark);
  cursor: pointer;
  font-size: var(--text-base);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--accent-dark);
  color: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn:focus-visible {
  outline: 3px solid var(--primary-200);
  outline-offset: 2px;
}

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-sm);
}

.btn[disabled]:hover, .btn[aria-disabled="true"]:hover {
  transform: none;
  box-shadow: var(--shadow-sm);
  background: var(--accent);
  color: var(--text);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-secondary);
  border-color: var(--border-hover);
  color: var(--text);
}

/* Simplified Table Design */
.table-container {
  overflow-x: auto;
  margin: 0;
  width: max-content;
  max-width: 100%;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: none;
}

.plans-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 520px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.plans-table th, .plans-table td {
  border: none;
  padding: var(--space-4) var(--space-3);
  text-align: center;
  vertical-align: middle;
  min-height: 56px;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.plans-table thead th {
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: 0.025em;
  text-transform: uppercase;
}

.plans-table thead th:first-child {
  border-top-left-radius: var(--radius-lg);
}

.plans-table thead th:last-child {
  border-top-right-radius: var(--radius-lg);
}

.plans-table tbody th[scope="row"] {
  background: var(--primary-50);
  color: var(--primary-dark);
  text-align: left;
  white-space: nowrap;
  font-weight: 600;
  border-right: 1px solid var(--border);
}

.plans-table tbody tr {
  background: var(--surface);
}

.plans-table tbody tr:nth-child(even) {
  background: var(--surface-secondary);
}

.plans-table tbody tr:hover {
  background: var(--primary-50);
}

.plans-table tbody tr:last-child th:first-child {
  border-bottom-left-radius: var(--radius-lg);
}

.plans-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: var(--radius-lg);
}

/* Cell content - simplified styling */
.cell-link {
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  text-decoration: none;
  background: var(--accent);
  color: var(--text);
  font-weight: 600;
  font-size: var(--text-sm);
  border: 1px solid var(--accent-dark);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.cell-link:hover {
  background: var(--accent-dark);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.cell-link:focus-visible {
  outline: 3px solid var(--primary-200);
  outline-offset: 2px;
}

.cell-empty {
  color: var(--text-muted);
  font-size: var(--text-sm);
  opacity: 0.7;
}

.cell-name {
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--text);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Stacked names */
.cell-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  align-items: center;
}

.cell-stack .cell-name {
  margin: 0;
  padding: var(--space-1) var(--space-2);
  font-size: 0.8rem;
}

.cell-stack .cell-link {
  margin: 0;
  padding: var(--space-1) var(--space-2);
  font-size: 0.8rem;
}

/* Active cell highlight */
.active-cell {
  background: var(--primary-50);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-200);
}

/* Layout system */
.layout {
  display: grid;
  grid-template-columns: minmax(450px, max-content) 1fr;
  gap: var(--space-8);
  align-items: start;
}

@media (max-width: 1100px) {
  .layout { 
    grid-template-columns: 1fr; 
    gap: var(--space-6);
  }
}

/* Teacher list container - cleaner design */
.teacher-list-container {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.view-toggle-buttons {
  margin-bottom: var(--space-5);
  display: flex;
  gap: var(--space-2);
  background: var(--surface-secondary);
  padding: var(--space-1);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.view-btn {
  flex: 1;
  height: 48px;
  padding: 0 var(--space-5);
  font-size: var(--text-sm);
  font-weight: 600;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-btn:hover {
  color: var(--text);
  background: var(--surface);
}

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

.teacher-content {
  transition: all 0.3s ease;
}

.subject-section, .cohort-section {
  margin-bottom: var(--space-8);
  background: var(--surface-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  border: 1px solid var(--border);
}

.subject-header, .cohort-header {
  margin: 0 0 var(--space-4) 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--primary-dark);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.teacher-list-vertical {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.teacher-btn {
  width: 100%;
  height: 56px;
  text-align: left;
  padding: 0 var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
  transition: all 0.2s ease;
}

.teacher-btn:hover {
  background: var(--surface);
  border-color: var(--primary-200);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.teacher-btn.active {
  background: var(--primary);
  border-color: var(--primary-dark);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.teacher-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--surface-secondary);
  transform: none;
}

.teacher-btn:disabled:hover {
  transform: none;
  box-shadow: none;
}

.cohort-tag, .subject-tag, .detail-tag {
  background: var(--primary-100);
  color: var(--primary-dark);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-xl);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--primary-200);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.teacher-btn.active .cohort-tag,
.teacher-btn.active .subject-tag,
.teacher-btn.active .detail-tag {
  background: var(--surface);
  color: var(--primary-dark);
  border-color: var(--primary-200);
}

.simple-list {
  display: grid;
  gap: var(--space-3);
}

/* Viewer - simplified design */
.viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  justify-self: stretch;
}

.viewer-header {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-5) var(--space-12);
  background: var(--surface-secondary);
  border-bottom: 1px solid var(--border);
}

.viewer-title {
  font-weight: 600;
  color: var(--primary-dark);
  font-size: var(--text-xl);
  text-align: center;
}

.viewer-actions {
  position: absolute;
  right: var(--space-5);
}

.viewer-actions a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--primary-50);
  border: 1px solid var(--primary-200);
  font-size: var(--text-sm);
  transition: all 0.2s ease;
}

.viewer-actions a:hover {
  background: var(--primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.viewer-tabs {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  background: var(--surface-secondary);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  font-size: var(--text-sm);
  transition: all 0.2s ease;
}

.tab:hover {
  background: var(--surface-secondary);
  border-color: var(--border-hover);
}

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

.tab .tab-title {
  font-weight: 500;
}

.tab .tab-close {
  appearance: none;
  border: none;
  background: var(--surface-secondary);
  color: inherit;
  cursor: pointer;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.tab .tab-close:hover {
  background: var(--border);
}

.tab.active .tab-close {
  background: rgba(255, 255, 255, 0.2);
}

.tab.active .tab-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.viewer-frame {
  display: block;
  width: 100%;
  height: 75vh;
  border: 0;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* Loading states */
.viewer-wrap {
  position: relative;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  overflow: hidden;
}

.viewer-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  z-index: 10;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.viewer-loading.active {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.viewer-error {
  font-size: var(--text-base);
  color: var(--error);
  font-weight: 500;
  text-align: center;
  padding: var(--space-5);
  background: #FEF2F2;
  border-radius: var(--radius-md);
  border: 1px solid #FECACA;
}

/* Special buttons */
.open-team-btn {
  margin-left: var(--space-3);
  padding: var(--space-1) var(--space-3);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--accent-dark);
  background: var(--accent-light);
  color: var(--text);
  border-radius: var(--radius-xl);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  transition: all 0.2s ease;
}

.open-team-btn:hover {
  background: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.open-all-team-btn,
.open-all-teachers-btn {
  background: var(--accent) !important;
  color: var(--text) !important;
  font-weight: 600 !important;
  border: 1px solid var(--accent-dark) !important;
  margin-bottom: var(--space-4);
}

.open-all-team-btn:hover,
.open-all-teachers-btn:hover {
  background: var(--accent-dark) !important;
  color: white !important;
  transform: translateY(-2px) !important;
  box-shadow: var(--shadow-md) !important;
}

.open-all-team-btn .cohort-tag,
.open-all-team-btn .detail-tag,
.open-all-teachers-btn .cohort-tag,
.open-all-teachers-btn .detail-tag {
  background: var(--accent-light) !important;
  color: var(--text) !important;
  border-color: var(--accent-dark) !important;
}

/* Accessibility improvements */
.visually-hidden {
  position: absolute !important;
  height: 1px; 
  width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}

/* Motion safety */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Responsive design improvements */
@media (max-width: 768px) {
  main {
    padding: var(--space-4) var(--space-4);
  }
  
  .intro {
    padding: var(--space-4);
    margin-bottom: var(--space-6);
  }
  
  .teacher-list-container {
    padding: var(--space-6);
  }
  
  .layout {
    gap: var(--space-4);
  }
  
  .table-container {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
  }
}

@media (max-width: 480px) {
  header {
    padding: var(--space-6) 0;
  }
  
  header h1 {
    font-size: var(--text-2xl);
  }
  
  .viewer-frame {
    height: 60vh;
  }
  
  .view-toggle-buttons {
    flex-direction: column;
    gap: var(--space-1);
  }
  
  .view-btn {
    height: 40px;
  }
}

/* Focus improvements for better accessibility */
*:focus-visible {
  outline: 3px solid var(--primary-200);
  outline-offset: 2px;
}

/* Improved scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--surface-secondary);
  border-radius: var(--radius-md);
}

::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: var(--radius-md);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Text selection */
::selection {
  background: var(--primary-200);
  color: var(--text);
}

::-moz-selection {
  background: var(--primary-200);
  color: var(--text);
}