:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #6b7280;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --accent: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --line: #e5e7eb;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  --radius: 20px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #d1fae5 0, transparent 35%), var(--bg);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; }
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(460px, 100%);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 28px;
  padding: 34px;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, #16a34a, #0891b2);
  color: white;
  font-weight: 900;
  font-size: 26px;
  box-shadow: 0 12px 28px rgba(22,163,74,.25);
  line-height: 1;
}
.brand h1, .brand p { margin: 0; }
.brand h1 { font-size: 24px; }
.brand p { color: var(--muted); font-size: 14px; }
.field { margin-bottom: 16px; }
label { display: block; margin-bottom: 8px; color: #374151; font-weight: 700; font-size: 14px; }
input, select, textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(22,163,74,.1); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 800;
  transition: .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-soft { background: #d1fae5; color: #065f46; }
.btn-blue { background: #dbeafe; color: #1e40af; }
.btn-amber { background: #fef3c7; color: #92400e; }
.btn-red { background: #fee2e2; color: #991b1b; }
.btn-full { width: 100%; }
.alert {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fef2f2;
  color: #991b1b;
  font-weight: 700;
  display: none;
}
.alert.show { display: block; }
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 280px;
  background: #064e3b;
  color: white;
  padding: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand p { color: #a7f3d0; }
.sidebar .brand { margin-bottom: 30px; }
.nav { display: grid; gap: 6px; }
.nav button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  background: transparent;
  color: #d1fae5;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: .2s ease;
}
.nav button .nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav button.active {
  background: linear-gradient(90deg, rgba(34,197,94,.4), rgba(255,255,255,.05));
  color: white;
  box-shadow: inset 3px 0 0 #4ade80;
}
.nav button:hover { background: rgba(255,255,255,.1); color: white; transform: translateX(2px); }
.main { flex: 1; padding: 28px; min-width: 0; animation: pageIn .35s cubic-bezier(.2,.7,.3,1); }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.topbar h2 { margin: 0; font-size: 30px; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card {
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(255,255,255,.75);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform .2s ease, box-shadow .2s ease;
}
.card.hover-lift:hover { transform: translateY(-3px); box-shadow: 0 28px 60px rgba(15,23,42,.12); }
.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon {
  position: absolute;
  right: 14px;
  top: 12px;
  font-size: 56px;
  opacity: .18;
  pointer-events: none;
  filter: grayscale(.1);
  transition: transform .3s ease;
}
.stat-card:hover .stat-icon { transform: scale(1.1) rotate(-5deg); opacity: .28; }
.stat-card.green { background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%); border-color: #a7f3d0; }
.stat-card.blue { background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); border-color: #bfdbfe; }
.stat-card.amber { background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%); border-color: #fde68a; }
.stat-card.purple { background: linear-gradient(135deg, #faf5ff 0%, #ede9fe 100%); border-color: #ddd6fe; }
.stat-title { color: var(--muted); font-weight: 800; position: relative; z-index: 1; }
.stat-value { font-size: 42px; font-weight: 900; margin-top: 8px; color: var(--primary-dark); position: relative; z-index: 1; }
.stat-card.blue .stat-value { color: #1e40af; }
.stat-card.amber .stat-value { color: #92400e; }
.stat-card.purple .stat-value { color: #5b21b6; }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-title h3 { margin: 0; font-size: 22px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #475569; font-size: 13px; background: #f0fdf4; }
tr:hover td { background: #f9fafb; }
.badge { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 900; }
.badge.active { background: #dcfce7; color: #166534; }
.badge.disabled { background: #e5e7eb; color: #374151; }
.toggle {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
}
.toggle input { display: none; }
.toggle .track {
  width: 42px; height: 24px; border-radius: 12px;
  background: #e5e7eb; position: relative; transition: .15s;
}
.toggle .track::after {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: white; transition: .15s;
}
.toggle input:checked + .track { background: var(--primary); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 420px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #064e3b;
  color: white;
  box-shadow: var(--shadow);
  display: none;
  z-index: 10;
}
.toast.show { display: block; }
.small { color: var(--muted); font-size: 13px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #ecfdf5; padding: 5px 7px; border-radius: 8px; color: #065f46; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .empty-icon { font-size: 56px; margin-bottom: 12px; display: block; opacity: .6; }
.empty .empty-text { font-size: 15px; font-weight: 600; }
.btn { transition: transform .15s ease, box-shadow .15s ease; }
.btn:active { transform: translateY(0) scale(.97); }
.btn-primary { box-shadow: 0 4px 12px rgba(22,163,74,.25); }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(22,163,74,.35); }
tr { transition: background .15s ease; }
.badge { transition: transform .15s ease; }
.badge:hover { transform: scale(1.05); }
.logo { transition: transform .3s ease; }
.brand:hover .logo { transform: rotate(-8deg) scale(1.05); }

.timetable-wrap { overflow-x: auto; padding: 10px 0; }
.timetable {
  border-collapse: separate;
  border-spacing: 8px;
  width: 100%;
  min-width: 900px;
  table-layout: fixed;
}
.timetable th, .timetable td {
  padding: 10px;
  text-align: center;
  border: 0;
  vertical-align: middle;
}
.timetable thead th {
  background: white;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  font-size: 13px;
  color: #475569;
  font-weight: 800;
  padding: 10px 6px;
}
.timetable .corner {
  background: linear-gradient(135deg, #a78bfa, #f472b6);
  color: white;
  font-weight: 900;
  border: 0;
}
.timetable .day-cell {
  font-weight: 900;
  border-radius: 14px;
  padding: 14px 10px;
  width: 110px;
  box-shadow: 0 2px 0 rgba(0,0,0,.04);
}
.timetable .day-mon { background: #fef9c3; color: #854d0e; }
.timetable .day-tue { background: #fce7f3; color: #9f1239; }
.timetable .day-wed { background: #dcfce7; color: #166534; }
.timetable .day-thu { background: #fed7aa; color: #9a3412; }
.timetable .day-fri { background: #dbeafe; color: #1e40af; }
.timetable .day-sat { background: #ede9fe; color: #5b21b6; }
.timetable .day-sun { background: #fee2e2; color: #991b1b; }

.timetable .slot {
  background: white;
  border: 2px solid #e5e7eb;
  border-radius: 14px;
  height: 78px;
  cursor: pointer;
  transition: .15s;
  position: relative;
  padding: 8px;
}
.timetable .slot:hover {
  border-color: var(--primary);
  background: #f0fdf4;
  transform: translateY(-1px);
}
.timetable .slot.filled {
  border-style: solid;
  background: #ecfdf5;
  border-color: #6ee7b7;
  cursor: grab;
}
.timetable .slot.filled:active { cursor: grabbing; }
.timetable .slot.dragging {
  opacity: 0.4;
  transform: scale(.96);
  border-style: dashed;
}
.timetable .slot.drop-target {
  border-color: var(--primary) !important;
  background: linear-gradient(135deg, #ecfdf5, #d1fae5) !important;
  transform: scale(1.05);
  box-shadow: 0 8px 20px rgba(22,163,74,.25);
}
.timetable .slot.swap-target {
  border-color: #f59e0b !important;
  background: linear-gradient(135deg, #fffbeb, #fef3c7) !important;
  transform: scale(1.05);
  box-shadow: 0 8px 20px rgba(245,158,11,.25);
}
.timetable .slot .subj {
  font-weight: 900;
  color: #065f46;
  font-size: 14px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.timetable .slot .room {
  font-size: 12px;
  color: #475569;
  margin-top: 4px;
}
.timetable .slot .del-x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(220,38,38,.1);
  color: #b91c1c;
  font-size: 14px;
  font-weight: 900;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
}
.timetable .slot.filled:hover .del-x { display: inline-flex; }
.timetable .slot .plus {
  color: #94a3b8;
  font-size: 22px;
  font-weight: 900;
}
.timetable .period-head { font-weight: 900; color: #475569; }
.timetable .period-head .period-time { font-size: 11px; color: #64748b; font-weight: 700; }
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  animation: fadeIn .15s ease;
}
.modal-overlay.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal {
  background: white;
  border-radius: 22px;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,.25);
  animation: slideUp .2s ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 8px;
}
.modal-header h3 { margin: 0; font-size: 22px; }
.modal-close {
  background: #f3f4f6;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 22px;
  color: #475569;
  display: grid; place-items: center;
}
.modal-close:hover { background: #e5e7eb; }
.modal-body { padding: 8px 24px 16px; }
.modal-footer {
  padding: 12px 24px 22px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-confirm-msg { padding: 4px 24px 18px; color: #475569; line-height: 1.6; }
.btn-ghost { background: transparent; color: #475569; }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #b91c1c; }
.status-pills { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  background: #f1f5f9;
  color: #64748b;
  border: 2px solid transparent;
  transition: all .15s ease;
}
.pill:hover { transform: translateY(-1px); background: #e2e8f0; }
.pill.present.active { background: #dcfce7; color: #166534; border-color: #22c55e; }
.pill.absent.active { background: #fee2e2; color: #991b1b; border-color: #ef4444; }
.pill.late.active { background: #fef3c7; color: #92400e; border-color: #f59e0b; }
.pill.leave.active { background: #dbeafe; color: #1e40af; border-color: #3b82f6; }
.pill.activity.active { background: #ede9fe; color: #5b21b6; border-color: #8b5cf6; }
.attendance-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px;
  border-radius: 14px;
  background: white;
  border: 2px solid #e5e7eb;
  cursor: pointer;
  transition: all .2s ease;
}
.attendance-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: 0 12px 28px rgba(22,163,74,.15); }
.attendance-card .a-period { font-size: 12px; color: var(--muted); font-weight: 800; }
.attendance-card .a-class { font-size: 18px; font-weight: 900; color: #064e3b; }
.attendance-card .a-subject { font-size: 14px; color: #475569; }
.attendance-card .a-status { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 800; }
.attendance-card.done { background: #ecfdf5; border-color: #22c55e; }
.attendance-card.partial { background: #fffbeb; border-color: #f59e0b; }
.view-toggle { display: inline-flex; background: #e5e7eb; border-radius: 12px; padding: 4px; gap: 2px; }
.view-toggle button {
  padding: 8px 14px; border-radius: 10px; background: transparent;
  font-weight: 800; color: #475569;
}
.view-toggle button.active { background: white; color: var(--primary-dark); box-shadow: 0 2px 6px rgba(0,0,0,.06); }
.class-tabs {
  display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap;
  border-bottom: 2px solid #e5e7eb; padding-bottom: 0;
}
.class-tabs button {
  padding: 10px 16px; background: transparent;
  font-weight: 800; color: #64748b;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  border-radius: 8px 8px 0 0;
  transition: all .15s ease;
}
.class-tabs button:hover { color: #166534; background: #f0fdf4; }
.class-tabs button.active { color: #166534; border-bottom-color: #16a34a; background: #f0fdf4; }
.class-tabs .count { font-size: 11px; color: #94a3b8; font-weight: 700; margin-left: 4px; }
.class-tabs button.active .count { color: #16a34a; }
@media (max-width: 900px) {
  .timetable { min-width: 720px; }
  .timetable .day-cell { width: 80px; padding: 10px 6px; font-size: 13px; }
  .timetable .slot { height: 64px; }
}
@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar { width: 100%; height: auto; position: static; }
  .main { padding: 18px; }
  .grid, .grid-2, .form-grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
}

@media print {
  body { background: white; }
  .sidebar, .topbar .actions, .toast, .modal-overlay { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; animation: none; }
  body > *:not(.shell) { display: none !important; }
  .main > section:not(#reportArea), .main > .topbar { display: none !important; }
  #reportArea { display: block !important; }
  #reportArea .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  #reportArea .stat-card .stat-icon { display: none; }
  #reportArea table { font-size: 12px; }
  #reportArea th, #reportArea td { padding: 6px; }
  @page { size: A4; margin: 1.5cm; }
}
