:root {
    --primary-color: #0d6efd;
    --primary-hover: #0b5ed7;
    --surface-page: #f5f7fb;
    --surface-card: #ffffff;
    --surface-muted: #f8f9fa;
    --border-soft: #dee2e6;
    --text-muted: #6c757d;
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --shadow-card: 0 6px 18px rgba(15, 23, 42, 0.08);
    /* Accent panels should match the site's primary blue theme. */
    --app-accent-gradient: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%);
}

html, body {
    /* Defensive reset: if Bootstrap reboot CSS fails to load for any reason,
       prevent the browser default margins/padding creating a top gap above navbar. */
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--surface-page);
}

/* Extra guard: navbar should never be offset from the top by margins. */
.navbar {
    margin: 0;
    position: relative;
    z-index: 1100;
}

.navbar .dropdown-menu {
    z-index: 1110;
}

.navbar .nav-item.dropdown {
    overflow: visible;
}

.navbar-utility-nav {
    align-items: center;
    gap: 0.15rem;
}

.navbar-utility-link {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    gap: 0.45rem;
}

.navbar-utility-link--icon-only {
    justify-content: center;
    min-width: 42px;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.navbar-utility-link--icon-only::after {
    margin-left: 0.35rem;
}

.navbar-brand img {
    height: 40px;
    margin-right: 10px;
}

.navbar-brand {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: calc(100% - 70px);
}

.navbar-brand-text {
    min-width: 0;
    white-space: nowrap;
}

.lang-choice {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.lang-flag {
    width: 18px;
    height: 12px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
    flex: 0 0 auto;
}

.notification-bell-link {
    position: relative;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.notification-bell-link .bi-bell {
    font-size: 1.1rem;
}

.notification-bell-badge {
    position: absolute;
    top: -0.28rem;
    right: -0.18rem;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #dc3545;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 0 0 2px var(--primary-color);
    pointer-events: none;
    z-index: 2;
}

.notification-dropdown {
    width: min(360px, calc(100vw - 1.25rem));
    max-height: 420px;
    overflow: hidden;
    border-radius: 0.85rem;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
}

.notification-dropdown .dropdown-header {
    padding: 0.85rem 1rem;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
}

.notification-dropdown .list-group {
    max-height: 340px;
    overflow-y: auto;
}

.modal {
    z-index: 2000 !important;
}

.modal-backdrop.show {
    z-index: 1995 !important;
}

.notification-item {
    border-left: 4px solid transparent;
    padding: 0.85rem 1rem;
    white-space: normal;
}

.notification-item--unread {
    background: #eef6ff;
    border-left-color: var(--primary-color);
}

.notification-item__title {
    display: block;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.35;
    color: #1f2937;
    margin-bottom: 0.15rem;
    word-break: break-word;
}

.notification-item__message {
    display: block;
    font-size: 0.84rem;
    line-height: 1.45;
    color: #6b7280;
    word-break: break-word;
}

.notification-item__time {
    margin-top: 0;
    font-size: 0.76rem;
    line-height: 1.35;
    color: #94a3b8;
}

@media (max-width: 991.98px) {
    .navbar-utility-nav {
        align-items: stretch;
        gap: 0;
    }

    .navbar-utility-link,
    .navbar-utility-link--icon-only {
        justify-content: flex-start;
        min-width: 0;
        padding-left: var(--bs-navbar-nav-link-padding-x);
        padding-right: var(--bs-navbar-nav-link-padding-x);
    }
}

.x-small {
    font-size: 0.72rem;
}

.app-avatar-xs {
    width: 26px;
    height: 26px;
    border-radius: 999px;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.35);
    vertical-align: -6px;
    margin-right: 6px;
    display: inline-block;
    flex: 0 0 auto;
}

.app-avatar-sm {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    object-fit: cover;
    background: #f3f4f6;
    border: 1px solid rgba(0,0,0,0.08);
}

.app-avatar-lg {
    width: 112px;
    height: 112px;
    border-radius: 999px;
    object-fit: cover;
    background: #f3f4f6;
    border: 1px solid rgba(0,0,0,0.08);
}

.app-avatar-fallback-icon {
    font-size: 2.25rem;
    line-height: 1;
}

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

.app-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.app-footer-link {
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
}

.app-footer-link:hover,
.app-footer-link:focus {
    color: #fff;
    text-decoration: underline;
}

.app-footer-link:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.75);
    outline-offset: 2px;
    border-radius: 4px;
}

.undo-submit-btn {
    background: #f0b90b !important;
    border-color: #f0b90b !important;
    color: #ffffff !important;
    font-weight: 600;
}

.undo-submit-btn:hover,
.undo-submit-btn:focus,
.undo-submit-btn:active {
    background: #d9a509 !important;
    border-color: #d9a509 !important;
    color: #ffffff !important;
}

.sidebar {
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    min-height: 0;
    padding: 26px 20px 20px;
    margin: 0 0.25rem;
    border-radius: 22px;
    border-right: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow: 10px 0 30px rgba(15, 23, 42, 0.04);
}

.app-desktop-sidebar {
    position: relative;
    display: flex;
    flex-direction: column;
    align-self: flex-start;
    overflow: visible;
    z-index: 30;
}

.app-desktop-sidebar__nav {
    flex: 1 1 auto;
    min-height: 0;
    padding-bottom: 1.25rem;
}

.app-sidebar-footer {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    z-index: 35;
}

.sidebar .nav {
    gap: 0.1rem;
}

.sidebar hr {
    margin: 1.2rem 0 0.95rem;
    border: 0;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
    opacity: 1;
}

.sidebar small.text-muted {
    display: block;
    padding: 0 0.75rem 0.25rem !important;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #8b95a7 !important;
}

.sidebar .nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    color: #4b5563;
    padding: 0.95rem 1rem;
    margin-bottom: 0;
    border-radius: 14px;
    font-weight: 500;
    transition: background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.sidebar .nav-link i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.3rem;
    min-width: 1.3rem;
    font-size: 1.15rem;
    color: #6b7280;
    transition: color 0.18s ease;
}

.sidebar .nav-link:hover {
    background: rgba(241, 245, 249, 0.92);
    color: #1f2937;
    transform: translateX(1px);
}

.sidebar .nav-link:hover i {
    color: #2563eb;
}

.sidebar .nav-link.active {
    background: linear-gradient(180deg, #eff6ff 0%, #eef5ff 100%);
    color: #2563eb;
    box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.18);
}

.sidebar .nav-link.active i {
    color: #2563eb;
}

.sidebar .nav-link.active .badge {
    background: #2563eb !important;
    color: #fff;
}

.sidebar .badge {
    margin-left: auto;
    font-size: 0.72rem;
    font-weight: 700;
}

.app-desktop-sidebar .nav-link::after,
.app-sidebar-toggle::after {
    content: attr(data-sidebar-tooltip);
    position: absolute;
    left: calc(100% + 0.7rem);
    top: 50%;
    transform: translateY(-50%);
    padding: 0.4rem 0.6rem;
    border-radius: 0.55rem;
    background: rgba(15, 23, 42, 0.92);
    color: #fff;
    font-size: 0.78rem;
    line-height: 1.2;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
    transition: opacity 0.16s ease;
    z-index: 1100;
}

.app-sidebar-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 24px;
    min-width: 24px;
    height: 52px;
    min-height: 52px;
    padding: 0;
    border-radius: 999px;
    color: #94a3b8;
    text-decoration: none;
    flex-shrink: 0;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(203, 213, 225, 0.9);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.1);
    z-index: 36;
}

.app-sidebar-toggle:hover,
.app-sidebar-toggle:focus {
    color: #475569;
    background: #ffffff;
    border-color: rgba(148, 163, 184, 0.42);
}

.app-sidebar-toggle__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 0;
    height: auto;
    border-radius: 0;
    background: transparent;
    color: currentColor;
    font-size: 0.95rem;
    line-height: 1;
    font-weight: 700;
    font-family: Arial, sans-serif;
}

@media (min-width: 768px) {
    .app-shell-row {
        flex-wrap: nowrap;
        overflow: visible;
    }

    .app-desktop-sidebar,
    .app-desktop-main {
        transition: flex-basis 0.2s ease, max-width 0.2s ease, width 0.2s ease;
    }

    .app-desktop-main {
        position: relative;
        overflow: visible;
        padding-left: 0.35rem;
    }

    body.sidebar-collapsed .app-desktop-sidebar {
        flex: 0 0 88px;
        max-width: 88px;
        width: 88px;
        padding-left: 12px;
        padding-right: 12px;
        margin-left: 0;
        margin-right: 0.25rem;
    }

    body.sidebar-collapsed .app-desktop-main {
        flex: 0 0 calc(100% - 88px);
        max-width: calc(100% - 88px);
    }

    body.sidebar-collapsed .app-desktop-sidebar .nav-link,
    body.sidebar-collapsed .app-sidebar-toggle {
        width: 56px;
        min-width: 56px;
        min-height: 56px;
        margin-left: auto;
        margin-right: auto;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        overflow: visible;
        border-radius: 16px;
    }

    body.sidebar-collapsed .app-desktop-sidebar .nav-link span,
    body.sidebar-collapsed .app-desktop-sidebar small,
    body.sidebar-collapsed .app-desktop-sidebar .badge {
        display: none !important;
    }

    body.sidebar-collapsed .app-desktop-sidebar .nav-link i {
        margin-right: 0 !important;
    }

    body.sidebar-collapsed .app-sidebar-toggle {
        width: 24px;
        min-width: 24px;
        min-height: 52px;
        height: 52px;
        padding: 0;
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid rgba(203, 213, 225, 0.9);
    }

    body.sidebar-collapsed .app-sidebar-toggle__icon {
        width: auto;
        min-width: 0;
        height: auto;
        background: transparent;
    }

    body.sidebar-collapsed .app-desktop-sidebar .nav-link:hover::after,
    body.sidebar-collapsed .app-desktop-sidebar .nav-link:focus-visible::after,
    body.sidebar-collapsed .app-sidebar-toggle:hover::after,
    body.sidebar-collapsed .app-sidebar-toggle:focus-visible::after {
        opacity: 1;
    }
}

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

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

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

.btn-primary,
.btn-outline-primary:hover {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: #fff !important;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    color: #fff !important;
}

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

.badge.bg-primary {
    background-color: var(--primary-color) !important;
}

.card {
    background: var(--surface-card);
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow-card);
    margin-bottom: 20px;
}

.app-card-interactive {
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.app-card-interactive:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.app-accent-gradient {
    background: var(--app-accent-gradient);
    color: #fff;
}

.app-accent-panel {
    background: var(--app-accent-gradient);
    color: #fff;
    border-radius: var(--radius-md);
}

.app-card-header-accent {
    background: var(--app-accent-gradient);
    color: #fff;
}

.app-card-header-accent a {
    color: inherit;
}

.app-hero {
    background: var(--app-accent-gradient);
    color: #fff;
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.app-muted-panel {
    background: var(--surface-muted);
    border: 1px solid var(--border-soft);
}

.app-empty-state-icon {
    color: #c2c8d0;
    font-size: 4rem;
}

.app-icon-lg {
    font-size: 2rem;
}

.app-icon-xl {
    font-size: 3rem;
}

.app-icon-xxl {
    font-size: 4rem;
}

.app-muted-icon {
    color: #c2c8d0;
}

.app-img-maxh-200 {
    max-height: 200px;
}

.app-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.app-page-title {
    margin: 0;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.app-page-subtitle {
    margin: 0.25rem 0 0;
    color: var(--text-muted);
}

.card-header h4,
.card-header h5 {
    letter-spacing: 0.2px;
}

.app-sticky-top-20 {
    top: 20px;
}

.soft-divider-on-dark {
    border-color: rgba(255, 255, 255, 0.2);
    opacity: 1;
}

/* Shared SDH student entry UI (used in lesson form + reuse). */
.student-row {
    background: var(--surface-muted);
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    position: relative;
}

.student-row .remove-student {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    cursor: pointer;
    color: #dc3545;
}

.add-student-btn {
    border: 2px dashed var(--border-soft);
    background: transparent;
    color: var(--text-muted);
    width: 100%;
    padding: 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.add-student-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #f0f7ff;
}

.badge-status {
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
}

.badge-draft { background-color: #6c757d; color: white; }
.badge-submitted { background-color: #ffc107; color: black; }
.badge-verified { background-color: #28a745; color: white; }
.badge-rejected { background-color: #dc3545; color: white; }

.badge-on-time { background-color: #28a745; color: white; }
.badge-late { background-color: #ffc107; color: black; }
.badge-not-submitted { background-color: #dc3545; color: white; }

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

@media (max-width: 991.98px) {
    .main-content {
        padding: 12px 0;
    }

    .sidebar {
        min-height: auto;
        padding: 12px 10px;
    }

    .sidebar .nav-link {
        padding: 8px 10px;
        margin-bottom: 4px;
    }

    .sidebar hr {
        margin: 0.5rem 0;
    }
}

@media (max-width: 767.98px) {
    .app-page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .app-desktop-sidebar {
        display: none;
    }

    .app-mobile-main {
        width: 100%;
        padding-bottom: 5.9rem;
    }

    .app-mobile-bottom-nav {
        position: fixed;
        left: 0.85rem;
        right: 0.85rem;
        bottom: max(0.85rem, env(safe-area-inset-bottom));
        z-index: 1085;
        display: grid;
        gap: 0.55rem;
        grid-auto-flow: column;
        justify-content: stretch;
        align-items: center;
        padding: 0.7rem 0.8rem;
        border-radius: 1.25rem;
        background: rgba(255, 255, 255, 0.95);
        border: 1px solid rgba(13, 110, 253, 0.12);
        box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
        backdrop-filter: blur(12px);
    }

    .app-mobile-bottom-nav__item {
        border: 0;
        background: transparent;
        color: #64748b;
        min-height: 46px;
        border-radius: 0.95rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
    }

    .app-mobile-bottom-nav__item i {
        font-size: 1.3rem;
        line-height: 1;
    }

    .app-mobile-bottom-nav__item.is-active {
        color: #fff;
        background: var(--app-accent-gradient);
        box-shadow: 0 10px 20px rgba(13, 110, 253, 0.22);
    }

    .app-mobile-bottom-nav__item:active {
        transform: translateY(1px);
    }

    .app-mobile-sheet {
        display: flex;
        flex-direction: column;
        height: auto !important;
        max-height: min(88dvh, calc(100dvh - 0.75rem));
        border-top-left-radius: 1.35rem;
        border-top-right-radius: 1.35rem;
        overflow: hidden;
        z-index: 1205 !important;
        box-shadow: 0 -18px 42px rgba(15, 23, 42, 0.22);
    }

    .app-mobile-sheet .offcanvas-header {
        flex: 0 0 auto;
        padding: 1.05rem 1.1rem 0.8rem;
        align-items: center;
    }

    .app-mobile-sheet .offcanvas-title {
        line-height: 1.3;
        margin: 0;
    }

    .app-mobile-sheet .offcanvas-body {
        flex: 1 1 auto;
        min-height: 0;
        padding: 0.25rem 1rem calc(1.15rem + env(safe-area-inset-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y;
    }

    .app-mobile-sheet__list {
        display: grid;
        gap: 0.6rem;
        padding-bottom: 0.2rem;
    }

    .app-mobile-sheet__link {
        display: flex;
        align-items: center;
        gap: 0.85rem;
        padding: 0.95rem 1rem;
        border-radius: 1rem;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        color: #0f172a;
        text-decoration: none;
        font-weight: 600;
    }

    .app-mobile-sheet__link i {
        font-size: 1.15rem;
        color: var(--primary-color);
        line-height: 1;
    }

    .offcanvas-backdrop.show {
        z-index: 1200 !important;
    }

    .app-footer {
        padding-bottom: 6rem !important;
    }
}
