/* ==========================================
   TOP HERITAGE SMS — CLEAN MODERN LIGHT THEME
   ========================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  /* === Core Palette (Derived from TH-logo.jpeg) === */
  --primary: #7B2D8B;
  /* Top Heritage Deep Purple */
  --primary-hover: #642072;
  /* Rich darker violet */
  --primary-light: #F8F0FA;
  /* Soft violet tint */
  --primary-border: #EAD6EF;
  /* Gentle violet border tint */

  --success: #10B981;
  --success-light: #ECFDF5;
  --success-border: #A7F3D0;

  --warning: #F59E0B;
  --warning-light: #FFFBEB;
  --warning-border: #FDE68A;

  --danger: #EF4444;
  --danger-light: #FEF2F2;
  --danger-border: #FECACA;

  --purple: #8B5CF6;
  --purple-light: #F5F3FF;
  --purple-border: #DDD6FE;

  --orange: #F97316;
  --orange-light: #FFF7ED;
  --orange-border: #FED7AA;

  --teal: #14B8A6;
  --teal-light: #F0FDFA;

  /* === Legacy variable aliases (keeps existing HTML/JS inline styles working) === */
  --primary-teal: var(--primary);
  --primary-teal-hover: var(--primary-hover);
  --primary-teal-glow: rgba(123, 45, 139, 0.12);
  --accent-amber: var(--warning);
  --accent-rose: var(--danger);
  --accent-emerald: var(--success);
  --accent-indigo: var(--purple);

  /* === Backgrounds === */
  --bg-page: #F1F5F9;
  --bg-white: #FFFFFF;
  --bg-obsidian: #F1F5F9;
  /* legacy alias */
  --bg-deep-navy: #FFFFFF;
  /* legacy alias */
  --bg-surface: #F8FAFC;
  /* legacy alias */
  --bg-surface-hover: #F1F5F9;
  /* legacy alias */

  /* === Text === */
  --text-primary: #0F172A;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --text-white: #0F172A;
  /* legacy alias — now dark */
  --text-dark: #0F172A;

  /* === Borders === */
  --border: #E2E8F0;
  --border-glass: #E2E8F0;
  /* legacy alias */
  --border-focus: #EAD6EF;

  /* === Shadows === */
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --shadow-glow: none;
  --shadow-xsx: none;
  --shadow-smx: none;
  --shadow-mdx: none;
  --shadow-lgx: none;
  --shadow-glowx: none;
  --shadow-mdz: none;

  /* === Typography === */
  --font-display: 'Plus Jakarta Sans', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;

  /* === Layout === */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 80px;
  --topbar-height: 68px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
}

/* ==========================================
   RESET & BASE
   ========================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  box-shadow: none !important;
}

html {
  scroll-behavior: smooth;
}

*::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

*::-webkit-scrollbar-track {
  background: var(--bg-page);
}

*::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 20px;
}

*::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #CBD5E1 var(--bg-page);
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--primary-hover);
}

button,
input,
select,
textarea {
  font-family: inherit;
}

/* ==========================================
   CORE CARD (replaces glass-card)
   ========================================== */
.glass-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.glass-card:hover {
  box-shadow: var(--shadow-mdz);
  border-color: #CBD5E1;
}

/* ==========================================
   FORMS
   ========================================== */
.form-group {
  margin-bottom: 18px;
  position: relative;
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-white);
  border: 1.5px solid #CBD5E1;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
  background: var(--bg-white);
}

.form-input::placeholder {
  color: #94A3B8;
}

select.form-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' viewBox='0 0 24 24'%3E%3Cpath stroke='%2394A3B8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all 0.18s ease;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-white);
  border-color: var(--border);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  background: var(--bg-page);
  border-color: #CBD5E1;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #DC2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
  transform: translateY(-1px);
}

.btn-accent {
  background: var(--warning);
  color: #fff;
  border-color: var(--warning);
}

.btn-accent:hover {
  background: #D97706;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

/* ==========================================
   ICON-ONLY ACTION BUTTONS (Table/Card Actions)
   ========================================== */
.btn-action {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  font-size: 0.875rem;
  flex-shrink: 0;
  text-decoration: none;
}

.btn-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Edit — Indigo tint */
.btn-action-edit {
  background: #EEF2FF;
  color: #4F46E5;
}

.btn-action-edit:hover {
  background: #E0E7FF;
  color: #4338CA;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(79, 70, 229, 0.2);
}

/* View — Slate tint */
.btn-action-view {
  background: #F8FAFC;
  color: #475569;
  border: 1px solid #E2E8F0;
}

.btn-action-view:hover {
  background: #F1F5F9;
  color: #334155;
  transform: translateY(-1px);
}

/* Delete — Red tint */
.btn-action-delete {
  background: #FEF2F2;
  color: #EF4444;
}

.btn-action-delete:hover {
  background: #FEE2E2;
  color: #DC2626;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(239, 68, 68, 0.2);
}

/* ==========================================
   BADGES
   ========================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-success {
  background: var(--success-light);
  color: #065F46;
  border: 1px solid var(--success-border);
}

.badge-danger {
  background: var(--danger-light);
  color: #991B1B;
  border: 1px solid var(--danger-border);
}

.badge-warning {
  background: var(--warning-light);
  color: #92400E;
  border: 1px solid var(--warning-border);
}

.badge-info {
  background: var(--primary-light);
  color: #1E40AF;
  border: 1px solid var(--primary-border);
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

/* ==========================================
   APP SHELL LAYOUT
   ========================================== */
.app-container {
  display: flex;
  min-height: 100vh;
}

.btn-menu-toggle {
  display: none !important;
}

/* ==========================================
   SIDEBAR
   ========================================== */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.sidebar-header {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-icon {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: var(--font-display);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(123, 45, 139, 0.35);
  overflow: hidden;
}

.logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.logo-text {
  font-size: 1rem;
  font-weight: 800;
  font-family: var(--font-display);
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.logo-sub {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  font-family: var(--font-body);
  letter-spacing: 0.02em;
  margin-top: 1px;
}

.sidebar-section-label {
  padding: 14px 16px 4px;
  font-size: 0.65rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.sidebar-menu {
  flex: 1;
  padding: 8px 12px;
  list-style: none;
  overflow-y: auto;
}

.menu-item {
  margin-bottom: 2px;
}

.menu-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: #334155;
  font-weight: 500;
  font-size: 0.925rem;
  transition: all 0.15s ease;
  position: relative;
}

.menu-link svg,
.menu-link i {
  width: 18px;
  height: 18px;
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 0.8;
  transition: opacity 0.15s ease;
}

.menu-link:hover {
  background: var(--bg-page);
  color: var(--primary);
}

.menu-link:hover svg,
.menu-link:hover i {
  opacity: 1;
}

.menu-item.active .menu-link {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.menu-item.active .menu-link svg,
.menu-item.active .menu-link i {
  opacity: 1;
  color: var(--primary);
}

/* Dropdown toggle button reset */
button.menu-link {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

/* Chevron positioning and rotation */
.menu-chevron {
  margin-left: auto;
  width: 14px !important;
  height: 14px !important;
  transition: transform 0.2s ease;
  opacity: 0.7;
}

.menu-dropdown.expanded .menu-chevron {
  transform: rotate(180deg);
}

/* Submenu layout with vertical connector line and smooth height transition */
.sidebar-submenu {
  list-style: none;
  padding-left: 14px;
  margin-left: 20px;
  border-left: 1.5px solid var(--border);
  margin-top: 2px;
  margin-bottom: 4px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-dropdown.expanded .sidebar-submenu {
  max-height: 320px;
}

/* Connector line turns brand purple when any child is active */
.menu-dropdown.active .sidebar-submenu {
  border-left-color: var(--primary-border);
}

/* Active parent toggle button highlight */
.menu-item.menu-dropdown.active>.dropdown-toggle {
  color: var(--primary);
  font-weight: 600;
}

.menu-item.menu-dropdown.active>.dropdown-toggle svg,
.menu-item.menu-dropdown.active>.dropdown-toggle i {
  opacity: 1;
  color: var(--primary);
}

.submenu-item {
  margin-bottom: 2px;
}

.submenu-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.865rem;
  transition: all 0.15s ease;
}

.submenu-link svg,
.submenu-link i {
  width: 15px;
  height: 15px;
  font-size: 0.85rem;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.15s ease;
}

.submenu-link:hover {
  background: var(--bg-page);
  color: var(--primary);
}

.submenu-link:hover svg,
.submenu-link:hover i {
  opacity: 1;
}

.submenu-item.active .submenu-link {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.submenu-item.active .submenu-link svg,
.submenu-item.active .submenu-link i {
  opacity: 1;
  color: var(--primary);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.user-snippet {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-page);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary-light);
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-display);
}

.user-role {
  font-size: 0.7rem;
  color: var(--primary);
  font-weight: 600;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ==========================================
   MAIN VIEWPORT
   ========================================== */
.app-viewport {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* TOPBAR */
.app-topbar {
  height: var(--topbar-height);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 99;
  box-shadow: var(--shadow-xs);
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

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

/* VIEWPORT BODY */
.viewport-body {
  padding: 28px;
  flex: 1;
}

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

.heritage-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.heritage-table th {
  background: #F8FAFC;
  padding: 12px 16px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.heritage-table td {
  padding: 13px 16px;
  border-bottom: 1px solid #F1F5F9;
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: background 0.15s ease;
}

.heritage-table tbody tr:hover td {
  background: #FAFBFD;
}

.heritage-table tbody tr:last-child td {
  border-bottom: none;
}

/* ==========================================
   STAT CARDS
   ========================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 26px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-details {
  flex: 1;
  min-width: 0;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-display);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 800;
  font-family: var(--font-display);
  color: var(--text-primary);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

/* Colorful stat cards (like sample) */
.stat-card-blue {
  background: linear-gradient(135deg, #3B82F6, #2563EB);
  border-color: transparent !important;
}

.stat-card-teal {
  background: linear-gradient(135deg, #14B8A6, #0D9488);
  border-color: transparent !important;
}

.stat-card-purple {
  background: linear-gradient(135deg, #8B5CF6, #7C3AED);
  border-color: transparent !important;
}

.stat-card-orange {
  background: linear-gradient(135deg, #F97316, #EA580C);
  border-color: transparent !important;
}

.stat-card-green {
  background: linear-gradient(135deg, #10B981, #059669);
  border-color: transparent !important;
}

.stat-card-rose {
  background: linear-gradient(135deg, #F43F5E, #E11D48);
  border-color: transparent !important;
}

.stat-card-blue .stat-label,
.stat-card-blue .stat-value,
.stat-card-teal .stat-label,
.stat-card-teal .stat-value,
.stat-card-purple .stat-label,
.stat-card-purple .stat-value,
.stat-card-orange .stat-label,
.stat-card-orange .stat-value,
.stat-card-green .stat-label,
.stat-card-green .stat-value,
.stat-card-rose .stat-label,
.stat-card-rose .stat-value {
  color: rgba(255, 255, 255, 0.92) !important;
}

.stat-card-blue .stat-icon,
.stat-card-teal .stat-icon,
.stat-card-purple .stat-icon,
.stat-card-orange .stat-icon,
.stat-card-green .stat-icon,
.stat-card-rose .stat-icon {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* ==========================================
   MODALS
   ========================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 16px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  width: 100%;
  max-width: 560px;
  transform: translateY(-16px) scale(0.98);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
}

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

.modal-header h3 {
  font-size: 1.05rem;
  color: var(--text-primary);
}

.modal-close {
  background: var(--bg-page);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1.1rem;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

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

/* ==========================================
   TOAST NOTIFICATIONS
   ========================================== */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
  width: calc(100% - 40px);
}

.toast {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  transform: translateX(calc(100% + 24px));
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.active {
  transform: translateX(0);
}

.toast-icon-container {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.toast-success {
  border-left: 3px solid var(--success);
}

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

.toast-error {
  border-left: 3px solid var(--danger);
}

.toast-error .toast-icon-container {
  background: var(--danger-light);
  color: var(--danger);
}

.toast-info {
  border-left: 3px solid var(--primary);
}

.toast-info .toast-icon-container {
  background: var(--primary-light);
  color: var(--primary);
}

.toast-warning {
  border-left: 3px solid var(--warning);
}

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

.toast-content-wrapper {
  flex: 1;
}

.toast-h {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-display);
  margin-bottom: 2px;
}

.toast-b {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ==========================================
   GRID LAYOUTS
   ========================================== */
.row-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

/* ==========================================
   AUTH PAGES (login/signup)
   ========================================== */
.auth-page {
  min-height: 100vh;
  background: var(--bg-page);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: var(--font-display);
  box-shadow: 0 2px 8px rgba(123, 45, 139, 0.35);
  overflow: hidden;
}

.auth-logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.auth-logo-text {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--font-display);
}

.auth-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 6px;
  font-family: var(--font-display);
}

.auth-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.text-muted {
  color: var(--text-muted) !important;
}

.text-primary-color {
  color: var(--primary) !important;
}

.text-success {
  color: var(--success) !important;
}

.text-danger {
  color: var(--danger) !important;
}

.text-warning {
  color: var(--warning) !important;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-display);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================
   EMPTY / LOADING STATES
   ========================================== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.35;
}

/* ==========================================
   LUCIDE ICON SIZING HELPERS
   ========================================== */
.icon-xs {
  width: 14px;
  height: 14px;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.icon-md {
  width: 20px;
  height: 20px;
}

.icon-lg {
  width: 24px;
  height: 24px;
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 230px;
  }

  .viewport-body {
    padding: 20px;
  }
}

@media (max-width: 768px) {
  .btn-menu-toggle {
    display: inline-flex !important;
  }

  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .app-viewport {
    margin-left: 0;
  }

  .app-topbar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px 12px !important;
    padding: 12px 16px !important;
    height: auto !important;
  }

  .page-title {
    order: 1 !important;
  }

  .btn-menu-toggle {
    order: 2 !important;
    margin-right: 0 !important;
  }

  .topbar-actions {
    order: 3 !important;
    width: 100% !important;
    justify-content: space-between !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    margin-top: 4px !important;
  }

  .viewport-body {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px !important;
  }

  .stats-grid .stat-card {
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 14px 12px !important;
    gap: 12px !important;
    border-radius: 12px !important;
  }

  .stats-grid .stat-icon {
    width: 38px !important;
    height: 38px !important;
    font-size: 0.95rem !important;
    border-radius: 8px !important;
  }

  .stats-grid .stat-label {
    font-size: 0.65rem !important;
    margin-bottom: 2px !important;
    letter-spacing: 0.02em !important;
  }

  .stats-grid .stat-value {
    font-size: 1.125rem !important;
  }

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

  .premium-kpi-card {
    padding: 14px 12px !important;
    min-height: 100px !important;
    border-radius: 12px !important;
  }

  .premium-kpi-card .kpi-label {
    font-size: 0.72rem !important;
  }



  .premium-kpi-card .kpi-subtext {
    font-size: 0.68rem !important;
  }

  .premium-kpi-card .kpi-icon-bg {
    font-size: 2.2rem !important;
    right: 8px !important;
    bottom: 8px !important;
  }

  .row-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 28px 20px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal-content {
    max-width: 100%;
  }
}

/* ==========================================
   SYSTEM-WIDE LIGHT THEME LEGIBILITY OVERRIDES
   ========================================== */

/* Overrides to make all white text legible inside glass cards, modals, and tables */
body .glass-card h1,
body .modal-content h1,
body .glass-card h2,
body .modal-content h2,
body .glass-card h3,
body .modal-content h3,
body .glass-card h4,
body .modal-content h4,
body .glass-card h5,
body .modal-content h5,
body .glass-card h6,
body .modal-content h6,
body .glass-card p,
body .modal-content p,
body .glass-card label,
body .modal-content label,
body .glass-card strong,
body .modal-content strong,
body .glass-card li,
body .modal-content li,
body .glass-card code,
body .modal-content code,
body .glass-card td,
body .modal-content td,
body .glass-card th,
body .modal-content th,
body .glass-card span:not(.badge):not(.user-role):not([class*="btn"]),
body .modal-content span:not(.badge):not(.user-role):not([class*="btn"]),
body .glass-card div:not(.stat-card):not(.stat-details):not(.user-info):not(.user-snippet):not(.logo-icon):not([class*="btn"]):not([class*="stat-card-"]),
body .modal-content div:not([class*="btn"]),
body .glass-card:not([class*="stat-card-"]) [style*="color: #fff"],
body .glass-card:not([class*="stat-card-"]) [style*="color:#fff"],
body .modal-content:not([class*="stat-card-"]) [style*="color: #fff"],
body .modal-content:not([class*="stat-card-"]) [style*="color:#fff"],
body .glass-card a:not([class*="btn"]),
body .modal-content a:not([class*="btn"]),
body .report-card-body,
body .report-school-name,
body .report-info-value,
body .report-remark-text,
body .student-name-cell,
body .score-cell .score-total,
body .report-results-table td:first-child,
body .report-summary-row td {
  color: var(--text-primary) !important;
}

/* Ensure report card body itself has a light background instead of dark transparent */
body .report-card-body {
  background: var(--bg-surface) !important;
  border-color: var(--border) !important;
}

/* Make sure report school header has correct line color */
body .report-school-header {
  border-bottom-color: var(--primary) !important;
}

/* Make sure report info box has correct border and bg */
body .report-student-info {
  background: var(--primary-light) !important;
  border-color: var(--primary-border) !important;
}

/* Allow text-muted to still be muted gray */
body .glass-card .text-muted,
body .modal-content .text-muted,
body .glass-card p[style*="color: var(--text-muted)"],
body .glass-card span[style*="color: var(--text-muted)"],
body .report-school-sub,
body .report-info-label {
  color: var(--text-secondary) !important;
}

/* Exclude elements that should genuinely remain white (like status badges or button texts) */
body .glass-card .btn *,
body .modal-content .btn *,
body .btn-primary,
body .btn-primary *,
body .btn-danger,
body .btn-danger *,
body .btn-accent,
body .btn-accent *,
body .stat-card-blue *,
body .stat-card-teal *,
body .stat-card-purple *,
body .stat-card-orange *,
body .stat-card-green *,
body .stat-card-rose * {
  color: #fff !important;
}

/* Explicitly style default stat cards (white background) so their labels, values, and icons are perfectly visible */
body .stat-card:not([class*="stat-card-"]) .stat-label {
  color: var(--text-secondary) !important;
}

body .stat-card:not([class*="stat-card-"]) .stat-value {
  color: var(--text-primary) !important;
}

/* Keep default stat icon blue but allow inline style icons (teal, rose, emerald, warning) to shine */
body .stat-card:not([class*="stat-card-"]) .stat-icon {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

body .stat-card:not([class*="stat-card-"]) .stat-icon i {
  color: inherit;
}

/* High specificity styles for badges to ensure they never fall back to white/invisible text */
body .badge-info {
  background: var(--primary-light) !important;
  color: #1E40AF !important;
  border: 1px solid var(--primary-border) !important;
}

body .badge-primary {
  background: var(--primary-light) !important;
  color: var(--primary) !important;
  border: 1px solid var(--primary-border) !important;
}

body .badge-success {
  background: var(--success-light) !important;
  color: #065F46 !important;
  border: 1px solid var(--success-border) !important;
}

body .badge-danger {
  background: var(--danger-light) !important;
  color: #991B1B !important;
  border: 1px solid var(--danger-border) !important;
}

body .badge-warning {
  background: var(--warning-light) !important;
  color: #92400E !important;
  border: 1px solid var(--warning-border) !important;
}

/* Ensure date picker icons are visible in light theme */
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.2);
  cursor: pointer;
}

/* ==========================================
   PREMIUM KPI CARDS (DASHBOARD REDESIGN)
   ========================================== */
.premium-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 26px;
}

.premium-kpi-card {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  padding: 24px 20px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.05);
  container-type: inline-size;
}

.premium-kpi-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.premium-kpi-card .kpi-label {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
  opacity: 0.85;
  color: #ffffff;
  margin-bottom: 4px;
}

.premium-kpi-card .kpi-value {
  font-size: clamp(1.25rem, 14cqw, 2.1rem);
  font-weight: 800;
  color: #ffffff;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
  z-index: 2;
  white-space: nowrap;
}

.premium-kpi-card .kpi-subtext {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.75;
  color: #ffffff;
  z-index: 2;
}

.premium-kpi-card .kpi-icon-bg {
  position: absolute;
  right: 18px;
  bottom: 12px;
  font-size: 4rem;
  opacity: 0.15;
  color: #ffffff;
  pointer-events: none;
  transition: transform 0.3s ease;
  z-index: 1;
}

.premium-kpi-card:hover .kpi-icon-bg {
  transform: scale(1.1) rotate(-5deg);
  opacity: 0.22;
}

/* Card-Specific Backdrops (Derived from logo brand purple theme) */
.kpi-card-students {
  background: var(--primary) !important;
  /* Top Heritage Deep Purple */
}

.kpi-card-teachers {
  background: #200E24 !important;
  /* Obsidian Deep Plum */
}

.kpi-card-revenue {
  background: linear-gradient(135deg, #7B2D8B, #4B1055) !important;
  /* Royal Violet Gradient */
}

.kpi-card-attendance {
  background: #5B21B6 !important;
  /* Royal Amethyst */
}

/* Ensure all nested text inside premium kpi card remains white */
.premium-kpi-card * {
  color: #ffffff !important;
}

/* Export Dropdown Menu */
.dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 110;
  min-width: 140px;
  display: none;
  padding: 6px 0;
}

.dropdown-menu.active {
  display: block;
}

.dropdown-item {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s ease;
}

.dropdown-item:hover {
  background: var(--bg-page);
  color: var(--primary);
}

/* ==========================================
   PRINT MEDIA & DYNAMIC PDF EXPORT STYLES
   ========================================== */
@media print {
  body.printing-active {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.printing-active .app-container,
  body.printing-active .modal-overlay,
  body.printing-active #toast-container,
  body.printing-active #sidebar-backdrop,
  body.printing-active .sidebar-backdrop {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
  }

  #print-section {
    display: block !important;
    visibility: visible !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    z-index: 9999999;
  }
}

@media screen {
  #print-section {
    display: none !important;
  }
}

/* ==========================================
   RESPONSIVE FILTER BAR UTILITIES
   ========================================== */
.filters-bar {
  margin-bottom: 24px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.filter-row-top {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 250px;
}

.filter-item-category {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.filter-select {
  width: auto;
  min-width: 180px;
  padding: 8px 12px;
}

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

.filter-date-group {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  flex: 1;
}

.filter-date-item {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filter-date-input {
  width: 140px;
  padding: 8px 12px;
}

.btn-reset-filters {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
}

@media (max-width: 768px) {
  .filter-row-top {
    flex-direction: column;
    align-items: stretch !important;
    gap: 12px;
  }

  .search-input-wrapper {
    width: 100%;
    min-width: unset;
  }

  .filter-item-category {
    width: 100%;
    justify-content: space-between;
  }

  .filter-select {
    flex: 1;
    width: 100% !important;
    min-width: unset;
  }

  .filter-row-bottom {
    flex-direction: column;
    align-items: stretch !important;
    gap: 12px;
  }

  .filter-date-group {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 12px;
  }

  .filter-date-item {
    width: 100%;
    justify-content: space-between;
  }

  .filter-date-item label {
    min-width: 60px;
  }

  .filter-date-input {
    flex: 1;
    width: 100% !important;
    min-width: unset;
  }

  .btn-reset-filters {
    width: 100%;
    justify-content: center;
  }
}

/* ==========================================
   PREMIUM APP PRELOADER
   ========================================== */
.app-preloader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  z-index: 999999;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.55s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.55s cubic-bezier(0.4, 0, 0.2, 1),
    visibility 0.55s ease;
  transform: scale(1);
}

.app-preloader.fade-out {
  opacity: 0;
  visibility: hidden;
  transform: scale(1.04);
  pointer-events: none;
}

/* Pulsing logo container */
.preloader-logo-wrap {
  width: 104px;
  height: 104px;
  border-radius: 26px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 28px;
  box-shadow:
    0 0 0 1px rgba(123, 45, 139, 0.06),
    0 8px 24px rgba(123, 45, 139, 0.14);
  animation: preloader-breath 2.6s infinite ease-in-out;
}

.preloader-logo-wrap img {
  width: 100%;
  height: 100%;
  border-radius: 22px;
  object-fit: cover;
}

/* Animated progress bar */
.preloader-bar-bg {
  width: 130px;
  height: 3.5px;
  background: rgba(123, 45, 139, 0.1);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}

.preloader-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary, #7B2D8B), #5B1B6A);
  border-radius: 99px;
  position: absolute;
  left: -40%;
  width: 40%;
  animation: preloader-sweep 1.7s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

/* Keyframes */
@keyframes preloader-breath {

  0%,
  100% {
    transform: scale(0.97);
    box-shadow:
      0 0 0 1px rgba(123, 45, 139, 0.06),
      0 8px 24px rgba(123, 45, 139, 0.13);
  }

  50% {
    transform: scale(1.03);
    box-shadow:
      0 0 0 2px rgba(123, 45, 139, 0.11),
      0 14px 38px rgba(123, 45, 139, 0.26);
  }
}

@keyframes preloader-sweep {
  0% {
    left: -40%;
    width: 30%;
  }

  40% {
    width: 55%;
  }

  100% {
    left: 110%;
    width: 30%;
  }
}

/* ==========================================
   PAGINATION STYLING & MOBILE OPTIMIZATION
   ========================================== */
.pagination-nav-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pagination-btn-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pagination-btn {
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .pagination-nav-container {
    flex-direction: column;
    gap: 12px;
    align-items: center;
    justify-content: center;
    padding: 16px 10px;
    text-align: center;
  }

  .pagination-btn-group {
    width: 100%;
    justify-content: center;
    gap: 8px;
  }

  .pagination-btn-text {
    display: none;
  }

  .pagination-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--bg-white, #FFFFFF) !important;
    border: 1px solid var(--border, #E2E8F0) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    font-size: 1.1rem;
    line-height: 1;
  }
  
  .pagination-btn:hover:not(:disabled) {
    background: var(--primary-light, #F8F0FA) !important;
    border-color: var(--primary, #7B2D8B) !important;
    color: var(--primary, #7B2D8B) !important;
  }

  .pagination-btn:disabled {
    opacity: 0.4;
  }
}