:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 0px;
    --primary: #2d5be3;
    --primary-dark: #1e3fb5;
    --sidebar-bg: #1a2236;
    --sidebar-text: #8fa3c0;
    --sidebar-active-bg: rgba(45, 91, 227, 0.15);
    --sidebar-active-text: #5b8af0;
    --topbar-bg: #1a2236;
    --body-bg: #f0f4f8;
    --card-shadow: 0 2px 12px rgba(0,0,0,0.08);
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--body-bg);
    margin: 0;
    overflow-x: hidden;
    color: #1f2937;
}

/* ===== SIDEBAR ===== */
#sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    position: fixed;
    top: 0; left: 0;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

#sidebar.collapsed {
    width: 0;
    transform: translateX(-100%);
}

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    gap: 12px;
    min-height: 72px;
}

.brand-logo {
    width: 42px;
    height: 42px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: white;
    flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { color: #ffffff; font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-sub { color: var(--sidebar-text); font-size: 11px; }

/* Logo image in sidebar */
.sidebar-logo {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: contain;
    flex-shrink: 0;
    background: white;
    padding: 3px;
}

/* Nav */
.sidebar-nav { padding: 8px 0 20px; flex: 1; }

.nav-label {
    color: rgba(143, 163, 192, 0.6);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 16px 20px 6px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--sidebar-text);
    font-size: 14px;
    font-weight: 500;
    border-radius: 0;
    transition: all 0.2s;
    white-space: nowrap;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,0.06);
    color: #ffffff;
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    border-right: 3px solid var(--primary);
}

.sidebar-nav .nav-link i {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* ===== MAIN CONTENT ===== */
#main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
    display: flex;
    flex-direction: column;
}

#main-content.expanded {
    margin-left: 0;
}

/* ===== TOPBAR ===== */
.topbar {
    background: var(--topbar-bg);
    border-bottom: none;
    padding: 0 24px;
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.topbar .container-fluid {
    gap: 12px;
    min-width: 0;
}

.sidebar-toggle {
    color: rgba(255,255,255,0.85);
    font-size: 22px;
    padding: 4px 8px;
    text-decoration: none;
    min-width: 44px;
    min-height: 44px;
}

.topbar-title {
    min-width: 0;
    flex: 1;
}

.topbar-title span {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    margin-left: 12px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 4px 0;
    min-height: 44px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #7b61ff);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
}

/* ===== PAGE CONTENT ===== */
.page-content {
    padding: 24px;
    flex: 1;
    width: 100%;
}

/* ===== STAT CARDS ===== */
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    border: none;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    min-height: 96px;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    color: inherit;
    text-decoration: none;
}

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-info { flex: 1; }
.stat-value { font-size: 28px; font-weight: 700; color: #1a2236; line-height: 1; }
.stat-label { font-size: 13px; color: #8fa3c0; margin-top: 4px; font-weight: 500; }

.bg-primary-soft { background: rgba(45, 91, 227, 0.12); color: var(--primary); }
.bg-success-soft { background: rgba(40, 199, 111, 0.12); color: #28c76f; }
.bg-info-soft    { background: rgba(30, 193, 220, 0.12); color: #1ec1dc; }
.bg-warning-soft { background: rgba(255, 159, 67, 0.12); color: #ff9f43; }
.bg-danger-soft  { background: rgba(234, 84, 85, 0.12);  color: #ea5455; }
.bg-purple-soft  { background: rgba(123, 97, 255, 0.12); color: #7b61ff; }
.bg-pink-soft    { background: rgba(232, 62, 140, 0.12); color: #e83e8c; }
.bg-teal-soft    { background: rgba(32, 201, 151, 0.12); color: #20c997; }

/* ===== CARDS ===== */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
}

.card-header {
    background: white;
    border-bottom: 1px solid #e5e9f2;
    border-radius: var(--radius) var(--radius) 0 0 !important;
    padding: 16px 20px;
    font-weight: 600;
    font-size: 15px;
    color: #1a2236;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.card-body {
    overflow-wrap: anywhere;
}

/* ===== TABLES ===== */
.table th {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #8fa3c0;
    background: #f8fafc;
    border-bottom: 2px solid #e5e9f2;
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
    font-size: 14px;
    color: #2d3748;
}

.table-responsive {
    border-radius: 0 0 var(--radius) var(--radius);
    -webkit-overflow-scrolling: touch;
}

.table-hover tbody tr:hover {
    background: #f8fafc;
}

/* ===== CHILD AVATAR ===== */
.child-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e5e9f2;
}

.child-avatar-placeholder {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 15px;
    font-weight: 700;
    border: 2px solid #e5e9f2;
}

/* ===== FORMS ===== */
.form-label { font-weight: 600; font-size: 13px; color: #4a5568; margin-bottom: 6px; }
.form-control, .form-select { border-radius: 8px; border-color: #d1d9e6; font-size: 14px; }
.form-control, .form-select, .btn {
    min-height: 44px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45,91,227,0.15);
}

/* ===== BUTTONS ===== */
.btn { border-radius: 8px; font-size: 14px; font-weight: 500; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background-color: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h4 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #1a2236;
}

.page-header .breadcrumb {
    margin: 0;
    font-size: 13px;
}

.page-header > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ===== PROFILE PAGE ===== */
.profile-photo {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.profile-photo-placeholder {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 48px;
    font-weight: 700;
    border: 4px solid white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.info-item { margin-bottom: 14px; }
.info-label { font-size: 12px; font-weight: 700; color: #8fa3c0; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 3px; }
.info-value { font-size: 15px; color: #2d3748; font-weight: 500; }

/* ===== LOGIN ===== */
.login-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a2236 0%, #2d5be3 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, var(--primary), #7b61ff);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 34px;
    color: white;
}

/* ===== CHARTS ===== */
.chart-container { position: relative; height: 260px; }

/* ===== ATTENDANCE ===== */
.attendance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.attendance-item {
    background: white;
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.06);
}

/* ===== BADGE OVERRIDES ===== */
.badge { font-weight: 600; font-size: 11.5px; padding: 4px 10px; border-radius: 6px; }

/* ===== DATATABLE OVERRIDES ===== */
.dataTables_wrapper .dataTables_filter input {
    border-radius: 8px;
    border: 1px solid #d1d9e6;
    padding: 6px 12px;
    font-size: 14px;
    width: min(100%, 280px);
}
.dataTables_wrapper .dataTables_length select {
    border-radius: 8px;
    border: 1px solid #d1d9e6;
    padding: 4px 8px;
}

.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin-top: 8px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    min-width: 36px;
}

/* ===== REPORT PRINT ===== */
@media print {
    #sidebar, .topbar, .no-print { display: none !important; }
    #main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    .print-letterhead { display: block !important; text-align: center; margin-bottom: 12px; }
}

.print-letterhead { display: none; }

.org-letterhead {
    text-align: center;
    line-height: 1.35;
    font-size: 12px;
    color: #1a2236;
    border-bottom: 2px solid #1a2236;
    padding-bottom: 8px;
}

.org-letterhead-title {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0.6px;
    margin-bottom: 4px;
}

.signature-block .signature-line {
    border-top: 1px solid #333;
    margin-bottom: 6px;
    margin-top: 28px;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.quick-action-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-radius: 14px;
    background: linear-gradient(180deg, #ffffff, #f8fbff);
    border: 1px solid #dce6f4;
    text-decoration: none;
    color: #1a2236;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.quick-action-link:hover {
    color: #1a2236;
    border-color: rgba(45,91,227,0.35);
    box-shadow: 0 8px 20px rgba(45,91,227,0.12);
}

.quick-action-link i {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(45, 91, 227, 0.1);
    color: var(--primary);
    font-size: 20px;
    flex-shrink: 0;
}

.quick-action-text strong,
.quick-action-text span {
    display: block;
}

.quick-action-text span {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
}

.child-hero {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 24px;
    border-bottom: 1px solid #e5e9f2;
    background: linear-gradient(135deg, #f0f4f8, #e8f0fe);
}

.child-hero-photo,
.child-hero-placeholder {
    width: 100px;
    height: 127px;
    border-radius: 8px;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(45,91,227,0.2);
}

.child-hero-photo {
    object-fit: cover;
    border: 3px solid #fff;
}

.child-hero-placeholder {
    background: linear-gradient(135deg, #2d5be3, #7b61ff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    color: #fff;
    font-weight: 700;
}

.section-panel {
    padding: 24px;
}

.detail-note-card {
    margin-top: 16px;
    padding: 16px;
    background: #fff;
    border: 1px solid #e5e9f2;
    border-radius: 12px;
}

.child-photo-pane {
    display: flex;
    align-items: flex-start;
    gap: 24px;
}

.child-photo-frame,
.child-photo-empty {
    width: 150px;
    height: 190px;
    border-radius: 8px;
    flex-shrink: 0;
}

.child-photo-frame {
    object-fit: cover;
    border: 3px solid #2d5be3;
    box-shadow: 0 4px 16px rgba(45,91,227,0.2);
}

.child-photo-empty {
    border: 3px dashed #dee2e6;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #6c757d;
}

.report-shell {
    padding: 24px;
}

.report-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.report-table th {
    white-space: normal;
}

.report-image-card {
    border: 1px solid #e5e9f2;
    border-radius: 12px;
    padding: 10px;
    height: 100%;
    background: #fff;
}

.report-image-card img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.profile-summary-card .user-avatar {
    width: 80px;
    height: 80px;
    font-size: 34px;
}

.profile-role-badge {
    font-size: 1rem;
    padding: 10px 14px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    #sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
    #sidebar.mobile-open { transform: translateX(0); }
    #main-content { margin-left: 0; }
    .topbar {
        padding: 0 12px;
        height: auto;
        min-height: 64px;
    }
    .topbar-title span {
        margin-left: 0;
        font-size: 15px;
    }
    .topbar-user {
        gap: 8px;
    }
    .page-content { padding: 16px 12px; }
    .page-header {
        align-items: flex-start;
    }
    .page-header h4 {
        font-size: 18px;
    }
    .page-header .breadcrumb {
        font-size: 12px;
    }
    .page-header > div:last-child,
    .page-header .btn,
    .page-header a.btn {
        width: 100%;
    }
    .stat-card {
        padding: 16px;
        gap: 12px;
        min-height: 88px;
    }
    .stat-icon {
        width: 46px;
        height: 46px;
        font-size: 20px;
    }
    .stat-value { font-size: 22px; }
    .stat-label { font-size: 12px; }
    .card-header,
    .card-body {
        padding-left: 14px;
        padding-right: 14px;
    }
    .login-card {
        padding: 32px 20px;
        border-radius: 16px;
    }
    .attendance-grid {
        grid-template-columns: 1fr;
    }
    .chart-container {
        height: 220px;
    }
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
    }
    .nav-tabs .nav-link {
        min-width: max-content;
    }
    .table th,
    .table td {
        font-size: 13px;
    }
    .page-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }
    .page-actions .btn,
    .page-actions a,
    .report-toolbar .btn,
    .report-toolbar a {
        width: 100%;
        justify-content: center;
    }
    .quick-actions-grid {
        grid-template-columns: 1fr 1fr;
    }
    .quick-action-link {
        padding: 14px;
        align-items: flex-start;
    }
    .child-hero {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
        padding: 18px;
    }
    .child-hero-photo,
    .child-hero-placeholder {
        width: 88px;
        height: 112px;
    }
    .section-panel,
    .report-shell {
        padding: 16px;
    }
    .child-photo-pane {
        flex-direction: column;
        gap: 16px;
    }
    .child-photo-frame,
    .child-photo-empty {
        width: 120px;
        height: 152px;
    }
    .report-table th,
    .report-table td {
        display: block;
        width: 100% !important;
    }
    .report-table tr {
        display: block;
        margin-bottom: 10px;
        border-bottom: 1px solid #e5e9f2;
    }
    .report-table th {
        border-bottom: none;
        padding-bottom: 4px;
        background: #f8fafc;
    }
    .report-table td {
        border-top: none;
        padding-top: 0;
    }
    .profile-summary-card .user-avatar {
        width: 72px;
        height: 72px;
        font-size: 30px;
    }
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: left;
        float: none !important;
    }
    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
        margin-left: 0 !important;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .page-content {
        padding: 20px;
    }
    .stat-card {
        padding: 18px;
    }
    .chart-container {
        height: 240px;
    }
}

@media (min-width: 1400px) {
    .page-content {
        padding: 28px 32px;
    }
}

/* Sidebar overlay for mobile */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1049;
}
#sidebar-overlay.show { display: block; }
