/**
 * Royal Stars International School
 * School Management and Monitoring System - Stylesheet
 */

/* ==================== CSS VARIABLES ==================== */
:root {
    --primary: #4a7c42;
    --primary-dark: #2d5a27;
    --primary-light: #6b9b63;
    --secondary: #5a8f52;
    --secondary-dark: #3d6b36;
    --accent: #d69e2e;
    --accent-light: #ecc94b;
    --background: #eae6f0;
    --card-bg: #ffffff;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --text-muted: #a0aec0;
    --success: #38a169;
    --success-light: #c6f6d5;
    --warning: #dd6b20;
    --warning-light: #feebc8;
    --error: #e53e3e;
    --error-light: #fed7d7;
    --gender-boy: #2b6cb0;
    --gender-girl: #d53f8c;
    --gender-sep-bg: #fdf2f8;
    --gender-sep-text: #97266d;
    --gender-sep-border: #f9a8d4;
    --border: #e2e8f0;
    --border-color: #e2e8f0;
    --table-header-tint: rgba(240, 247, 239, 0.6);
    --table-stripe-tint: rgba(247, 250, 252, 0.5);
    --table-hover-bg: var(--background);
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-sm: 4px;
    --transition: all 0.3s ease;
    --font-heading: 'Playfair Display', Georgia, serif;
    --font-body: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Glassmorphism tokens */
    --glass-bg: rgba(255, 255, 255, 0.42);
    --glass-bg-strong: rgba(255, 255, 255, 0.58);
    --glass-border: rgba(255, 255, 255, 0.55);
    --glass-border-hover: rgba(255, 255, 255, 0.8);
    --glass-blur: 16px;
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);

    /* Scrollbar tints: the default pair rides light surfaces, the on-dark
       pair rides the green sidebar gradient. The dark theme flips the
       default pair (see the DARK THEME section). */
    --scrollbar-thumb: rgba(45, 55, 72, 0.30);
    --scrollbar-thumb-hover: rgba(45, 55, 72, 0.50);
    --scrollbar-thumb-on-dark: rgba(255, 255, 255, 0.30);
    --scrollbar-thumb-on-dark-hover: rgba(255, 255, 255, 0.55);
}

/* ==================== RESET & BASE ==================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background-color: var(--background);
    background-image:
        radial-gradient(ellipse at 5% 2%, rgba(74,124,66,0.30) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 0%, rgba(214,158,46,0.25) 0%, transparent 45%),
        radial-gradient(ellipse at 50% 40%, rgba(13,148,136,0.14) 0%, transparent 55%),
        radial-gradient(ellipse at 95% 50%, rgba(124,58,237,0.18) 0%, transparent 42%),
        radial-gradient(ellipse at 15% 75%, rgba(244,114,182,0.15) 0%, transparent 48%),
        radial-gradient(ellipse at 60% 95%, rgba(59,130,246,0.16) 0%, transparent 45%),
        radial-gradient(ellipse at 35% 20%, rgba(251,191,36,0.10) 0%, transparent 40%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    /* Phones: 100vh is taller than the visible screen (address bar), which
       left a strip of blank page under short content. svh is the safe size. */
    min-height: 100svh;
}

/* Blurred drifting orbs are desktop decoration: two 600-700px elements with a
   120px blur are expensive to paint on phones, where nobody misses them. */
@media (max-width: 768px) {
    body::before,
    body::after {
        display: none;
    }
}

/* Soft floating orbs that drift slowly behind page content. */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    filter: blur(120px);
    will-change: transform;
}
body::before {
    width: 700px;
    height: 700px;
    top: -8%;
    right: -2%;
    background: radial-gradient(circle, rgba(13,148,136,0.30) 0%, transparent 70%);
    animation: orbDrift1 28s ease-in-out infinite;
}
body::after {
    width: 600px;
    height: 600px;
    bottom: -5%;
    left: 8%;
    background: radial-gradient(circle, rgba(124,58,237,0.24) 0%, transparent 70%);
    animation: orbDrift2 34s ease-in-out infinite;
}
@keyframes orbDrift1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%      { transform: translate(30px, 22px) scale(1.06); }
    66%      { transform: translate(-18px, -12px) scale(0.95); }
}
@keyframes orbDrift2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%      { transform: translate(-22px, -28px) scale(1.08); }
    66%      { transform: translate(28px, 14px) scale(0.94); }
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.3;
    color: var(--primary);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-light);
}

img {
    max-width: 100%;
    height: auto;
}

/* ==================== CUSTOM SCROLLBARS ==================== */
/* Slim rounded scrollbars everywhere (page body, tables, dropdowns, modals).
   Thumb tints are tokens: the dark theme flips the default pair, and the
   sidebar rules below use the on-dark pair over the green gradient. Firefox
   gets the standard scrollbar-width/scrollbar-color pair instead. */
html {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* Sidebar scroll regions — the whole-sidebar fallback, the nav fallback and
   the .sidebar-links list — get a light translucent thumb that floats over
   the green gradient (and over the dark theme's charcoal sidebar). */
.sidebar,
.sidebar-nav,
.sidebar-links {
    scrollbar-color: var(--scrollbar-thumb-on-dark) transparent;
}

.sidebar::-webkit-scrollbar,
.sidebar-nav::-webkit-scrollbar,
.sidebar-links::-webkit-scrollbar {
    width: 10px;
}

.sidebar::-webkit-scrollbar-thumb,
.sidebar-nav::-webkit-scrollbar-thumb,
.sidebar-links::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb-on-dark);
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 8px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.sidebar-nav::-webkit-scrollbar-thumb:hover,
.sidebar-links::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-on-dark-hover);
}

/* ==================== LAYOUT ==================== */
.wrapper {
    display: flex;
    min-height: 100vh;
    min-height: 100svh;
}

.sidebar {
    width: 260px;
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 60%, #1e4420 100%);
    color: white;
    position: fixed;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* fallback: scrolls whole only when no .sidebar-links list */
    z-index: 1000;
    transition: var(--transition);
    box-shadow: 2px 0 16px rgba(0,0,0,0.10);
}

.sidebar-header {
    padding: 24px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.sidebar-logo-icon {
    width: 48px;
    height: 48px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--primary);
}

.sidebar-logo h2 {
    color: white;
    font-size: 1.25rem;
    margin: 0;
}

.sidebar-tagline {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Column layout: the logo, Back/Forward/Back-to-Hub buttons and the footer
   stay locked in place; only the feature list below them scrolls. */
.sidebar-nav {
    padding: 16px 0;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* fallback for sidebars without a .sidebar-links list */
}

.sidebar-nav ul {
    list-style: none;
}

/* Locked Back to Hub / Back / Forward controls above the scrolling list. */
.sidebar-controls {
    flex: 0 0 auto;
}

/* The one scrolling region: this section's feature links. */
.sidebar-links {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.95rem;
    border-left: 3px solid transparent;
    transition: var(--transition);
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-left-color: var(--accent);
}

.sidebar-nav li a.active {
    background: rgba(255, 255, 255, 0.13);
    box-shadow: inset 3px 0 12px -4px rgba(214, 158, 46, 0.25);
}

.sidebar-nav li a i {
    margin-right: 12px;
    width: 20px;
    text-align: center;
}

.sidebar-nav .nav-section {
    padding: 14px 24px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.45);
}

/* Persistent pinned entries below the section-scoped nav list.
   "Help & Guide" triggers the onboarding tour replay; "Give Feedback"
   opens the feedback page. Both sit below a separator line. */
.sidebar-nav li.nav-tour,
.sidebar-nav li.nav-feedback {
    margin-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}
/* Remove the double border between the two pinned items. */
.sidebar-nav li.nav-feedback {
    margin-top: 0;
    border-top: none;
}

/* Collapsible nav group (e.g. Reports -> Continuous Assessment / Terminal Reports) */
.sidebar-nav .nav-parent > a {
    cursor: pointer;
}
.sidebar-nav .nav-parent .nav-caret {
    margin-left: auto;
    margin-right: 0;
    width: auto;
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}
.sidebar-nav .nav-parent.open .nav-caret {
    transform: rotate(180deg);
}
.sidebar-nav .nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
    background: rgba(255, 255, 255, 0.06);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
.sidebar-nav .nav-parent.open .nav-submenu {
    max-height: none;
}
.sidebar-nav .nav-submenu li a {
    padding-left: 40px;
    font-size: 0.9rem;
}
.sidebar-nav .nav-submenu li a i {
    flex-shrink: 0;
}
.sidebar-nav .nav-submenu li a span {
    min-width: 0;
    overflow-wrap: break-word;
}

/* "Back to Hub" shortcut at the top of the sidebar nav, just below the badge. */
.sidebar-nav .sidebar-back {
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-nav .sidebar-back a {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    justify-content: center;
}

/* Bigger, centered arrow when collapsed; it glides left as the label reveals. */
.sidebar-nav .sidebar-back a i {
    font-size: 1.3rem;
    margin-right: 0;
    transition: margin-right 0.3s ease;
}

.sidebar-nav .sidebar-back a:hover i {
    margin-right: 10px;
}

/* Show only the arrow by default; slide the label in on hover. */
.sidebar-nav .sidebar-back a span {
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: max-width 0.3s ease, opacity 0.3s ease;
}

.sidebar-nav .sidebar-back a:hover span {
    max-width: 140px;
    opacity: 1;
}

/* On the mobile off-canvas menu (no hover), match other items: label always shown. */
@media (max-width: 768px) {
    .sidebar-nav .sidebar-back a {
        justify-content: flex-start;
    }
    .sidebar-nav .sidebar-back a i {
        margin-right: 12px;
    }
    .sidebar-nav .sidebar-back a span {
        max-width: 140px;
        opacity: 1;
    }
}

/* Browser-style back/forward controls under Back to Hub */
.sidebar-nav .sidebar-history {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-nav .sidebar-history a {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    padding: 10px 8px;
    border-radius: 8px;
    transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-nav .sidebar-history a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.sidebar-nav .sidebar-history a i {
    font-size: 1.1rem;
    margin-right: 0;
    transition: margin-right 0.3s ease;
}

.sidebar-nav .sidebar-history a:hover i {
    margin-right: 6px;
}

.sidebar-nav .sidebar-history a span {
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: max-width 0.3s ease, opacity 0.3s ease;
}

.sidebar-nav .sidebar-history a:hover span {
    max-width: 80px;
    opacity: 1;
}

@media (max-width: 768px) {
    .sidebar-nav .sidebar-history a {
        justify-content: flex-start;
    }
    .sidebar-nav .sidebar-history a i {
        margin-right: 10px;
    }
    .sidebar-nav .sidebar-history a span {
        max-width: 80px;
        opacity: 1;
    }
}

/* Clickable school badge / name (shortcut to home; see js/main.js). */
.sidebar-logo[role="link"] {
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-logo[role="link"]:hover {
    opacity: 0.85;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
}

.main-content {
    flex: 1;
    min-width: 0;
    margin-left: 260px;
    min-height: 100vh;
    min-height: 100svh;
    position: relative;
    z-index: 1;
}

.main-header {
    background: rgba(255, 255, 255, 0.62);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.06);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(226,232,240,0.6);
}

.main-header h1 {
    font-size: 1.5rem;
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-dropdown {
    position: relative;
}

.user-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: var(--radius);
    transition: var(--transition);
}

.user-dropdown-toggle:hover {
    background: rgba(74, 124, 66, 0.06);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-info {
    text-align: left;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.user-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow);
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
    z-index: 1000;
}

.user-dropdown:not(.user-menu-enhanced):hover .user-dropdown-menu,
.user-dropdown:not(.user-menu-enhanced):focus-within .user-dropdown-menu,
.user-dropdown.user-menu-enhanced.is-open .user-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown-menu a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--text-primary);
    transition: var(--transition);
}

.user-dropdown-menu a:hover {
    background: rgba(74, 124, 66, 0.08);
    color: var(--primary);
}

.user-dropdown-menu a i {
    margin-right: 10px;
    width: 18px;
}

/* ==================== NOTIFICATION BELL ==================== */
.notif-bell {
    position: relative;
}

.notif-bell-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--background);
    color: var(--text-secondary);
    font-size: 1.05rem;
    cursor: pointer;
    transition: var(--transition);
}

.notif-bell-btn:hover {
    background: var(--primary-light);
    color: #fff;
}

.notif-bell.has-unread .notif-bell-btn {
    color: var(--primary);
}

/* Gentle wiggle when there are unread items. */
.notif-bell.has-unread .notif-bell-btn i {
    transform-origin: 50% 4px;
    animation: notif-swing 2.4s ease-in-out infinite;
}

@keyframes notif-swing {
    0%, 82%, 100% { transform: rotate(0); }
    86% { transform: rotate(14deg); }
    90% { transform: rotate(-11deg); }
    94% { transform: rotate(7deg); }
    98% { transform: rotate(-3deg); }
}

.notif-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: linear-gradient(135deg, #f56565, #e53e3e);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--card-bg, #fff);
    display: none;
}

.notif-bell.has-unread .notif-badge {
    display: block;
}

.notif-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 340px;
    max-width: 88vw;
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
    z-index: 1200;
    overflow: hidden;
}

.notif-bell.open .notif-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.notif-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.4);
    font-weight: 700;
    color: var(--text-primary);
}

.notif-dropdown-header button {
    border: none;
    background: none;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.notif-dropdown-header button:hover {
    text-decoration: underline;
}

.notif-list {
    max-height: 380px;
    overflow-y: auto;
}

.notif-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.35);
    color: var(--text-primary);
    text-decoration: none;
    transition: var(--transition);
}

.notif-item:last-child {
    border-bottom: none;
}

.notif-item:hover {
    background: rgba(74, 124, 66, 0.06);
}

.notif-item.unread {
    background: rgba(74, 124, 66, 0.1);
}

.notif-item-icon {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    color: #fff;
    font-size: 0.85rem;
}

.notif-item-icon.type-grade { background: #3182ce; }
.notif-item-icon.type-report { background: var(--accent); }
.notif-item-icon.type-account { background: #805ad5; }
.notif-item-icon.type-announcement { background: var(--primary); }
.notif-item-icon.type-warning { background: #dd6b20; }
.notif-item-icon.type-security { background: #c53030; }

.notif-item-icon.type-watch { background: #b7791f; }

.notif-item-body {
    flex: 1;
    min-width: 0;
}

.notif-item-title {
    font-weight: 600;
    font-size: 0.88rem;
    margin: 0 0 2px;
}

.notif-item-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0 0 4px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.notif-item-time {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.notif-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.notif-empty i {
    display: block;
    font-size: 1.8rem;
    margin-bottom: 8px;
    color: var(--border);
}

/* "View all notifications" footer link in the bell dropdown */
.notif-view-all {
    display: block;
    text-align: center;
    padding: 10px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary);
    border-top: 1px solid rgba(226, 232, 240, 0.4);
    text-decoration: none;
    transition: background 0.15s ease;
}
.notif-view-all:hover {
    background: rgba(74, 124, 66, 0.06);
}
.notif-view-all i {
    font-size: 0.7rem;
    margin-left: 4px;
}

/* Notification bell on hub pages (.hub-topbar) */
.hub-topbar .notif-bell {
    display: inline-flex;
    align-items: center;
    margin-right: 8px;
}
.hub-topbar .notif-bell-btn {
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    width: 38px;
    height: 38px;
}
.hub-topbar .notif-bell-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* Phones: the bell sits mid-header (left of the profile chip), so a 340px
   panel anchored to the bell's right edge spilled off the left side of the
   screen. Anchor the panel to the header bar instead and span the screen. */
@media (max-width: 768px) {
    .main-header .notif-bell,
    .hub-topbar .notif-bell {
        position: static;
    }
    .main-header .notif-dropdown,
    .hub-topbar .notif-dropdown {
        top: calc(100% + 6px);
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
        /* Nested inside the header's own backdrop-filter, the panel's blur
           let the page text show through the list. Use a solid panel. */
        background: #fff;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
    html[data-theme="dark"] .main-header .notif-dropdown,
    html[data-theme="dark"] .hub-topbar .notif-dropdown {
        background: #1b2432;
    }
    .notif-list {
        max-height: min(380px, 60vh);
    }
    .notif-item-text {
        -webkit-line-clamp: 3;
    }
}

/* ==================== NOTIFICATIONS PAGE ==================== */
.notif-page-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.notif-page-item {
    display: flex;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s ease;
    cursor: pointer;
}
.notif-page-item:last-child {
    border-bottom: none;
}
.notif-page-item:hover {
    background: var(--background);
}
.notif-page-item.unread {
    background: rgba(74, 124, 66, 0.05);
    border-left: 3px solid var(--primary);
}
.notif-page-item .notif-page-icon {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    color: #fff;
    font-size: 1rem;
}
.notif-page-item .notif-page-icon.type-grade { background: #3182ce; }
.notif-page-item .notif-page-icon.type-report { background: var(--accent); }
.notif-page-item .notif-page-icon.type-account { background: #805ad5; }
.notif-page-item .notif-page-icon.type-announcement { background: var(--primary); }
.notif-page-item .notif-page-icon.type-warning { background: #dd6b20; }
.notif-page-item .notif-page-icon.type-security { background: #c53030; }
.notif-page-item .notif-page-icon.type-watch { background: #b7791f; }
.notif-page-body {
    flex: 1;
    min-width: 0;
}
.notif-page-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin: 0 0 4px;
}
.notif-page-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 6px;
}
.notif-page-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.notif-page-empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-secondary);
}
.notif-page-empty i {
    display: block;
    font-size: 2.5rem;
    margin-bottom: 12px;
    color: var(--border);
}
.notif-page-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}
.notif-page-actions .btn {
    font-size: 0.85rem;
}

/* ---- Notifications filter side menu ---- */
.notif-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}
.notif-filters {
    flex: 0 0 200px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: sticky;
    top: 20px;
}
.notif-filters-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin: 0 0 8px;
    padding: 0 8px;
}
.notif-filter-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}
.notif-filter-item i {
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
}
.notif-filter-item span:nth-of-type(1) {
    flex: 1;
}
.notif-filter-item:hover {
    background: var(--background);
    color: var(--text);
}
.notif-filter-item.active {
    background: rgba(74, 124, 66, 0.1);
    color: var(--primary);
    font-weight: 600;
}
.notif-filter-count {
    background: var(--border);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    min-width: 22px;
    text-align: center;
}
.notif-filter-item.active .notif-filter-count {
    background: var(--primary);
    color: #fff;
}
.notif-filters-action {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.notif-content {
    flex: 1;
    min-width: 0;
}

/* Notification item row with archive button */
.notif-page-item-wrap {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s ease;
}
.notif-page-item-wrap:last-child {
    border-bottom: none;
}
.notif-page-item-wrap:hover {
    background: var(--background);
}
/* Override the per-item hover/border from the old layout. */
.notif-page-item-wrap .notif-page-item {
    border-bottom: none;
    flex: 1;
    min-width: 0;
}
.notif-page-item-wrap .notif-page-item:hover {
    background: transparent;
}

/* Archive / restore button */
.notif-archive-form {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    padding: 0 12px;
}
.notif-archive-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.85rem;
}
.notif-archive-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(74, 124, 66, 0.08);
}

/* Archived items get a muted look. */
.notif-page-item.archived {
    opacity: 0.65;
}
.notif-page-item.archived .notif-page-icon {
    filter: grayscale(0.4);
}

/* "NEW" badge inside the title line. */
.notif-new-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 6px;
    vertical-align: middle;
    text-transform: uppercase;
}

/* Responsive: stack the filter menu above the list on narrow screens. */
@media (max-width: 768px) {
    .notif-layout {
        flex-direction: column;
        gap: 16px;
    }
    .notif-filters {
        flex: 1 1 auto;
        flex-direction: row;
        flex-wrap: wrap;
        position: static;
        gap: 4px;
    }
    .notif-filters-title {
        width: 100%;
        margin-bottom: 4px;
    }
    .notif-filter-item {
        flex: 0 0 auto;
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    .notif-filters-action {
        width: 100%;
    }
}

.main-body {
    padding: 32px;
    animation: pageEnter 0.38s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

/* Page enter: gentle scale + fade (no harsh directional slide). */
@keyframes pageEnter {
    from { opacity: 0; transform: scale(0.97) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Exit animation applied just before the browser navigates away. */
.main-body.page-exit,
.hub-main.page-exit {
    animation: pageExit 0.26s cubic-bezier(0.55, 0.06, 0.68, 0.19) both;
}
@keyframes pageExit {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to   { opacity: 0; transform: scale(0.97) translateY(10px); }
}

/* ==================== CARDS ==================== */
.card {
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(226, 232, 240, 0.5);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.05);
    overflow: hidden;
    transition: var(--transition);
}

.card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.06), 0 12px 28px rgba(0,0,0,0.04);
    transform: translateY(-2px);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 1.1rem;
    color: var(--primary);
}

.card-body {
    padding: 24px;
}

.card-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--background);
}

/* Student-list filters remain below the live header without covering its menus. */
@media screen {
    .card.student-list-filters {
        position: sticky;
        top: var(--student-filter-top, 88px);
        z-index: 90;
        background: var(--card-bg);
        transform: none;
        transition: none;
    }
    html[data-theme="dark"] .card.student-list-filters { background: var(--card-bg); }
    .student-list-filters > .card-body { overflow-x: auto; }
    .student-list-filters > .card-body:focus-visible {
        outline: 2px solid var(--primary);
        outline-offset: -2px;
    }
    .student-list-filters form { flex-wrap: nowrap; }
    .student-list-filters form > * { flex-shrink: 0; }
    .student-list-filters #searchInput { flex: 1 0 16rem; min-width: 16rem; }
}
@media screen and (max-width: 768px) {
    .student-list-filters > .card-body { padding: 12px 16px; }
}

/* ==================== MESSAGE FONT CONTROLS ==================== */
.message-font-controls { margin: 6px 0 10px; min-width: 0; max-width: 100%; }
.message-font-controls:empty { display: none; }
.message-font-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.message-font-label { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); margin-right: 4px; }
.message-font-controls .message-font-select { width: auto; min-width: 100px; max-width: 100%; padding: 5px 28px 5px 9px; font-size: 0.82rem; }
.message-font-controls .btn-sm { min-height: 34px; padding: 5px 10px; }
.message-font-controls .message-font-help { margin: 5px 0 0; font-size: 0.76rem; line-height: 1.4; color: var(--text-secondary); }
[data-message-font-editor][data-message-font-sized="draft"],
[data-message-font-print-target][data-message-font-sized="print"] { font-size: var(--message-font-size) !important; }
[data-message-font-print-target] { overflow-wrap: anywhere; }
@media (max-width: 560px) {
    .message-font-row .message-font-label { flex-basis: 100%; }
}
@media print {
    .message-font-controls { display: none !important; }
}

/* Finance roster cards reuse the finance header's gradient palette. */
.fin-stats.fin-roster-stats {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}
.fin-roster-stats .fin-stat {
    min-width: 0;
}
.fin-roster-stats .fin-stat h2,
.fin-roster-stats .fin-stat .sub {
    overflow-wrap: anywhere;
}
.fin-search-control {
    flex: 1 1 220px;
    min-width: 0;
}

/* ==================== STATS CARDS ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--glass-shadow);
    border-color: var(--glass-border-hover);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.primary {
    background: rgba(26, 54, 93, 0.1);
    color: var(--primary);
}

.stat-icon.success {
    background: var(--success-light);
    color: var(--success);
}

.stat-icon.warning {
    background: var(--warning-light);
    color: var(--warning);
}

.stat-icon.secondary {
    background: rgba(197, 48, 48, 0.1);
    color: var(--secondary);
}

.stat-icon.accent {
    background: rgba(214, 158, 46, 0.1);
    color: var(--accent);
}

.stat-content h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 400;
    font-family: var(--font-body);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-content h2 {
    font-size: 1.75rem;
    color: var(--text-primary);
    margin: 4px 0;
}

.stat-content p {
    font-size: 0.85rem;
    color: var(--success);
}

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 22px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.25s ease;
    gap: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    box-shadow: 0 4px 12px rgba(74, 124, 66, 0.25);
    transform: translateY(-1px);
    color: white;
}

.btn-secondary {
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-secondary:hover {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(74, 124, 66, 0.15);
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--error) 0%, #c53030 100%);
    color: white;
}

.btn-danger:hover {
    box-shadow: 0 4px 12px rgba(229, 62, 62, 0.25);
    transform: translateY(-1px);
}

.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, #2f855a 100%);
    color: white;
}

.btn-success:hover {
    box-shadow: 0 4px 12px rgba(56, 161, 105, 0.25);
    transform: translateY(-1px);
}

.btn-warning {
    background: linear-gradient(135deg, var(--warning) 0%, #c05621 100%);
    color: white;
}

.btn-warning:hover {
    box-shadow: 0 4px 12px rgba(221, 107, 32, 0.25);
    transform: translateY(-1px);
}

/* Destructive action (delete / wipe). Several pages use btn-error but the
   class was never defined, leaving those buttons as unstyled text. */
.btn-error {
    background: linear-gradient(135deg, var(--error) 0%, #c53030 100%);
    color: white;
}

.btn-error:hover {
    box-shadow: 0 4px 12px rgba(229, 62, 62, 0.25);
    transform: translateY(-1px);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
    border-radius: 8px;
}

.btn-lg {
    padding: 14px 30px;
    font-size: 1.1rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ==================== FORMS ==================== */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 7px;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    color: var(--text-primary);
}

.form-control:hover {
    border-color: var(--glass-border-hover);
    background: rgba(255, 255, 255, 0.65);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(74, 124, 66, 0.12), 0 2px 8px rgba(74, 124, 66, 0.06);
    background: var(--glass-bg-strong);
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-control.error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.10);
}

.form-error {
    color: var(--error);
    font-size: 0.85rem;
    margin-top: 4px;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%234a7c42'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2.5' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 18px;
    padding-right: 44px;
    cursor: pointer;
}

.form-select option {
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-primary);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

/* Textarea gets a slightly taller, softer feel. */
textarea.form-control {
    min-height: 100px;
    resize: vertical;
    line-height: 1.55;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* ==================== TABLES ==================== */
.table-container {
    overflow-x: auto;
    max-width: 100%;
}

.parent-child-selector {
    flex-wrap: wrap;
}
.parent-child-selector .form-select {
    width: 250px;
    max-width: 100%;
    min-width: 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--table-header-tint);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table tbody tr {
    transition: var(--transition);
}

.table tbody tr:hover {
    background: var(--table-hover-bg);
}

.table tbody tr:nth-child(even) {
    background: var(--table-stripe-tint);
}

.table tbody tr:nth-child(even):hover {
    background: var(--table-hover-bg);
}

/* ---- Fit-to-width + pinned-column table variants ----------------------
   Wide tables (Users, SMS delivery log) overflow the viewport at 100% zoom,
   and because .table-container's sideways scrollbar only exists at the very
   bottom of the table, the row buttons were unreachable without first
   scrolling all the way down. Two layers fix that: .table-compact trims the
   padding and keeps every cell on ONE line (long values clip with an
   ellipsis via .cell-trunc, or stack via .cell-stacked — hover the cell for
   the full value), and .table-pin-last glues the last column (the action
   buttons) to the visible right edge, so even on a window too narrow to
   fit the table the buttons stay on screen. */
.table-compact th,
.table-compact td {
    padding: 8px 9px;
    white-space: nowrap;
}

/* One-line value that may clip with an ellipsis (pair it with a title=). */
.table-compact .cell-trunc {
    display: block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Pinned actions cell: slim icon-only buttons on ONE row (the wide .btn-sm
   pill padding would need ~270px for five actions), a tighter gap, and a
   width floor so the auto layout can never crush the column — flex-wrap
   lets the Super badge fold to a second line instead. */
.table-compact .actions-cell { min-width: 196px; }
.table-compact .actions-cell .btn-sm { padding: 4px 8px; }
.table-compact .actions-cell .d-flex { gap: 4px; }

/* Users table: FIXED columns. Auto layout refuses to take shrink room
   from the name/email cells (the nowrap badges and the button row corner
   the space), so eight columns never fit a 100%-zoom laptop screen.
   Fixed layout with px widths on every column makes the outcome
   deterministic: the 8 columns sum to ~957px, so at 100% zoom they fit
   a 1366 laptop exactly (wide screens grow all columns proportionally;
   narrower windows overflow by the difference and the pinned actions
   column keeps the buttons reachable while the table scrolls). Long
   names/emails clip via .cell-trunc — hover shows the full value. */
/* Name absorbs spare width so the two pinned columns keep exact offsets.
   On phones they scroll normally, leaving room to read the other columns. */
.table-users-fit {
    table-layout: fixed;
    min-width: 957px;
    background: var(--card-bg);
    --users-actions-width: 204px;
}
.users-table-scroll:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: -2px;
}
.users-page .users-filters { flex-wrap: wrap; }
.users-page .users-filters input[name="search"] { flex: 1 1 200px; min-width: 0; }
.table-users-fit .cell-trunc { min-width: 0; max-width: 100%; }
.table-users-fit td:nth-child(2) a { min-width: 0; }
.table-users-fit .actions-cell > .d-flex { flex-wrap: wrap; align-items: center; }
.table-users-fit .actions-cell .btn:focus-visible {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
}
.table-users-fit th:nth-child(1) { width: 41px; }    /* No. */
.table-users-fit th:nth-child(2) { width: auto; }   /* Name (avatar + clip) */
.table-users-fit th:nth-child(3) { width: 150px; }   /* Email (clip + title) */
.table-users-fit th:nth-child(4) { width: 130px; }   /* Role badge */
.table-users-fit th:nth-child(5) { width: 100px; }   /* Phone */
.table-users-fit th:nth-child(6) { width: 92px; }    /* Status badge */
.table-users-fit th:nth-child(7) { width: 116px; }   /* Created */
.table-users-fit th:nth-child(8) { width: var(--users-actions-width); }   /* Actions */

/* Two-line cell (date over time) — keeps the When column narrow. */
.table-compact .cell-stacked {
    white-space: normal;
    line-height: 1.3;
}
.table-compact .cell-stacked .stack-line { display: block; }
.table-compact .cell-stacked .stack-sub {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Pinned last column. Its background must be OPAQUE — the normal header
   and zebra tints are translucent and would show the scrolling cells
   underneath — so the same tints are layered over --card-bg, which stays
   pixel-identical in the light and dark themes. */
.table-pin-last th:last-child,
.table-pin-last td:last-child,
.table-pin-last .pinned-context {
    position: sticky;
    right: 0;
    z-index: 1;
    background: var(--card-bg);
    box-shadow: inset 12px 0 10px -12px rgba(0, 0, 0, 0.45);
}
.table-users-fit .pinned-context { right: var(--users-actions-width); }
.table.table-pin-last thead th:last-child,
.table.table-pin-last thead .pinned-context {
    z-index: 2;
    background: linear-gradient(var(--table-header-tint), var(--table-header-tint)), var(--card-bg);
}
.table-pin-last tbody tr:nth-child(even) td:last-child,
.table-pin-last tbody tr:nth-child(even) .pinned-context {
    background: linear-gradient(var(--table-stripe-tint), var(--table-stripe-tint)), var(--card-bg);
}
.table-pin-last tbody tr:hover td:last-child,
.table-pin-last tbody tr:nth-child(even):hover td:last-child,
.table-pin-last tbody tr:hover .pinned-context {
    background: linear-gradient(var(--table-hover-bg), var(--table-hover-bg)), var(--card-bg);
}
@media screen and (max-width: 768px) {
    .table-users-fit.table-pin-last th:last-child,
    .table-users-fit.table-pin-last td:last-child,
    .table-users-fit.table-pin-last .pinned-context {
        position: static;
        box-shadow: none;
    }
}
/* The empty-state row is a single colspan cell — nothing to pin. */
.table-pin-last td[colspan]:last-child {
    position: static;
    background: transparent;
    box-shadow: none;
}

/* Broadsheet detail layout (P1, P2, Total, Grade per subject) */
.broadsheet-detail th,
.broadsheet-detail td {
    padding: 6px 4px;
    font-size: 0.82rem;
    white-space: nowrap;
}
.broadsheet-detail .subj-group {
    background: rgba(26, 54, 93, 0.08);
    border-bottom: 2px solid rgba(26, 54, 93, 0.2);
    font-size: 0.78rem;
    letter-spacing: 0.3px;
    text-transform: none;
    min-width: 140px;
}
.broadsheet-detail .sub-col {
    padding: 4px 2px;
    font-size: 0.72rem;
    min-width: 30px;
    text-transform: uppercase;
}
.broadsheet-detail .sub-col.p1 { color: #6366f1; }
.broadsheet-detail .sub-col.p2 { color: #0891b2; }
.broadsheet-detail .sub-col.tot { background: #fdf6ec; font-weight: 700; }
.broadsheet-detail .sub-col.grd { background: #e8f5e9; font-weight: 600; min-width: 28px; }
.broadsheet-detail td.sub-col.p1 { color: var(--text-secondary); font-size: 0.8rem; }
.broadsheet-detail td.sub-col.p2 { color: var(--text-secondary); font-size: 0.8rem; }
.broadsheet-detail td.sub-col.tot { font-weight: 600; color: var(--text); }
.broadsheet-detail td.sub-col.grd { font-weight: 700; color: #2d6a4f; }

/* ==================== BADGES ==================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-primary {
    background: rgba(26, 54, 93, 0.1);
    color: var(--primary);
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-danger {
    background: var(--error-light);
    color: var(--error);
}

.badge-secondary {
    background: rgba(113, 128, 150, 0.1);
    color: var(--text-secondary);
}

/* ==================== STATIC TERM CHIP ==================== */
/* The teacher and parent portals display the school's current term (from the
   academic calendar) as a fixed chip — the term is never a dropdown there. */
.term-static {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.25;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: var(--glass-bg-strong);
    color: var(--text-primary);
    white-space: nowrap;
    cursor: default;
}

.term-static i {
    color: var(--primary);
    font-size: 0.9em;
}

/* ==================== TIMETABLE TYPE TABS ==================== */
.tt-type-tabs {
    display: flex;
    gap: 4px;
    background: rgba(0,0,0,0.04);
    border-radius: 12px;
    padding: 4px;
    width: fit-content;
}
.tt-type-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.tt-type-tab:hover {
    background: rgba(255,255,255,0.5);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text-dark);
}
.tt-type-tab.active {
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* Timetable filter row */
.tt-filters {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.tt-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
}
.tt-filter-group .form-label {
    font-size: 0.8rem;
    margin-bottom: 0;
}

/* Inline form row (for add slot forms) */
.tt-inline-form {
    margin-top: 8px;
}
.tt-form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.tt-form-row .form-group {
    min-width: 120px;
    flex: 1;
}

/* ==================== DUTY ROSTER GRID ==================== */
.duty-roster-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    border-top: 1px solid rgba(0,0,0,0.08);
}
.duty-day-card {
    border-right: 1px solid rgba(0,0,0,0.08);
    min-height: 120px;
}
.duty-day-card:last-child {
    border-right: none;
}
.duty-day-header {
    background: var(--primary);
    color: #fff;
    text-align: center;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    padding: 10px 8px;
    text-transform: uppercase;
}
.duty-day-body {
    padding: 8px;
}
.duty-entry {
    background: rgba(74, 124, 66, 0.06);
    border: 1px solid rgba(74, 124, 66, 0.15);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 8px;
}
.duty-entry:last-child {
    margin-bottom: 0;
}
.duty-entry-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.duty-entry-main strong {
    font-size: 0.85rem;
    color: var(--text-dark);
}
.duty-label {
    font-size: 0.78rem;
    color: var(--primary);
    font-weight: 600;
}
.duty-entry-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.btn-xs {
    padding: 2px 6px;
    font-size: 0.7rem;
    border-radius: 4px;
}

/* Responsive: stack duty roster on mobile */
@media (max-width: 768px) {
    .duty-roster-grid {
        grid-template-columns: 1fr;
    }
    .duty-day-card {
        border-right: none;
        border-bottom: 1px solid rgba(0,0,0,0.08);
    }
    .tt-filters {
        flex-direction: column;
    }
    .tt-form-row {
        flex-direction: column;
    }
}

/* ==================== GRID-BASED TIMETABLES ==================== */

/* View switcher (List / Grid buttons) */
.tt-view-switcher {
    display: inline-flex;
    gap: 0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--card);
}
.tt-view-switcher .btn {
    border: none;
    border-radius: 0;
    padding: 6px 14px;
    font-size: 0.82rem;
    line-height: 1.4;
    background: transparent;
    color: var(--text-muted, #555);
}
.tt-view-switcher .btn + .btn {
    border-left: 1px solid var(--border);
}
.tt-view-switcher .btn-primary {
    background: var(--primary, #2b7a4a);
    color: #fff;
}
.tt-view-switcher .btn-secondary {
    background: transparent;
    color: var(--text-muted, #555);
}
.tt-view-switcher .btn:hover {
    opacity: 0.85;
}

/* Shared grid table styling */
.tt-class-grid,
.tt-dept-grid,
.tt-exam-grid,
.tt-duty-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    table-layout: fixed;
}

.tt-class-grid th,
.tt-class-grid td,
.tt-dept-grid th,
.tt-dept-grid td,
.tt-exam-grid th,
.tt-exam-grid td,
.tt-duty-table th,
.tt-duty-table td {
    border: 1px solid rgba(0,0,0,0.10);
    padding: 8px 6px;
    text-align: center;
    vertical-align: middle;
}

.tt-class-grid thead th,
.tt-dept-grid thead th,
.tt-exam-grid thead th,
.tt-duty-table thead th {
    background: rgba(74, 124, 66, 0.10);
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.tt-day-head,
.tt-class-head,
.tt-exam-class-head {
    width: 90px;
    background: rgba(74, 124, 66, 0.14) !important;
}

.tt-time-head {
    min-width: 90px;
}

.tt-break-head {
    background: rgba(113, 128, 150, 0.12) !important;
    color: var(--text-secondary) !important;
    min-width: 55px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    padding: 12px 4px;
}

.tt-break-label {
    font-size: 0.68rem;
    font-weight: 800;
    margin-top: 6px;
}

.tt-day-cell,
.tt-class-cell,
.tt-exam-class-cell {
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(74, 124, 66, 0.06);
}

.tt-slot-cell,
.tt-exam-slot-cell {
    min-height: 48px;
}

.tt-break-cell {
    background: repeating-linear-gradient(
        45deg,
        rgba(113, 128, 150, 0.04),
        rgba(113, 128, 150, 0.04) 8px,
        rgba(113, 128, 150, 0.08) 8px,
        rgba(113, 128, 150, 0.08) 16px
    );
}

.tt-entry {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tt-subject,
.tt-exam-subject {
    font-weight: 700;
    color: var(--text-dark);
    font-size: 0.82rem;
    text-transform: uppercase;
    line-height: 1.25;
}

.tt-teacher,
.tt-activity,
.tt-exam-meta {
    font-size: 0.74rem;
    color: var(--text-secondary);
    line-height: 1.25;
}

.tt-activity {
    font-weight: 600;
    text-transform: uppercase;
}

.tt-empty {
    color: var(--text-muted);
    opacity: 0.5;
}

.tt-entry-actions {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.tt-entry:hover .tt-entry-actions,
.tt-exam-entry:hover .tt-entry-actions {
    opacity: 1;
}

/* Department grid specific */
.tt-dept-grid .tt-day-cell {
    vertical-align: middle;
    font-size: 0.9rem;
}

/* Exam grid specific */
.tt-exam-title {
    text-align: center;
    margin-bottom: 16px;
}

.tt-exam-title h2 {
    margin: 0 0 4px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.tt-exam-title p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.tt-exam-date-head {
    min-width: 110px;
}

.tt-exam-date-head div:first-child {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.tt-exam-date {
    font-size: 0.88rem;
    font-weight: 700;
}

.tt-exam-entry {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Duty roster weekly table */
.tt-duty-table {
    font-size: 0.88rem;
}

.tt-duty-table thead th {
    background: rgba(74, 124, 66, 0.12);
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
}

.tt-duty-week {
    text-align: center;
    width: 150px;
}

.tt-duty-number {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
}

.tt-duty-date {
    font-weight: 600;
}

.tt-duty-teacher {
    font-weight: 700;
    text-transform: uppercase;
    text-align: center;
}

.tt-duty-seniors {
    text-align: center;
}

.tt-duty-senior {
    font-weight: 600;
    text-transform: uppercase;
}

.tt-duty-sep {
    font-weight: 800;
    color: var(--text-secondary);
    margin: 2px 0;
}

.tt-duty-actions {
    white-space: nowrap;
    text-align: center;
}

.tt-duty-actions form,
.tt-duty-actions button {
    display: inline-block;
    vertical-align: middle;
}

/* Duty week form */
.tt-duty-form h4 {
    margin-bottom: 12px;
    color: var(--text-dark);
}

/* Print styles for timetables */
@media print {
    .tt-class-grid-wrapper,
    .tt-dept-grid-wrapper,
    .tt-exam-grid-wrapper,
    .tt-duty-wrapper {
        overflow: visible;
    }
    .tt-entry-actions,
    .tt-duty-actions,
    .tt-duty-form,
    .no-print {
        display: none !important;
    }
    .tt-class-grid,
    .tt-dept-grid,
    .tt-exam-grid,
    .tt-duty-table {
        font-size: 8pt;
    }
    .tt-class-grid th,
    .tt-class-grid td,
    .tt-dept-grid th,
    .tt-dept-grid td,
    .tt-exam-grid th,
    .tt-exam-grid td,
    .tt-duty-table th,
    .tt-duty-table td {
        padding: 4px 3px;
    }
}

/* ==================== VIEW MODE TABS ==================== */
.view-mode-tabs {
    display: flex;
    gap: 4px;
    background: rgba(0,0,0,0.04);
    border-radius: 12px;
    padding: 4px;
    width: fit-content;
}
.view-mode-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.view-mode-tab:hover {
    background: rgba(255,255,255,0.5);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text-dark);
}
.view-mode-tab.active {
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ==================== SUBJECT TABS (Booklet view) ==================== */
.subject-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: thin;
}
.subject-tabs::-webkit-scrollbar {
    height: 6px;
}
.subject-tabs::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}
.subject-tab {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
    background: rgba(0,0,0,0.04);
    border: 1px solid transparent;
    transition: background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.subject-tab:hover {
    background: rgba(255,255,255,0.6);
    color: var(--text-dark);
    border-color: var(--glass-border);
}
.subject-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(74, 124, 66, 0.25);
}

/* ==================== BOOKLET RECORDING SHEET ==================== */
.booklet-sheet {
    padding: 0;
}
.booklet-header {
    text-align: center;
    padding: 24px 20px 16px;
    border-bottom: 2px solid var(--primary);
}
.booklet-header h2 {
    margin: 0 0 8px;
    font-size: 1.3rem;
    letter-spacing: 0.06em;
    color: var(--primary-dark);
}
.booklet-meta {
    display: flex;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.booklet-meta strong {
    color: var(--text-dark);
}

/* Booklet table */
.booklet-table {
    font-size: 0.85rem;
    border-collapse: collapse;
    width: 100%;
}
.booklet-table th,
.booklet-table td {
    border: 1px solid rgba(0,0,0,0.15);
    padding: 6px 8px;
    white-space: nowrap;
}
.booklet-table thead th {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: center;
    vertical-align: middle;
    padding: 8px 6px;
}
.booklet-th-name {
    text-align: left !important;
    min-width: 180px;
    background: var(--primary-dark) !important;
}
.booklet-th-group {
    background: var(--primary-light) !important;
    color: #fff;
}
.booklet-th-sub {
    background: #3d6a36 !important;
}
.booklet-th-a50, .booklet-th-b50 {
    background: #8b1a1a !important;
}
.booklet-th-exam {
    background: #4a5568 !important;
}
.booklet-th-total {
    background: #8b1a1a !important;
    min-width: 80px;
}
.booklet-th-pos {
    min-width: 70px;
    background: #2d4a28 !important;
}
.booklet-th-comp {
    background: var(--primary) !important;
    min-width: 60px;
}

/* Body cells */
.booklet-td-name {
    text-align: left;
    font-weight: 600;
    min-width: 180px;
}
.booklet-sid {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
}
.booklet-td-score {
    min-width: 52px;
}
.booklet-td-sub {
    background: rgba(74, 124, 66, 0.06);
    font-weight: 600;
    min-width: 52px;
}
.booklet-td-red {
    background: rgba(139, 26, 26, 0.06);
    color: #8b1a1a;
    font-weight: 700;
    min-width: 52px;
}
.booklet-td-total {
    background: rgba(139, 26, 26, 0.10);
    color: #8b1a1a;
    font-weight: 800;
    font-size: 0.95rem;
    min-width: 70px;
}
.booklet-td-pos {
    background: rgba(74, 124, 66, 0.08);
    font-weight: 700;
    min-width: 70px;
}

/* Zebra striping */
.booklet-table tbody tr:nth-child(even) {
    background: rgba(0,0,0,0.02);
}
.booklet-table tbody tr:hover {
    background: rgba(74, 124, 66, 0.06);
}

/* Print styles */
@media print {
    .no-print,
    .sidebar,
    .main-header,
    .view-mode-tabs,
    .subject-tabs,
    .card-header button {
        display: none !important;
    }
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
    .main-body {
        padding: 0 !important;
    }
    .booklet-sheet {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
    }
    .booklet-sheet .card-body {
        display: none;
    }
    .booklet-table th,
    .booklet-table td {
        border: 1px solid #333 !important;
        padding: 4px 6px !important;
    }
    .booklet-table thead th {
        background: #333 !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    body {
        background: #fff !important;
    }
    body::before, body::after {
        display: none !important;
    }
}

/* ==================== ATTENDANCE BOOKLET ==================== */
.att-phone { display: none; }
.booklet-week-controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 12px; }
.booklet-week-controls label { min-width: 180px; font-weight: 600; }
.booklet-week-controls p { flex: 1; min-width: 180px; font-size: .8rem; color: var(--text-secondary); }
.attendance-booklet-table [data-booklet-week][hidden] { display: none !important; }
.attendance-booklet-sheet[data-booklet-filter] { min-width: 0; max-width: 100%; }
.attendance-booklet-sheet[data-booklet-filter] .attendance-booklet-table { font-size: .75rem; }
.attendance-booklet-sheet[data-booklet-filter] .attendance-booklet-table th,
.attendance-booklet-sheet[data-booklet-filter] .attendance-booklet-table td { padding: 3px 4px; }
.attendance-booklet-sheet[data-booklet-filter] .attendance-booklet-table .att-bth-week { text-transform: none; }
#grade-entry-progress [hidden], .grade-entry-table [hidden] { display: none !important; }
#grade-missing-badge { gap: .25em; }
.card-header.grade-entry-header { flex-wrap: wrap; gap: 12px; }
.grade-entry-header > h3 { flex: 1 1 240px; min-width: 0; }
.grade-entry-header .grade-entry-tools { flex-wrap: wrap; max-width: 100%; }
.grade-entry-tools > .text-secondary { white-space: nowrap; }
.grade-entry-scroll { overflow: auto; max-width: 100%; max-height: 70vh; isolation: isolate; }
.grade-entry-scroll .grade-entry-table { border-collapse: separate; border-spacing: 0; min-width: 520px; }
.grade-entry-table .grade-name-cell { position: sticky; left: 0; z-index: 2; min-width: 150px; max-width: 220px; white-space: normal; overflow-wrap: anywhere; background: var(--card-bg); color: var(--text-primary); box-shadow: 2px 0 0 var(--border); text-align: left; }
.grade-entry-table thead .grade-name-cell { background: var(--primary); color: var(--card-bg); z-index: 3; }
.aw-correction { min-width: 210px; max-width: 340px; margin-top: 8px; }
.aw-enhanced .aw-correction { display: none; }
.aw-other-fallback, .aw-dialog .aw-dialog-other[hidden] { display: none; }
.aw-other-fallback.aw-other-selected, .aw-correction:has(.aw-reason option[value="other"]:checked) .aw-other-fallback { display: block; }
.aw-correction:has(.aw-reason option:not([value="other"]):checked) .aw-other-fallback { display: none; }
.grade-name summary { cursor: pointer; }
.grade-name summary span { overflow-wrap: anywhere; }
.grade-entry-table .grade-name[open] summary span { -webkit-line-clamp: unset; overflow: visible; }
.grade-entry-table .aw-pending { display: block; color: var(--text-secondary); font-size: .75rem; margin-top: 4px; }
.aw-submit-note { margin-bottom: 12px; color: var(--text-secondary); }
.aw-dialog { margin: auto; padding: 20px; width: calc(100% - 24px); max-width: 520px; max-height: calc(100dvh - 24px); overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); color: var(--text-primary); box-shadow: var(--shadow-lg); }
.aw-dialog:not([open]) { display: none; }
.aw-dialog::backdrop { background: var(--text-primary); opacity: .55; }
.aw-dialog h2 { font-size: 1.3rem; margin-bottom: 8px; }
.aw-dialog p, .aw-dialog label { display: block; margin: 10px 0; }
.aw-dialog-pupil { color: var(--primary); }
.aw-dialog-diff { margin: 12px 0; padding: 12px 12px 12px 28px; border-radius: var(--radius-sm); background: var(--warning-light); font-weight: 700; }
.aw-dialog-error { color: var(--error); }
.aw-dialog-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 10px; margin-top: 14px; }
.gov-correction-detail { padding: 16px; margin-bottom: 20px; border: 1px solid var(--border); border-radius: var(--radius); scroll-margin-top: 100px; }
.gov-correction-detail .table td.gov-mark-change { white-space: nowrap; font-weight: 700; color: var(--primary); }
.gov-correction-detail .table td { white-space: normal; overflow-wrap: anywhere; }
@media screen {
    .attendance-booklet-sheet[data-booklet-filter] .att-holiday-label { max-height: 96px; overflow: hidden; text-overflow: ellipsis; }
}
@media screen and (max-width: 760px) {
    .grade-entry-scroll .grade-entry-table .grade-name-cell { width: 116px; min-width: 116px; max-width: 116px; box-sizing: border-box; padding: 8px; }
    .grade-entry-table .grade-name-avatar { display: none; }
    .grade-entry-scroll { scroll-padding-inline-start: 116px; }
    .grade-entry-table .grade-name summary span { display: -webkit-inline-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; vertical-align: middle; max-width: 82px; }
    .grade-entry-scroll input[type="number"] { min-width: 70px; }
    .attendance-booklet-sheet { min-width: 0; max-width: 100%; }
    .attendance-booklet-sheet .booklet-header { padding: 12px; }
    .attendance-booklet-sheet .booklet-header h2 { font-size: 1.1rem; }
    .attendance-booklet-sheet .booklet-meta { font-size: .75rem; gap: 6px 12px; }
    .attendance-booklet-sheet > .card-header { display: flex; flex-wrap: wrap; }
    .attendance-booklet-sheet > .attendance-booklet-scroll { display: block; min-width: 0; max-width: 100%; }
    .att-phone { display: block; padding: 8px; min-width: 0; }
    .att-phone-nav { display: flex; align-items: end; gap: 6px; }
    .att-phone-nav label { flex: 1; min-width: 0; font-size: .8rem; }
    .att-phone-nav select { width: 100%; min-height: 44px; padding: 6px; font-size: .8rem; }
    .att-phone-nav button { min-width: 44px; min-height: 44px; padding: 4px; }
    .att-phone-note, .att-phone [data-week-label] { font-size: .75rem; margin: 8px 0; }
    .att-phone-scroll { overflow: auto; max-height: 65vh; max-height: 65dvh; isolation: isolate; }
    .att-phone-scroll:focus-visible { outline: 2px solid var(--primary); }
    .att-phone-table { width: 100%; min-width: 310px; border-collapse: separate; border-spacing: 0; font-size: .72rem; }
    .att-phone-table th, .att-phone-table td { padding: 5px 3px; border-bottom: 1px solid var(--border); text-align: center; }
    .att-phone-table thead { position: sticky; top: 0; z-index: 4; }
    .att-phone-table thead th { background: var(--primary); color: #fff; }
    .att-phone-table tr > th:first-child:not([colspan]) { position: sticky; left: 0; z-index: 2; min-width: 96px; max-width: 125px; white-space: normal; overflow-wrap: anywhere; text-align: left; background: var(--card-bg); box-shadow: 1px 0 0 var(--border); }
    .att-phone-table thead tr > th:first-child { background: var(--primary); z-index: 5; }
    .att-phone-table td { min-width: 25px; }
    .att-phone-table .att-phone-group th { text-align: left; background: var(--table-header-tint); padding: 7px; }
    .att-phone-table [data-phone-total] { white-space: nowrap; font-weight: 700; }
    .teacher-booklet-page .main-body { padding: 10px; }
}
@media print {
    body.teacher-booklet-page * { display: none !important; }
    body.teacher-booklet-page::before { content: "Attendance booklet printing is available to administrators only."; display: block !important; }
}
.attendance-booklet-sheet {
    padding: 0;
}
.attendance-booklet-scroll {
    overflow: auto;
    max-height: 70vh;
    max-height: 70dvh;
    isolation: isolate;
    scrollbar-gutter: stable;
}
.attendance-booklet-scroll:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: -3px;
}
@media screen {
    .attendance-booklet-table {
        border-collapse: separate;
        border-spacing: 0;
    }
    /* Keep both week and date rows together; no guessed second-row offset. */
    .attendance-booklet-table thead {
        position: sticky;
        top: 0;
        z-index: 4;
    }
    .attendance-booklet-table .att-bth-name,
    .attendance-booklet-table .att-btd-name {
        position: sticky;
        left: 0;
        z-index: 2;
        box-shadow: 2px 0 0 var(--border);
        white-space: normal;
        overflow-wrap: anywhere;
    }
    .attendance-booklet-table .att-btd-name {
        background: var(--card-bg);
    }
    .attendance-booklet-table thead .att-bth-name {
        z-index: 5;
        background: var(--primary);
    }
}

.attendance-booklet-table {
    font-size: 0.82rem;
    border-collapse: separate;
    border-spacing: 0;
    width: auto;
    min-width: 100%;
}
.attendance-booklet-table th,
.attendance-booklet-table td {
    border: 1px solid rgba(0,0,0,0.15);
    padding: 5px 6px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}
.attendance-booklet-table thead th {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.attendance-booklet-table .att-booklet-group-heading th,
.grade-entry-table .grade-group-heading th {
    background: var(--table-header-tint);
    color: var(--text-primary);
    text-align: left;
    font-size: .95rem;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
    padding: 10px 14px;
    border-top: 2px solid var(--border);
}
.att-booklet-group-count,
.grade-group-count {
    display: inline-block;
    min-width: 26px;
    margin-left: 6px;
    padding: 1px 9px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: .8rem;
    text-align: center;
}
.att-bth-num,
.att-btd-num {
    min-width: 32px;
    max-width: 40px;
    background: rgba(0,0,0,0.03);
}
.att-bth-adm,
.att-btd-adm {
    min-width: 100px;
}
.att-bth-name,
.att-btd-name {
    text-align: left !important;
    min-width: 180px;
    max-width: 240px;
}
.att-bth-dob,
.att-btd-dob {
    min-width: 90px;
}
.att-bth-week {
    background: var(--primary-dark) !important;
    border-left: 2px solid rgba(255,255,255,0.25);
}
.att-bth-day {
    min-width: 34px;
    padding: 6px 4px;
}
.att-day-num {
    display: block;
    font-size: 0.65rem;
    font-weight: 400;
    opacity: 0.85;
    margin-top: 1px;
}
.att-bth-week-total,
.att-btd-week-total,
.att-bth-total,
.att-btd-grand-total {
    min-width: 48px;
    background: rgba(74, 124, 66, 0.10);
    font-weight: 700;
    border-left: 2px solid rgba(0,0,0,0.15);
}
.att-btd-mark {
    min-width: 34px;
    font-weight: 600;
}
/* Weekly total: week figure beside the running total to date (red, as in the paper register),
   split by a vertical rule. */
.attendance-booklet-table td.att-btd-week-total {
    white-space: nowrap;
}
.att-wk-week,
.att-wk-cum {
    display: inline-block;
    min-width: 1.6em;
    line-height: 1.25;
    vertical-align: middle;
}
.att-wk-week {
    padding-right: 4px;
}
.att-wk-cum {
    padding-left: 4px;
    border-left: 1px solid rgba(0,0,0,0.25);
    color: var(--error);
}
html[data-theme="dark"] .att-wk-cum {
    color: #fc8181;
    border-left-color: rgba(255,255,255,0.25);
}
.att-wk-legend {
    white-space: nowrap;
}
.att-mark-blank {
    display: inline-block;
    width: 8px;
}
.attendance-booklet-table .att-holiday {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
.att-btd-holiday {
    min-width: 34px;
}
.att-holiday-label {
    display: inline-block;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.08em;
    white-space: normal;
    max-height: 22rem;
    padding: 12px 0;
}
.att-btd-name {
    font-weight: 600;
    padding-left: 10px;
}
.att-btd-adm {
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.att-totals-divider td {
    border-top: 2px solid rgba(0,0,0,0.25);
}
.att-totals-label {
    text-align: left !important;
    font-weight: 700;
    background: rgba(74, 124, 66, 0.08);
    padding-left: 10px;
}
.att-total-cell {
    font-weight: 700;
    background: rgba(74, 124, 66, 0.06);
}
.att-totals-bold td {
    font-weight: 800;
}
.att-totals-bold .att-totals-label {
    background: rgba(74, 124, 66, 0.12);
}
.attendance-booklet-table tbody tr:nth-child(even):not(.att-totals-divider):not(.att-totals-bold) {
    background: rgba(0,0,0,0.02);
}

/* Teacher preview: compact full-term register at every screen width. */
@media screen {
    .teacher-booklet-page .attendance-booklet-sheet {
        min-width: 0;
        max-width: 100%;
    }
    .teacher-booklet-page .attendance-booklet-sheet > .att-phone { display: none; }
    .teacher-booklet-page .attendance-booklet-sheet > .card-header {
        display: flex;
        padding: 8px 10px;
    }
    .teacher-booklet-page .attendance-booklet-sheet > .attendance-booklet-scroll {
        display: block;
        min-width: 0;
        max-width: 100%;
    }
    .teacher-booklet-page .attendance-booklet-sheet .booklet-header { padding: 10px; }
    .teacher-booklet-page .attendance-booklet-sheet .booklet-header h2 { font-size: 1rem; }
    .teacher-booklet-page .attendance-booklet-sheet .booklet-meta {
        font-size: .72rem;
        gap: 6px 12px;
    }
    .teacher-booklet-page .attendance-booklet-table { font-size: .72rem; }
    .teacher-booklet-page .attendance-booklet-table th,
    .teacher-booklet-page .attendance-booklet-table td {
        padding: 3px 2px;
        line-height: 1.25;
    }
    .teacher-booklet-page .attendance-booklet-table thead th {
        font-size: .68rem;
        letter-spacing: 0;
    }
    .teacher-booklet-page .attendance-booklet-table .att-bth-num,
    .teacher-booklet-page .attendance-booklet-table .att-btd-num {
        min-width: 24px;
        max-width: 28px;
    }
    .teacher-booklet-page .attendance-booklet-table .att-bth-adm,
    .teacher-booklet-page .attendance-booklet-table .att-btd-adm { min-width: 70px; }
    .teacher-booklet-page .attendance-booklet-table .att-btd-adm { font-size: .68rem; }
    .teacher-booklet-page .attendance-booklet-table .att-bth-name,
    .teacher-booklet-page .attendance-booklet-table .att-btd-name {
        min-width: 120px;
        max-width: 170px;
        padding: 3px 6px;
    }
    .teacher-booklet-page .attendance-booklet-table .att-bth-dob,
    .teacher-booklet-page .attendance-booklet-table .att-btd-dob { min-width: 72px; }
    .teacher-booklet-page .attendance-booklet-table .att-bth-day,
    .teacher-booklet-page .attendance-booklet-table .att-btd-mark,
    .teacher-booklet-page .attendance-booklet-table .att-btd-holiday { min-width: 24px; }
    .teacher-booklet-page .attendance-booklet-table .att-bth-week-total,
    .teacher-booklet-page .attendance-booklet-table .att-btd-week-total,
    .teacher-booklet-page .attendance-booklet-table .att-bth-total,
    .teacher-booklet-page .attendance-booklet-table .att-btd-grand-total { min-width: 40px; }
    .teacher-booklet-page .attendance-booklet-table .att-day-num { font-size: .60rem; }
    .teacher-booklet-page .attendance-booklet-table .att-wk-legend {
        font-size: .55rem;
        white-space: normal;
    }
    .teacher-booklet-page .attendance-booklet-table .att-wk-week { padding-right: 2px; }
    .teacher-booklet-page .attendance-booklet-table .att-wk-cum { padding-left: 2px; }
    .teacher-booklet-page .attendance-booklet-table .att-booklet-group-heading th {
        font-size: .75rem;
        padding: 5px 6px;
    }
    .teacher-booklet-page .attendance-booklet-table .att-booklet-group-count {
        font-size: .65rem;
        min-width: 20px;
        padding: 1px 5px;
    }
    .teacher-booklet-page .attendance-booklet-table .att-holiday-label { padding: 6px 0; }
}

/* Register "every five" rule: a bold line under each fifth learner, as in the
   paper class register. Used by the attendance marking/summary tables and the
   attendance and assessment booklets. */
.table tr.row-five > td,
.table tr.row-five > th {
    border-bottom: 2px solid #2d3748;
}
html[data-theme="dark"] .table tr.row-five > td,
html[data-theme="dark"] .table tr.row-five > th {
    border-bottom-color: #cbd5e0;
}

@media print {
    .attendance-booklet-sheet {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
    }
    .attendance-booklet-table th,
    .attendance-booklet-table td {
        border: 1px solid #333 !important;
        padding: 3px 4px !important;
        font-size: 0.75rem !important;
    }
    .attendance-booklet-table thead th {
        background: #333 !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .att-bth-week {
        background: #444 !important;
    }
    .attendance-booklet-table .att-holiday {
        background: #eee !important;
        color: #333 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .att-btd-week-total,
    .att-btd-grand-total,
    .att-total-cell,
    .att-totals-label {
        background: rgba(74, 124, 66, 0.12) !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .attendance-booklet-scroll {
        overflow: visible !important;
        max-height: none !important;
        scrollbar-gutter: auto;
    }
    .attendance-booklet-table {
        border-collapse: collapse;
    }
    .attendance-booklet-table thead,
    .attendance-booklet-table .att-bth-name,
    .attendance-booklet-table .att-btd-name {
        position: static !important;
        box-shadow: none;
    }
    .att-wk-cum {
        color: #c53030 !important;
        border-left-color: #333 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .table tr.row-five > td,
    .table tr.row-five > th {
        border-bottom: 2px solid #000 !important;
    }
    .att-booklet-group-heading,
    .grade-group-heading {
        break-after: avoid;
        page-break-after: avoid;
    }
    .attendance-booklet-table .att-booklet-group-heading th,
    .att-booklet-group-count,
    .grade-entry-table .grade-group-heading th,
    .grade-group-count {
        background: #eee !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ==================== ALERTS ==================== */
.alert {
    padding: 16px 20px;
    padding-right: 44px; /* room for the dismiss button */
    border-radius: var(--radius);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

/* Dismiss button injected by JS into every alert. */
.alert-dismiss {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.06);
    color: inherit;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
    opacity: 0.7;
}
.alert-dismiss:hover {
    background: rgba(0, 0, 0, 0.12);
    opacity: 1;
    transform: scale(1.1);
}

.alert-success {
    background: rgba(198, 246, 213, 0.7);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--success);
    border-left: 4px solid var(--success);
}

.alert-warning {
    background: rgba(254, 235, 200, 0.7);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--warning);
    border-left: 4px solid var(--warning);
}

.alert-error {
    background: rgba(254, 215, 215, 0.7);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--error);
    border-left: 4px solid var(--error);
}

.alert-info {
    background: rgba(26, 54, 93, 0.08);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--primary);
    border-left: 4px solid var(--primary);
}

/* ==================== LOGIN PAGE ==================== */
.login-page {
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    /* Column + auto vertical margins centre the card, and when it is taller
       than a short phone screen the top stays reachable instead of being
       clipped above the viewport (flex align-items:center does that). */
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.login-container {
    width: 100%;
    max-width: 440px;
    margin: auto 0;
}

.login-card {
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.login-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 40px 40px 60px;
    text-align: center;
    position: relative;
    margin-bottom: -40px;
}

.login-logo {
    width: 80px;
    height: 80px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 2rem;
    color: var(--primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.login-header h1 {
    color: white;
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.login-header p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

.login-body {
    padding: 40px;
}

.login-footer {
    padding: 20px 40px;
    background: rgba(240, 247, 239, 0.6);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ==================== GRADE DISPLAY ==================== */
.grade-a-plus, .grade-a { color: var(--success); }
.grade-b-plus, .grade-b { color: var(--primary); }
.grade-c-plus, .grade-c { color: var(--accent); }
.grade-d { color: var(--warning); }
.grade-f { color: var(--error); }

/* ==================== UTILITIES ==================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-primary { color: var(--primary); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }

.p-1 { padding: 8px; }
.p-2 { padding: 16px; }
.p-3 { padding: 24px; }
.p-4 { padding: 32px; }

.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }

.grid {
    display: grid;
    gap: 24px;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Announcement editor and history share the full content width. */
.announcement-layout {
    grid-template-columns: minmax(0, 1fr);
}

.announcement-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
}

.announcement-layout > .card,
.announcement-form-grid > * {
    min-width: 0;
}

.announcement-form-grid .form-group {
    margin-bottom: 0;
    overflow-wrap: anywhere;
}

.announcement-form-grid .announcement-field-wide {
    grid-column: 1 / -1;
}

.announcement-form-grid .form-control {
    min-width: 0;
    max-width: 100%;
}

@media (max-width: 768px) {
    .announcement-form-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Compact 2-column button grid used by the dashboard Quick Actions card. */
.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.quick-actions-grid .btn {
    justify-content: flex-start;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 640px) {
    .quick-actions-grid {
        grid-template-columns: 1fr;
    }
}

.hidden { display: none !important; }

/* ==================== ANIMATIONS ==================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { 
        opacity: 0;
        transform: translateY(20px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

.animate-slide-in {
    animation: slideIn 0.4s ease-in-out;
}

/* ==================== RESPONSIVE ==================== */
/* Mobile sidebar toggle (hamburger) + dimming overlay. Hidden on desktop. */
.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--primary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 6px 10px;
    margin-right: 8px;
    border-radius: var(--radius);
    line-height: 1;
}

.menu-toggle:hover {
    background: rgba(74, 124, 66, 0.1);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 1199px) {
    .sidebar {
        width: 80px;
    }
    
    .sidebar-header,
    .sidebar-nav li a span,
    .sidebar-footer {
        display: none;
    }
    
    .sidebar-nav li a {
        justify-content: center;
        padding: 14px;
    }
    
    .sidebar-nav li a i {
        margin: 0;
        font-size: 1.25rem;
    }
    
    .main-content {
        margin-left: 80px;
    }
}

@media (min-width: 769px) and (max-width: 1199px) {
    .sidebar-nav .nav-submenu li a {
        padding: 14px;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .menu-toggle {
        display: inline-flex;
        align-items: center;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-header,
    .sidebar-nav li a span,
    .sidebar-footer {
        display: block;
    }
    
    .sidebar-nav li a {
        justify-content: flex-start;
        padding: 12px 24px;
    }
    
    .sidebar-nav li a i {
        margin-right: 12px;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
    
    .main-header {
        padding: 12px 16px;
    }

    .main-header h1 {
        margin-right: auto;
        font-size: 1.25rem;
    }
    
    .main-body {
        padding: 16px;
    }
    
    .table th, .table td {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
}

/* ==================== MODAL ==================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: var(--transition);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.25rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Student discount editor: fixed chrome, independently scrolling content. */
#discountModal { padding: 12px; transition: none; }
#discountModal .modal {
    width: 100%; max-width: 760px; max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px); display: flex; flex-direction: column;
    overflow: hidden; background: var(--card-bg); transition: none;
}
#discountModal * { transition-property: color, background-color, border-color; }
#discountModal .modal-header, #discountModal .modal-footer { flex-shrink: 0; gap: 12px; }
#discountModal .modal-header h3 { margin: 0; }
#discountModal .modal-close {
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 40px; width: 40px; height: 40px; border-radius: var(--radius-sm);
}
#discountModal .modal-close:hover { background: var(--background); }
#discountModal .modal-body { overflow-y: auto; min-height: 0; overscroll-behavior: contain; scrollbar-gutter: stable; }
#discountModal .discount-student { display: grid; gap: 4px; overflow-wrap: anywhere; margin-bottom: 12px; }
#discountModal .discount-intro { margin: 0 0 16px; color: var(--text-secondary); line-height: 1.5; }
#discountModal .discount-general { padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--background); }
#discountModal summary { cursor: pointer; font-weight: 600; }
#discountModal summary span { font-weight: 400; }
#discountModal .form-control { margin-bottom: 12px; min-width: 0; min-height: 44px; }
/* Keep a native dropdown arrow in both themes, including hover/focus. */
#discountModal select.form-select { appearance: auto; padding-right: 12px; background-image: none; }
#discountModal .discount-field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
#discountModal .discount-field-grid > div { min-width: 0; }
#discountModal .form-hint { display: block; color: var(--text-secondary); line-height: 1.5; margin: 0 0 16px; }
#discountModal .discount-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 4px 0 16px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); }
#discountModal .discount-summary > div { display: flex; flex-direction: column; justify-content: center; gap: 6px; min-width: 0; }
#discountModal .discount-summary strong { font-size: 1.15rem; overflow-wrap: anywhere; }
#discountModal .discount-summary-label, #discountModal .discount-summary-note { color: var(--text-secondary); font-size: .85rem; }
#discountModal .discount-saving { border-radius: var(--radius-sm); padding: 12px; background: var(--card-bg); border: 1px solid var(--primary); }
#discountModal .discount-rate { font-size: 1.1rem; font-weight: 700; color: var(--primary-dark); }
#discountModal .discount-summary-note { grid-column: 1 / -1; margin: 0; }
#discountModal .discount-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
#discountModal :is(button, summary):focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
html[data-theme="dark"] #discountModal .discount-rate { color: var(--primary-light); }
@media (max-width: 540px) {
    #discountModal .discount-summary, #discountModal .discount-field-grid { grid-template-columns: 1fr; }
    #discountModal .discount-field-grid { gap: 0; }
    #discountModal .modal-body, #discountModal .modal-header, #discountModal .modal-footer { padding: 12px 16px; }
    #discountModal .discount-actions .btn { width: 100%; }
}

/* ==================== MEDIA CROP UPLOAD (guided photo uploader) ==================== */
.media-crop-modal {
    max-width: 680px;
    padding: 24px;
    overflow-x: auto;
}

.media-crop-modal h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
}

.media-crop-intro {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 4px 0 16px;
}

.media-crop-aspects {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}

.media-crop-aspects .btn[aria-pressed="true"] {
    background: var(--primary);
    border-color: var(--primary-dark);
    color: #fff;
}

.media-crop-aspect-hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 14px;
}

.media-crop-stage {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #1e2430;
    margin: 0 auto 14px;
    cursor: grab;
    touch-action: none;
}

.media-crop-stage:active {
    cursor: grabbing;
}

.media-crop-stage img {
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
    will-change: transform;
}

.media-crop-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.9rem;
}

.media-crop-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.media-crop-controls input[type="range"] {
    flex: 1;
    min-width: 140px;
    accent-color: var(--primary);
}

.media-crop-controls .form-control {
    flex: 1;
    min-width: 200px;
}

.media-crop-size {
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
}

.media-crop-status {
    min-height: 1.2em;
    margin: 8px 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.media-crop-status.is-error {
    color: var(--error);
}

.media-crop-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 14px;
}

/* ==================== LOGIN BACKGROUND MANAGER (settings) ==================== */
.loginbg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
}

.loginbg-item {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    overflow: hidden;
    transition: var(--transition);
}

.loginbg-item.is-inactive .loginbg-thumb {
    opacity: 0.45;
    filter: grayscale(0.6);
}

.loginbg-thumb {
    aspect-ratio: 16 / 9;
    background-color: var(--background);
    background-size: cover;
    background-position: center;
    position: relative;
}

.loginbg-tag-stock,
.loginbg-tag-hidden {
    position: absolute;
    top: 8px;
}

.loginbg-tag-stock {
    left: 8px;
}

.loginbg-tag-hidden {
    right: 8px;
}

.loginbg-meta {
    padding: 8px 10px 4px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
    flex: 1;
}

.loginbg-actions {
    display: flex;
    gap: 8px;
    padding: 8px 10px 10px;
}

.loginbg-actions form {
    flex: 1;
    display: flex;
}

.loginbg-actions .btn {
    flex: 1;
    white-space: nowrap;
}

/* ==================== PAGINATION ==================== */
.pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 24px;
}

.pagination a,
.pagination span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: var(--transition);
}

.pagination a {
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.pagination a:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination span {
    background: var(--primary);
    color: white;
}

.pagination-info {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Audit log pagers share numbered navigation without affecting other lists. */
.booklet-records,
.contact-message-records,
.audit-log-records { scroll-margin-top: 100px; }
.booklet-records .card-header { flex-wrap: wrap; gap: 10px; }
.contact-message-records .table { min-width: 900px; }
.audit-log-records .log-record-actions { flex-wrap: wrap; }
.log-record-table th:first-child,
.log-record-table td:first-child:not([colspan]) { width: 56px; white-space: nowrap; }
/* Long audit details wrap inside a bounded column so the IP column stays on screen. */
.log-record-table .log-detail-cell { min-width: 240px; max-width: 460px; overflow-wrap: anywhere; }
.log-record-table .log-ip-cell { white-space: nowrap; }
.log-detail-raw { margin-top: 6px; }
.log-detail-raw summary { cursor: pointer; color: var(--primary); font-size: 0.85rem; }
.log-detail-raw pre { max-height: 240px; overflow: auto; margin: 6px 0 0; padding: 8px 10px;
    white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.78rem; line-height: 1.4;
    background: var(--table-header-tint); border: 1px solid var(--border-color); border-radius: var(--radius-sm); }
.log-pagination .pagination { flex-wrap: wrap; margin-top: 0; }
.log-pagination .pagination a,
.log-pagination .pagination span { min-width: 36px; width: auto; padding: 0 8px; }
.log-pagination .pagination a:focus-visible,
.booklet-records .table-container:focus-visible,
.contact-message-records .table-container:focus-visible,
.audit-log-records .table-container:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 2px; }
html[data-theme="dark"] .log-pagination .pagination [aria-current="page"],
html[data-theme="dark"] .log-pagination .pagination a:hover { background: var(--primary-dark); }

/* ==================== GENDER ACCENTS (Students list) ==================== */
.gender-boy { color: var(--gender-boy); }
.gender-girl { color: var(--gender-girl); }

.students-gender-chips {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
}

/* Finance-only headings: separate screen paging from complete print rosters. */
.fin-print-heading { display: none; }
.fin-roster-heading { break-after: avoid; }
.fin-roster-heading[data-fin-heading="class"] td { font-size: 0.95rem; }
.fin-roster-label {
    padding: 6px 14px;
    background: var(--gender-sep-bg);
    color: var(--gender-sep-text);
    font-weight: 700;
}
.fin-roster-label[data-fin-heading="class"] { border-top: 2px solid var(--gender-sep-border); }
.fin-debtor-legend { list-style: none; padding: 0; margin: 12px 0 0; }
.fin-debtor-legend li { display: flex; align-items: center; gap: 8px; padding: 4px 0; flex-wrap: wrap; }
.fin-debtor-legend small { color: var(--text-secondary); }
.fin-notice-class[hidden] { display: none !important; }
@media screen {
    html[data-theme="dark"] .fin-roster-heading td,
    html[data-theme="dark"] .fin-roster-label { background: #302437; color: #f6c6e2; border-color: #71445f; }
    html[data-theme="dark"] #feeCollectForm .typeahead-dropdown { background: #1b2432; border-color: #4a5872; }
    html[data-theme="dark"] #feeCollectForm .ta-name,
    html[data-theme="dark"] #feeCollectForm .typeahead-selected { color: #e6ebf2; }
    html[data-theme="dark"] #feeCollectForm .ta-meta { color: #aebbd0; }
}
@media print {
    tr.fin-print-heading { display: table-row; }
    .fin-roster-heading td { color: #111 !important; background: #ececec !important; }
}

.gender-separator-row td {
    background: var(--gender-sep-bg);
    color: var(--gender-sep-text);
    font-weight: 700;
    font-size: 0.82rem;
    padding: 6px 14px;
    border-top: 2px solid var(--gender-sep-border);
}

/* Inline delete/edit forms inside table action cells. */
.row-action-form { display: inline; }

/* ==================== EMPTY STATE ==================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    background: var(--background);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 2rem;
    color: var(--text-muted);
}

.empty-state h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ==================== LOADING ==================== */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

/* ==================== LOGIN BACKGROUND ==================== */
/* The background is a smooth crossfade carousel of school photos — three
   building exteriors and three campus-life photos. The .login-bg-slider
   div sits behind everything; the ::before pseudo-element adds the green
   tint overlay on top of the photos for brand contrast and text legibility. */

.login-page {
    position: relative;
    min-height: 100vh;
    min-height: 100svh;
}

/* Carousel container: fixed full-viewport, sits behind the overlay and card. */
.login-bg-slider {
    position: fixed;
    top: 0;
    left: 0;
    /* 100% (not 100vw): vw includes the scrollbar and added a sideways
       scrollbar whenever the login card was taller than the screen. */
    width: 100%;
    height: 100vh;
    /* Match the visible screen on phones (dvh shrinks with the address bar),
       so the picture never runs on below the fold. */
    height: 100dvh;
    z-index: 0;
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

/* Each slide: full-viewport background image with a slow, subtle Ken Burns
   zoom. All slides start invisible; the animation cycles them in sequence.
   The cycle duration is set via the --cycle CSS variable on .login-bg-slider
   (30 s for 6 images at 5 s each). The animation-delay is set inline per
   slide by login.php.

   Keyframe percentages are tuned for 6 slides. Each slide is visible for
   5 s, with a 1.5 s crossfade that overlaps the next slide's fade-in so
   there is no dark gap between images. The Ken Burns zoom goes from 1.0
   to 1.06 over the visible period — slow enough to be felt, not seen. */
.login-bg-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    opacity: 0;
    transform: scale(1.0);
    animation: loginBgCrossfade var(--cycle, 30s) ease-in-out infinite;
}

@keyframes loginBgCrossfade {
    0%      { opacity: 0; transform: scale(1.0); }
    5%      { opacity: 1; }                          /* 1.5 s — smooth fade-in  */
    16.67%  { opacity: 1; transform: scale(1.03); }  /* 5 s — crossfade begins  */
    21.67%  { opacity: 0; transform: scale(1.06); }  /* 6.5 s — crossfade ends  */
    100%    { opacity: 0; transform: scale(1.06); }
}

/* Respect users who prefer reduced motion: show the first image only. */
@media (prefers-reduced-motion: reduce) {
    .login-bg-slide {
        animation: none;
        opacity: 0;
    }
    .login-bg-slide:first-child {
        opacity: 1;
        transform: scale(1);
    }
}

/* Green tint overlay on top of the carousel images for brand contrast. */
.login-page::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(rgba(31, 111, 67, 0.45), rgba(31, 111, 67, 0.45));
    z-index: 1;
}

.login-container {
    position: relative;
    z-index: 2;
}

/* Phones: one still picture and no crossfade. login.php only supplies a
   background-image for the first slide below 769px, so the other pictures are
   never downloaded, and the Ken Burns/crossfade compositing stops entirely. */
@media (max-width: 768px) {
    .login-bg-slide {
        animation: none !important;
        opacity: 0;
        transform: none;
    }

    .login-bg-slide:first-child {
        opacity: 1;
    }

    /* A still background needs less blur than a moving one. */
    .login-card {
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
    }
}

/* ==================== LOGO STYLES (school crest image) ==================== */
/* Shared logo mark: the official Royal Stars crest (images/4.jpeg). The path is
   relative to this stylesheet (css/), so ../images/4.jpeg resolves to the
   project-root image for every portal page regardless of its folder depth. */
.login-logo,
.sidebar-logo-icon,
.hub-brand-logo {
    position: relative;
    background: #ffffff url("../images/4.jpeg") center center / contain no-repeat;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    flex: 0 0 auto;
}

/* No CSS star glyph now that the real crest image is used. */
.login-logo::before,
.sidebar-logo-icon::before,
.hub-brand-logo::before {
    content: none;
}

.login-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 1rem;
}

.login-logo span {
    display: none;
}

.sidebar-logo-icon {
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
}

/* ==================== REPORT TABLE STYLES ==================== */
.report-table th,
.report-table td {
    text-align: center;
    vertical-align: middle;
    padding: 12px 8px;
}

.report-table th:first-child,
.report-table td:first-child {
    text-align: left;
    padding-left: 15px;
}

/* Print Styles */
@media print {
    .sidebar,
    .main-header,
    .card-header h3 .text-secondary,
    .btn,
    .alert {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        page-break-inside: avoid;
    }
    
    .table {
        font-size: 10pt;
    }
    
    .table th,
    .table td {
        padding: 6px 4px !important;
        border: 1px solid #ddd !important;
    }
    
    .badge {
        border: 1px solid #999 !important;
        background: white !important;
        color: black !important;
    }

    /* Scrollable wrappers (.table-container) keep their scrollbar and clip on
       paper — flatten them so printed sheets (staff directory, payroll
       sheet) flow at full width instead of showing a "scroll wheel". */
    .table-container {
        overflow: visible !important;
        max-width: none !important;
    }
    .table-container .table th,
    .table-container .table td {
        overflow-wrap: anywhere;
    }

    /* Compact/pinned table variants must not clip on paper: let cells wrap
       again, unhide truncated values, and un-pin the actions column. */
    .table-users-fit { min-width: 0; }
    .table-compact th,
    .table-compact td { white-space: normal !important; }
    .table-compact .cell-trunc {
        max-width: none !important;
        overflow: visible !important;
    }
    .table-pin-last th:last-child,
    .table-pin-last td:last-child,
    .table-pin-last .pinned-context {
        position: static !important;
        box-shadow: none !important;
    }

    /* Transient / floating UI must never land on paper. */
    .loading-overlay,
    .sidebar-overlay,
    .toast-stack,
    .toast,
    .portal-tour-tooltip {
        display: none !important;
    }

    /* Long printed tables must be allowed to break across pages: keep-together
       on the enclosing card clips them, while rows themselves stay intact. */
    .card {
        page-break-inside: auto;
    }
    .table tr {
        page-break-inside: avoid;
    }
}

/* ==================== PARENT PORTAL: PRINTING DISABLED ==================== */
/* Parents are view-only: block browser printing (Ctrl+P) on every parent page. */
@media print {
    body.no-print-page * {
        display: none !important;
    }
    body.no-print-page::before {
        content: "Printing is not available on the parent portal.";
        display: block !important;
        padding: 48px 24px;
        text-align: center;
        font-size: 16pt;
        color: #000;
    }
}

/* ==================== PORTAL HUB (full-screen card landing) ==================== */
.hub-body {
    min-height: 100vh;
    background-color: #f4f7f3;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(74,124,66,0.10) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(214,158,46,0.07) 0%, transparent 45%),
        radial-gradient(ellipse at 40% 90%, rgba(74,124,66,0.06) 0%, transparent 50%);
    display: flex;
    flex-direction: column;
}

.hub-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: linear-gradient(90deg, var(--primary-dark) 0%, var(--primary) 60%, var(--secondary) 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.10), 0 1px 3px rgba(0,0,0,0.06);
    position: relative;
    z-index: 2;
}

.hub-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.hub-brand-logo {
    width: 44px;
    height: 44px;
}

.hub-brand-logo::before {
    font-size: 1.5rem;
}

.hub-brand-text h1 {
    font-family: 'Playfair Display', serif;
    font-size: 1.4rem;
    margin: 0;
    line-height: 1.1;
    color: #fff;
}

.hub-brand-text span {
    font-size: 0.8rem;
    opacity: 0.85;
    letter-spacing: 0.5px;
}

.hub-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hub-user .user-avatar {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.hub-user-name {
    font-weight: 600;
    line-height: 1.1;
}

.hub-user-role {
    font-size: 0.78rem;
    opacity: 0.85;
}

.hub-logout {
    color: #fff;
    opacity: 0.85;
    font-size: 1.1rem;
    padding: 8px;
    border-radius: var(--radius);
    transition: var(--transition);
}

.hub-logout:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.hub-main {
    flex: 1 1 auto;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 48px 32px;
    position: relative;
    z-index: 1;
}

.hub-back-card {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 22px;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    color: var(--primary-dark);
    font-weight: 600;
    font-size: 0.92rem;
    text-decoration: none;
    margin-bottom: 24px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.hub-back-card:hover {
    background: rgba(255, 255, 255, 0.80);
    transform: translateX(-4px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.10);
    border-color: var(--primary-light);
}
.hub-back-card i {
    font-size: 1rem;
    color: var(--primary);
}

.hub-welcome {
    text-align: center;
    margin-bottom: 40px;
    /* Entrance animation (tiles stagger below). Visible by default so a
       blocked or failed animation can never strand the heading invisible —
       hubCardIn still starts from opacity 0, so the entrance is unchanged. */
    opacity: 1;
    animation: hubCardIn 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

.hub-welcome h2 {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    color: var(--primary-dark);
    margin: 0 0 6px;
}

.hub-welcome p {
    color: var(--text-secondary);
    margin: 0;
}

.hub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 24px;
}

.hub-tile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 16px;
    padding: 28px 24px;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05), 0 8px 24px rgba(0,0,0,0.04);
    transition: var(--transition);
    min-height: 170px;
    /* Staggered entrance: tiles pop in one by one with spring easing. Visible
       by default for the same reason as .hub-welcome above — the keyframes
       still animate in from opacity 0. */
    opacity: 1;
    animation: hubCardIn 0.52s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Hub card entrance — scale + rise with spring overshoot. */
@keyframes hubCardIn {
    from { opacity: 0; transform: scale(0.94) translateY(22px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.hub-tile:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 8px 20px rgba(0,0,0,0.08), 0 20px 40px rgba(0,0,0,0.06);
    border-color: var(--primary-light);
    background: rgba(255, 255, 255, 0.92);
}

.hub-tile-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: #fff;
}

.hub-tile-body h3 {
    font-size: 1.25rem;
    margin: 0 0 6px;
    color: var(--text-primary);
}

.hub-tile-body p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.45;
}

@media (max-width: 640px) {
    .hub-topbar { padding: 14px 18px; }
    .hub-main { padding: 32px 18px; }
    .hub-welcome h2 { font-size: 1.6rem; }
    .hub-user-info { display: none; }
    .hub-grid { grid-template-columns: 1fr 1fr; gap: 16px; }
    .hub-tile { min-height: 150px; padding: 20px 16px; }
    .hub-tile-icon { width: 52px; height: 52px; font-size: 1.4rem; }
    .hub-tile-body h3 { font-size: 1.05rem; }
}

@media (max-width: 400px) {
    .hub-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Hub tile enhancements: bento hero, role-themed colours, badges, cross-portal
   ========================================================================== */
.hub-tile { position: relative; }

/* Bento hero tile — spans 2 columns, larger icon and padding. */
.hub-tile.hero {
    grid-column: span 2;
    min-height: 200px;
    padding: 36px 32px;
    background: rgba(255, 255, 255, 0.88);
}
.hub-tile.hero .hub-tile-icon {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    font-size: 2.2rem;
}
.hub-tile.hero .hub-tile-body h3 { font-size: 1.6rem; }
.hub-tile.hero .hub-tile-body p { font-size: 1rem; }

/* Role-themed icon gradients (admin/bursar stay green — the default). */
body[data-role="teacher"] .hub-tile-icon {
    background: linear-gradient(135deg, #3b7bb8 0%, #5ba0d8 100%);
}
body[data-role="parent"] .hub-tile-icon {
    background: linear-gradient(135deg, #c89028 0%, #e8b54a 100%);
}
body[data-role="hod"] .hub-tile-icon {
    background: linear-gradient(135deg, #2a8a8a 0%, #4db8b8 100%);
}
body[data-role="headteacher"] .hub-tile-icon {
    background: linear-gradient(135deg, #6b4a8a 0%, #9a6abf 100%);
}

/* Cross-portal tile — slate gray icon to signal “not native to your role”. */
.hub-tile.cross-portal .hub-tile-icon {
    background: linear-gradient(135deg, #64748b 0%, #94a3b8 100%);
}

/* Badge pill in the top-right corner of a tile. */
.hub-tile-badge {
    position: absolute;
    top: 14px;
    right: 14px;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-secondary);
    line-height: 1.4;
    white-space: nowrap;
}
.hub-tile-badge.role {
    background: var(--primary-light);
    color: #fff;
}
.hub-tile-badge.cross-portal {
    background: rgba(100, 116, 139, 0.15);
    color: #64748b;
}

/* Mini stat pills (for hero tiles). */
.hub-tile-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}
.hub-tile-stat {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 3px 12px;
    border-radius: 20px;
    background: rgba(74, 124, 66, 0.10);
    color: var(--primary-dark);
}

@media (max-width: 640px) {
    .hub-tile.hero { grid-column: span 2; min-height: 160px; padding: 24px 20px; }
    .hub-tile.hero .hub-tile-icon { width: 60px; height: 60px; font-size: 1.6rem; }
    .hub-tile.hero .hub-tile-body h3 { font-size: 1.25rem; }
    .hub-tile-badge { font-size: 0.62rem; padding: 2px 8px; }
}

@media (max-width: 400px) {
    .hub-tile.hero { grid-column: span 1; }
}

/* ==========================================================================
   Toggle switches (used for feature-access permissions in the user modal)
   ========================================================================== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 27px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
    margin: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: #d2d8d2;
    border-radius: 27px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, .2);
    transition: background .35s cubic-bezier(.4, 0, .2, 1), box-shadow .35s ease;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    height: 21px;
    width: 21px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
    transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), box-shadow .35s ease;
}
.toggle-switch input:checked + .toggle-slider {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 55%, var(--primary-dark) 100%);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, .12), 0 2px 10px rgba(74, 124, 66, .5);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(23px);
    box-shadow: 0 2px 7px rgba(0, 0, 0, .35);
}
.toggle-switch input:focus-visible + .toggle-slider {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.toggle-switch input:disabled + .toggle-slider {
    opacity: .55;
    cursor: not-allowed;
}

/* A single feature row: icon + label on the left, toggle on the right. */
.perm-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-weight: normal;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    background: #fff;
    transition: border-color .2s ease, box-shadow .2s ease, background .2s ease, transform .1s ease;
}
.perm-toggle:hover {
    border-color: var(--primary-light);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}
.perm-toggle:active {
    transform: scale(.99);
}
/* Flashy highlight when the feature is enabled. */
.perm-toggle:has(input:checked) {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(107, 155, 99, .12) 0%, rgba(74, 124, 66, .06) 100%);
}
.perm-toggle:has(input:checked) .perm-toggle-label i {
    color: var(--primary);
}
.perm-toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}
.perm-toggle-label i {
    width: 18px;
    text-align: center;
    color: var(--text-secondary);
    transition: color .2s ease;
}

/* ---- Compact permission grid (sectioned checkbox list) ----
   A dense multi-column layout for the Feature Access screens: each column
   holds sections whose bold uppercase title is itself the "select all"
   checkbox for the plain checkboxes beneath it. */
.perm-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 28px;
    align-items: start;
}
@media (max-width: 992px) {
    .perm-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .perm-grid { grid-template-columns: 1fr; }
}
.perm-sec {
    margin-bottom: 22px;
    break-inside: avoid;
}
.perm-sec-title {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin: 0 0 8px;
    font-weight: 700;
    font-size: 0.86rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text);
    cursor: pointer;
}
.perm-sec-title input {
    margin: 2px 0 0;
    flex-shrink: 0;
}
.perm-item {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin: 0 0 6px;
    padding-left: 0;
    font-weight: normal;
    font-size: 0.86rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1.35;
}
.perm-item input {
    margin: 2px 0 0;
    flex-shrink: 0;
}
.perm-item:has(input:checked) {
    color: var(--primary);
    font-weight: 600;
}
.perm-item input:disabled,
.perm-sec-title input:disabled {
    cursor: not-allowed;
}
.perm-item-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.perm-hint {
    font-size: 0.74rem;
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.35;
}
.perm-item:has(input:checked) .perm-hint {
    color: var(--text-secondary);
}

/* ==================== GALLERY ==================== */
.badge-muted {
    background: rgba(113, 128, 150, 0.12);
    color: var(--text-secondary);
}

.gallery-toolbar {
    margin-bottom: 16px;
}

.gallery-meta {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 4px 0;
}

.gallery-desc {
    color: var(--text-secondary);
    margin-top: 6px;
}

.gallery-desc-sm {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 4px;
}

.gallery-caption {
    font-weight: 600;
    color: var(--text-primary);
}

.gallery-album-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.gallery-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.gallery-form .form-hint {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.gallery-form .form-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

/* Flashy gallery forms */
.gallery-form-flashy {
    position: relative;
    padding: 20px;
    border-radius: var(--radius);
    background:
        linear-gradient(var(--card-bg), var(--card-bg)) padding-box,
        linear-gradient(135deg, var(--primary), var(--accent)) border-box;
    border: 1px solid transparent;
    box-shadow: var(--shadow);
}

.gallery-form-flashy::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    border-radius: var(--radius) var(--radius) 0 0;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}

.gallery-form-flashy .form-group {
    margin-bottom: 14px;
}

.gallery-form-flashy label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.gallery-form-flashy input[type="text"],
.gallery-form-flashy input[type="date"],
.gallery-form-flashy textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--background);
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.gallery-form-flashy input[type="text"]:focus,
.gallery-form-flashy input[type="date"]:focus,
.gallery-form-flashy textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--card-bg);
    box-shadow: 0 0 0 3px rgba(74, 124, 66, 0.15);
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

@media (max-width: 560px) {
    .form-grid-2 { grid-template-columns: 1fr; }
}

/* Upload dropzone */
.gallery-dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
    padding: 26px 18px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--background);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.gallery-dropzone:hover,
.gallery-dropzone.is-dragover {
    border-color: var(--primary);
    background: rgba(74, 124, 66, 0.05);
    box-shadow: 0 0 0 3px rgba(74, 124, 66, 0.1);
}

.gallery-dropzone > i {
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 4px;
}

.gallery-dropzone-title {
    font-weight: 600;
    color: var(--text-primary);
}

.gallery-dropzone-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.gallery-dropzone-file {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary);
    margin-top: 4px;
    word-break: break-all;
}

.gallery-dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.empty-state > i {
    font-size: 2.5rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: block;
}

/* Album grid */
.gallery-album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.gallery-album-card {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
}

.gallery-album-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.gallery-album-card.is-hidden {
    opacity: 0.6;
}

.gallery-album-cover {
    position: relative;
    display: block;
    aspect-ratio: 4 / 3;
    background: var(--background);
    overflow: hidden;
}

.gallery-album-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-album-cover-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 2.5rem;
    color: var(--text-muted);
}

.gallery-album-count {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
}

.gallery-album-body {
    display: block;
    padding: 14px 16px;
}

.gallery-album-body h3 {
    font-size: 1.05rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Image grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.gallery-item {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.gallery-item.is-hidden {
    opacity: 0.6;
}

.gallery-thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--background);
    overflow: hidden;
}

.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-zoomable {
    cursor: zoom-in;
    transition: transform 0.3s ease;
}

.gallery-zoomable:hover {
    transform: scale(1.03);
}

/* Video thumbnails */
.gallery-thumb.is-video {
    background: #000;
}

.gallery-thumb.is-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    cursor: zoom-in;
}

.gallery-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    pointer-events: none;
    transition: background 0.15s ease, transform 0.15s ease;
}

.gallery-thumb.is-video:hover .gallery-play {
    background: var(--primary);
    transform: translate(-50%, -50%) scale(1.08);
}

.gallery-cover-flag {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
}

.gallery-hidden-flag {
    position: absolute;
    top: 8px;
    right: 8px;
}

.gallery-website-flag {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: #2d7a2d;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.gallery-check-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}

.gallery-check-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.gallery-item-body {
    padding: 12px 14px;
}

/* Lightbox */
.gallery-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 30px;
}

.gallery-lightbox.open {
    display: flex;
}

.gallery-lightbox img {
    max-width: 92vw;
    max-height: 82vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}

.gallery-lightbox video {
    max-width: 92vw;
    max-height: 82vh;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    background: #000;
}

.gallery-lightbox-caption {
    color: #fff;
    margin-top: 14px;
    font-size: 0.95rem;
    text-align: center;
    max-width: 80vw;
}

.gallery-lightbox-close {
    position: absolute;
    top: 18px;
    right: 26px;
    color: #fff;
    font-size: 2.4rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
}

/* ==================== HOVER TIP (QTIP) ==================== */
.qtip {
    position: fixed;
    z-index: 3000;
    background: #2d3748;
    color: #fff;
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.3;
    padding: 6px 10px;
    border-radius: 6px;
    max-width: 240px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
    white-space: normal;
}

.qtip.qtip-show {
    opacity: 1;
    transform: translateY(0);
}

.qtip::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
}

.qtip.qtip-top::after {
    top: 100%;
    border-top-color: #2d3748;
}

.qtip.qtip-bottom::after {
    bottom: 100%;
    border-bottom-color: #2d3748;
}

/* Screen-only report scrolling leaves the page's vertical scroll unrestricted. */
@media screen {
    .report-table-scroll { width:100%; max-width:100%; min-width:0; overflow-x:auto; -webkit-overflow-scrolling:touch; margin-bottom:16px; }
    .report-table-scroll:focus-visible { outline:3px solid var(--primary, #2563eb); outline-offset:-3px; }
    .report-scroll-hint { font-size:.82rem; margin:6px 0; color:var(--text-muted, #64748b); }
    .ps-report .report-scroll-hint { color:inherit; }
    .report-table-scroll > .ps-entry-tbl { min-width:480px; }
    .report-table-scroll > .ps-tbl { min-width:430px; }
    .report-table-scroll > .ps-picker-table { min-width:720px; }
    .report-table-scroll > .tr-table { min-width:650px; }
    .report-table-scroll > .tr-key { min-width:430px; }
    .terminal-report-page .terminal-report.provisional { overflow:clip; }
    .ps-entry-tbl input:focus-visible + .ps-entry-dot { outline:3px solid #2563eb; outline-offset:3px; }
    .ps-filters { display:flex; flex-wrap:wrap; gap:10px; align-items:center; }
    .ps-filters .form-control { width:auto; max-width:100%; min-width:0; }
    .preschool-page .main-header, .terminal-report-page .main-header,
    .preschool-page .header-actions, .terminal-report-page .header-actions { flex-wrap:wrap; gap:12px; }
    .terminal-report-page form.d-flex, .terminal-report-page .card-body > .d-flex { flex-wrap:wrap; }
    .terminal-report-page .form-control, .preschool-page .form-control { max-width:100%; min-width:0; }
    .preschool-page .main-body, .terminal-report-page .main-body,
    .preschool-page .card-body, .terminal-report-page .card-body, #ps-edit-area { min-width:0; }
    .ps-progress { --progress-color:#b91c1c; display:flex; align-items:center; gap:8px; width:240px; max-width:100%; margin:0 auto 10px; font-size:.82rem; line-height:1.4; }
    .ps-progress[data-state="partial"] { --progress-color:#c26908; }
    .ps-progress[data-state="complete"] { --progress-color:#15803d; }
    .ps-progress[data-state="unavailable"] { --progress-color:#64748b; }
    .ps-progress-track { flex:1; min-width:0; height:6px; border-radius:3px; background:var(--border, #e2e8f0); overflow:hidden; }
    .ps-progress[data-state="empty"] .ps-progress-track { background:#fca5a5; }
    .ps-progress-track > span { display:block; height:100%; background:var(--progress-color); }
    .ps-progress [data-progress-label] { flex:0 0 4ch; text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; }
    .ps-picker-table .ps-progress { width:160px; min-width:120px; margin:0; }
    .ps-editor-identity { display:flex; flex-wrap:wrap; align-items:center; justify-content:center; gap:6px 16px; margin:0 0 10px; }
    .ps-editor-identity > strong { min-width:0; overflow-wrap:anywhere; }
    .ps-editor-identity .ps-progress { margin:0; }
    .booklet-recording-scroll { max-width:100%; overflow-x:auto; isolation:isolate; }
    .booklet-recording-scroll:focus-visible { outline:3px solid var(--primary); outline-offset:-3px; }
    .ps-picker-table, .booklet-recording-scroll .booklet-table { border-collapse:separate; border-spacing:0; }
    .ps-picker-table .ps-picker-name, .booklet-recording-scroll :is(.booklet-th-name, .booklet-td-name) {
        position:sticky; left:0; z-index:2; width:220px; min-width:220px; max-width:220px;
        white-space:normal; overflow-wrap:anywhere; background:var(--card-bg); box-shadow:2px 0 0 var(--border); box-sizing:border-box;
    }
    .ps-picker-table thead .ps-picker-name { z-index:3; background:var(--card-bg); }
    .booklet-recording-scroll .booklet-th-name { z-index:3; }
    .ps-picker-name .d-flex > span { min-width:0; white-space:normal; }
    .ps-picker-name .d-flex > :first-child { flex-shrink:0; }
}
@media screen and (max-width:600px) {
    .preschool-page .ps-report, .terminal-report-page .terminal-report { padding:12px; }
    .ps-report .ps-req, #ps-edit-area .grid, .terminal-report-page .card-body .grid,
    .terminal-report-page .tr-meta, .terminal-report-page .tr-foot { grid-template-columns:minmax(0, 1fr); }
    .ps-report .ps-data strong { min-width:0; margin-right:6px; }
    .ps-report .ps-head h1, .terminal-report-page .tr-head h1 { overflow-wrap:anywhere; }
    .ps-report .ps-remarks, .terminal-report-page .tr-meta, .terminal-report-page .tr-foot { overflow-wrap:anywhere; }
    .terminal-report-page .tr-head.tr-head-branded { grid-template-columns:minmax(0, 1fr); }
}
/* Shared progressive header enhancement; the fallback menu stays reachable without JavaScript. */
.portal-sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; border:0; }
.user-dropdown:not(.user-menu-enhanced) .user-dropdown-menu { position:static; opacity:1; visibility:visible; transform:none; }
.user-menu-identity { display:none; padding:12px 16px; border-bottom:1px solid var(--border); overflow-wrap:anywhere; }
.user-menu-identity strong, .user-menu-identity small { display:block; }
.user-menu-identity small { color:var(--text-secondary); }
.user-dropdown-toggle:focus-visible { outline:2px solid var(--primary); outline-offset:2px; }
.portal-header-controls { display:flex; align-items:center; gap:inherit; min-width:0; }
.portal-page-actions { display:contents; }
.portal-page-actions:empty, .hub-mobile-account { display:none; }
.att-skip-clock { display:inline-flex; vertical-align:middle; }
body > .att-skip-clock { margin:8px 16px; }
.att-skip-clock a { display:inline-flex; align-items:center; gap:6px; padding:6px 10px; border:1px solid var(--border); border-radius:20px; background:var(--card-bg); color:var(--text-primary); font-size:.85rem; font-variant-numeric:tabular-nums; white-space:nowrap; }
.att-skip-clock[data-expired] a { border-color:var(--warning); }
@media screen and (max-width:768px) {
    .main-header.portal-header-ready, .hub-topbar.portal-header-ready { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; gap:6px 8px; padding:8px 12px; }
    .main-header.portal-header-ready.portal-header-has-toggle { grid-template-columns:44px minmax(0,1fr) auto; }
    .portal-header-ready > :is(.header-actions, .hub-user) { display:contents; }
    .portal-header-ready .portal-header-controls { grid-row:1; grid-column:-2; gap:4px; flex-wrap:nowrap; }
    .portal-header-ready .portal-page-actions:not(:empty) { display:flex; flex-wrap:wrap; grid-column:1 / -1; grid-row:2; align-items:center; justify-content:flex-end; gap:6px 10px; min-width:0; }
    .portal-page-actions > .btn { white-space:nowrap; max-width:100%; min-height:36px; padding:6px 10px; font-size:.85rem; line-height:1.4; }
    .main-header.portal-header-ready > h1 { min-width:0; margin:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:1.1rem; grid-row:1; grid-column:1; }
    .main-header.portal-header-has-toggle > h1 { grid-column:2; }
    .portal-header-ready > .menu-toggle { grid-row:1; grid-column:1; width:44px; min-height:44px; padding:0; justify-content:center; margin:0; }
    .portal-header-ready .user-menu-enhanced .user-info,
    .portal-header-ready .user-menu-enhanced .user-dropdown-toggle > i { display:none; }
    .portal-header-ready .user-menu-enhanced .user-dropdown-toggle { min-width:44px; min-height:44px; padding:2px; gap:0; justify-content:center; }
    .portal-header-ready .user-menu-identity { display:block; }
    .portal-header-ready .user-dropdown { position:static; }
    .portal-header-ready .user-dropdown-menu { top:calc(100% + 6px); left:auto; right:8px; width:260px; min-width:0; max-width:calc(100vw - 16px); max-height:70vh; overflow-y:auto; background:var(--card-bg); color:var(--text-primary); }
    .portal-header-ready .notif-dropdown { max-width:calc(100vw - 16px); }
    .portal-header-ready .theme-toggle, .portal-header-ready .notif-bell { margin:0; flex-shrink:0; }
    .hub-topbar.portal-header-ready .hub-brand { min-width:0; gap:6px; }
    .hub-topbar.portal-header-ready .hub-brand-logo { flex-shrink:0; }
    .hub-topbar.portal-header-ready .hub-brand-text { min-width:0; }
    .hub-topbar.portal-header-ready .hub-brand-text h1 { font-size:1rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
    .hub-topbar.portal-header-ready .hub-brand-text > span { display:none; }
    .hub-topbar.portal-header-ready .hub-user-link, .hub-topbar.portal-header-ready .portal-header-controls > .hub-logout { display:none !important; }
    .hub-topbar.portal-header-ready .hub-mobile-account { display:block; }
    .ps-picker-table .ps-picker-name, .booklet-recording-scroll :is(.booklet-th-name, .booklet-td-name) { width:140px; min-width:140px; max-width:140px; padding:8px; }
    .ps-picker-name .d-flex { gap:6px; }
    .ps-picker-name .d-flex > :first-child { width:28px !important; height:28px !important; font-size:.7rem !important; }
}
@media print {
    .report-table-scroll { display:contents !important; overflow:visible !important; width:auto !important; max-width:none !important; max-height:none !important; }
    .ps-progress, .ps-editor-identity, .report-scroll-hint, .att-skip-clock { display:none !important; }
    .booklet-recording-scroll { overflow:visible !important; }
    .ps-picker-name, .booklet-th-name, .booklet-td-name { position:static !important; box-shadow:none !important; }
}

/* Larger pupil portraits are scoped to reports, not roster avatars or custom forms. */
.terminal-report,
.mock-report,
.ps-report {
    --report-photo-width: 140px;
    --report-photo-height: 150px;
}

.ps-report .ps-photo,
.ps-report .ps-photo-empty {
    width: var(--report-photo-width);
    height: var(--report-photo-height);
    max-width: 100%;
    box-sizing: border-box;
    background: #fff;
}

.ps-report .ps-photo {
    display: block;
    /* Fill the frame, anchoring the crop to the top of the portrait. */
    object-fit: cover;
    object-position: center top;
}

.ps-report .ps-photo-empty {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ps-report .ps-top {
    grid-template-columns: minmax(0, 1fr) var(--report-photo-width);
}

.ps-report .ps-data {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Report crests are real images so they print with background graphics off. */
.report-school-logo {
    display: block;
    width: 80px;
    height: 80px;
    object-fit: contain;
    background: #fff;
    justify-self: center;
}

.report-school-identity {
    min-width: 0;
    overflow-wrap: anywhere;
}

.ps-head-identity,
.tr-head.tr-head-branded {
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr) 90px;
    gap: 12px;
    align-items: center;
    break-inside: avoid;
    page-break-inside: avoid;
}

.tr-head.tr-head-branded {
    grid-template-columns: var(--report-photo-width, 90px) minmax(0, 1fr) var(--report-photo-width, 90px);
}

.ps-head-identity::after {
    content: "";
}

.tr-head.tr-head-branded .tr-photo {
    float: none;
    margin: 0;
}

@media screen and (max-width: 600px) {
    .ps-head-identity { grid-template-columns: minmax(0, 1fr); }
    .ps-head-identity::after { display: none; }
    .tr-head.tr-head-branded { grid-template-columns: minmax(0, 1fr) var(--report-photo-width, 90px); }
    .tr-head-branded .report-school-logo { grid-column: 1 / -1; }
    .ps-report .ps-top { grid-template-columns: minmax(0, 1fr); }
    .ps-report .ps-top > :last-child { grid-row: 1; justify-self: end; }
}

/* Print portraits extend left toward the school name without growing taller. */
@media print {
    .terminal-report,
    .mock-report,
    .ps-report {
        --report-photo-width: 230px;
    }

    /* Keep the crest track compact so the wider portrait does not crowd the title. */
    .terminal-report .tr-head.tr-head-branded {
        grid-template-columns: 90px minmax(0, 1fr) var(--report-photo-width);
    }

    .mock-page .mock-report .mock-report-heading {
        flex-wrap: nowrap;
        gap: 12px;
    }

    .mock-page .mock-report .mock-report-titles {
        min-width: 0;
        overflow-wrap: anywhere;
    }
}

/* ============================================
   TERMINAL REPORT - ONE-PAGE PRINT FIT
   Compacts the GES terminal report (.terminal-report / .tr-*) so the whole
   card prints on a single A4 page in every portal. The pre-school report
   (.ps-report) keeps its own print styles and is NOT affected.
   ============================================ */
@media print {
    @page {
        size: A4 portrait;
        margin: 8mm;
    }

    .terminal-report {
        max-width: 100% !important;
        padding: 10px 14px !important;
        margin: 0 !important;
        border-width: 1px !important;
        border-radius: 0 !important;
        page-break-inside: avoid;
    }

    .terminal-report .tr-head {
        padding-bottom: 6px !important;
        margin-bottom: 8px !important;
    }

    .terminal-report .tr-head h1 {
        font-size: 1.15rem !important;
    }

    .terminal-report .tr-head p {
        margin: 2px 0 0 !important;
        font-size: 0.8rem !important;
    }

    .terminal-report .tr-meta {
        gap: 2px 18px !important;
        margin-bottom: 8px !important;
        font-size: 0.74rem !important;
    }

    .terminal-report .tr-meta div {
        padding: 1px 0 !important;
    }

    .terminal-report .tr-meta strong {
        min-width: 105px !important;
    }

    .terminal-report .tr-table {
        margin-bottom: 8px !important;
        font-size: 0.7rem !important;
    }

    .terminal-report .tr-table th,
    .terminal-report .tr-table td {
        padding: 2px 4px !important;
    }

    .terminal-report .tr-foot {
        gap: 2px 18px !important;
        font-size: 0.72rem !important;
        margin-bottom: 8px !important;
    }

    .terminal-report .tr-foot div {
        padding: 2px 0 !important;
    }

    .terminal-report .tr-key {
        font-size: 0.62rem !important;
    }

    .terminal-report .tr-key th,
    .terminal-report .tr-key td {
        padding: 1px 4px !important;
    }

    .terminal-report .tr-sign {
        margin-top: 14px !important;
        font-size: 0.72rem !important;
    }

    .terminal-report .tr-sign div {
        padding-top: 3px !important;
    }
}

/* Preschool booklet pages are designed at A5, not shrunken from A4. */
.ps-print-controls { max-width: 900px; margin: 0 auto 12px; }
.ps-print-options { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.ps-print-options .form-select { width: auto; max-width: 100%; }
.ps-booklet-help { margin: 10px 0 0; font-size: 0.9rem; line-height: 1.5; }

@media print {
    @page preschool-booklet {
        size: A5 portrait;
        margin: 12mm 12mm 12mm 20mm;
    }
    @page preschool-booklet:left { margin-left: 12mm; margin-right: 20mm; }
    @page preschool-booklet:right { margin-left: 20mm; margin-right: 12mm; }

    body.ps-booklet-print { page: preschool-booklet; }
    body.ps-booklet-print .wrapper { display: block; min-height: 0; }
    body.ps-booklet-print .main-content,
    body.ps-booklet-print .main-body { width: auto; min-width: 0; padding: 0 !important; margin: 0 !important; }
    body.ps-booklet-print .main-body { animation: none !important; transform: none !important; }
    body.ps-booklet-print .ps-report {
        --report-photo-width: 40mm;
        --report-photo-height: 50mm;
        page: preschool-booklet;
        width: 100%; max-width: none; padding: 0; margin: 0;
        font-size: 12pt; line-height: 1.4;
    }
    body.ps-booklet-print .ps-report,
    body.ps-booklet-print .ps-report * {
        font-family: Arial, Helvetica, sans-serif;
        color: #000 !important; background: #fff !important;
        border-color: #333 !important;
        overflow-wrap: anywhere;
    }
    body.ps-booklet-print .ps-head { break-inside: avoid; margin-bottom: 4mm; }
    body.ps-booklet-print .ps-head-identity { grid-template-columns: minmax(0, 1fr); gap: 2mm; }
    body.ps-booklet-print .ps-head-identity::after { display: none; }
    body.ps-booklet-print .report-school-logo { width: 20mm; height: 20mm; }
    body.ps-booklet-print .ps-head h1 { font-size: 16pt; letter-spacing: 0; line-height: 1.2; }
    body.ps-booklet-print .ps-head p { font-size: 11pt; }
    body.ps-booklet-print .ps-head .ps-title { font-size: 12pt; }
    body.ps-booklet-print .ps-top { grid-template-columns: minmax(0, 1fr) var(--report-photo-width); gap: 3mm; }
    body.ps-booklet-print .ps-data { min-width: 0; }
    body.ps-booklet-print .ps-data strong { min-width: 0; margin-right: 1mm; }
    body.ps-booklet-print .ps-photo,
    body.ps-booklet-print .ps-photo-empty { width: var(--report-photo-width); height: var(--report-photo-height); font-size: 10pt; }
    body.ps-booklet-print .ps-data h4,
    body.ps-booklet-print .ps-data div,
    body.ps-booklet-print .ps-section .ps-desc,
    body.ps-booklet-print .ps-key,
    body.ps-booklet-print .ps-req,
    body.ps-booklet-print .ps-req h4,
    body.ps-booklet-print .ps-remarks div,
    body.ps-booklet-print .ps-sign div { font-size: 12pt; }
    body.ps-booklet-print .ps-section h3 { font-size: 13pt; border-bottom: 1pt solid #333; }
    body.ps-booklet-print .ps-section h3,
    body.ps-booklet-print .ps-section .ps-desc,
    body.ps-booklet-print .ps-data h4,
    body.ps-booklet-print .ps-req h4 { break-after: avoid; }
    body.ps-booklet-print .ps-tbl { table-layout: fixed; font-size: 12pt; }
    body.ps-booklet-print .ps-tbl th,
    body.ps-booklet-print .ps-tbl td { padding: 1.5mm 1mm; vertical-align: middle; }
    body.ps-booklet-print .ps-tbl th:nth-child(n+3),
    body.ps-booklet-print .ps-tbl td.mark { width: 7mm !important; }
    body.ps-booklet-print .ps-tbl th:first-child,
    body.ps-booklet-print .ps-tbl td:first-child { width: 9mm !important; }
    body.ps-booklet-print .ps-tbl thead { display: table-header-group; }
    body.ps-booklet-print .ps-tbl tr,
    body.ps-booklet-print .ps-data div,
    body.ps-booklet-print .ps-req li,
    body.ps-booklet-print .ps-remarks div,
    body.ps-booklet-print .ps-sign { break-inside: avoid; page-break-inside: avoid; }
    body.ps-booklet-print .ps-tbl td.hit { font-weight: 700; }
    body.ps-booklet-print .ps-key { display: block; break-inside: avoid; }
    body.ps-booklet-print .ps-key span { display: block; }
    body.ps-booklet-print .ps-req { display: block; }
    body.ps-booklet-print .ps-req > div { margin-bottom: 4mm; }
    body.ps-booklet-print .ps-sign { gap: 6mm; margin-top: 12mm; }
}

/* ==================== Attendance Status Pills ==================== */
/* Checkbox group styled as tick pills; the tick stays visible and the pill
   takes the status colour when selected. */
.att-status-boxes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 8px;
}

.att-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0;
    padding: 6px 12px;
    border: 1.5px solid var(--gray-300, #cbd5e0);
    border-radius: 999px;
    background: var(--white, #fff);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-600, #4a5568);
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
}

.att-pill:hover {
    border-color: var(--primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.att-pill input.att-status-box {
    accent-color: currentColor;
    width: 15px;
    height: 15px;
    margin: 0;
    cursor: pointer;
}

/* Selected state, coloured per status */
.att-pill:has(input:checked) {
    color: var(--white, #fff);
}

.att-pill-present:has(input:checked) {
    background: var(--success);
    border-color: var(--success);
}

.att-pill-absent:has(input:checked) {
    background: var(--error);
    border-color: var(--error);
}

.att-pill-late:has(input:checked) {
    background: var(--warning);
    border-color: var(--warning);
}

.att-pill-excused:has(input:checked) {
    background: #3182ce;
    border-color: #3182ce;
}

.att-pill:has(input:checked) input.att-status-box {
    accent-color: rgba(255, 255, 255, 0.9);
}

/* JavaScript fallback — the attendance-marking script toggles this class
   on the label whenever a checkbox is checked/unchecked. This mirrors the
   :has(input:checked) rules above so the pill colour change works even in
   browsers that don't fully support :has() in this context. */
.att-pill.att-pill-active {
    color: var(--white, #fff);
}
.att-pill-present.att-pill-active {
    background: var(--success);
    border-color: var(--success);
}
.att-pill-absent.att-pill-active {
    background: var(--error);
    border-color: var(--error);
}
.att-pill-late.att-pill-active {
    background: var(--warning);
    border-color: var(--warning);
}
.att-pill-excused.att-pill-active {
    background: #3182ce;
    border-color: #3182ce;
}
.att-pill.att-pill-active input.att-status-box {
    accent-color: rgba(255, 255, 255, 0.9);
}

/* ==================== REDUCED MOTION ==================== */
@media (prefers-reduced-motion: reduce) {
    body::before,
    body::after { animation: none; }
    .hub-tile,
    .hub-welcome { animation: none; opacity: 1; }
    .main-body { animation: none; }
    .main-body.page-exit,
    .hub-main.page-exit { animation: none; }
}

/* ==================== PORTAL TOUR / ONBOARDING ==================== */
/* The guided tour overlay, spotlight, and tooltip card. The tour engine
   lives in js/main.js and highlights elements one at a time. */

/* Dark overlay with a transparent hole punched around the target element.
   Uses a massive box-shadow so the spotlight covers the whole viewport. */
.portal-tour-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.portal-tour-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* The spotlight rectangle — positioned by JS over the target element. */
.portal-tour-spotlight {
    position: fixed;
    z-index: 100001;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    border: 3px solid var(--secondary, #c9a227);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}
.portal-tour-spotlight::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    animation: tourPulse 1.5s ease-in-out infinite;
}
@keyframes tourPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* The tooltip card shown next to the spotlighted element. */
.portal-tour-tooltip {
    position: fixed;
    z-index: 100002;
    max-width: 360px;
    min-width: 280px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.portal-tour-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}
/* Arrow pointing toward the spotlighted element. */
.portal-tour-tooltip::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--primary, #1f6f43);
    transform: rotate(45deg);
}
.portal-tour-tooltip[data-placement="bottom"]::before {
    top: -7px;
    left: 50%;
    margin-left: -7px;
}
.portal-tour-tooltip[data-placement="top"]::before {
    bottom: -7px;
    left: 50%;
    margin-left: -7px;
}
.portal-tour-tooltip[data-placement="left"]::before {
    right: -7px;
    top: 50%;
    margin-top: -7px;
}
.portal-tour-tooltip[data-placement="right"]::before {
    left: -7px;
    top: 50%;
    margin-top: -7px;
}

.portal-tour-header {
    background: var(--primary, #1f6f43);
    color: #fff;
    padding: 14px 18px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.portal-tour-header i {
    font-size: 1.3rem;
}
.portal-tour-step {
    margin-left: auto;
    font-size: 0.8rem;
    opacity: 0.8;
    white-space: nowrap;
}
.portal-tour-title {
    font-weight: 700;
    font-size: 1.05rem;
}

.portal-tour-body {
    padding: 16px 18px;
    color: #374151;
    font-size: 0.92rem;
    line-height: 1.55;
}

.portal-tour-footer {
    padding: 0 18px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}
.portal-tour-skip {
    margin-right: auto;
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: color 0.15s ease, background 0.15s ease;
}
.portal-tour-skip:hover {
    color: #6b7280;
    background: #f3f4f6;
}
.portal-tour-btn {
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.portal-tour-btn-prev {
    background: #e5e7eb;
    color: #374151;
}
.portal-tour-btn-prev:hover {
    background: #d1d5db;
}
.portal-tour-btn-next {
    background: var(--primary, #1f6f43);
    color: #fff;
}
.portal-tour-btn-next:hover {
    background: var(--primary-dark, #155032);
}
.portal-tour-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Progress dots at the bottom of the tooltip. */
.portal-tour-progress {
    display: flex;
    gap: 5px;
    padding: 0 18px 14px;
    justify-content: center;
}
.portal-tour-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
    transition: all 0.2s ease;
}
.portal-tour-dot.active {
    background: var(--primary, #1f6f43);
    width: 22px;
    border-radius: 4px;
}
.portal-tour-dot.done {
    background: var(--secondary, #c9a227);
}

/* ============================================================
   DARK THEME
   Toggled per user via <html data-theme="dark"> (cookie-backed,
   echoed server-side to avoid a flash). Light stays the default.
   ============================================================ */
html[data-theme="dark"] {
    color-scheme: dark;
    --background: #10151f;
    --card-bg: #1b2432;
    --text-primary: #e8edf5;
    --text-secondary: #a3b0c6;
    --text-muted: #71809a;
    --border: #2c3a52;
    --border-color: #2c3a52;
    --table-header-tint: rgba(255, 255, 255, 0.05);
    --table-stripe-tint: rgba(255, 255, 255, 0.03);
    --table-hover-bg: rgba(107, 155, 99, 0.10);
    --glass-bg: rgba(27, 36, 50, 0.60);
    --glass-bg-strong: rgba(27, 36, 50, 0.88);
    --glass-border: rgba(148, 163, 184, 0.16);
    --glass-border-hover: rgba(148, 163, 184, 0.32);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --success-light: rgba(56, 161, 105, 0.16);
    --warning-light: rgba(221, 107, 32, 0.16);
    --error-light: rgba(229, 62, 62, 0.16);
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.45);
    /* Flip the default scrollbar tints for dark surfaces. The sidebar keeps
       the on-dark pair — it is dark in both themes. */
    --scrollbar-thumb: rgba(255, 255, 255, 0.22);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.40);
}

/* Dim the colourful ambient glows so dark mode stays easy on the eyes. */
html[data-theme="dark"] body {
    background-image:
        radial-gradient(ellipse at 5% 2%, rgba(74,124,66,0.14) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 0%, rgba(214,158,46,0.08) 0%, transparent 45%),
        radial-gradient(ellipse at 50% 40%, rgba(13,148,136,0.07) 0%, transparent 55%),
        radial-gradient(ellipse at 95% 50%, rgba(124,58,237,0.10) 0%, transparent 42%),
        radial-gradient(ellipse at 15% 75%, rgba(244,114,182,0.06) 0%, transparent 48%),
        radial-gradient(ellipse at 60% 95%, rgba(59,130,246,0.08) 0%, transparent 45%);
}
html[data-theme="dark"] body::before {
    background: radial-gradient(circle, rgba(13,148,136,0.12) 0%, transparent 70%);
}
html[data-theme="dark"] body::after {
    background: radial-gradient(circle, rgba(124,58,237,0.10) 0%, transparent 70%);
}

/* Typography & links: lift colours for contrast on dark surfaces. */
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6 { color: #9dc79b; }
/* Links lift for dark surfaces — but NOT .btn links: the button variants set
   their own label colour (white on the gradients, green on outline buttons),
   and this rule would otherwise override them and wash the labels out. */
html[data-theme="dark"] a:not(.btn) { color: var(--primary-light); }
html[data-theme="dark"] .text-secondary { color: var(--text-secondary); }

/* Surfaces that hard-code light backgrounds. */
html[data-theme="dark"] .main-header {
    background: rgba(16, 21, 31, 0.72);
    border-bottom: 1px solid var(--glass-border);
}
html[data-theme="dark"] .card {
    background: var(--glass-bg-strong);
    border-color: var(--glass-border);
}
/* Calendar previews follow the portal theme; paper keeps its light palette. */
@media screen {
    html[data-theme="dark"] .cal-sheet {
        background: var(--card-bg);
        color: var(--text-primary);
        border-color: var(--border);
    }
    html[data-theme="dark"] .cal-sheet .cal-meta-empty,
    html[data-theme="dark"] .cal-sheet .cal-empty {
        color: var(--text-secondary);
    }
    html[data-theme="dark"] .cal-sheet .cal-table th {
        border-bottom-color: var(--text-secondary);
    }
    html[data-theme="dark"] .cal-sheet .cal-holiday td {
        background: var(--warning-light);
    }
    html[data-theme="dark"] .cal-sheet .cal-holiday-badge { color: #fbd38d; }
    html[data-theme="dark"] .cal-sheet .cal-edit { color: #93c5fd; }
    html[data-theme="dark"] .cal-sheet .cal-del { color: #feb2b2; }
    html[data-theme="dark"] .cal-sheet .cal-edit:hover,
    html[data-theme="dark"] .cal-sheet .cal-del:hover { color: var(--text-primary); }
    html[data-theme="dark"] .cal-sheet .cal-edit:focus-visible,
    html[data-theme="dark"] .cal-sheet .cal-del:focus-visible {
        color: var(--text-primary);
        outline: 2px solid currentColor;
        outline-offset: 2px;
    }
}
/* The login card's footer strip hard-codes a milky light tint; in dark mode
   it becomes a dark translucent strip over the (already dark) glass card. */
html[data-theme="dark"] .login-footer {
    background: rgba(16, 21, 31, 0.55);
}

/* Sidebar (every portal): the bright brand-green gradient glows against the
   dark theme, and the global a-rule above would paint every nav link
   --primary-light (muddy green-on-green). Switch to a deep forest-charcoal
   gradient and restore the sidebar's white link/hover system. Specificity
   is kept above html[data-theme="dark"] a:not(.btn). */
html[data-theme="dark"] .sidebar {
    background: linear-gradient(180deg, #223527 0%, #16241a 55%, #0f1a12 100%);
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .sidebar-logo h2 { color: #fff; }
html[data-theme="dark"] .sidebar-nav li a { color: rgba(255, 255, 255, 0.82); }
html[data-theme="dark"] .sidebar-nav li a:hover,
html[data-theme="dark"] .sidebar-nav li a.active { color: #fff; }
html[data-theme="dark"] .sidebar-nav .sidebar-back a,
html[data-theme="dark"] .sidebar-nav .sidebar-history a { color: rgba(255, 255, 255, 0.75); }
html[data-theme="dark"] .sidebar-nav .sidebar-history a:hover { color: #fff; }

/* Terminal report sheet (admin/teacher/hod/headteacher): each page styles the
   printable .terminal-report inline with paper whites (#fff sheet, #f0f0f0
   header cells, #f7f7f7 total row) and near-black grid lines, so in dark mode
   the sheet blazes white against the page. Re-skin it for screen only —
   printing still lands on the white paper the @media print blocks expect. */
@media screen {
    html[data-theme="dark"] .terminal-report {
        background: #1b2432;
        border-color: #4a5872;
        color: #e6ebf2;
    }
    html[data-theme="dark"] .terminal-report h1 { color: inherit; }
    html[data-theme="dark"] .tr-head { border-bottom-color: #8a94a6; }
    html[data-theme="dark"] .tr-meta div,
    html[data-theme="dark"] .tr-foot div { border-bottom-color: #46536b; }
    html[data-theme="dark"] .tr-table th,
    html[data-theme="dark"] .tr-table td { border-color: #4a5872; }
    html[data-theme="dark"] .tr-table th { background: rgba(255, 255, 255, 0.06); }
    html[data-theme="dark"] .tr-table tr.total-row td { background: rgba(255, 255, 255, 0.1); }
    html[data-theme="dark"] .tr-key th,
    html[data-theme="dark"] .tr-key td { border-color: #4a5872; }
    html[data-theme="dark"] .tr-sign div { border-top-color: #8a94a6; }
}
html[data-theme="dark"] .table th {
    background: var(--table-header-tint);
}
html[data-theme="dark"] .users-page .btn-secondary {
    background: var(--card-bg);
    border-color: #9dc79b;
    color: #9dc79b;
}
html[data-theme="dark"] .users-page .btn-secondary:hover,
html[data-theme="dark"] .users-page .btn-secondary:focus-visible {
    background: #9dc79b;
    color: var(--background);
}
html[data-theme="dark"] .table-users-fit a:not(.btn) { color: #9dc79b; }
html[data-theme="dark"] .table-users-fit a:not(.btn):hover { color: #c6f6d5; }
html[data-theme="dark"] .broadsheet-detail .subj-group {
    background: rgba(255, 255, 255, 0.06);
    border-bottom-color: rgba(255, 255, 255, 0.15);
}
html[data-theme="dark"] .broadsheet-detail .sub-col.tot {
    background: rgba(253, 246, 236, 0.1);
}
html[data-theme="dark"] .broadsheet-detail .sub-col.grd {
    background: rgba(232, 245, 233, 0.1);
    color: #86efac;
}
html[data-theme="dark"] .broadsheet-detail td.sub-col.grd {
    color: #86efac;
}
html[data-theme="dark"] .table tbody tr:nth-child(even) {
    background: var(--table-stripe-tint);
}
html[data-theme="dark"] .table tbody tr:hover,
html[data-theme="dark"] .table tbody tr:nth-child(even):hover {
    background: var(--table-hover-bg);
}
html[data-theme="dark"] .hub-tile {
    background: var(--glass-bg-strong);
    border-color: var(--glass-border);
}
html[data-theme="dark"] .hub-tile:hover {
    background: rgba(35, 46, 66, 0.95);
}
html[data-theme="dark"] .loading-overlay { background: rgba(16, 21, 31, 0.85); }
html[data-theme="dark"] .portal-tour-tooltip { background: #1b2432; }
html[data-theme="dark"] .portal-tour-body { color: var(--text-primary); }
html[data-theme="dark"] .portal-tour-skip { color: var(--text-muted); }
html[data-theme="dark"] .portal-tour-skip:hover { color: var(--text-secondary); background: rgba(255,255,255,0.06); }
html[data-theme="dark"] .portal-tour-btn-prev { background: #2c3a52; color: var(--text-primary); }
html[data-theme="dark"] .portal-tour-btn-prev:hover { background: #3a4a66; }
html[data-theme="dark"] .portal-tour-dot { background: #3a4a66; }
html[data-theme="dark"] .toggle-slider { background: #3a465c; }
html[data-theme="dark"] .perm-toggle { background: rgba(255, 255, 255, 0.04); }
html[data-theme="dark"] .att-pill {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border-color: var(--glass-border-hover);
}
/* Checked / active status pills keep their colours in dark mode — the
   generic reset above out-specifies the light-theme state rules further
   up, so without these every pill would render the same grey. */
html[data-theme="dark"] .att-pill-present:has(input:checked),
html[data-theme="dark"] .att-pill-present.att-pill-active {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}
html[data-theme="dark"] .att-pill-absent:has(input:checked),
html[data-theme="dark"] .att-pill-absent.att-pill-active {
    background: var(--error);
    border-color: var(--error);
    color: #fff;
}
html[data-theme="dark"] .att-pill-late:has(input:checked),
html[data-theme="dark"] .att-pill-late.att-pill-active {
    background: var(--warning);
    border-color: var(--warning);
    color: #fff;
}
html[data-theme="dark"] .att-pill-excused:has(input:checked),
html[data-theme="dark"] .att-pill-excused.att-pill-active {
    background: #3182ce;
    border-color: #3182ce;
    color: #fff;
}
html[data-theme="dark"] .user-dropdown-toggle:hover { background: rgba(107, 155, 99, 0.12); }
html[data-theme="dark"] .user-dropdown-menu a:hover { background: rgba(107, 155, 99, 0.14); }

/* Hub pages carry an inline light photo backdrop; keep the image but dim it
   with a dark multiply blend so it stays visible without washing out text. */
html[data-theme="dark"] .hub-body {
    background-color: rgba(16, 21, 31, 0.72) !important;
    background-blend-mode: multiply;
}
html[data-theme="dark"] .hub-welcome h2 { color: #9dc79b; }

/* The "Back to My Hub" glass pill kept its light white-glass background in
   dark mode, so it glowed bright against the dimmed photo backdrop while
   everything around it went dark. Give it the same dark chrome as the tiles
   and topbar. */
html[data-theme="dark"] .hub-back-card {
    background: rgba(27, 36, 50, 0.72);
    border-color: var(--glass-border);
    color: #e8edf5;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
html[data-theme="dark"] .hub-back-card:hover {
    background: rgba(35, 46, 66, 0.95);
    border-color: var(--glass-border-hover);
    color: #e8edf5;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .hub-back-card i { color: #9dc79b; }

/* Hub topbar: replace the green brand gradient with the dark chrome used by
   section-page headers so the bar matches the rest of dark mode. The white
   text, glass chips and crest tile already sit well on a dark surface. */
html[data-theme="dark"] .hub-topbar {
    background: rgba(16, 21, 31, 0.72);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

/* Alerts: dark translucent tints with light text. */
html[data-theme="dark"] .alert-success { background: rgba(56, 161, 105, 0.18); color: #9ae6b4; }
html[data-theme="dark"] .alert-warning { background: rgba(221, 107, 32, 0.18); color: #fbd38d; }
html[data-theme="dark"] .alert-error   { background: rgba(229, 62, 62, 0.18); color: #feb2b2; }
html[data-theme="dark"] .alert-info    { background: rgba(59, 130, 246, 0.15); color: #bfdbfe; }
html[data-theme="dark"] .alert-dismiss:hover { background: rgba(255, 255, 255, 0.12); }

/* Badges: keep the hue, lift the text. */
html[data-theme="dark"] .badge-primary { background: rgba(107, 155, 99, 0.18); color: #9dc79b; }
html[data-theme="dark"] .badge-success { color: #6ee7a8; }
html[data-theme="dark"] .badge-warning { color: #fbd38d; }
html[data-theme="dark"] .badge-danger  { color: #feb2b2; }

/* Support-center chat bubbles (inline page styles). */
html[data-theme="dark"] .chat-thread {
    background: rgba(0, 0, 0, 0.25);
    border-color: var(--glass-border);
}
html[data-theme="dark"] .chat-msg-user {
    background: rgba(42, 53, 74, 0.95);
    border-color: var(--glass-border);
}
html[data-theme="dark"] .chat-presence {
    background: rgba(27, 36, 50, 0.9);
    border-color: var(--glass-border);
    color: var(--text-secondary);
}
html[data-theme="dark"] .chat-typing { color: var(--text-secondary); }

/* ---------------- Theme toggle button ---------------- */
.theme-toggle { display: inline-flex; align-items: center; }
.theme-toggle-btn {
    display: flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; border: none; border-radius: 50%;
    background: var(--background); color: var(--text-secondary);
    font-size: 1.05rem; cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}
.theme-toggle-btn:hover {
    color: var(--accent); transform: rotate(15deg) scale(1.06);
}
/* On hub pages and the login page the header is dark/imagery: use a glass chip. */
.hub-topbar .theme-toggle-btn,
.theme-toggle-floating .theme-toggle-btn {
    background: rgba(255, 255, 255, 0.15); color: #fff; box-shadow: none;
}
.hub-topbar .theme-toggle-btn:hover,
.theme-toggle-floating .theme-toggle-btn:hover { background: rgba(255, 255, 255, 0.25); }
.theme-toggle-floating {
    position: fixed; top: 18px; right: 18px; z-index: 60;
}
@media print {
    .theme-toggle { display: none !important; }
}

/* ── Toast notifications (styled replacement for native alert()) ───── */
.toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: min(400px, calc(100vw - 36px));
    pointer-events: none;
}
.toast {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 38px 18px 16px;
    background: #1f2937;
    color: #f3f4f6;
    border-radius: 12px;
    border-left: 4px solid #6b7280;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.38);
    font-size: 0.95rem;
    line-height: 1.45;
    pointer-events: auto;
    animation: toast-in 0.32s cubic-bezier(0.21, 1.02, 0.55, 1);
}
.toast-icon { font-size: 1.15rem; margin-top: 2px; flex-shrink: 0; }
.toast-body { flex: 1; word-break: break-word; }
.toast-close {
    position: absolute;
    top: 5px; right: 7px;
    background: none;
    border: 0;
    color: rgba(255, 255, 255, 0.55);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
}
.toast-close:hover { color: #fff; }
.toast-progress {
    position: absolute;
    left: 0; bottom: 0;
    height: 3px;
    width: 100%;
    transform-origin: left;
    animation-name: toast-progress;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(28px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}
@keyframes toast-out {
    to { opacity: 0; transform: translateX(34px); }
}
@keyframes toast-progress {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}
.toast.toast-out { animation: toast-out 0.3s ease forwards; }

.toast-error   { border-left-color: #ef4444; }
.toast-error   .toast-icon     { color: #f87171; }
.toast-error   .toast-progress { background: #ef4444; }
.toast-warning { border-left-color: #f59e0b; }
.toast-warning .toast-icon     { color: #fbbf24; }
.toast-warning .toast-progress { background: #f59e0b; }
.toast-success { border-left-color: #10b981; }
.toast-success .toast-icon     { color: #34d399; }
.toast-success .toast-progress { background: #10b981; }
.toast-info    { border-left-color: #3b82f6; }
.toast-info    .toast-icon     { color: #60a5fa; }
.toast-info    .toast-progress { background: #3b82f6; }

html[data-theme="dark"] .toast {
    background: #28323f;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6);
}

/* ============================================================
   DARK MODE FORM & DROPDOWN FIXES
   ============================================================ */

/* Form controls: make sure inputs/selects use the dark glass tokens
   and do not revert to hard-coded light hover/focus backgrounds. */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background: var(--glass-bg);
    color: var(--text-primary);
    border-color: var(--glass-border);
}

html[data-theme="dark"] .form-control:hover,
html[data-theme="dark"] .form-select:hover {
    background: var(--glass-bg-strong);
    border-color: var(--glass-border-hover);
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    outline: none;
    background: var(--glass-bg-strong);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(107, 155, 99, 0.18), 0 2px 8px rgba(0, 0, 0, 0.25);
}

html[data-theme="dark"] .form-control::placeholder {
    color: var(--text-muted);
}

/* Dropdown menus were rendering with a white background and light text in
   some browsers. Force the dark card surface and light text so every option
   is readable. */
html[data-theme="dark"] .form-select option,
html[data-theme="dark"] select option,
html[data-theme="dark"] select optgroup {
    background: var(--card-bg);
    color: var(--text-primary);
}

html[data-theme="dark"] .form-select option:checked,
html[data-theme="dark"] select option:checked {
    background: var(--primary-dark);
    color: #ffffff;
}

/* ============================================================
   DARK MODE INLINE-STYLE RESCUE
   A lot of PHP pages still use hard-coded light-mode colours.
   The rules below lift those colours in dark mode without editing
   every inline style.
   ============================================================ */

/* Dark text colours -> light primary text */
html[data-theme="dark"] [style*="color:#2d3748"],
html[data-theme="dark"] [style*="color:#1a202c"],
html[data-theme="dark"] [style*="color:#000000"],
html[data-theme="dark"] [style*="color:#000;"],
html[data-theme="dark"] [style*="color:#333"],
html[data-theme="dark"] [style*="color:#4a5568"] {
    color: var(--text-primary) !important;
}

/* Muted grey text -> muted dark text */
html[data-theme="dark"] [style*="color:#718096"] {
    color: var(--text-secondary) !important;
}

/* Light alert/note surfaces: keep them readable on dark backgrounds */
html[data-theme="dark"] [style*="background:#fffbeb"] {
    background: rgba(251, 191, 36, 0.12) !important;
    border-color: rgba(251, 191, 36, 0.35) !important;
}
html[data-theme="dark"] [style*="background:#ebf8ff"] {
    background: rgba(59, 130, 246, 0.12) !important;
    border-color: rgba(59, 130, 246, 0.35) !important;
}
html[data-theme="dark"] [style*="background:#fdf2f8"] {
    background: rgba(236, 72, 153, 0.12) !important;
    border-color: rgba(236, 72, 153, 0.35) !important;
}
html[data-theme="dark"] [style*="color:#744210"],
html[data-theme="dark"] [style*="color:#2a4365"],
html[data-theme="dark"] [style*="color:#97266d"] {
    color: #e2e8f0 !important;
}

/* Continuous-assessment report views (includes/report-card-table.php) and
   the class-performance Total/Aggregate columns wash their GES section
   headers and score cells with hard-coded light tints: blue = Continuous
   Assessment, orange = Exam, green = Total, grey = summary row. Lift each
   tint to its translucent dark equivalent so the column grouping stays
   readable on dark cards. (Both spacing variants are listed because the
   PHP sources mix "background:#hex" and "background: #hex".) */
html[data-theme="dark"] [style*="background: #e3f2fd"],
html[data-theme="dark"] [style*="background:#e3f2fd"],
html[data-theme="dark"] [style*="background: #f5f9ff"],
html[data-theme="dark"] [style*="background:#f5f9ff"] {
    background: rgba(59, 130, 246, 0.14) !important;
}
html[data-theme="dark"] [style*="background: #fff3e0"],
html[data-theme="dark"] [style*="background:#fff3e0"],
html[data-theme="dark"] [style*="background: #fffaf2"],
html[data-theme="dark"] [style*="background:#fffaf2"],
html[data-theme="dark"] [style*="background: #fdf6ec"],
html[data-theme="dark"] [style*="background:#fdf6ec"] {
    background: var(--warning-light) !important;
}
html[data-theme="dark"] [style*="background: #e8f5e9"],
html[data-theme="dark"] [style*="background:#e8f5e9"] {
    background: var(--success-light) !important;
}
html[data-theme="dark"] [style*="background: #f5f5f5"],
html[data-theme="dark"] [style*="background:#f5f5f5"] {
    background: rgba(255, 255, 255, 0.06) !important;
}
html[data-theme="dark"] [style*="background: #f8f9fa"],
html[data-theme="dark"] [style*="background:#f8f9fa"] {
    background: rgba(255, 255, 255, 0.04) !important;
}
/* Attendance strip under the report-card table: the hairline #eee border
   lifts to the dark border token. */
html[data-theme="dark"] [style*="border-top: 1px solid #eee"] {
    border-color: var(--border) !important;
}

/* Booklet recording sheet (view=booklet on the CA pages): the dark header
   solids keep their white text, but the black cell grid and zebra wash
   vanish on dark cards and the dark-red 50%-column figures go illegible. */
html[data-theme="dark"] .booklet-table th,
html[data-theme="dark"] .booklet-table td {
    border-color: rgba(255, 255, 255, 0.16);
}
html[data-theme="dark"] .booklet-td-red,
html[data-theme="dark"] .booklet-td-total {
    color: #fca5a5;
}
html[data-theme="dark"] .booklet-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}
html[data-theme="dark"] .booklet-header h2 {
    color: #86efac;
}

/* Class Report Cards page chrome: the dashed report page used the missing
   --surface token (so it stayed paper-white in dark mode); its navy/black
   hairlines also vanish on dark cards. The page background itself is fixed
   at the source (var(--card-bg, #fff)). */
html[data-theme="dark"] .report-card-head {
    border-bottom-color: var(--border);
}
html[data-theme="dark"] .report-signatures .sig-line {
    border-bottom-color: rgba(255, 255, 255, 0.25);
}

/* ---- Neutral hairline borders used across many pages ---- */
html[data-theme="dark"] [style*="#e2e8f0"],
html[data-theme="dark"] [style*="#cbd5e0"] {
    border-color: var(--border) !important;
}
html[data-theme="dark"] [style*="#bee3f8"] {
    border-color: rgba(59, 130, 246, 0.35) !important;
}

/* ---- Off-white panel surfaces (Add User, student form, SMS, etc.) ---- */
html[data-theme="dark"] [style*="background: #fafcfa"],
html[data-theme="dark"] [style*="background:#fafcfa"],
html[data-theme="dark"] [style*="background:#f7fafc"],
html[data-theme="dark"] [style*="background: #f7fafc"] {
    background: rgba(255, 255, 255, 0.03) !important;
    border-color: var(--border) !important;
}

/* ---- White modal / grid surfaces ---- */
html[data-theme="dark"] [style*="background:#fff;"],
html[data-theme="dark"] [style*="background: #fff;"] {
    background: var(--card-bg) !important;
    border-color: var(--border) !important;
}

/* ---- Neutral gray panels (SMS, student form, attendance) ---- */
html[data-theme="dark"] [style*="background:#edf2f7"],
html[data-theme="dark"] [style*="background: #edf2f7"],
html[data-theme="dark"] [style*="background:#f1f5f9"],
html[data-theme="dark"] [style*="background: #f1f5f9"],
html[data-theme="dark"] [style*="background:#fafafa"],
html[data-theme="dark"] [style*="background: #fafafa"] {
    background: rgba(255, 255, 255, 0.04) !important;
}
html[data-theme="dark"] [style*="background:#eee;"],
html[data-theme="dark"] [style*="background:#f4f4f4"],
html[data-theme="dark"] [style*="background: #f4f4f4"] {
    background: rgba(255, 255, 255, 0.06) !important;
}

/* ---- Green-tint info panels (SMS, user features) ---- */
html[data-theme="dark"] [style*="background:#f0f4ef"],
html[data-theme="dark"] [style*="background: #f0f4ef"],
html[data-theme="dark"] [style*="background: #eef2ec"],
html[data-theme="dark"] [style*="background:#eef2ec"],
html[data-theme="dark"] [style*="background: #eef3ea"],
html[data-theme="dark"] [style*="background:#eef3ea"] {
    background: rgba(74, 124, 66, 0.10) !important;
}

/* ---- Semantic status surfaces (attendance banners, booklet chips, fees badges) ---- */
html[data-theme="dark"] [style*="background:#f0fff4"],
html[data-theme="dark"] [style*="background: #f0fff4"] {
    background: var(--success-light) !important;
    border-color: rgba(56, 161, 105, 0.35) !important;
}
html[data-theme="dark"] [style*="background:#fff5f5"],
html[data-theme="dark"] [style*="background: #fff5f5"] {
    background: var(--error-light) !important;
    border-color: rgba(229, 62, 62, 0.35) !important;
}
html[data-theme="dark"] [style*="background:#fff0f6"],
html[data-theme="dark"] [style*="background: #fff0f6"] {
    background: rgba(236, 72, 153, 0.12) !important;
    border-color: rgba(236, 72, 153, 0.35) !important;
}
html[data-theme="dark"] [style*="background:#fffaf0"],
html[data-theme="dark"] [style*="background: #fffaf0"] {
    background: var(--warning-light) !important;
    border-color: rgba(221, 107, 32, 0.35) !important;
}
html[data-theme="dark"] [style*="background:#fff8e1"],
html[data-theme="dark"] [style*="background: #fff8e1"] {
    background: var(--warning-light) !important;
}

/* ---- Fee / booklet / parent badge tints ---- */
html[data-theme="dark"] [style*="background:#fdf3e3"],
html[data-theme="dark"] [style*="background: #fdf3e3"] {
    background: rgba(221, 107, 32, 0.16) !important;
    border-color: rgba(221, 107, 32, 0.35) !important;
}
html[data-theme="dark"] [style*="background:#e8f0f9"],
html[data-theme="dark"] [style*="background: #e8f0f9"] {
    background: rgba(49, 130, 206, 0.16) !important;
    border-color: rgba(49, 130, 206, 0.40) !important;
}
html[data-theme="dark"] [style*="background:#e6f0fa"],
html[data-theme="dark"] [style*="background: #e6f0fa"] {
    background: rgba(59, 130, 246, 0.12) !important;
}
html[data-theme="dark"] [style*="background:#e8f0fe"],
html[data-theme="dark"] [style*="background: #e8f0fe"] {
    background: rgba(59, 130, 246, 0.16) !important;
    border-color: rgba(59, 130, 246, 0.35) !important;
}

/* ---- Dark text lifts for inline-styled labels ---- */
html[data-theme="dark"] [style*="color:#999"] {
    color: var(--text-muted) !important;
}
html[data-theme="dark"] [style*="color:#555"] {
    color: var(--text-primary) !important;
}
html[data-theme="dark"] [style*="color:#3d6b35"],
html[data-theme="dark"] [style*="color:#42503f"],
html[data-theme="dark"] [style*="color:#2f855a"] {
    color: #9dc79b !important;
}
html[data-theme="dark"] [style*="color:#c53030"] {
    color: #feb2b2 !important;
}
html[data-theme="dark"] [style*="color:#d53f8c"] {
    color: #f9a8d4 !important;
}
html[data-theme="dark"] [style*="color:#975a16"] {
    color: #f6ad55 !important;
}
html[data-theme="dark"] [style*="color:#1d4e89"],
html[data-theme="dark"] [style*="color:#1a4f8b"],
html[data-theme="dark"] [style*="color:#2b6cb0"] {
    color: #7cb3f5 !important;
}

/* ---- Photo preview box (shared by user-form + student-form) ---- */
html[data-theme="dark"] .photo-preview-box {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border);
}
html[data-theme="dark"] .photo-placeholder {
    color: var(--text-muted);
}

/* ---- Photo drop zone (js/photo-dropzone.js; user-form + student-form) ---- */
.photo-dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 120px;
    padding: 14px 16px;
    border: 2px dashed #cbd5e0;
    border-radius: 12px;
    background: #f7fafc;
    color: #4a5568;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background-color .15s;
}
.photo-dropzone:hover,
.photo-dropzone:focus-within {
    border-color: var(--primary, #2d5a27);
}
.photo-dropzone:focus-within {
    outline: 2px solid var(--primary, #2d5a27);
    outline-offset: 2px;
}
.photo-dropzone.is-dragover,
.photo-preview-box.is-dragover {
    border-color: var(--primary, #2d5a27);
    border-style: solid;
    background: #eef6ec;
}
.photo-dropzone > i { font-size: 1.6rem; color: var(--primary, #2d5a27); margin-bottom: 4px; }
.photo-dropzone-title { font-weight: 600; }
.photo-dropzone-sub { font-size: .85rem; }
.photo-dropzone-sub u { color: var(--primary, #2d5a27); }
.photo-dropzone-file { font-size: .8rem; font-weight: 600; color: var(--primary, #2d5a27); word-break: break-all; }
.photo-dropzone-file:empty { display: none; }
/* Visually hidden but still focusable, so the keyboard can open the picker. */
.photo-dropzone-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}
html[data-theme="dark"] .photo-dropzone {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border);
    color: var(--text-muted);
}
html[data-theme="dark"] .photo-dropzone.is-dragover,
html[data-theme="dark"] .photo-preview-box.is-dragover {
    background: rgba(124, 179, 245, 0.08);
    border-color: #7cb3f5;
}
html[data-theme="dark"] .photo-dropzone > i,
html[data-theme="dark"] .photo-dropzone-sub u,
html[data-theme="dark"] .photo-dropzone-file {
    color: #7cb3f5;
}

/* ---- Preschool readonly span (class=form-control, inline bg #f7f7f7) ---- */
html[data-theme="dark"] span.form-control[style*="background:#f7f7f7"] {
    background: var(--glass-bg) !important;
}

/* ============================================================
   GRADE ENTRY PICKER — subject chips + assessment type cards
   (shared by admin and teacher grade-entry pages)
   ============================================================ */
.ge-picker .ge-step { margin-bottom: 16px; }
.ge-picker .ge-step:last-child { margin-bottom: 0; }
.ge-step-label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 9px;
}
.ge-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.68rem;
    flex: none;
}
.ge-step-context {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

/* Subject chips (step 2) */
.ge-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ge-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 20px;
    background: var(--glass-bg-strong);
    border: 1px solid var(--border);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    transition: var(--transition);
}
.ge-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}
.ge-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.ge-chip-count {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 10px;
    background: rgba(74, 124, 66, 0.14);
    color: var(--primary-dark);
}
.ge-chip.active .ge-chip-count { background: rgba(255, 255, 255, 0.25); color: #fff; }
.ge-chip-count.ge-zero { background: rgba(160, 174, 192, 0.18); color: var(--text-secondary); }

/* Assessment type cards (step 3) */
.ge-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
}
.ge-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-height: 150px;
    padding: 15px 15px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-primary);
    text-decoration: none;
    transition: var(--transition);
}
a.ge-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
    color: var(--text-primary);
}
.ge-card-head { display: flex; align-items: center; gap: 10px; }
.ge-card-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    background: rgba(74, 124, 66, 0.12);
    color: var(--primary);
}
.ge-card-title { font-weight: 700; font-size: 0.95rem; line-height: 1.25; }
.ge-card-sub { font-size: 0.72rem; color: var(--text-secondary); }
.ge-card-titleline {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.35;
    min-height: 2.2em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.ge-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 3px 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.ge-card-meta i { margin-right: 3px; font-size: 0.72rem; }
.ge-card-state {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.8rem;
    font-weight: 700;
}
.ge-card-note { font-size: 0.72rem; color: var(--text-muted); }
.ge-card-actions {
    margin-top: auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.ge-card-mini {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-decoration: underline;
}
.ge-card-mini:hover { color: var(--primary); }

/* Open card: green accent, whole card is the link */
.ge-card-open { border-color: rgba(56, 161, 105, 0.35); cursor: pointer; }
.ge-card-open .ge-card-state { color: var(--success); }
.ge-card-current { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Locked card: greyed, lock badge in the corner */
.ge-card-locked {
    background: rgba(160, 174, 192, 0.08);
    opacity: 0.88;
    cursor: default;
}
.ge-card-locked .ge-card-icon { background: rgba(221, 107, 32, 0.14); color: var(--warning); }
.ge-card-locked .ge-card-state { color: var(--warning); }
.ge-lock-badge {
    position: absolute;
    top: 11px;
    right: 11px;
    color: var(--warning);
    font-size: 0.95rem;
}

/* Missing card: dashed placeholder */
.ge-card-missing {
    background: transparent;
    border: 1.5px dashed var(--border);
    opacity: 0.75;
}
.ge-card-missing .ge-card-icon { background: rgba(160, 174, 192, 0.14); color: var(--text-muted); }
.ge-card-missing .ge-card-state { color: var(--text-muted); }

@media (max-width: 640px) {
    .ge-cards { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 10px; }
    .ge-card { min-height: 138px; padding: 12px 12px 11px; }
    .ge-card-icon { width: 32px; height: 32px; font-size: 0.9rem; }
    .ge-chips { gap: 6px; }
    .ge-chip { padding: 6px 12px; font-size: 0.85rem; }
}

/* Manage-mode cards: static divs with inline action buttons */
.ge-card-manage {
    cursor: default;
}
.ge-card-actions-manage {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}
.ge-card-actions-manage .btn {
    padding: 3px 8px;
    font-size: 0.7rem;
    border-radius: 5px;
    line-height: 1.3;
}
.ge-card-actions-manage .btn i {
    font-size: 0.65rem;
    margin-right: 2px;
}

/* Dark theme: glass surfaces like the rest of the portal */
html[data-theme="dark"] .ge-chip {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--glass-border);
}
html[data-theme="dark"] .ge-chip:hover {
    border-color: var(--primary-light);
    color: #9dc79b;
}
html[data-theme="dark"] .ge-chip.active { background: var(--primary); color: #fff; }
html[data-theme="dark"] .ge-chip-count { background: rgba(107, 155, 99, 0.18); color: #9dc79b; }
html[data-theme="dark"] .ge-card {
    background: var(--glass-bg-strong);
    border-color: var(--glass-border);
}
html[data-theme="dark"] .ge-card-locked { background: rgba(255, 255, 255, 0.03); }
html[data-theme="dark"] .ge-card-missing { background: rgba(0, 0, 0, 0.15); }
html[data-theme="dark"] .ge-card-mini { color: var(--text-secondary); }

/* Timetable paper layout: named page rules do not alter report/booklet printing. */
.tt-print-header, .tt-print-time { display: none; }
@media print {
    @page timetable-landscape {
        size: A4 landscape;
        margin: 10mm;
    }
    body.timetable-print-page {
        page: timetable-landscape;
        margin: 0;
        min-height: 0;
        background: #fff !important;
        color-scheme: light;
        font-size: 10pt;
        line-height: 1.35;
    }
    body.timetable-print-page * {
        font-family: Arial, Helvetica, sans-serif !important;
        color: #111 !important;
        box-shadow: none !important;
        text-shadow: none !important;
        background: transparent !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        animation: none !important;
        transition: none !important;
    }
    body.timetable-print-page::before,
    body.timetable-print-page::after,
    body.timetable-print-page > :not(.wrapper),
    body.timetable-print-page .sidebar,
    body.timetable-print-page .main-header,
    body.timetable-print-page .no-print,
    body.timetable-print-page .tt-type-tabs,
    body.timetable-print-page .tt-view-switcher,
    body.timetable-print-page .tt-exam-title,
    body.timetable-print-page .tt-entry-actions,
    body.timetable-print-page .tt-duty-actions,
    body.timetable-print-page .btn,
    body.timetable-print-page form,
    body.timetable-print-page .alert,
    body.timetable-print-page .empty-state-icon,
    body.timetable-print-page .card-header i {
        display: none !important;
    }
    body.timetable-print-page .wrapper {
        display: block;
        min-height: 0;
    }
    body.timetable-print-page .main-content,
    body.timetable-print-page .main-body {
        width: 100%;
        min-width: 0;
        max-width: none;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        transform: none !important;
    }
    body.timetable-print-page .tt-print-header {
        display: flex;
        align-items: center;
        gap: 5mm;
        padding: 0 0 4mm;
        margin-bottom: 5mm;
        border-bottom: 1.5pt solid #333;
        break-inside: avoid;
        break-after: avoid;
    }
    body.timetable-print-page .tt-print-header img {
        flex: 0 0 20mm;
        width: 20mm;
        height: 20mm;
        object-fit: contain;
    }
    body.timetable-print-page .tt-print-identity {
        flex: 1;
        min-width: 0;
        text-align: center;
        padding-right: 25mm;
        overflow-wrap: anywhere;
    }
    body.timetable-print-page .tt-print-header h1 { font-size: 18pt; margin: 0 0 1.5mm; }
    body.timetable-print-page .tt-print-header h2 { font-size: 13pt; margin: 0 0 1.5mm; }
    body.timetable-print-page .tt-print-header p { font-size: 10pt; margin: 0.5mm 0 0; }
    body.timetable-print-page .tt-print-scope { font-weight: 700; }
    body.timetable-print-page .tt-print-time { display: block; font-size: 9pt; margin-top: 1mm; }
    body.timetable-print-page .table-container {
        overflow: visible !important;
        width: 100%;
        max-width: none;
    }
    body.timetable-print-page .table {
        width: 100%;
        min-width: 0;
        table-layout: fixed;
        border-collapse: collapse;
        font-size: 10pt;
        margin: 0;
    }
    body.timetable-print-page .table th,
    body.timetable-print-page .table td {
        min-width: 0;
        padding: 2.5mm 1.5mm !important;
        border: 0.6pt solid #555 !important;
        vertical-align: middle;
        font-size: 10pt;
        line-height: 1.35;
        letter-spacing: 0;
        white-space: normal !important;
        overflow-wrap: anywhere;
        hyphens: auto;
        text-transform: none;
    }
    body.timetable-print-page .table th {
        font-weight: 700;
        background: #eee !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    body.timetable-print-page .table thead { display: table-header-group; }
    body.timetable-print-page .table tr { break-inside: avoid; page-break-inside: avoid; }
    body.timetable-print-page .tt-day-head { width: 25mm; }
    body.timetable-print-page .tt-class-head,
    body.timetable-print-page .tt-exam-class-head { width: 25mm; }
    body.timetable-print-page .tt-break-head {
        writing-mode: horizontal-tb;
        transform: none;
    }
    body.timetable-print-page .tt-subject,
    body.timetable-print-page .tt-exam-subject { font-size: 10pt; text-transform: none; }
    body.timetable-print-page .tt-teacher,
    body.timetable-print-page .tt-activity,
    body.timetable-print-page .tt-exam-meta,
    body.timetable-print-page .tt-break-label,
    body.timetable-print-page .tt-exam-date-head div { font-size: 9pt; line-height: 1.35; }
    body.timetable-print-page .tt-entry,
    body.timetable-print-page .tt-exam-entry { display: block; }
    body.timetable-print-page .tt-entry + .tt-entry,
    body.timetable-print-page .tt-exam-entry + .tt-exam-entry { border-top: 0.5pt dotted #888; margin-top: 2mm; padding-top: 2mm; }
    body.timetable-print-page .tt-empty { opacity: 1; }
    body.timetable-print-page .card {
        border: 0 !important;
        border-radius: 0;
        transform: none !important;
        overflow: visible;
        break-inside: auto;
        page-break-inside: auto;
    }
    body.timetable-print-page .card-body { padding: 0 !important; }
    body.timetable-print-page .tt-day-list { display: block; }
    body.timetable-print-page .tt-day-list > .card { margin-bottom: 4mm; }
    body.timetable-print-page .tt-day-list .card-header { padding: 2mm 0; border: 0; break-after: avoid; }
    body.timetable-print-page .tt-day-list h3 { font-size: 12pt; }
    body.timetable-print-page .tt-duty-table th:first-child { width: 40mm; }
    body.timetable-print-page .tt-duty-number { font-size: 11pt; }
    body.timetable-print-page .tt-duty-teacher,
    body.timetable-print-page .tt-duty-senior { text-transform: none; }
    body.timetable-print-page .empty-state { padding: 6mm 0; text-align: center; }
    body.timetable-print-page .empty-state h3 { font-size: 12pt; }
}

/* Homepage content editor; isolated from report and public-site layouts. */
.website-editor { max-width: 1400px; }
.website-editor > p, .website-panel > p { margin-bottom: 16px; }
.website-editor .website-panel { padding: 24px; margin: 24px 0; }
.website-editor h2 { font-size: 1.4rem; margin-bottom: 16px; }
.website-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 16px 0; }
.website-editor [hidden] { display: none !important; }
.website-help, .website-field small { color: var(--text-secondary); }
.website-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.website-fields > .website-fields, .website-field-wide, .website-repeater { grid-column: 1 / -1; }
.website-field { min-width: 0; margin-bottom: 0; }
.website-field label { display: block; margin-bottom: 6px; font-weight: 600; }
.website-field textarea { resize: vertical; }
.website-field small { display: block; margin-top: 4px; }
.website-image-preview { display: block; max-width: 100%; width: 180px; height: 120px; object-fit: contain; margin-top: 8px; background: var(--background); border-radius: var(--radius-sm); }
.website-repeater, .website-row { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.website-repeater legend, .website-row legend { padding: 0 8px; font-weight: 700; }
.website-repeater legend small { font-weight: 400; }
.website-error { border: 1px solid var(--error); border-left-width: 4px; padding: 16px; margin: 16px 0; overflow-wrap: anywhere; }
.website-error a { display: block; text-decoration: underline; }
.website-section-picker { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.website-section-picker select { flex: 1; min-width: 180px; }
.website-publish, .website-history form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 16px 0; }
.website-publish p { flex-basis: 100%; }
.website-history { border-top: 1px solid var(--border); padding: 16px 0; overflow-wrap: anywhere; }
.website-history summary { cursor: pointer; font-weight: 600; }
.website-history > a { display: inline-block; margin-top: 12px; }
@media (max-width: 768px) {
    .website-fields { grid-template-columns: minmax(0, 1fr); }
    .website-editor .website-panel { padding: 16px; }
    .website-repeater, .website-row { padding: 10px; }
    .website-actions .btn { white-space: normal; }
}

/* Opt-in page sections. Hidden panels keep their form controls intact. */
[data-section-navigation] { min-width: 0; }
[data-section-panel] { scroll-margin-top: 110px; }
[data-section-navigation] [data-section-panel][hidden] { display: none !important; }
.page-section-nav { display: flex; gap: 8px; max-width: 100%; overflow-x: auto; padding: 8px; margin-bottom: 8px; background: var(--glass-bg); border: 1px solid var(--border); border-radius: var(--radius); }
.page-section-button { flex: 0 0 auto; padding: 10px 16px; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--text-secondary); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.page-section-button:hover { background: var(--table-hover-bg); color: var(--text-primary); }
.page-section-button.active { background: var(--primary); color: var(--white, #fff); }
.page-section-button.has-attention { border-color: var(--warning); }
.page-section-button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.page-section-status, .section-save-note { color: var(--text-secondary); font-size: .85rem; margin-bottom: 16px; }
.section-save-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 24px; }
.section-save-actions .section-save-note { flex-basis: 100%; margin: 0; }
[data-section-navigation] .set-hint, [data-section-navigation] .set-meta, [data-section-navigation] .rs-setting-desc { color: var(--text-secondary); }
@media (max-width: 768px) {
    .page-section-button { padding: 10px 12px; }
    .page-section-status { font-size: .8rem; }
}
@media print {
    [data-section-navigation] [data-section-panel][hidden]:not(.no-print) { display: block !important; }
}

/* Request workspace: portal chrome and tokens, without affecting other sections. */
.gov-workspace { max-width: 1440px; margin-inline: auto; min-width: 0; }
.gov-workspace .card { min-width: 0; margin-bottom: 24px; }
.gov-workspace .card:hover { transform: none; }
.gov-workspace .card:not(.gov-panel) { padding: 24px; }
.gov-workspace h2 { font-size: 1.3rem; }
.gov-workspace h3 { font-size: 1.1rem; }
.gov-workspace .card > h2, .gov-workspace .card > h3 { margin-bottom: 12px; }
.gov-workspace p { overflow-wrap: anywhere; }
.gov-workspace .card > p, .gov-workspace .card-body > p { margin-bottom: 12px; }
.gov-workspace .card-body > p:last-child { margin-bottom: 0; }
.gov-intro { color: var(--text-secondary); margin-bottom: 20px; }
.gov-workspace .card-header { gap: 16px; flex-wrap: wrap; }
.gov-workspace .card-header p { color: var(--text-secondary); margin-top: 6px; }
.gov-workspace .card-header h2 i { margin-right: 8px; font-size: 1rem; }
.gov-workspace .gov-eyebrow { margin: 0 0 6px; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.gov-note { display: flex; align-items: flex-start; gap: 12px; padding: 16px 20px; margin-bottom: 20px; background: var(--glass-bg); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: var(--radius); }
.gov-note > i { color: var(--primary); margin-top: 5px; }
.gov-note p { margin: 0; font-size: .95rem; }
.gov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(270px, 100%), 1fr)); gap: 20px; }
.gov-grid > * { min-width: 0; }
.gov-workspace label { display: block; margin: 0 0 16px; font-weight: 600; }
.gov-workspace label .form-control { margin-top: 6px; font-weight: 400; }
.gov-workspace input[type="checkbox"] { accent-color: var(--primary); margin-right: 6px; }
.gov-workspace textarea { min-height: 100px; resize: vertical; }
.gov-workspace .gov-filters { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px; }
.gov-filters label { flex: 0 1 260px; margin-bottom: 0; }
.gov-filter-body { border-bottom: 1px solid var(--border); }
.gov-workspace .table-container { width: 100%; max-width: 100%; }
.gov-workspace .table { width: 100%; }
.gov-workspace .table th, .gov-workspace .table td { vertical-align: top; }
.gov-workspace .table td { overflow-wrap: anywhere; }
.gov-workspace .gov-request-table { min-width: 700px; }
.gov-workspace .gov-grade-impact .table th { white-space: normal; }
.gov-workspace .gov-grade-impact .gov-grade-reason { margin-top: 12px; }
.gov-workspace .badge { white-space: nowrap; }
.gov-request-link { display: grid; gap: 4px; font-weight: 600; }
.gov-reference, .gov-cell-detail { display: block; color: var(--text-secondary); font-size: .85rem; font-weight: 400; }
.gov-workspace .gov-selected td { background: var(--table-hover-bg); }
.gov-workspace .gov-selected td:first-child { box-shadow: inset 3px 0 var(--primary); }
.gov-metadata { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px; margin-bottom: 20px; }
.gov-metadata dt { font-size: .85rem; color: var(--text-secondary); }
.gov-metadata dd { margin: 4px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.gov-reason { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--glass-bg); margin-bottom: 20px; }
.gov-reason p { margin-top: 4px; white-space: pre-wrap; }
.gov-actions, .gov-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.gov-nav { margin: 16px 0; }
.gov-nav a { text-decoration: underline; }
.gov-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--border); color: var(--text-secondary); }
.gov-empty { text-align: center; padding: 32px 16px; }
.gov-empty > i { font-size: 2rem; color: var(--text-secondary); margin-bottom: 12px; }
.gov-empty h3 { margin-bottom: 8px; }
.gov-empty p { color: var(--text-secondary); }
.gov-workspace details { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; }
.gov-workspace summary { cursor: pointer; font-weight: 600; overflow-wrap: anywhere; }
.gov-workspace summary:focus-visible, .gov-workspace a:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.gov-workspace details[open] > summary { margin-bottom: 16px; }
.gov-workspace details.gov-overview { padding: 0; }
.gov-overview > summary { padding: 16px 24px; }
.gov-overview > summary .badge { margin-left: 12px; }
.gov-workspace .gov-overview[open] > summary { margin-bottom: 0; border-bottom: 1px solid var(--border); }
.gov-summary-list { display: flex; flex-wrap: wrap; gap: 12px; list-style: none; margin-bottom: 12px; }
.gov-summary-list li { padding: 8px 12px; background: var(--glass-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.gov-json { padding: 16px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 480px; overflow: auto; background: var(--background); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .85rem; }
.gov-workspace #request-detail, .gov-workspace #request-list { scroll-margin-top: 100px; }
@media (max-width: 768px) {
    .gov-workspace .card:not(.gov-panel), .gov-workspace .card-header, .gov-workspace .card-body { padding: 16px; }
    .gov-workspace h2 { font-size: 1.15rem; }
    .gov-workspace .gov-filters label { flex-basis: 100%; }
    .gov-metadata { grid-template-columns: minmax(0, 1fr); }
    .gov-workspace .btn { white-space: normal; }
    .gov-pagination, .gov-overview > summary { padding: 16px; }
    .gov-note { padding: 14px; }
}

/* ==================== INSTALLABLE APP (PWA) CARD ==================== */
/* Built by js/main.js on the login page and the portal hub only. */
.pwa-install {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 16px 0 24px;
    padding: 14px 16px;
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow);
    color: var(--text-primary);
    animation: fadeIn 0.3s ease both;
}
.login-container .pwa-install { margin-bottom: 0; }
.pwa-install-icon {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border-radius: 10px;
    background: #f7f7f7;
}
.pwa-install-text { flex: 1 1 auto; min-width: 0; line-height: 1.35; }
.pwa-install-text strong { display: block; color: var(--primary-dark); }
.pwa-install-text span { display: block; font-size: 0.88rem; color: var(--text-secondary); }
.pwa-install-actions { display: flex; gap: 8px; flex: 0 0 auto; }
html[data-theme="dark"] .pwa-install {
    background: #28323f;
    border-color: rgba(255, 255, 255, 0.08);
    border-left-color: var(--primary-light);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6);
    color: #e2e8f0;
}
html[data-theme="dark"] .pwa-install-text strong { color: #9ae6b4; }
html[data-theme="dark"] .pwa-install-text span { color: #cbd5e0; }
@media (max-width: 480px) {
    .pwa-install { flex-wrap: wrap; }
    .pwa-install-text { flex-basis: calc(100% - 58px); }
    .pwa-install-actions { width: 100%; justify-content: flex-end; }
}
@media print {
    .pwa-install { display: none !important; }
}

/* ==================== ASSESSMENT OVERVIEW: CARD / LIST VIEW ==================== */
/* includes/grade-completion.php — admin Assessments "Assessment overview & bulk reopen". */
.ge-duplicate-warning { align-items: flex-start; }
.ge-duplicate-warning > span { flex-shrink: 0; }
.ge-warning-message { flex: 1; min-width: 0; overflow-wrap: anywhere; }
@media screen and (max-width: 768px) {
    body:has(#assessment-overview) .main-header { flex-wrap: wrap; gap: 8px; }
    body:has(#assessment-overview) .main-header h1 { min-width: 0; }
    body:has(#assessment-overview) .header-actions { flex-wrap: wrap; gap: 8px; max-width: 100%; }
    body:has(#assessment-overview) .user-info { display: none; }
    body:has(#assessment-overview) .user-dropdown-toggle { padding: 8px; gap: 0; }
    #assessment-overview .ov-cards { grid-template-columns: minmax(0, 1fr); }
}
.ov-summary-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: .75rem;
}
.ov-view-toggle {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    overflow: hidden;
    background: var(--card-bg);
}
.ov-view-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
}
.ov-view-btn + .ov-view-btn { border-left: 1px solid var(--border-color); }
.ov-view-btn:hover { color: var(--primary); text-decoration: none; }
.ov-view-btn.active { background: var(--primary); color: #fff; }
.ov-select-all {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: .75rem;
    font-size: .9rem;
    cursor: pointer;
}
.ov-class-heading {
    margin: 1rem 0 .5rem;
    font-size: 1rem;
    color: var(--primary-dark, var(--primary));
}
.ov-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: .5rem;
}
.ov-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-top: 4px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
/* Marks colours: red none entered, orange some missing, green all entered, grey dashed not created. */
.ov-card--empty { border-top-color: var(--error); background: rgba(229, 62, 62, 0.06); }
.ov-card--partial { border-top-color: var(--warning); background: rgba(221, 107, 32, 0.07); }
.ov-card--done { border-top-color: var(--success); }
.ov-card--none { border-style: dashed; border-top-style: dashed; border-top-color: var(--text-muted); }
.ov-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: -.25rem 0 .75rem; font-size: .82rem; color: var(--text-secondary); }
.ov-key { display: inline-flex; align-items: center; gap: 6px; }
.ov-key::before { content: ""; flex: 0 0 auto; box-sizing: border-box; width: 14px; height: 10px; border-radius: 3px; }
.ov-key--empty::before { background: var(--error); }
.ov-key--partial::before { background: var(--warning); }
.ov-key--done::before { background: var(--success); }
.ov-key--none::before { border: 2px dashed var(--text-muted); }
.table tr.ov-row > td:first-child { box-shadow: inset 4px 0 0 var(--ov-row-strip, transparent); }
.table tr.ov-row--empty { --ov-row-strip: var(--error); }
.table tr.ov-row--partial { --ov-row-strip: var(--warning); }
.table tr.ov-row--done { --ov-row-strip: var(--success); }
.table tr.ov-row--none { --ov-row-strip: var(--text-muted); }
.table tr.ov-row--empty > td { background: rgba(229, 62, 62, 0.06); }
.table tr.ov-row--partial > td { background: rgba(221, 107, 32, 0.07); }
.ov-card-top { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 6px 8px; }
.ov-card-pick { display: inline-flex; padding-top: 2px; cursor: pointer; }
.ov-card-subject { flex: 1 1 6rem; min-width: 0; line-height: 1.3; overflow-wrap: anywhere; }
.ov-card-top .badge { flex: 0 0 auto; margin-left: auto; white-space: nowrap; }
.ov-card-top .badge i, .table tr.ov-row .badge i { margin-right: 4px; }
.ov-card-type { font-size: .88rem; }
.ov-progress {
    height: 8px;
    border-radius: 999px;
    background: rgba(160, 174, 192, 0.25);
    overflow: hidden;
}
.ov-progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
}
.ov-card--done .ov-progress span { background: var(--success); }
.ov-card--partial .ov-progress span { background: var(--warning); }
.ov-card-marks { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; font-size: .88rem; }
.ov-card-meta { display: flex; flex-direction: column; gap: 2px; font-size: .82rem; color: var(--text-secondary); }
.ov-card-meta i { width: 14px; text-align: center; margin-right: 4px; }
.ov-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
html[data-theme="dark"] .ov-card { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35); }
html[data-theme="dark"] .ov-card--empty,
html[data-theme="dark"] .table tr.ov-row--empty > td { background: rgba(229, 62, 62, 0.12); }
html[data-theme="dark"] .ov-card--partial,
html[data-theme="dark"] .table tr.ov-row--partial > td { background: rgba(221, 107, 32, 0.12); }
html[data-theme="dark"] .ov-card--empty { border-top-color: #fc8181; }
html[data-theme="dark"] .table tr.ov-row--empty { --ov-row-strip: #fc8181; }
html[data-theme="dark"] .ov-key--empty::before { background: #fc8181; }
html[data-theme="dark"] .ov-legend { color: #cbd5e0; }
html[data-theme="dark"] .ov-class-heading { color: #9dc79b; }
html[data-theme="dark"] .ov-view-toggle { background: transparent; }
html[data-theme="dark"] a.ov-view-btn { color: #cbd5e0; }
html[data-theme="dark"] a.ov-view-btn:hover { color: #9ae6b4; }
html[data-theme="dark"] a.ov-view-btn.active,
html[data-theme="dark"] a.ov-view-btn.active:hover { background: var(--primary); color: #fff; }
@media print {
    .ov-view-toggle, .ov-card-actions, .ov-card-pick, .ov-select-all { display: none !important; }
    .ov-card { break-inside: avoid; box-shadow: none; }
    .ov-card, .ov-key::before, .table tr.ov-row > td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
