/*
 * OneRoster Application Styles
 * A clean, modern design system for the Eduframe OneRoster integration.
 */

:root {
  color-scheme: light;
  --color-surface: #ffffff;
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-light: #eef2ff;
  --color-secondary: #0f172a;
  --color-success: #059669;
  --color-success-light: #ecfdf5;
  --color-warning: #d97706;
  --color-warning-light: #fffbeb;
  --color-danger: #dc2626;
  --color-danger-light: #fef2f2;
  --color-gray-50: #f8fafc;
  --color-gray-100: #f1f5f9;
  --color-gray-200: #e2e8f0;
  --color-gray-300: #cbd5e1;
  --color-gray-400: #94a3b8;
  --color-gray-500: #64748b;
  --color-gray-600: #475569;
  --color-gray-700: #334155;
  --color-gray-800: #1e293b;
  --color-gray-900: #0f172a;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --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);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

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

body {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--color-gray-800);
  background-color: var(--color-gray-50);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

/* === Layout === */
.app-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Navigation === */
.navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-gray-200);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.navbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 4rem;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--color-gray-900);
  font-weight: 700;
  font-size: 1.125rem;
}

.navbar-brand svg {
  width: 1.75rem;
  height: 1.75rem;
  color: var(--color-primary);
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  text-decoration: none;
  color: var(--color-gray-600);
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

.nav-link:hover {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
}

.nav-link.active {
  color: var(--color-primary);
  background-color: var(--color-primary-light);
}

.nav-link svg {
  width: 1.125rem;
  height: 1.125rem;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.tenant-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.75rem;
  background: var(--color-gray-100);
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-gray-600);
}

.tenant-badge::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-success);
}

/* === Main Content === */
.main-content {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
}

/* === Page Header === */
.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-gray-900);
  margin: 0 0 0.25rem;
}

.page-header p {
  color: var(--color-gray-500);
  margin: 0;
  font-size: 0.9375rem;
}

/* === Cards === */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-gray-900);
  margin: 0;
}

.card-body {
  padding: 1.5rem;
}

.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-gray-100);
  background: var(--color-gray-50);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
}

.btn svg {
  width: 1rem;
  height: 1rem;
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-secondary {
  background-color: var(--color-surface);
  color: var(--color-gray-700);
  border-color: var(--color-gray-300);
}

.btn-secondary:hover {
  background-color: var(--color-gray-50);
  border-color: var(--color-gray-400);
}

.btn-danger {
  background-color: var(--color-surface);
  color: var(--color-danger);
  border-color: var(--color-gray-300);
}

.btn-danger:hover {
  background-color: var(--color-danger-light);
  border-color: var(--color-danger);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-ghost {
  background: transparent;
  color: var(--color-gray-600);
  border-color: transparent;
}

.btn-ghost:hover {
  background-color: var(--color-gray-100);
  color: var(--color-gray-900);
}

/* === Forms === */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-gray-700);
  margin-bottom: 0.375rem;
}

.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-gray-900);
  background-color: var(--color-surface);
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgb(79 70 229 / 0.1);
}

.form-inline {
  display: flex;
  align-items: end;
  gap: 0.75rem;
}

.form-inline .form-group {
  flex: 1;
  margin-bottom: 0;
}

/* === Tables === */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  background: var(--color-gray-50);
}

th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--color-gray-600);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-gray-200);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-gray-100);
  color: var(--color-gray-700);
}

tbody tr:hover {
  background-color: var(--color-gray-50);
}

code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 0.125rem 0.375rem;
  background: var(--color-gray-100);
  border-radius: 0.25rem;
  color: var(--color-gray-700);
}

/* === Flash Messages === */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.flash-notice {
  background-color: var(--color-success-light);
  color: var(--color-success);
  border: 1px solid #a7f3d0;
}

.flash-alert {
  background-color: var(--color-danger-light);
  color: var(--color-danger);
  border: 1px solid #fecaca;
}

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

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-gray-500);
  text-transform: uppercase;
  letter-spacing: 0.025em;
  margin-bottom: 0.25rem;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-gray-900);
}

/* === Progress Bar === */
.progress-bar-container {
  width: 100%;
  height: 0.5rem;
  background-color: var(--color-gray-200);
  border-radius: 9999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background-color: var(--color-primary);
  border-radius: 9999px;
  transition: width 0.5s ease;
}

.progress-bar.success {
  background-color: var(--color-success);
}

.progress-bar.danger {
  background-color: var(--color-danger);
}

/* === Status Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  text-transform: capitalize;
}

.badge-pending {
  background-color: var(--color-gray-100);
  color: var(--color-gray-600);
}

.badge-running {
  background-color: #dbeafe;
  color: #1d4ed8;
}

.badge-completed {
  background-color: var(--color-success-light);
  /* Darker than --color-success: 5.2:1 on the light background (AA). */
  color: #047857;
}

.badge-failed {
  background-color: var(--color-danger-light);
  /* Darker than --color-danger: 5.9:1 on the light background (AA). */
  color: #b91c1c;
}

/* === Sync Progress === */
.sync-timeline {
  position: relative;
  padding-left: 1.5rem;
}

.sync-timeline::before {
  content: "";
  position: absolute;
  left: 0.5rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-gray-200);
}

.sync-step {
  position: relative;
  padding: 0.75rem 0;
  padding-left: 1.5rem;
}

.sync-step::before {
  content: "";
  position: absolute;
  left: -1.125rem;
  top: 1.15rem;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--color-gray-300);
  border: 2px solid white;
  box-shadow: var(--shadow-sm);
}

.sync-step.completed::before {
  background: var(--color-success);
}

.sync-step.running::before {
  background: var(--color-primary);
  animation: pulse 1.5s infinite;
}

.sync-step.failed::before {
  background: var(--color-danger);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgb(79 70 229 / 0.4); }
  50% { box-shadow: 0 0 0 6px rgb(79 70 229 / 0); }
}

.sync-step-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--color-gray-800);
  text-transform: capitalize;
}

.sync-step-meta {
  font-size: 0.8125rem;
  color: var(--color-gray-500);
  margin-top: 0.125rem;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-gray-500);
}

.empty-state svg {
  width: 3rem;
  height: 3rem;
  margin-bottom: 1rem;
  color: var(--color-gray-300);
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-gray-700);
  margin: 0 0 0.25rem;
}

.empty-state p {
  margin: 0;
  font-size: 0.875rem;
}

/* === Login Page === */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1.5rem;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-gray-900);
  margin: 1rem 0 0.5rem;
}

.login-card p {
  color: var(--color-gray-500);
  margin: 0 0 1.5rem;
  font-size: 0.9375rem;
}

.login-logo {
  width: 3.5rem;
  height: 3.5rem;
  color: var(--color-primary);
  margin: 0 auto;
}

.login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1.5rem;
  background-color: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
  font-family: inherit;
}

.login-btn:hover {
  background-color: var(--color-primary-hover);
}

/* === Quick Actions === */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.action-card {
  background: var(--color-surface);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.action-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.action-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.action-icon svg {
  width: 1.25rem;
  height: 1.25rem;
}

.action-icon.primary {
  background-color: var(--color-primary-light);
  color: var(--color-primary);
}

.action-icon.success {
  background-color: var(--color-success-light);
  color: var(--color-success);
}

.action-icon.warning {
  background-color: var(--color-warning-light);
  color: var(--color-warning);
}

.action-content h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-gray-900);
  margin: 0 0 0.25rem;
}

.action-content p {
  font-size: 0.8125rem;
  color: var(--color-gray-500);
  margin: 0;
}

/* === Responsive === */
@media (max-width: 768px) {
  .navbar-nav {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }

  .form-inline {
    flex-direction: column;
    align-items: stretch;
  }
}

/* === Utility === */
.text-muted { color: var(--color-gray-500); }
.text-sm { font-size: 0.8125rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }


/* --- Accessibility ------------------------------------------------------- */

/* Visible keyboard focus for all interactive elements (a11yproject: Keyboard). */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius);
}

/* Skip link: visually hidden until keyboard-focused (a11yproject: Controls). */
.skip-link {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 100;
  padding: 0.5rem 1rem;
  background-color: var(--color-primary);
  color: #ffffff;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
  transform: translateY(-300%);
}

.skip-link:focus {
  transform: translateY(0);
}

/* Screen-reader-only content (table captions etc.). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Honour reduced-motion preferences (a11yproject: Animation). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* The skip-link target receives focus programmatically (tabindex="-1"); it is
   not interactive, so don't draw the focus ring around the whole region. */
#main-content:focus,
#main-content:focus-visible {
  outline: none;
}
/* --- Dark mode ------------------------------------------------------------ */
/*
 * Applied via html[data-theme="dark"]. The inline script in the layout head
 * resolves the theme (saved preference, falling back to prefers-color-scheme)
 * before first paint; the navbar toggle switches and persists it. Without
 * JavaScript the app stays in light mode.
 */
[data-theme="dark"] {
  color-scheme: dark;
  --color-surface: #1e293b;
  /* Lighter accents so text/icons keep AA contrast on dark surfaces. */
  --color-primary: #a5b4fc;
  --color-primary-hover: #c7d2fe;
  --color-primary-light: rgb(99 102 241 / 0.18);
  --color-secondary: #e2e8f0;
  --color-success: #34d399;
  --color-success-light: rgb(16 185 129 / 0.15);
  --color-warning: #fbbf24;
  --color-warning-light: rgb(245 158 11 / 0.15);
  --color-danger: #f87171;
  --color-danger-light: rgb(239 68 68 / 0.15);
  /* Inverted gray ramp: existing component styles keep working unchanged. */
  --color-gray-50: #0f172a;
  --color-gray-100: #1e293b;
  --color-gray-200: #334155;
  --color-gray-300: #475569;
  --color-gray-400: #64748b;
  --color-gray-500: #94a3b8;
  --color-gray-600: #cbd5e1;
  --color-gray-700: #e2e8f0;
  --color-gray-800: #f1f5f9;
  --color-gray-900: #f8fafc;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.5), 0 1px 2px -1px rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
}

/* Filled controls keep the strong indigo background so their white text
   stays at 5.5:1 (the lighter dark-mode --color-primary is for text/icons). */
[data-theme="dark"] .btn-primary,
[data-theme="dark"] .skip-link,
[data-theme="dark"] .login-btn {
  background-color: #4f46e5;
  border-color: #4f46e5;
}

[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .login-btn:hover {
  background-color: #6366f1;
  border-color: #6366f1;
}

[data-theme="dark"] .progress-bar {
  background-color: #6366f1;
}

/* Status colors tuned for dark surfaces (all >= 4.5:1 on their backgrounds). */
[data-theme="dark"] .badge-running {
  background-color: #1e3a8a;
  color: #bfdbfe;
}

[data-theme="dark"] .badge-completed {
  color: #34d399;
}

[data-theme="dark"] .badge-failed {
  color: #fca5a5;
}

[data-theme="dark"] .flash-notice {
  border-color: #065f46;
}

[data-theme="dark"] .flash-alert {
  border-color: #7f1d1d;
}

/* The sun/moon icons inside the theme toggle. Visibility is driven by the
   html[data-theme] attribute the pre-paint head script sets, so the correct
   icon shows before any body JavaScript runs. */
.theme-toggle-icon {
  width: 1.125rem;
  height: 1.125rem;
}

.theme-icon-sun {
  display: none;
}

[data-theme="dark"] .theme-icon-sun {
  display: inline;
}

[data-theme="dark"] .theme-icon-moon {
  display: none;
}

/* The skip-link target receives focus programmatically (tabindex="-1"); it is
   not interactive, so don't draw the focus ring around the whole region. */
#main-content:focus,
#main-content:focus-visible {
  outline: none;
}
