/* ==========================================================================
   School Library Management System (SLMS) - Premium Modern Stylesheet
   Theme: Professional Blue & Clean White with Dark Mode Support
   ========================================================================== */

:root {
    --primary-color: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-subtle: #eff6ff;
    --secondary-color: #475569;
    --accent-color: #0284c7;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #06b6d4;
    
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-card-subtle: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --sidebar-width: 260px;
    --sidebar-mini-width: 72px;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active-bg: #1d4ed8;
    --sidebar-active-text: #ffffff;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-bs-theme="dark"] {
    --bg-body: #0b1120;
    --bg-card: #1e293b;
    --bg-card-subtle: #182234;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --primary-subtle: #1e293b;
    --sidebar-bg: #0b1120;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Base resets & typography */
body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition-fast);
}

a:hover {
    color: var(--primary-hover);
}

/* --------------------------------------------------------------------------
   App Layout: Sidebar & Main Wrapper
   -------------------------------------------------------------------------- */
#app-wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    flex-shrink: 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid rgba(255,255,255,0.06);
}

#sidebar::-webkit-scrollbar {
    width: 5px;
}
#sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
}

#sidebar .brand-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    transition: padding 0.2s ease;
}

#sidebar .brand-header .brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

#sidebar .nav-section-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    font-weight: 700;
    color: #64748b;
    letter-spacing: 0.08em;
    padding: 16px 20px 6px 20px;
    white-space: nowrap;
    transition: all 0.2s ease;
}

#sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 18px;
    color: var(--sidebar-text);
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 6px;
    margin: 2px 10px;
    transition: var(--transition-fast);
    white-space: nowrap;
}

#sidebar .nav-link i {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

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

#sidebar .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.35);
}

#main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    transition: margin-left 0.3s ease-in-out;
}

/* --------------------------------------------------------------------------
   Top Navbar
   -------------------------------------------------------------------------- */
#top-navbar {
    height: 64px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.user-profile-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px;
    border-radius: 50px;
    background: var(--bg-card-subtle);
    cursor: pointer;
    border: 1px solid var(--border-color);
}

.avatar-img {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    background: #cbd5e1;
}

.avatar-initial {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

/* --------------------------------------------------------------------------
   Page Container & Cards
   -------------------------------------------------------------------------- */
.page-container {
    padding: 24px;
    flex-grow: 1;
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* --------------------------------------------------------------------------
   KPI Stat Counter Cards
   -------------------------------------------------------------------------- */
.kpi-card {
    border-radius: 14px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition-fast);
}

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

.kpi-icon-wrapper {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.kpi-blue { background: rgba(29, 78, 216, 0.12); color: #1d4ed8; }
.kpi-green { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.kpi-amber { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.kpi-red { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.kpi-purple { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }
.kpi-cyan { background: rgba(6, 182, 212, 0.12); color: #06b6d4; }

.kpi-value {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.kpi-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* --------------------------------------------------------------------------
   Tables & Data Presentation
   -------------------------------------------------------------------------- */
.table {
    color: var(--text-primary);
    vertical-align: middle;
}

.table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    background: var(--bg-card-subtle);
    padding: 12px 16px;
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.88rem;
}

.table-hover tbody tr:hover {
    background-color: var(--bg-card-subtle);
}

.badge-pill {
    padding: 5px 10px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.74rem;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* --------------------------------------------------------------------------
   Buttons & Form Controls
   -------------------------------------------------------------------------- */
.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    font-weight: 500;
    border-radius: 8px;
    padding: 8px 16px;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

.form-control, .form-select {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-card);
    border-color: var(--primary-color);
    color: var(--text-primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

.form-label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

/* --------------------------------------------------------------------------
   Barcode & QR Code Printing Sheet
   -------------------------------------------------------------------------- */
.barcode-card {
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 14px;
    text-align: center;
    background: #ffffff;
    color: #0f172a;
}

.barcode-canvas, .qr-canvas {
    max-width: 100%;
    height: auto;
}

/* --------------------------------------------------------------------------
   Receipt Styling (A5 Standard Format: 148mm x 210mm)
   -------------------------------------------------------------------------- */
.receipt-box {
    width: 148mm;
    max-width: 100%;
    min-height: 205mm;
    margin: 20px auto;
    background: #ffffff;
    color: #0f172a;
    padding: 14mm 12mm 12mm 12mm;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    position: relative;
    display: flex;
    flex-direction: column;
}

.receipt-header {
    text-align: center;
    border-bottom: 2px dashed #cbd5e1;
    padding-bottom: 12px;
    margin-bottom: 14px;
}

.receipt-footer {
    text-align: center;
    border-top: 1.5px dashed #cbd5e1;
    padding-top: 10px;
    margin-top: auto;
    font-size: 0.74rem;
    color: #64748b;
}

/* Print Rules specifically tailored for A5 paper (148mm x 210mm) */
@page {
    size: A5 portrait;
    margin: 6mm 8mm 6mm 8mm;
}

@media print {
    html, body {
        width: 148mm !important;
        max-width: 148mm !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        color: #000000 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    #app-wrapper, #main-content, .page-container {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        display: block !important;
    }
    #sidebar, #top-navbar, .no-print, .btn, .pagination, .toast-container {
        display: none !important;
    }
    .receipt-box {
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        height: auto !important;
        margin: 0 auto !important;
        padding: 4mm 5mm !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }
    .card {
        border: 1px solid #cbd5e1 !important;
        box-shadow: none !important;
    }
    .table-sm > :not(caption) > * > * {
        padding: 0.2rem 0.3rem !important;
    }
}

/* --------------------------------------------------------------------------
   Mini / Icon-Only Sidebar: Manual Toggle & Half-Screen Responsive
   -------------------------------------------------------------------------- */

/* 1. Desktop Manual Icon-Only Mode (via body.sidebar-mini) */
body.sidebar-mini #sidebar {
    width: var(--sidebar-mini-width) !important;
}
body.sidebar-mini #sidebar .brand-header {
    padding: 0 !important;
    justify-content: center !important;
}
body.sidebar-mini #sidebar .brand-header .brand-title {
    justify-content: center !important;
    gap: 0 !important;
}
body.sidebar-mini #sidebar .brand-header .brand-title .brand-text {
    display: none !important;
}
body.sidebar-mini #sidebar .nav-section-title {
    font-size: 0 !important;
    height: 1px !important;
    line-height: 0 !important;
    padding: 0 !important;
    margin: 12px 14px !important;
    background: rgba(255, 255, 255, 0.1) !important;
    overflow: hidden !important;
}
body.sidebar-mini #sidebar .nav-link {
    justify-content: center !important;
    padding: 10px 0 !important;
    margin: 4px 10px !important;
    border-radius: 8px !important;
    gap: 0 !important;
}
body.sidebar-mini #sidebar .nav-link span {
    display: none !important;
}
body.sidebar-mini #sidebar .nav-link i {
    font-size: 1.25rem !important;
    margin: 0 !important;
    width: auto !important;
    text-align: center !important;
}
body.sidebar-mini #main-content {
    margin-left: var(--sidebar-mini-width) !important;
}

/* 2. Half-Screen & Tablet Responsive Mode (576px to 1200px)
      Automatically collapses sidebar into icon-only mode on half-screen or tablet */
@media (min-width: 576px) and (max-width: 1200px) {
    body:not(.sidebar-expanded) #sidebar {
        width: var(--sidebar-mini-width) !important;
        transform: translateX(0) !important;
    }
    body:not(.sidebar-expanded) #sidebar .brand-header {
        padding: 0 !important;
        justify-content: center !important;
    }
    body:not(.sidebar-expanded) #sidebar .brand-header .brand-title {
        justify-content: center !important;
        gap: 0 !important;
    }
    body:not(.sidebar-expanded) #sidebar .brand-header .brand-title .brand-text {
        display: none !important;
    }
    body:not(.sidebar-expanded) #sidebar .nav-section-title {
        font-size: 0 !important;
        height: 1px !important;
        line-height: 0 !important;
        padding: 0 !important;
        margin: 12px 14px !important;
        background: rgba(255, 255, 255, 0.1) !important;
        overflow: hidden !important;
    }
    body:not(.sidebar-expanded) #sidebar .nav-link {
        justify-content: center !important;
        padding: 10px 0 !important;
        margin: 4px 10px !important;
        border-radius: 8px !important;
        gap: 0 !important;
    }
    body:not(.sidebar-expanded) #sidebar .nav-link span {
        display: none !important;
    }
    body:not(.sidebar-expanded) #sidebar .nav-link i {
        font-size: 1.25rem !important;
        margin: 0 !important;
        width: auto !important;
        text-align: center !important;
    }
    body:not(.sidebar-expanded) #main-content {
        margin-left: var(--sidebar-mini-width) !important;
    }

    /* Flyout / expanded mode when user toggles sidebar on half-screen */
    body.sidebar-expanded #sidebar {
        width: var(--sidebar-width) !important;
        z-index: 1050 !important;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.5) !important;
    }
    body.sidebar-expanded #main-content {
        margin-left: var(--sidebar-mini-width) !important;
    }
}

/* 3. Small Mobile Devices (< 576px): Slide-in Offcanvas */
@media (max-width: 575.98px) {
    #sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        box-shadow: none;
    }
    #sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 35px rgba(0, 0, 0, 0.65);
    }
    #main-content {
        margin-left: 0 !important;
    }
}
