/* ==========================================================================
   GLOBAL RESET & BOX SIZING
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    margin: 0;
    padding: 0;
    font-size: 100%;                          /* ← use browser default (16px) */
    -webkit-text-size-adjust: 100%;           /* iOS: prevent font zoom */
    -webkit-tap-highlight-color: transparent; /* iOS: remove gray tap flash */
    text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-size: 1rem;                          /* ← explicitly 16px */
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    overflow-x: hidden;
    overscroll-behavior-y: none;              /* prevent iOS rubber band */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}


/* ==========================================================================
   0. LOGIN PAGE (centered card with glass effect)
   ========================================================================== */
.login-container {
    min-height: 100vh;
    min-height: 100dvh;                       /* modern browsers (iOS 15+) */
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: url('../images/library-background.jpg') no-repeat center center fixed;
    background-size: cover;
    -webkit-background-size: cover;           /* iOS 14 and older */
}

.login-card {
    background: rgba(255, 255, 255, 0.5) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 420px;                         /* stops wide-screen stretch */
    color: black;
}

.login-card .form-control {
    background: rgba(255, 255, 255, 0.5) !important;
    color: #000 !important;
    border: 1px solid rgba(0, 0, 0, 0.2);
    min-height: 44px;                         /* iOS tap target */
}

.login-card .card-header {
    background: transparent !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: black;
}


/* ==========================================================================
   1. SIDEBAR (fixed, dark, 250px wide)
   ========================================================================== */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    padding: 0;
    width: 250px;                             /* ← fixed width */
    box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.1);
    background-color: #1e2225;
    transition: all 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;        /* smooth scroll on iOS */
    height: 100vh;
}

.sidebar-heading {
    font-size: 0.875rem;
    text-transform: uppercase;
    padding: 1rem;
    color: #999;
}

.sidebar .nav-item {
    transition: all 0.3s ease-in-out;
    padding-left: 0;
    border-left: 4px solid transparent;
    margin: 0;
}

.sidebar .nav-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-left: 4px solid #8860d0;
}

.sidebar .nav-link {
    font-weight: 500;
    color: #fff;
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    min-height: 44px;                         /* iOS tap target */
}

.sidebar .nav-link i {
    margin-right: 0.5rem;
    min-width: 18px;
    text-align: center;
}

.sidebar .nav-link.active {
    color: #000;
    background-color: #fff;
    border-left: 4px solid #8860d0;
}

/* Nested sidebar items (submenus) */
.sidebar .collapse .nav-link,
.sidebar .submenu .nav-link {
    padding-left: 2.5rem;
    font-size: 0.85rem;
    opacity: 0.9;
}


/* ==========================================================================
   2. MAIN CONTENT (fills the right side, matches sidebar width)
   ========================================================================== */
main {
    margin-left: 250px;                       /* ← matches sidebar width */
    width: calc(100% - 250px);                /* ← fills remaining space */
    min-height: 100vh;
    min-height: 100dvh;                       /* iOS dynamic viewport */
    padding: 1rem 1.5rem 70px 1.5rem;         /* ← bottom 70px for footer */
    transition: all 0.3s ease;
    background-color: #f5f6fa;
}

main .page-header,
main .sticky-navbar {
    margin: -1rem -1.5rem 1rem -1.5rem;
    padding: 1rem 1.5rem;
    background-color: #fff;
    border-bottom: 1px solid #e5e5e5;
}

/* NOTE: main::after removed — footer now handles bottom spacing */


/* ==========================================================================
   3. TABLET (≤ 992px): slightly narrower sidebar
   ========================================================================== */
@media (max-width: 992px) {
    .sidebar { width: 220px; }
    main {
        margin-left: 220px;
        width: calc(100% - 220px);
        padding: 1rem 1rem 70px 1rem;
    }
}


/* ==========================================================================
   4. MOBILE (≤ 768px): icon-only sidebar, compact layout
   ========================================================================== */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
        padding-top: 60px;
    }
    .sidebar .nav-link {
        justify-content: center;
        padding: 0.75rem 0;
        font-size: 1rem;
    }
    .sidebar .nav-link i {
        margin-right: 0;
        font-size: 1.15rem;
    }
    .sidebar .nav-link span {
        display: none;
    }
    .sidebar .nav-item.active,
    .sidebar .nav-link.active {
        border-left-width: 3px;
    }

    main {
        margin-left: 60px !important;
        width: calc(100% - 60px) !important;
        padding: 0.75rem 0.75rem 70px 0.75rem;
    }

    main .page-header,
    main .sticky-navbar {
        margin: -0.75rem -0.75rem 0.75rem -0.75rem;
        padding: 0.75rem;
    }

    /* Cards and tables become full width */
    .card { border-radius: 0.5rem; }
    .table { font-size: 0.8rem; }
    .table th,
    .table td { padding: 0.4rem 0.35rem; }

    /* Buttons stay tappable */
    .btn { min-height: 40px; padding: 0.4rem 0.85rem; font-size: 0.85rem; }

    /* Summary boxes stack nicely */
    .row.mb-3 > [class*="col-"] { margin-bottom: 0.5rem; }
}

/* ==========================================================================
   5. SMALL PHONES (≤ 480px): even tighter
   ========================================================================== */
@media (max-width: 480px) {
    main {
        padding: 0.5rem 0.5rem 70px 0.5rem;
    }

    main .page-header,
    main .sticky-navbar {
        margin: -0.5rem -0.5rem 0.5rem -0.5rem;
        padding: 0.6rem;
    }

    h1, h2, h3, h4, h5 { font-size: 1rem; }
    .card-header h3,
    .card-header h4 { font-size: 0.95rem; }

    .table { font-size: 0.72rem; }
    .table th,
    .table td { padding: 0.3rem 0.25rem; }

    .btn { font-size: 0.78rem; padding: 0.35rem 0.7rem; }
}


/* ==========================================================================
   6. CARDS, BUTTONS, TABLES, FORMS
   ========================================================================== */
.card {
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    border-radius: 0.5rem;
    background-color: #ffffff;
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
    font-weight: 600;
}

.stats-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border: none;
    padding: 1.5rem;
    border-radius: 0.5rem;
}

.btn {
    border-radius: 0.375rem;
    font-weight: 500;
}

.btn-primary {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-primary:hover {
    background-color: #0b5ed7;
    border-color: #0a58ca;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 0;
}

.form-control,
.form-select {
    border-radius: 0.375rem;
    min-height: 44px;                          /* iOS tap target */
}


/* ==========================================================================
   7. FOOTER (fixed bottom-right corner, aligned with sidebar)
   ========================================================================== */

/* --- Legacy footer (kept for backward compatibility) --- */
.footer {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    background-color: #ffffff;
    color: #333333;
    border-top: 1px solid #dee2e6;
    padding: 6px 20px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    font-size: 0.8rem;
    z-index: 1000;
    text-align: right;
}

.footer .footer-credit {
    color: #0d6efd;
    font-weight: bold;
}

@media (max-width: 768px) {
    .footer {
        font-size: 0.72rem;
        text-align: center;
        padding: 5px 10px;
        padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px));
    }
}

/* --- Main footer: FIXED bottom-right, aligned to sidebar width --- */
.main-footer {
    position: fixed;                          /* ← always visible */
    bottom: 0;
    right: 0;
    left: 250px;                              /* ← matches sidebar width */
    z-index: 998;                             /* ← below sidebar (1040) */
    background-color: #ffffff;
    color: #6c757d;
    border-top: 1px solid #e0e0e0;
    padding: 8px 25px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    font-size: 13px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    text-align: right;
    white-space: nowrap;
    transition: left 0.3s ease;
}

.main-footer .footer-credit {
    color: #6c757d;
    line-height: 1.4;
}

.main-footer .footer-credit a {
    text-decoration: none;
    color: inherit;
}

.main-footer .footer-credit strong {
    color: #4a148c;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.main-footer .footer-credit a:hover strong {
    color: #6a1b9a;
    text-decoration: underline;
}

/* Dark mode */
body.dark-mode .main-footer {
    background-color: var(--card-dark) !important;
    color: #9e9e9e !important;
    border-top-color: var(--border-dark) !important;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

body.dark-mode .main-footer .footer-credit {
    color: #9e9e9e;
}

body.dark-mode .main-footer .footer-credit strong {
    color: #b39ddb;
}

body.dark-mode .main-footer .footer-credit a:hover strong {
    color: #d1c4e9;
}

/* Tablet (sidebar = 220px) */
@media (max-width: 992px) {
    .main-footer { left: 220px; }
}

/* Mobile (sidebar = 60px) */
@media (max-width: 768px) {
    .main-footer {
        left: 60px;
        font-size: 11px;
        padding: 6px 12px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
        text-align: center;
        white-space: normal;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .main-footer {
        font-size: 9px;
        padding: 5px 10px;
        padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px));
    }
}


/* ==========================================================================
   8. DARK MODE THEME
   ========================================================================== */
:root {
    --bg-dark: #121212;
    --card-dark: #1e1e1e;
    --border-dark: #2d2d2d;
    --text-dark: #f0f0f0;
}

body.dark-mode {
    background-color: var(--bg-dark) !important;
    color: var(--text-dark) !important;
}

body.dark-mode main {
    background-color: var(--bg-dark) !important;
    color: var(--text-dark) !important;
}

body.dark-mode .card,
body.dark-mode .card-header {
    background-color: var(--card-dark) !important;
    border-color: var(--border-dark) !important;
    color: var(--text-dark) !important;
}

body.dark-mode .sidebar {
    background-color: var(--card-dark) !important;
}

body.dark-mode .table,
body.dark-mode .form-control,
body.dark-mode .form-select {
    background-color: #1a1a1a !important;
    color: var(--text-dark) !important;
    border-color: var(--border-dark) !important;
}

body.dark-mode .footer {
    background-color: var(--card-dark) !important;
    color: var(--text-dark) !important;
    border-top-color: var(--border-dark) !important;
}

body.dark-mode main .page-header,
body.dark-mode main .sticky-navbar {
    background-color: var(--card-dark) !important;
    border-bottom-color: var(--border-dark) !important;
}

/* Exceptions that stay light in dark mode */
.recent-issued-card,
.recent-issued-table {
    background-color: #ffffff !important;
    color: #000000 !important;
}

body.dark-mode .recent-issued-card,
body.dark-mode .recent-issued-table {
    background-color: #1e1e1e !important;
    color: #f0f0f0 !important;
}