/* ============================================================
   SI-MUTASI SISWA - SMP NEGERI 5 MUARA SIRAM
   Vanilla CSS Modern Design System
   ============================================================ */

:root {
  --primary: #1e3a8a;
  --primary-light: #3b82f6;
  --primary-dark: #172554;
  --primary-gradient: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  
  --emerald: #059669;
  --emerald-light: #d1fae5;
  --emerald-dark: #064e3b;
  
  --amber: #d97706;
  --amber-light: #fef3c7;
  --amber-dark: #78350f;
  
  --rose: #e11d48;
  --rose-light: #ffe4e6;
  
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.12), 0 8px 10px -6px rgba(0,0,0,0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

/* ============================================================
   LAYOUT WRAPPER
   ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: 270px;
  background-color: #0f172a;
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  border-right: 1px solid #1e293b;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 12px;
}

.school-badge-icon {
  width: 44px;
  height: 44px;
  background: var(--primary-gradient);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

.sidebar-brand h2 {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #ffffff;
  line-height: 1.2;
}

.sidebar-brand p {
  font-size: 11px;
  color: var(--slate-400);
  font-weight: 500;
  margin-top: 2px;
}

/* NAV LINKS */
.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  color: var(--slate-300);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  transition: all 0.2s ease;
  cursor: pointer;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.06);
  color: white;
}

.nav-item.active {
  background: var(--primary-gradient);
  color: white;
  box-shadow: 0 4px 14px rgba(37,99,235,0.25);
}

.nav-item i {
  width: 18px;
  height: 18px;
}

/* SIDEBAR FOOTER (SUPABASE STATUS) */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid #1e293b;
  background-color: rgba(15, 23, 42, 0.6);
}

.cloud-status-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #1e293b;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  border: 1px solid #334155;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #94a3b8;
}

.dot.online {
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.dot.offline {
  background-color: #f59e0b;
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main-content {
  margin-left: 270px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* TOPBAR */
.topbar {
  background-color: white;
  border-bottom: 1px solid var(--border);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.topbar-title h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--slate-900);
}

.topbar-title p {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary-gradient);
  color: white;
  box-shadow: 0 2px 6px rgba(37,99,235,0.25);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-success {
  background-color: var(--emerald);
  color: white;
}

.btn-success:hover {
  background-color: #047857;
}

.btn-outline {
  background-color: white;
  border-color: var(--border);
  color: var(--slate-700);
}

.btn-outline:hover {
  background-color: var(--slate-50);
  border-color: var(--slate-300);
}

.btn-danger {
  background-color: var(--rose);
  color: white;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

/* PAGE CONTENT CONTAINER */
.page-body {
  padding: 28px 32px;
  flex: 1;
}

/* ============================================================
   STATISTICS CARDS (DASHBOARD)
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 28px;
}

.stat-card {
  background-color: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.stat-info p {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--slate-500);
  margin-bottom: 4px;
}

.stat-info h3 {
  font-size: 26px;
  font-weight: 800;
  color: var(--slate-900);
  line-height: 1;
}

.stat-info span {
  font-size: 11px;
  color: var(--slate-400);
  margin-top: 6px;
  display: inline-block;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon.emerald { background-color: #ecfdf5; color: var(--emerald); }
.stat-icon.amber { background-color: #fffbeb; color: var(--amber); }
.stat-icon.blue { background-color: #eff6ff; color: var(--primary-light); }
.stat-icon.purple { background-color: #f5f3ff; color: #8b5cf6; }

/* ============================================================
   BANNER KOP SEKOLAH KESISWAAN
   ============================================================ */
.school-hero-banner {
  background: linear-gradient(135deg, #1e3a8a 0%, #1e293b 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.school-hero-text h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.school-hero-text p {
  font-size: 12.5px;
  color: #cbd5e1;
  margin-top: 4px;
}

.school-hero-meta {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 11.5px;
  color: #93c5fd;
}

.school-hero-actions {
  display: flex;
  gap: 10px;
}

/* ============================================================
   CARD CONTAINERS & CONTROLS
   ============================================================ */
.card {
  background-color: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title h3 {
  font-size: 16px;
  font-weight: 800;
  color: var(--slate-900);
}

.card-title .badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: var(--radius-full);
}

.badge-in { background-color: var(--emerald-light); color: var(--emerald-dark); }
.badge-out { background-color: var(--amber-light); color: var(--amber-dark); }

.card-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input-wrap {
  position: relative;
}

.search-input-wrap i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--slate-400);
}

.search-input {
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  width: 220px;
  outline: none;
  transition: all 0.2s;
}

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

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--slate-700);
  outline: none;
  background-color: white;
}

/* ============================================================
   TABLE STYLING
   ============================================================ */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  background-color: var(--slate-50);
  color: var(--slate-600);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--slate-800);
  vertical-align: middle;
}

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

.student-name-cell {
  font-weight: 700;
  color: var(--slate-900);
}

.sub-cell {
  font-size: 11px;
  color: var(--slate-500);
}

.class-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 700;
}

.pill-vii { background-color: #e0f2fe; color: #0369a1; }
.pill-viii { background-color: #f3e8ff; color: #7e22ce; }
.pill-ix { background-color: #fef3c7; color: #b45309; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--slate-400);
}

.empty-state i {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
}

/* ============================================================
   MODALS (POPUP FORM INPUT)
   ============================================================ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background-color: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 800;
  color: var(--slate-900);
}

.btn-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--slate-400);
  transition: color 0.2s;
}

.btn-close:hover {
  color: var(--slate-700);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.col-span-2 {
  grid-column: span 2;
}

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--slate-700);
}

.form-input, .form-select, .form-textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--slate-800);
  outline: none;
  transition: all 0.2s;
}

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

.form-textarea {
  resize: vertical;
  min-height: 60px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background-color: var(--slate-50);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* ============================================================
   SETTINGS VIEW (SUPABASE & BACKUP)
   ============================================================ */
.settings-box {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

.settings-box h4 {
  font-size: 16px;
  font-weight: 800;
  color: var(--slate-900);
  margin-bottom: 6px;
}

.settings-box p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 18px;
}

.code-block {
  background-color: #0f172a;
  color: #38bdf8;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-family: 'Consolas', monospace;
  font-size: 12px;
  overflow-x: auto;
  margin: 12px 0;
  line-height: 1.5;
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background-color: #0f172a;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.25s ease-out;
}

.toast.success { border-left: 4px solid var(--emerald); }
.toast.error { border-left: 4px solid var(--rose); }

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

/* ============================================================
   PRINT MEDIA STYLES (A4 LANDSCAPE RESMI KESISWAAN)
   ============================================================ */
@media print {
  @page {
    size: A4 landscape;
    margin: 1cm;
  }
  
  body {
    background-color: white !important;
    color: black !important;
    font-size: 9pt;
  }
  
  .sidebar, .topbar, .school-hero-banner, .card-controls, .btn, .modal-overlay, .toast-container, .no-print {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0 !important;
  }
  
  .page-body {
    padding: 0 !important;
  }
  
  .card {
    border: none !important;
    box-shadow: none !important;
  }

  .print-kop {
    display: block !important;
    text-align: center;
    border-bottom: 3px double #000;
    padding-bottom: 8px;
    margin-bottom: 16px;
  }

  .print-kop h3 { font-size: 12pt; text-transform: uppercase; margin: 0; }
  .print-kop h2 { font-size: 14pt; text-transform: uppercase; margin: 2px 0; }
  .print-kop h1 { font-size: 16pt; font-weight: bold; margin: 2px 0; }
  .print-kop p { font-size: 8.5pt; margin: 1px 0; }

  .print-title {
    display: block !important;
    text-align: center;
    margin-bottom: 14px;
  }

  .print-title h3 {
    font-size: 12pt;
    font-weight: bold;
    text-decoration: underline;
  }

  .data-table {
    border-collapse: collapse !important;
    width: 100% !important;
    font-size: 8pt !important;
  }

  .data-table th, .data-table td {
    border: 1px solid #000 !important;
    padding: 4px 6px !important;
    color: #000 !important;
  }

  .data-table th {
    background-color: #f1f5f9 !important;
  }

  .print-signatures {
    display: flex !important;
    justify-content: space-between;
    margin-top: 30px;
    page-break-inside: avoid;
  }

  .sig-col {
    text-align: center;
    width: 250px;
  }

  .sig-space {
    height: 55px;
  }

  .sig-name {
    font-weight: bold;
    text-decoration: underline;
  }
}

/* ============================================================
   MOBILE RESPONSIVE & OFF-CANVAS DRAWER
   ============================================================ */
.mobile-menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  color: var(--slate-700);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.mobile-menu-btn:hover {
  background-color: var(--slate-100);
}

.btn-close-sidebar {
  display: none;
  background: none;
  border: none;
  color: var(--slate-400);
  cursor: pointer;
  padding: 4px;
}

.btn-close-sidebar:hover {
  color: white;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  z-index: 45;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

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

/* TABLET BREAKPOINT (<= 1024px) */
@media screen and (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .school-hero-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
}

/* MOBILE BREAKPOINT (<= 768px) */
@media screen and (max-width: 768px) {
  .mobile-menu-btn {
    display: inline-flex;
  }

  .btn-close-sidebar {
    display: block;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
  }

  .main-content {
    margin-left: 0;
    width: 100%;
  }

  .topbar {
    padding: 12px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .topbar-left {
    justify-content: flex-start;
  }

  .topbar-title h1 {
    font-size: 17px;
  }

  .topbar-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }

  .topbar-actions .btn {
    padding: 7px 11px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .page-body {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-info h3 {
    font-size: 22px;
  }

  .stat-icon {
    width: 40px;
    height: 40px;
  }

  .school-hero-banner {
    padding: 18px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
  }

  .school-hero-text h2 {
    font-size: 16px;
  }

  .school-hero-meta {
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
  }

  .school-hero-actions {
    width: 100%;
  }

  .school-hero-actions a {
    width: 100%;
    text-align: center;
  }

  .card-header {
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .card-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .search-input-wrap, .search-input {
    width: 100% !important;
  }

  .filter-select {
    width: 100%;
  }

  .card-controls .btn {
    width: 100%;
  }

  /* MODALS MOBILE */
  .modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }

  .modal-card {
    max-height: 94vh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .modal-body {
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .form-group.col-span-2 {
    grid-column: span 1;
  }

  .form-input, .form-select, .form-textarea {
    font-size: 15px; /* iOS friendly minimum to avoid auto zoom */
    padding: 10px 12px;
    min-height: 42px;
  }

  /* TOAST MOBILE */
  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }

  .toast {
    width: 100%;
  }
}

/* SMALL PHONES (<= 480px) */
@media screen and (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions .btn-text {
    display: none;
  }

  .topbar-actions .btn {
    padding: 8px 12px;
  }
}

.print-kop, .print-title, .print-signatures {
  display: none;
}


/* USER ROLE CONTROLS (MODE GURU & MODE ADMIN) */
.user-role-badge-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.role-subpill {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

@media screen and (max-width: 640px) {
  .role-subpill {
    display: none;
  }
}
