:root {
    --primary-color: #002147;
    --secondary-color: #003366;
    --accent-color: #FFD700;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
}

.card {
    border: none;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    transition: all 0.3s;
    margin-bottom: 20px;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.12);
}

.card-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    font-weight: 600;
    border-radius: 15px 15px 0 0 !important;
    padding: 15px 20px;
}

.card-body {
    padding: 20px;
}

.stat-card {
    text-align: center;
    padding: 30px 20px;
}

.stat-card .icon {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.stat-card .number {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-card .label {
    font-size: 1rem;
    color: var(--dark-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,33,71,0.3);
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--primary-color) 100%);
}

.btn-success {
    background: linear-gradient(135deg, #28a745 0%, #218838 100%);
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-weight: 600;
}

.btn-danger {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-weight: 600;
}

.btn-warning {
    background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-weight: 600;
    color: #333;
}

.form-control {
    border-radius: 10px;
    border: 2px solid #e0e0e0;
    padding: 12px 15px;
    transition: all 0.3s;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(0,33,71,0.1);
}

.form-label {
    font-weight: 600;
    color: var(--dark-color);
}

.table {
    border-radius: 10px;
    overflow: hidden;
}

.table thead {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.table thead th {
    border: none;
    padding: 15px;
    font-weight: 600;
}

.table tbody tr {
    transition: all 0.3s;
}

.table tbody tr:hover {
    background-color: rgba(0,33,71,0.05);
}

.alert {
    border-radius: 10px;
    border: none;
    padding: 15px 20px;
}

.page-header {
    margin-bottom: 30px;
}

.page-header h1 {
    color: var(--primary-color);
    font-weight: 700;
    margin-bottom: 10px;
}

.page-header .breadcrumb {
    background: none;
    padding: 0;
    margin: 0;
}

.breadcrumb-item a {
    color: var(--primary-color);
    text-decoration: none;
}

.breadcrumb-item.active {
    color: var(--dark-color);
}

.modal-content {
    border-radius: 15px;
    border: none;
}

.modal-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border-radius: 15px 15px 0 0;
}

.modal-title {
    font-weight: 600;
}

.btn-close {
    filter: brightness(0) invert(1);
}

/* AI Assistant Styles */
.ai-assistant-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 5px 20px rgba(0,33,71,0.3);
    transition: all 0.3s;
    z-index: 1000;
}

.ai-assistant-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(0,33,71,0.4);
}

.ai-assistant-panel {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}

.ai-assistant-panel.show {
    display: flex;
}

.ai-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-header h5 {
    margin: 0;
    font-weight: 600;
}

.ai-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
}

.ai-message {
    background: white;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.ai-message.user {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    margin-left: 20px;
}

.ai-message.assistant {
    background: white;
    margin-right: 20px;
}

.ai-footer {
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    background: white;
}

/* Print Styles */
@media print {
    .app-topbar,
    .app-sidebar,
    .sidebar-overlay,
    .btn,
    .no-print,
    .ai-assistant-btn,
    .ai-assistant-panel {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        margin-top: 0 !important;
    }
    
    body {
        background: white;
    }
    
    .main-content {
        padding: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .card-header {
        background: white !important;
        color: black !important;
        border-bottom: 2px solid #000;
    }
    
    @page {
        size: A4 portrait;
        margin: 10mm;
    }
}

/* Report Card Styles */
.report-card {
    background: white;
    padding: 30px;
    border: 2px solid #000;
    position: relative;
}

.report-card::before {
    content: 'MEHS';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 100px;
    color: rgba(0,33,71,0.05);
    font-weight: 700;
    pointer-events: none;
}

.report-header {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 2px solid #000;
    padding-bottom: 20px;
}

.report-header img {
    max-width: 100px;
    margin-bottom: 10px;
}

.report-header h2 {
    color: var(--primary-color);
    font-weight: 700;
    margin-bottom: 5px;
}

.report-header .motto {
    font-style: italic;
    color: var(--dark-color);
}

.report-header .academic-year {
    font-weight: 600;
    margin-top: 10px;
}

.student-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.student-photo {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 10px;
    border: 2px solid var(--primary-color);
}

.student-details h4 {
    color: var(--primary-color);
    font-weight: 700;
    margin-bottom: 10px;
}

.student-details p {
    margin: 5px 0;
    font-weight: 500;
}

.report-table {
    margin-bottom: 30px;
}

.report-table table {
    width: 100%;
    border-collapse: collapse;
}

.report-table th,
.report-table td {
    border: 1px solid #000;
    padding: 12px;
    text-align: center;
}

.report-table th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.report-summary {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.report-summary h4 {
    color: var(--primary-color);
    font-weight: 700;
    margin-bottom: 15px;
}

.report-summary .summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.report-summary .summary-item {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: white;
    border-radius: 5px;
}

.report-summary .summary-item strong {
    color: var(--primary-color);
}

.report-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 2px solid #000;
}

.signature-section {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
}

.signature-box {
    text-align: center;
    width: 30%;
}

.signature-box .signature-line {
    border-bottom: 1px solid #000;
    margin-bottom: 10px;
    height: 50px;
}

.signature-box p {
    font-weight: 600;
    margin: 0;
}

.school-stamp {
    text-align: center;
    margin-top: 30px;
    padding: 20px;
    border: 2px dashed #000;
}

/* Responsive */
@media (max-width: 768px) {
    .stat-card .number {
        font-size: 2rem;
    }
    
    .ai-assistant-panel {
        width: 300px;
        right: 10px;
        bottom: 90px;
    }
    
    .student-info {
        flex-direction: column;
        text-align: center;
    }
    
    .signature-section {
        flex-direction: column;
        gap: 20px;
    }
    
    .signature-box {
        width: 100%;
    }
}

/* ==========================================================================
   APP SHELL - responsive topbar + sidebar
   Replaces the old single-row navbar (which only ever really worked on a
   desktop-width screen; on a phone its dropdowns were nearly unusable).
   Mobile:  sidebar is an off-canvas drawer, topbar search collapses to icon.
   Tablet:  sidebar is off-canvas, topbar shows the search bar.
   Desktop: sidebar is a fixed column, content shifts right of it.
   ========================================================================== */

:root {
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --surface: #ffffff;
    --surface-alt: #f5f7fa;
    --text-main: #1e2532;
    --text-muted: #6b7686;
    --border-soft: #e7eaf0;
}

html[data-theme="dark"] {
    --surface: #151b26;
    --surface-alt: #0f141d;
    --text-main: #e8ecf3;
    --text-muted: #9aa5b5;
    --border-soft: #26303f;
    --light-color: #1c2432;
    --dark-color: #e8ecf3;
}

html[data-theme="dark"] body { background-color: var(--surface-alt); color: var(--text-main); }
html[data-theme="dark"] .card,
html[data-theme="dark"] .app-sidebar,
html[data-theme="dark"] .app-topbar,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .notif-panel { background: var(--surface); color: var(--text-main); }
html[data-theme="dark"] .table { color: var(--text-main); }
html[data-theme="dark"] .form-control { background: var(--surface-alt); color: var(--text-main); border-color: var(--border-soft); }
html[data-theme="dark"] .form-control:focus { color: var(--text-main); }
html[data-theme="dark"] .side-link { color: var(--text-muted); }
html[data-theme="dark"] .side-link:hover,
html[data-theme="dark"] .side-link.active { background: rgba(255,255,255,0.06); color: #fff; }

* { box-sizing: border-box; }

body.has-app-shell {
    padding-top: var(--topbar-height);
}

/* ---- Top bar ---- */
.app-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    z-index: 1050;
}

.icon-btn {
    background: transparent;
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    position: relative;
    transition: background 0.2s;
}
.icon-btn:hover, .icon-btn:focus { background: rgba(255,255,255,0.15); color: #fff; }

/* PWA Install Button */
#pwaInstallBtn {
    background: linear-gradient(135deg, #28a745 0%, #218838 100%);
    animation: pulse-pwa 2s ease-in-out infinite;
}

#pwaInstallBtn:hover {
    background: linear-gradient(135deg, #34ce57 0%, #28a745 100%);
    transform: scale(1.1);
}

@keyframes pulse-pwa {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
    }
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
}
.app-brand i { color: var(--accent-color); font-size: 1.3rem; }
.app-brand-text { overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

.topbar-search {
    position: relative;
    flex: 1;
    max-width: 420px;
    display: flex;
    align-items: center;
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
    padding: 0 12px;
    height: 40px;
    margin-left: 8px;
}
.topbar-search i { color: rgba(255,255,255,0.85); font-size: 0.9rem; }
.topbar-search input {
    background: transparent;
    border: none;
    color: #fff;
    padding: 0 10px;
    width: 100%;
    outline: none;
}
.topbar-search input::placeholder { color: rgba(255,255,255,0.75); }

.search-toggle-mobile { display: none; }

.search-results {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 340px;
    max-height: 420px;
    overflow-y: auto;
    background: var(--surface);
    color: var(--text-main);
    border-radius: 12px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.25);
    z-index: 1100;
}
.search-results.show { display: block; }
.search-results .result-group-label {
    padding: 8px 14px 4px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 700;
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--text-main);
}
.search-result-item:hover { background: var(--surface-alt); }
.search-result-item i { color: var(--primary-color); width: 20px; text-align: center; }
.search-result-item .title { font-weight: 600; display: block; font-size: 0.9rem; }
.search-result-item .subtitle { font-size: 0.76rem; color: var(--text-muted); }
.search-empty, .notif-empty { padding: 20px 14px; text-align: center; color: var(--text-muted); font-size: 0.85rem; }

.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }

.notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--danger-color);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 20px;
    min-width: 16px;
    text-align: center;
}

.user-chip { width: auto; padding: 0 10px 0 8px; gap: 6px; }
.user-chip-name { font-size: 0.85rem; font-weight: 600; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.notif-panel, .dropdown-menu { border: none; border-radius: 14px; box-shadow: 0 15px 40px rgba(0,0,0,0.2); }
.notif-panel { width: 340px; padding: 0; overflow: hidden; }
.notif-panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px; font-weight: 700; border-bottom: 1px solid var(--border-soft);
}
.btn-link-small { background: none; border: none; color: var(--primary-color); font-size: 0.78rem; font-weight: 600; }
.notif-panel-body { max-height: 360px; overflow-y: auto; }
.notif-item { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); text-decoration: none; color: var(--text-main); }
.notif-item:hover { background: var(--surface-alt); }
.notif-item.unread { background: rgba(0,86,179,0.06); }
.notif-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary-color); margin-top: 6px; flex-shrink: 0; }
.notif-item .body { flex: 1; }
.notif-item .title { font-weight: 700; font-size: 0.85rem; }
.notif-item .msg { font-size: 0.8rem; color: var(--text-muted); }
.notif-item .time { font-size: 0.7rem; color: var(--text-muted); margin-top: 3px; }

/* ---- Sidebar ---- */
.app-sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border-soft);
    z-index: 1040;
    transform: translateX(0);
    transition: transform 0.25s ease;
}
.sidebar-scroll { height: 100%; overflow-y: auto; padding: 14px 10px 90px; }

.side-section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 16px 10px 6px;
}
.side-section-label:first-child { padding-top: 6px; }

.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 2px;
}
.side-link i { width: 18px; text-align: center; color: var(--text-muted); }
.side-link:hover { background: var(--surface-alt); color: var(--primary-color); }
.side-link.active { background: var(--primary-color); color: #fff; }
.side-link.active i { color: #fff; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1035;
}

/* ---- Main content shifts right of the fixed sidebar on desktop ---- */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: 0;
    padding: 24px;
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left 0.25s ease;
}
.main-content-guest { margin-left: 0; padding: 0; min-height: 100vh; }

/* Collapsed state toggled from desktop hamburger button */
body.sidebar-collapsed .app-sidebar { transform: translateX(-100%); }
body.sidebar-collapsed .main-content { margin-left: 0; }

/* ---- Responsive tables: allow horizontal scroll instead of squashing ---- */
.table-responsive-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ==========================================================================
   Breakpoints
   ========================================================================== */

/* Tablets and small laptops */
@media (max-width: 992px) {
    .app-sidebar { transform: translateX(-100%); box-shadow: 0 0 30px rgba(0,0,0,0.2); }
    body.sidebar-open .app-sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }
    .main-content { margin-left: 0; }
    body.sidebar-collapsed .app-sidebar { transform: translateX(-100%); }
}

/* Phones */
@media (max-width: 576px) {
    .app-brand-text { display: none; }
    .topbar-search { display: none; }
    .search-toggle-mobile { display: inline-flex; }
    .user-chip-name { display: none; }
    .main-content { padding: 14px; }

    /* When the mobile search icon is tapped, show the search bar as a full-width row under the topbar */
    body.mobile-search-open .topbar-search {
        display: flex;
        position: fixed;
        top: var(--topbar-height);
        left: 0; right: 0;
        max-width: none;
        margin: 0;
        border-radius: 0;
        height: 52px;
        background: var(--primary-color);
        z-index: 1049;
        padding: 0 14px;
    }
    body.mobile-search-open .search-results { width: 100%; left: 14px; right: 14px; top: calc(100% + 60px); }

    .notif-panel { width: calc(100vw - 24px); right: -50px; }

    .stat-card { padding: 18px 12px; }
    .card-body { padding: 15px; }
    .page-header h1 { font-size: 1.4rem; }
}

/* Touch-friendly minimum tap targets everywhere on the two school sides */
@media (max-width: 768px) {
    .btn { min-height: 44px; }
    .form-control, .form-select { min-height: 44px; }
    .side-link { min-height: 46px; }
}
