/* ==========================================================================
   SIPENA: Sistem Penilaian Akademik SMAN 1 Banjar
   Design System: Swiss & Minimalist Modern Platform Architecture
   Compliant with W3C modern-web-guidance and modern-web-application-hardening
   ========================================================================== */

:root {
  color-scheme: light dark;
  accent-color: #1e40af;
  interpolate-size: allow-keywords;

  /* Color Palette — Academic Navy & Pure Swiss Tokens */
  --color-primary: #1e40af;
  --color-primary-hover: #1e3a8a;
  --color-primary-light: #eff6ff;
  --color-brand: #1e40af;
  
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-hover: #f1f5f9;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  
  --color-text-primary: #0f172a;
  --color-text-secondary: #475569;
  --color-text-tertiary: #64748b;
  --color-text-muted: #94a3b8;

  --color-success: #16a34a;
  --color-success-bg: #f0fdf4;
  --color-success-border: #bbf7d0;

  --color-warning: #d97706;
  --color-warning-bg: #fffbeb;
  --color-warning-border: #fde68a;

  --color-danger: #dc2626;
  --color-danger-bg: #fef2f2;
  --color-danger-border: #fecaca;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.06);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  --shadow-focus: 0 0 0 3px rgba(30, 64, 175, 0.2);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #090d16;
    --color-surface: #111827;
    --color-surface-hover: #1f2937;
    --color-border: #1f2937;
    --color-border-strong: #374151;

    --color-text-primary: #f8fafc;
    --color-text-secondary: #cbd5e1;
    --color-text-tertiary: #94a3b8;
    --color-text-muted: #64748b;

    --color-primary-light: rgba(30, 64, 175, 0.2);
    --color-success-bg: rgba(22, 163, 74, 0.15);
    --color-warning-bg: rgba(217, 119, 6, 0.15);
    --color-danger-bg: rgba(220, 38, 38, 0.15);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-hover: #f1f5f9;
  --color-border: #e2e8f0;
  --color-text-primary: #0f172a;
  --color-text-secondary: #475569;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #090d16;
  --color-surface: #111827;
  --color-surface-hover: #1f2937;
  --color-border: #1f2937;
  --color-text-primary: #f8fafc;
  --color-text-secondary: #cbd5e1;
}

/* Base resets & typography */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Standard W3C Scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}
@supports not (scrollbar-color: auto) {
  *::-webkit-scrollbar { width: 6px; height: 6px; }
  *::-webkit-scrollbar-thumb { background: var(--color-border-strong); border-radius: 4px; }
}

/* Focus visibility & high-contrast */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* App Shell */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: inherit;
}

.brand img {
  width: 38px;
  height: auto;
  object-fit: contain;
}

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

.brand-text p {
  font-size: 0.75rem;
  color: var(--color-text-tertiary);
  font-weight: 500;
}

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

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  font-size: 0.825rem;
  font-weight: 600;
}

.role-tag {
  background: var(--color-primary);
  color: #ffffff;
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: 700;
}

/* Layout Container */
.main-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
  flex: 1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  font-family: inherit;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

@media (prefers-reduced-motion: no-preference) {
  .btn {
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  }
  .btn:active {
    transform: scale(0.98);
  }
}

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

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

.btn-success {
  background: var(--color-success);
  color: #ffffff;
}
.btn-success:hover {
  filter: brightness(0.92);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

/* Forms & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.form-label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.form-input, .form-select {
  width: 100%;
  padding: 0.55rem 0.85rem;
  font-size: 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus, .form-select:focus {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.form-input:user-invalid {
  border-color: var(--color-danger);
}
.form-input:user-invalid:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

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

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  background: var(--color-primary-light);
  color: var(--color-primary);
  flex-shrink: 0;
}

.stat-content h3 {
  font-size: 0.78rem;
  color: var(--color-text-tertiary);
  font-weight: 600;
  text-transform: uppercase;
}

.stat-content p {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--color-text-primary);
  line-height: 1.1;
  margin-top: 0.2rem;
}

/* Weight Badge Strip */
.weights-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}

.weight-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  background: var(--color-primary-light);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 700;
}

/* Dynamic Gradebook Table Container */
.gradebook-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  position: relative;
  max-height: 75vh;
}

.gradebook-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  white-space: nowrap;
}

.gradebook-table th, .gradebook-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  text-align: center;
}

.gradebook-table thead th {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  font-weight: 700;
  font-size: 0.78rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.gradebook-table thead tr:first-child th {
  border-bottom: 2px solid var(--color-border-strong);
}

/* Sticky Student Columns */
.sticky-col-1 {
  position: sticky;
  left: 0;
  z-index: 20;
  background: var(--color-surface);
  width: 48px;
}
.sticky-col-2 {
  position: sticky;
  left: 48px;
  z-index: 20;
  background: var(--color-surface);
  width: 110px;
}
.sticky-col-3 {
  position: sticky;
  left: 158px;
  z-index: 20;
  background: var(--color-surface);
  min-width: 220px;
  text-align: left !important;
  box-shadow: 2px 0 5px rgba(0,0,0,0.04);
}

.gradebook-table thead th.sticky-col-1,
.gradebook-table thead th.sticky-col-2,
.gradebook-table thead th.sticky-col-3 {
  background: var(--color-bg);
  z-index: 30;
}

.gradebook-table tbody tr:hover td {
  background-color: var(--color-surface-hover);
}

/* Grade Cell Input */
.score-input {
  width: 58px;
  padding: 0.25rem 0.35rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-family: var(--font-mono);
  outline: none;
  transition: all 0.1s ease;
}

.score-input:focus {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
  background: #ffffff;
  color: #000000;
}

.score-input:user-invalid {
  border-color: var(--color-danger);
  background: var(--color-danger-bg);
}

/* Computed Values */
.computed-cell {
  font-family: var(--font-mono);
  font-weight: 700;
}

.grade-badge {
  display: inline-block;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 800;
}
.grade-a { background: #dcfce7; color: #15803d; }
.grade-b { background: #e0f2fe; color: #0369a1; }
.grade-c { background: #fef9c3; color: #a16207; }
.grade-d { background: #fee2e2; color: #b91c1c; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
}
.status-tuntas { background: var(--color-success-bg); color: var(--color-success); border: 1px solid var(--color-success-border); }
.status-belum { background: var(--color-danger-bg); color: var(--color-danger); border: 1px solid var(--color-danger-border); }

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

.toolbar-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

/* Login Fullscreen */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.5rem;
  background: var(--color-bg);
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.login-card img {
  width: 72px;
  height: auto;
  margin-bottom: 1rem;
}

/* Print View Override */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .app-header, .toolbar, .btn, .weights-strip, .theme-toggle-btn {
    display: none !important;
  }
  .main-container {
    max-width: 100% !important;
    padding: 0 !important;
  }
  .card, .gradebook-wrapper {
    border: none !important;
    box-shadow: none !important;
  }
  .score-input {
    border: none !important;
    background: transparent !important;
  }
}
