/* Modern, Professional Mobile-First Design System */
:root {
    /* Premium Petrol & Amber Theme */
    --primary-color: #083344;
    --primary-light: #0e7490;
    --primary-dark: #020617;
    --secondary-color: #f59e0b;
    --secondary-light: #fbbf24;
    --accent-color: #6366f1;

    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.7);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --border-color: #e2e8f0;
    --border-glass: rgba(255, 255, 255, 0.2);

    --danger-color: #ef4444;
    --success-color: #10b981;

    /* Map colors - Refined */
    --c-fiction: #10b981;
    --c-nonfiction: #f59e0b;
    --c-science: #0ea5e9;
    --c-history: #8b5cf6;
    --c-children: #f43f5e;

    /* Spacing & Effects */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --glass-blur: blur(12px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Native feel selection control */
.app-header, 
.bottom-nav, 
.nav-item, 
.header-action, 
.view-title,
button,
label {
    -webkit-user-select: none;
    user-select: none;
}

/* Allow selection in content areas */
.book-card, 
.detail-content, 
.membership-status,
input, 
textarea {
    -webkit-user-select: text;
    user-select: text;
}

/* Fix iOS automatically turning phone numbers into blue links */
a[href^="tel:"], 
a[href^="sms:"], 
a[x-apple-data-detectors] {
    color: inherit !important;
    text-decoration: none !important;
    font-size: inherit !important;
    font-family: inherit !important;
    font-weight: inherit !important;
    line-height: inherit !important;
}

body {
    font-family: 'Outfit', 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    height: 100vh;
    /* iOS friendly full height */
    min-height: -webkit-fill-available;
    height: 100dvh;
    overflow: hidden;
}

/* Glassmorphism Utility */
.glass {
    background: var(--surface-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-glass);
}

/* App Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: env(safe-area-inset-top) 16px 0 16px;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    grid-template-rows: 64px;
    align-items: center;
    gap: 8px;
    height: calc(64px + env(safe-area-inset-top));
    box-shadow: 0 1px 10px rgba(0, 0, 0, 0.05);
    z-index: 2000;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.header-action {
    background: #f1f5f9;
    border: 1.5px solid rgba(0, 0, 0, 0.06);
    color: var(--primary-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2;
    flex-shrink: 0;
}

.header-action:hover {
    background: rgba(14, 116, 144, 0.1);
    border-color: var(--primary-light);
    transform: translateY(-1px) scale(1.05);
}

.header-action:active {
    transform: scale(0.88);
    background: rgba(14, 116, 144, 0.18);
}

.app-title {
    flex: 1;
    text-align: center;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 1px;
    color: var(--primary-color);
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Outfit', sans-serif;
}

/* Main Content Area */
main {
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    /* Move padding to .view so scroll containers handle their own clearance */
    padding-top: 0;
    padding-bottom: 0;
}

/* Views Management */
.view {
    display: none;
    padding: calc(64px + 12px + env(safe-area-inset-top)) 20px calc(100px + 24px + env(safe-area-inset-bottom)) 20px;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    /* iOS native smooth scrolling */
    -webkit-overflow-scrolling: touch;
}

.view.active-view {
    display: block;
}

/* Welcome view needs flex to center hero content */
#welcome-view.active-view {
    display: flex;
    flex-direction: column;
}


@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Loading States */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(8, 51, 68, 0.1);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    left: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: space-around;
    padding: 10px 8px;
    border-radius: 28px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.nav-item {
    position: relative;
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 16px;
    min-width: 70px;
}

.nav-item.active {
    color: var(--primary-color);
    background: rgba(8, 51, 68, 0.08);
}

.nav-icon {
    font-size: 24px;
    margin-bottom: 4px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.nav-item:active .nav-icon {
    transform: scale(1.1) translateY(-2px);
}

.nav-item:active {
    background: rgba(8, 51, 68, 0.15);
}

.view-title {
    display: none;
    /* Hide redundant title as it's now in the header */
}

/* Maps and generic layouts */
.library-map-wrapper {
    background: var(--surface-color);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.library-map {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.map-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.map-shelf {
    flex: 1;
    height: 100px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.map-shelf:active {
    transform: scale(0.95);
}

.bg-fiction {
    background: linear-gradient(135deg, var(--c-fiction), #059669);
}

.bg-nonfiction {
    background: linear-gradient(135deg, var(--c-nonfiction), #d97706);
}

.bg-science {
    background: linear-gradient(135deg, var(--c-science), #0284c7);
}

.bg-history {
    background: linear-gradient(135deg, var(--c-history), #7c3aed);
}

.bg-children {
    background: linear-gradient(135deg, var(--c-children), #e11d48);
}

.map-aisle {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 4px;
    background: repeating-linear-gradient(45deg, transparent, transparent 20px, rgba(0, 0, 0, 0.01) 20px, rgba(0, 0, 0, 0.02) 40px);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
}

.map-entrance {
    text-align: center;
    padding-top: 32px;
    font-weight: 800;
    font-size: 13px;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 2px;
    border-top: 2px dashed var(--border-color);
    margin-top: 16px;
}

/* ── App Footer (Professional) ───────────────────── */
.app-footer {
    background: #083344;
    margin-top: 48px;
    width: 100%;
}

.footer-container {
    max-width: 1100px;
    margin: 0 auto;
}

/* ── Top section: brand ── */
.footer-brand {
    padding: 36px 20px 28px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-align: center;
}

.footer-brand .footer-logo {
    font-size: 14px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 4px;
    color: #ffffff;
    display: block;
    margin-bottom: 10px;
}

.footer-brand .footer-tagline {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.7;
    margin-bottom: 20px;
    font-weight: 400;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

/* Social icons */
.footer-socials {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.footer-socials a {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.7);
    transition: all 0.25s ease;
    text-decoration: none;
}

.footer-socials a:hover {
    background: var(--primary-light);
    border-color: var(--primary-light);
    color: white;
    transform: translateY(-2px);
}

/* GitHub open-source pill badge (Specific override) */
.footer-socials a.footer-github-link {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    padding: 10px 22px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 50px !important;
    color: #ffffff !important;
    text-decoration: none !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    letter-spacing: 0.5px !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    white-space: nowrap !important;
    width: auto !important;
    height: auto !important;
    min-width: unset !important;
}

.footer-socials a.footer-github-link svg,
.footer-socials a.footer-github-link i {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    display: block !important;
    margin: 0 !important;
    color: #ffffff !important;
}

.footer-github-link:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--primary-light);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}


/* ── Middle section: links + contact side by side ── */
.footer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    margin-bottom: 0;
}

/* On mobile, stack columns to prevent long email from breaking layout, and left-align for a cleaner look */
@media (max-width: 768px) {
    .footer-grid {
        grid-template-columns: 1fr;
    }

    .footer-brand {
        text-align: left;
    }

    .footer-brand .footer-tagline {
        margin-left: 0;
        margin-right: 0;
    }

    .footer-socials {
        justify-content: flex-start;
    }

    .footer-links {
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        text-align: left;
    }

    .footer-links ul {
        align-items: flex-start;
    }

    .footer-contact {
        text-align: left;
    }

    .footer-contact p {
        justify-content: flex-start;
        word-break: break-word;
        text-align: left;
    }
}

/* Brand spans full width */
.footer-brand {
    grid-column: 1 / -1;
}

.footer-links,
.footer-contact {
    padding: 28px 20px;
}

.footer-links {
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.footer-col h4 {
    font-size: 9px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    color: var(--primary-light);
    margin-bottom: 14px;
}

.footer-links ul {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.footer-links a {
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 13px;
    font-weight: 400;
    transition: all 0.2s;
    line-height: 1;
}

.footer-links a:hover {
    color: #ffffff;
    padding-left: 4px;
}

.footer-contact p {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.65);
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
    line-height: 1.6;
    word-break: break-word;
    /* Ensure long emails don't overflow */
    overflow-wrap: break-word;
}

.footer-contact p:last-child {
    font-size: 12px;
    /* Slightly smaller for long emails if needed */
}

.footer-contact i,
.footer-contact svg {
    color: var(--primary-light);
    width: 13px;
    height: 13px;
    margin-top: 3px;
    flex-shrink: 0;
    opacity: 0.8;
}

/* ── Divider ── */
.footer-divider {
    width: 100%;
    height: 1px;
    background: rgba(255, 255, 255, 0.07);
    margin: 0;
}

/* ── Bottom bar ── */
.footer-bottom {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    text-align: center;
    padding: 16px 20px;
}

.footer-copy {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.35);
    font-weight: 400;
}

.footer-credits {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.25);
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1.7;
}

.footer-credits strong {
    color: rgba(255, 255, 255, 0.45);
    font-weight: 700;
}


/* Print Styling for Membership Cards */
@media print {
    @page {
        margin: 0;
        /* Important: Hides default browser header/footer date and URLs */
    }

    body {
        margin: 0;
        /* Reset body margin for print */
    }

    body * {
        visibility: hidden;
    }

    #printable-card-area,
    #printable-card-area * {
        visibility: visible;
    }

    #printable-card-area {
        position: absolute !important;
        left: 0;
        top: 0;
        width: 100%;
        display: flex !important;
        justify-content: center;
        align-items: center;
        padding-top: 50px;
    }

    .print-card {
        width: 350px;
        height: 220px;
        background: white !important;
        color: black !important;
        border: 2px solid #083344 !important;
        border-radius: 16px;
        padding: 24px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        box-shadow: none !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        font-family: 'Outfit', sans-serif;
    }

    .print-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        border-bottom: 2px solid #f1f5f9;
        padding-bottom: 12px;
    }

    .print-card h2 {
        color: #083344 !important;
        margin: 0;
        font-size: 20px;
        font-weight: 800;
    }

    .print-card p {
        margin: 2px 0;
        font-size: 13px;
        color: #475569;
        font-weight: 500;
    }

    .print-barcode-container {
        background: white !important;
        padding: 8px;
        border: 1px solid #f1f5f9;
        text-align: center;
        margin-top: 16px;
    }

    .print-barcode-container svg {
        max-width: 100%;
        height: auto;
    }

    .print-card-footer {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        margin-top: 12px;
        font-size: 10px;
        color: #94a3b8;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 1px;
    }
}

#printable-card-area {
    display: none;
}

/* Base Footer Reset (Mobile) */
.footer-nav {
    display: none;
    /* Hide new navigation links on mobile per user request */
}

/* Structural resets — footer-grid must remain grid, not block */
.footer-col,
.footer-brand,
.footer-info,
.footer-base {
    width: 100%;
}

/* ── Network Monitor Banner ── */
.network-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5000; /* Above header and modals */
    transform: translateY(-100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.network-banner.active {
    transform: translateY(0);
}

.network-banner-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
    font-size: 14px;
    font-weight: 700;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.banner-offline {
    background: var(--danger-color);
}

.banner-weak {
    background: var(--secondary-color);
}

.network-icon {
    display: flex;
    align-items: center;
}

.network-icon svg {
    width: 18px;
    height: 18px;
}

.network-subtext {
    font-size: 11px;
    opacity: 0.8;
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 500;
}

@media (max-width: 480px) {
    .network-subtext {
        display: none;
    }
}