:root {
  --red: #d63a33;
  --red-dark: #b92e28;
  --red-soft: #fff1f2;
  --body: #f8f9fa;
  --panel: #ffffff;
  --text: #191919;
  --muted: #6b7280;
  --line: #e8e8ec;
  --sidebar: #ffffff;
  --sidebar-text: #323232;
  --topbar: rgba(255, 255, 255, .92);
  --shadow: 0 18px 42px rgba(31, 41, 55, .09);
  --radius: 8px;
}

[data-theme="dark"] {
  --body: #111113;
  --panel: #1b1b1f;
  --text: #f5f5f5;
  --muted: #a1a1aa;
  --line: #2f2f35;
  --sidebar: #17171a;
  --sidebar-text: #e5e7eb;
  --topbar: rgba(27, 27, 31, .92);
  --red-soft: rgba(214, 58, 51, .18);
  --shadow: 0 18px 42px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--body);
  font-family: "Poppins", system-ui, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

a { color: var(--red); text-decoration: none; }

.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 282px;
  min-height: 100vh;
  background: var(--sidebar);
  color: var(--sidebar-text);
  border-right: 1px solid var(--line);
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  transition: width .22s ease, transform .22s ease;
}

body.sidebar-collapsed .sidebar { width: 88px; }

.brand {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
}

.brand-logo,
.preloader-logo,
.auth-logo,
.brand-mark,
.avatar,
.auth-mark {
  background: var(--red);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: transparent;
  border-radius: var(--radius);
  flex: 0 0 auto;
}

.auth-logo {
  width: 124px;
  height: auto;
  object-fit: contain;
  background: transparent;
  margin-bottom: 18px;
}

.preloader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: var(--body);
  transition: opacity .35s ease, visibility .35s ease;
}

.preloader.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.preloader-card {
  min-width: 220px;
  padding: 28px;
  display: grid;
  place-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.preloader-logo {
  width: 90px;
  height: 90px;
  object-fit: contain;
  background: transparent;
  animation: logoPulse 1.2s ease-in-out infinite;
}

.loader-ring {
  width: 42px;
  height: 42px;
  border: 4px solid var(--red-soft);
  border-top-color: var(--red);
  border-radius: 999px;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes logoPulse { 50% { transform: scale(1.04); } }

.mobile-overlay {
  position: fixed;
  inset: 0;
  z-index: 1030;
  background: rgba(17, 24, 39, .48);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}

.mobile-overlay.show {
  opacity: 1;
  visibility: visible;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  flex: 0 0 auto;
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
}

.brand small {
  color: var(--muted);
  font-size: .76rem;
}

.sidebar-nav {
  display: grid;
  gap: 4px;
  overflow-y: auto;
}

.sidebar .nav-link,
.logout {
  color: var(--sidebar-text);
  border-radius: var(--radius);
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .9rem;
  font-weight: 500;
  transition: background .18s ease, color .18s ease;
}

.sidebar .nav-link i,
.logout i {
  color: var(--red);
  font-size: 1.08rem;
  flex: 0 0 22px;
  text-align: center;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active,
.logout:hover {
  background: var(--red-soft);
  color: var(--red);
}

.sidebar .nav-link.active {
  box-shadow: inset 3px 0 0 var(--red);
}

.logout { margin-top: auto; }

body.sidebar-collapsed .brand div,
body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .logout span {
  display: none;
}

.content-shell {
  min-width: 0;
  flex: 1;
  margin-left: 282px;
  transition: margin-left .22s ease;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body.sidebar-collapsed .content-shell { margin-left: 88px; }

.topbar {
  min-height: 72px;
  background: var(--topbar);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
}

.search-form {
  height: 42px;
  max-width: 520px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 13px;
}

.search-form input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  width: 100%;
}

.topbar-actions,
.head-actions,
.toolbar,
.calendar-strip,
.workflow,
.filter-pills,
.class-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.topbar-actions { margin-left: auto; }

.icon-btn,
.profile-btn,
.actions button,
.report-grid button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
}

.icon-btn,
.profile-btn {
  height: 40px;
  min-width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
}

.icon-btn:hover,
.profile-btn:hover,
.btn-light:hover,
.actions button:hover,
.report-grid button:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-soft);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--red);
  position: absolute;
  top: 8px;
  right: 9px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  font-size: .76rem;
}

.main-content { padding: 26px; flex: 1; }

.app-footer {
  padding: 18px 26px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: .88rem;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}

.breadcrumb {
  margin-bottom: 5px;
  font-size: .84rem;
}

.breadcrumb,
.breadcrumb a,
.breadcrumb-item.active { color: var(--muted); }

.page-head h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2vw, 2rem);
  font-weight: 800;
}

.kpi-grid,
.summary-grid,
.settings-grid,
.report-grid {
  display: grid;
  gap: 16px;
}

.kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 22px; }
.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.report-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 18px; }

.panel,
.kpi-card,
.summary-card,
.class-card,
.auth-card,
.insight-card,
.timeline-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel { padding: 20px; margin-bottom: 22px; }
.kpi-card { min-height: 152px; padding: 18px; }
.class-card { min-height: 270px; padding: 18px; }
.summary-card { padding: 18px; border-left: 4px solid var(--red); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel h2,
.class-card h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.panel-head span,
.kpi-card p,
.kpi-card small,
.summary-card span,
.class-card p,
.teacher-card p,
.notification-list small,
.profile-stack span {
  color: var(--muted);
}

.kpi-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: inline-grid;
  place-items: center;
  color: #fff;
  margin-bottom: 14px;
  background: var(--red);
}

.bg-red,
.bg-blue,
.bg-green,
.bg-violet,
.bg-orange,
.bg-cyan { background: var(--red); }

.kpi-card p,
.kpi-card small { margin: 0; }

.kpi-card strong,
.summary-card strong {
  display: block;
  font-size: 1.68rem;
  line-height: 1.1;
  margin: 5px 0 6px;
}

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  margin-bottom: 0;
  font-size: .9rem;
}

.table thead th {
  color: var(--text);
  background: var(--red-soft);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td,
.table th {
  padding: 13px 12px;
  vertical-align: middle;
  border-color: var(--line);
}

.table-responsive { width: 100%; }

.dataTables_wrapper,
.dt-container,
.dt-search,
.dt-length,
.dt-info,
.dt-paging {
  color: var(--text);
}

.dt-search input,
.dt-length select,
.form-control,
.form-select {
  background-color: var(--panel);
  border-color: var(--line);
  color: var(--text);
  border-radius: var(--radius);
}

.dt-search input:focus,
.form-control:focus,
.form-select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 .18rem rgba(214, 58, 51, .16);
}

.dt-container .dt-paging {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.dt-container .dt-paging .dt-paging-button.page-item.active .page-link,
.dt-container .pagination .page-item.active .page-link {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.dt-container .page-link {
  color: var(--red);
  background: var(--panel);
  border-color: var(--line);
}

.dt-container .page-link:hover {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.data-table tbody tr:hover,
.data-table tbody tr.selected {
  --bs-table-bg: var(--red-soft);
}

.actions { white-space: nowrap; }

.actions button {
  min-height: 31px;
  padding: 5px 8px;
  margin-right: 4px;
}

.notification-list,
.profile-stack {
  display: grid;
  gap: 10px;
}

.notification-list > div,
.profile-stack > div,
.calendar-strip span,
.workflow span,
.filter-pills button,
.notice-chip {
  border: 1px solid var(--line);
  background: var(--body);
  border-radius: var(--radius);
  padding: 11px 12px;
}

.timeline {
  position: relative;
  display: grid;
  gap: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  margin: 7px auto 0;
  border-radius: 999px;
  background: var(--red);
  box-shadow: 0 0 0 5px var(--red-soft);
}

.alert-stack {
  display: grid;
  gap: 10px;
}

.alert-row,
.quick-action {
  border: 1px solid var(--line);
  background: var(--body);
  border-radius: var(--radius);
  padding: 12px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.quick-action {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 8px;
  color: var(--text);
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.quick-action:hover,
.panel:hover,
.class-card:hover,
.kpi-card:hover {
  transform: translateY(-2px);
}

.quick-action:hover {
  border-color: var(--red);
  background: var(--red-soft);
}

.notification-list > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notification-list span { flex: 1; }

.profile-stack > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.teacher-card { text-align: center; }

.teacher-photo {
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  margin: 0 auto 14px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 1.35rem;
  font-weight: 800;
}

.workflow span.done {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.filter-pills { margin-bottom: 18px; }

.filter-pills button.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.class-card > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.class-card p { margin: 13px 0; }
.class-card a { overflow-wrap: anywhere; }
.class-actions { margin-top: 18px; justify-content: space-between; }

.progress {
  min-width: 160px;
  height: 18px;
  border-radius: 999px;
  background: var(--line);
}

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

.settings-grid label {
  color: var(--muted);
  font-size: .88rem;
  font-weight: 600;
}

.settings-grid .form-control,
.settings-grid .form-select { margin-top: 7px; }

.form-check {
  align-self: end;
  padding: 12px 12px 12px 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--body);
}

.form-check-input:checked {
  background-color: var(--red);
  border-color: var(--red);
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.quick-grid .btn {
  min-height: 70px;
}

.report-grid button {
  text-align: left;
  font-weight: 600;
  padding: 12px;
}

.nav-tabs,
.nav-pills { gap: 6px; }

.nav-tabs .nav-link,
.nav-pills .nav-link {
  border-radius: var(--radius);
  color: var(--muted);
}

.nav-pills .nav-link.active,
.nav-tabs .nav-link.active {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.notice-chip {
  display: inline-flex;
  margin: 4px;
}

.btn {
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 600;
}

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

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

.btn-outline-primary {
  color: var(--red);
  border-color: var(--red);
}

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

.btn-light {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}

.modal-content,
.dropdown-menu,
.toast {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
}

.dropdown-item { color: var(--text); }
.dropdown-item:hover { background: var(--red-soft); color: var(--red); }

.floating-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-floating > label {
  color: var(--muted);
}

.invalid-feedback,
.valid-feedback {
  display: block;
}

.calendar-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.calendar-toolbar .form-select {
  max-width: 220px;
}

.calendar-shell {
  min-height: 680px;
}

.fc {
  color: var(--text);
}

.fc .fc-button-primary {
  background: var(--red);
  border-color: var(--red);
}

.fc .fc-button-primary:hover,
.fc .fc-button-primary:not(:disabled).fc-button-active {
  background: var(--red-dark);
  border-color: var(--red-dark);
}

.fc .fc-toolbar-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.fc .fc-daygrid-event,
.fc .fc-timegrid-event {
  border-radius: 6px;
  border: 0;
  padding: 3px 5px;
}

.fc .fc-scrollgrid,
.fc-theme-standard td,
.fc-theme-standard th {
  border-color: var(--line);
}

.calendar-fallback {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
}

.calendar-day {
  min-height: 130px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--body);
  padding: 10px;
}

.calendar-event {
  margin-top: 8px;
  padding: 8px;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  font-size: .8rem;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.analytics-card {
  min-height: 340px;
}

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(214, 58, 51, .16), transparent 45%),
    radial-gradient(circle at bottom right, rgba(31, 41, 55, .14), transparent 36%),
    var(--body);
}

.auth-theme {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 10;
}

.auth-shell {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: .9fr 1.1fr;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.auth-side {
  background: var(--red);
  color: #fff;
  padding: 38px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
}

.auth-side h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
}

.auth-mark {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: #fff;
  color: var(--red);
}

.auth-card {
  box-shadow: none;
  border: 0;
  padding: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-card h2 {
  font-weight: 800;
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--muted);
}

.password-field {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--muted);
}

.auth-footer {
  position: fixed;
  bottom: 14px;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--muted);
  font-size: .86rem;
}

@media (max-width: 1199.98px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    width: 282px;
  }

  .sidebar.show { transform: translateX(0); }
  body.sidebar-collapsed .sidebar { width: 282px; }
  body.sidebar-collapsed .brand div,
  body.sidebar-collapsed .sidebar .nav-link span,
  body.sidebar-collapsed .logout span { display: block; }

  .content-shell,
  body.sidebar-collapsed .content-shell { margin-left: 0; }

  .kpi-grid,
  .summary-grid,
  .settings-grid,
  .report-grid,
  .quick-actions,
  .analytics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .auth-shell { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}

@media (max-width: 767.98px) {
  .topbar {
    align-items: stretch;
    flex-wrap: wrap;
    padding: 12px 14px;
    position: sticky;
    top: 0;
  }

  .search-form {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .main-content { padding: 18px 14px; }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions { gap: 6px; }
  .topbar-actions .btn span,
  .profile-copy { display: none; }

  .kpi-grid,
  .summary-grid,
  .settings-grid,
  .report-grid,
  .quick-grid,
  .quick-actions,
  .floating-grid,
  .analytics-grid { grid-template-columns: 1fr; }

  .panel,
  .class-card,
  .auth-card { padding: 16px; }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar { width: 100%; }
  .toolbar > * { flex: 1 1 150px; }

  .calendar-toolbar .form-select,
  .calendar-toolbar .btn {
    max-width: none;
    flex: 1 1 100%;
  }

  .calendar-shell {
    min-height: 560px;
  }

  .calendar-fallback {
    grid-template-columns: 1fr;
  }

  .auth-body {
    padding: 16px;
  }

  .auth-shell {
    margin: 46px 0 40px;
  }
}
