/* Apex Academy School Management System - Professional UI Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #4338ca;
    --primary-hover: #3730a3;
    --primary-light: #e0e7ff;
    --primary-subtle: #eef2ff;
    --secondary: #64748b;
    --success: #059669;
    --success-light: #d1fae5;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0284c7;
    --info-light: #e0f2fe;
    --dark: #0f172a;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active-bg: #4338ca;
    --sidebar-active-text: #ffffff;
    --topbar-bg: #ffffff;
    --body-bg: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-heading: 'Outfit', var(--font-sans);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
}

/* Universal Box-Sizing & Viewport Boundary Controls */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background-color: var(--body-bg);
    color: #1e293b;
    font-size: 0.925rem;
    overflow-x: hidden !important;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    position: relative;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

h1, h2, h3, h4, h5, h6, .brand-font {
    font-family: var(--font-heading);
    font-weight: 700;
    letter-spacing: -0.02em;
    word-break: break-word;
    overflow-wrap: break-word;
}

p, .breadcrumb {
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Layout Wrapper */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    position: relative;
}

/* Sidebar */
.app-sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.08);
    max-width: 85vw;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-decoration: none;
    color: #ffffff;
}

.sidebar-brand img, .sidebar-brand .logo-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #4338ca, #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 1.2rem;
    box-shadow: 0 4px 12px rgba(67, 56, 202, 0.4);
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-brand-title {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.2;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-brand-subtitle {
    font-size: 0.72rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.sidebar-menu-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.sidebar-menu-wrapper::-webkit-scrollbar {
    width: 4px;
}

.sidebar-menu-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.menu-section-header {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: #64748b;
    padding: 0.75rem 0.75rem 0.25rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.65rem 0.85rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.88rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    margin-bottom: 2px;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    color: #64748b;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.sidebar-link:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.06);
}

.sidebar-link:hover i {
    color: #a5b4fc;
}

.sidebar-link.active {
    color: #ffffff;
    background: linear-gradient(135deg, #4338ca, #4f46e5);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(67, 56, 202, 0.35);
}

.sidebar-link.active i {
    color: #ffffff;
}

.sidebar-user-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: rgba(0, 0, 0, 0.15);
}

.sidebar-user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

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

.sidebar-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.72rem;
    color: #94a3b8;
    text-transform: capitalize;
}

/* Main Content Area */
.app-main {
    flex: 1 1 auto;
    margin-left: 260px;
    min-height: 100vh;
    min-width: 0 !important;
    max-width: calc(100% - 260px);
    width: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--body-bg);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden !important;
}

/* Page Main Body */
.app-main > main {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Zero padding fluid container safety */
.container-fluid.p-0 {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

/* Prevent negative row margins from expanding the page */
.container-fluid.p-0 > .row {
    margin-left: 0;
    margin-right: 0;
}

.container-fluid.p-0 > .row > [class*="col-"] {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

/* Topbar */
.app-topbar {
    height: 70px;
    background-color: var(--topbar-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Cards & Components */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    max-width: 100%;
    min-width: 0;
}

.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.35rem;
    font-weight: 600;
    max-width: 100%;
    box-sizing: border-box;
}

.card-body {
    padding: 1.35rem;
    max-width: 100%;
    box-sizing: border-box;
}

/* KPI Stat Cards */
.stat-card {
    border-radius: var(--radius-md);
    position: relative;
    border: 1px solid var(--border-color);
    background: #ffffff;
    padding: 1.35rem;
    max-width: 100%;
    min-width: 0;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

/* Buttons */
.btn {
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: 0.55rem 1.1rem;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 2px 4px rgba(67, 56, 202, 0.2);
}

.btn-primary:hover, .btn-primary:focus {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: 0 4px 8px rgba(67, 56, 202, 0.3);
}

/* Touch Friendly Mobile Targets */
@media (max-width: 991.98px) {
    .btn {
        min-height: 40px;
        padding: 0.5rem 1rem;
    }
}

/* Tables & Touch-Friendly Horizontal Scrolling */
.table-responsive {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: #ffffff;
    margin-bottom: 0;
    position: relative;
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.table-responsive > .table {
    margin-bottom: 0;
    width: 100%;
}

@media (max-width: 991.98px) {
    .table-responsive > .table:not(.table-sm):not(.table-compact) {
        min-width: 620px;
    }
}

.table {
    margin-bottom: 0;
}

.table th {
    background-color: #f8fafc;
    color: #475569;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.88rem;
}

/* DataTables Responsive Mobile Containment */
.dataTables_wrapper {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
}

.dataTables_wrapper .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
    align-items: center;
}

@media (max-width: 767.98px) {
    div.dataTables_wrapper div.dataTables_length,
    div.dataTables_wrapper div.dataTables_filter,
    div.dataTables_wrapper div.dataTables_info,
    div.dataTables_wrapper div.dataTables_paginate {
        text-align: left !important;
        margin-bottom: 0.5rem;
    }
    div.dataTables_wrapper div.dataTables_filter input {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
    }
    div.dataTables_wrapper div.dataTables_paginate ul.pagination {
        justify-content: flex-start !important;
        flex-wrap: wrap !important;
        gap: 2px;
    }
}

/* QR Code Scanner Interface */
.scanner-container {
    max-width: 540px;
    width: 100%;
    margin: 0 auto;
    border-radius: var(--radius-lg);
    background: #000;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
}

#reader {
    width: 100% !important;
    border: none !important;
}

#reader video {
    width: 100% !important;
    height: auto !important;
    object-fit: cover !important;
}

#reader__scan_region {
    background: transparent !important;
}

#reader__camera_selection {
    max-width: 100%;
    margin-bottom: 10px;
}

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    z-index: 1045;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
    justify-content: space-around;
    align-items: center;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #64748b;
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    flex: 1;
    height: 100%;
    padding-top: 4px;
}

.mobile-nav-item i {
    font-size: 1.15rem;
    margin-bottom: 2px;
}

.mobile-nav-item.active {
    color: var(--primary);
}

body.teacher-portal .mobile-nav-item.active {
    color: var(--success);
}

/* Floating Center QR Action in Mobile Nav */
.mobile-nav-qr {
    position: relative;
    top: -12px;
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, #4338ca, #6366f1);
    color: #ffffff !important;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(67, 56, 202, 0.45);
    border: 3px solid #ffffff;
    flex-shrink: 0;
}

body.teacher-portal .mobile-nav-qr {
    background: linear-gradient(135deg, #059669, #10b981);
    box-shadow: 0 6px 16px rgba(5, 150, 105, 0.45);
}

.mobile-nav-qr i {
    font-size: 1.4rem;
    margin: 0;
}

/* Mobile Breakpoints (< 992px) */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

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

    .app-main {
        margin-left: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        padding-bottom: 74px;
        overflow-x: hidden !important;
    }

    .mobile-bottom-nav {
        display: flex;
    }

    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(15, 23, 42, 0.6);
        backdrop-filter: blur(2px);
        z-index: 1035;
        display: none;
    }

    .sidebar-backdrop.show {
        display: block;
    }
}

/* Small Screen Mobile Devices (< 768px) */
@media (max-width: 767.98px) {
    .app-topbar {
        height: 58px;
        padding: 0 0.85rem;
    }

    .app-main > main {
        padding: 0.85rem !important;
    }

    .card-body {
        padding: 1rem !important;
    }

    .card-header {
        padding: 0.85rem 1rem !important;
    }

    .stat-card {
        padding: 0.9rem !important;
    }

    .stat-icon {
        width: 38px !important;
        height: 38px !important;
        font-size: 1.1rem !important;
    }

    /* Prevent iOS Safari auto-zoom on input focus */
    .form-control,
    .form-select,
    .input-group input,
    .select2-container .select2-selection--single,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="search"] {
        font-size: 16px !important;
    }

    .modal-dialog {
        margin: 0.5rem auto !important;
        max-width: calc(100% - 1rem) !important;
    }

    /* Stack filter actions nicely */
    .filter-actions {
        width: 100%;
        margin-top: 0.5rem;
    }
}

/* Landscape / Horizontal Mobile Orientation (< 520px height) */
@media (max-height: 520px) and (orientation: landscape) {
    .app-topbar {
        height: 48px !important;
        padding: 0 0.85rem !important;
    }

    .mobile-bottom-nav {
        height: 46px !important;
    }

    .mobile-nav-item i {
        font-size: 0.95rem !important;
        margin-bottom: 1px !important;
    }

    .mobile-nav-item span {
        font-size: 0.6rem !important;
    }

    .mobile-nav-qr {
        width: 40px !important;
        height: 40px !important;
        top: -6px !important;
    }

    .mobile-nav-qr i {
        font-size: 1.1rem !important;
    }

    .app-main {
        padding-bottom: 54px !important;
    }

    .app-main > main {
        padding: 0.65rem 0.85rem !important;
    }

    .stat-card {
        padding: 0.75rem !important;
    }

    .sidebar-brand {
        padding: 0.75rem 1rem !important;
    }
}

/* Student ID Card Printable Design */
.student-id-card {
    width: 340px;
    height: 530px;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
    border: 1px solid #cbd5e1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    page-break-inside: avoid;
}

.id-card-header {
    background: linear-gradient(135deg, #1e1b4b, #312e81, #4338ca);
    color: #ffffff;
    padding: 1.25rem 1rem 1rem;
    text-align: center;
    position: relative;
}

.id-card-photo-wrapper {
    position: relative;
    margin-top: -30px;
    display: flex;
    justify-content: center;
}

.id-card-photo {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid #ffffff;
    object-fit: cover;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.id-card-qr-box {
    background: #ffffff;
    padding: 8px;
    border-radius: 10px;
    border: 1px dashed #cbd5e1;
    display: inline-block;
}

@media print {
    body * {
        visibility: hidden;
    }
    .printable-area, .printable-area * {
        visibility: visible;
    }
    .printable-area {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
    .no-print {
        display: none !important;
    }
}
