/**
 * Palavi Library - User Panel Layout
 * ------------------------------------------------------------------
 * Built in: Module 6 (User Dashboard). Visually redesigned as part of
 * a full UI/UX overhaul - see assets/css/glass.css for the shared
 * design tokens this file builds on. Class names are unchanged so
 * every user/*.php page picks up the new look automatically.
 * ------------------------------------------------------------------
 * Mobile-app-style layout for the member-facing area: desktop sidebar
 * + a floating pill bottom navigation on mobile, book cards, progress
 * bars, subscription banner, achievement badges.
 */

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.user-shell {
    display: flex;
    min-height: 100vh;
}

/* ---------------------------------------------------------------
   SIDEBAR (desktop)
   --------------------------------------------------------------- */
.user-sidebar {
    width: 250px;
    flex-shrink: 0;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    margin: 0;
    border-radius: 0;
    border-right: 1px solid var(--border-glass);
    border-top: none;
    border-bottom: none;
    border-left: none;
    box-shadow: none;
}

.user-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 20px;
}

.user-sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--brand-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    box-shadow: var(--shadow-glow);
}

.user-sidebar-brand .brand-name {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}

.user-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px 9px 18px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 3px;
    transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease, transform var(--duration-fast) ease;
}

.user-nav-link i {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    transition: transform var(--duration-fast) var(--ease-standard);
}

.user-nav-link:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
    transform: translateX(2px);
}

.user-nav-link:hover i {
    transform: scale(1.1);
}

.user-nav-link.active {
    background: var(--bg-glass-strong);
    color: var(--brand-primary);
    font-weight: 700;
}

.user-nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    border-radius: var(--radius-pill);
    background: var(--brand-gradient);
}

/* ---------------------------------------------------------------
   MAIN CONTENT + TOPBAR
   --------------------------------------------------------------- */
.user-main {
    flex: 1;
    min-width: 0;
    padding: 20px 24px 110px;
}

.user-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 20px;
    margin-bottom: 22px;
    /* Without its own stacking context + z-index, the profile dropdown
     * (which overflows below the topbar's own short height) gets
     * visually painted over by the next section (e.g. the subscription
     * banner) - a later DOM sibling always paints on top of an
     * unelevated stacking context, regardless of the dropdown's own
     * z-index:1000, since that only wins *within* this element's
     * context. admin-topbar already has this exact fix - see admin.css. */
    position: sticky;
    top: 12px;
    z-index: 20;
}

.user-greeting-title {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.01em;
}

.user-greeting-subtitle {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.user-topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-mobile-toggle {
    display: none;
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
    background: var(--bg-glass);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

/* Mobile-only brand mark on the left of the topbar - hidden on
   desktop/tablet (the sidebar's own logo already covers that), shown
   at phone widths where it replaces the hamburger's old left-hand
   spot (see the max-width: 575.98px block below, which moves the
   hamburger to the right instead). */
.user-topbar-logo {
    display: none;
    align-items: center;
}

.user-topbar-logo img {
    height: 28px;
    width: auto;
}

/* ---------------------------------------------------------------
   SUBSCRIPTION BANNER
   --------------------------------------------------------------- */
.subscription-banner {
    background: var(--brand-gradient);
    border-radius: var(--radius-xl);
    padding: 24px 28px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-glow);
    position: relative;
    overflow: hidden;
}

.subscription-banner::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 100% 0%, rgba(255, 255, 255, 0.22), transparent 55%);
    pointer-events: none;
}

.subscription-banner h5 { margin: 0 0 4px; font-weight: 700; }
.subscription-banner p { margin: 0; opacity: 0.92; font-size: 0.88rem; }

.subscription-banner.is-free {
    background: linear-gradient(135deg, #575c6e, #23252f);
}

.subscription-banner.is-suspended {
    background: linear-gradient(135deg, #F5A623, #d9791f);
}

/* ---------------------------------------------------------------
   SECTION HEADERS
   --------------------------------------------------------------- */
.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.01em;
}

.section-header a {
    font-size: 0.85rem;
    color: var(--brand-primary);
    text-decoration: none;
    font-weight: 600;
    transition: opacity var(--duration-fast) ease;
}

.section-header a:hover { opacity: 0.7; }

/* ---------------------------------------------------------------
   BOOK CARDS
   --------------------------------------------------------------- */
.book-scroll-row {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding: 4px 2px 14px;
    scrollbar-width: thin;
}

.book-card {
    flex-shrink: 0;
    width: 150px;
    text-decoration: none;
    color: inherit;
    transition: transform var(--duration-base) var(--ease-standard);
}

.book-card:hover {
    transform: translateY(-4px);
}

.book-cover-wrapper {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 2 / 3;
    background: var(--brand-gradient);
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--duration-base) ease;
}

/* Some older/budget Android WebView versions (common on cheaper phones
 * and tablets) don't support the aspect-ratio property above - without
 * it, this wrapper has no height at all (nothing else here sets one),
 * so the img's height:100% collapses to zero and the cover silently
 * disappears. The classic padding-top percentage trick works on every
 * browser ever shipped, so it's used here ONLY as a fallback for
 * exactly those devices - modern browsers keep using aspect-ratio
 * above and never see this block. */
@supports not (aspect-ratio: 1 / 1) {
    .book-cover-wrapper {
        height: 0;
        padding-top: 150%; /* 2:3 ratio, matches aspect-ratio: 2 / 3 */
    }

    .book-cover-wrapper img,
    .book-cover-wrapper .book-cover-fallback {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

.book-card:hover .book-cover-wrapper {
    box-shadow: var(--shadow-lg);
}

.book-cover-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--duration-slow) var(--ease-standard);
}

.book-card:hover .book-cover-wrapper img {
    transform: scale(1.06);
}

.book-cover-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #fff;
    font-size: 2rem;
}

.book-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: rgba(0, 0, 0, 0.25);
}

.book-progress-bar-fill {
    height: 100%;
    background: var(--brand-secondary);
}

.book-card-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-card-author {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.book-access-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.92);
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    box-shadow: var(--shadow-xs);
    backdrop-filter: blur(4px);
}

.book-access-badge.is-premium {
    background: var(--brand-gradient-warm);
    color: #fff;
}

/* Grid variant for library/search/favorites full listings */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
}

/* ---------------------------------------------------------------
   STAT CARDS
   --------------------------------------------------------------- */
.stat-card {
    padding: 18px;
    text-align: center;
    height: 100%;
}

.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #fff;
    margin: 0 auto 10px;
    box-shadow: var(--shadow-sm);
}

.stat-icon.bg-purple { background: linear-gradient(135deg, #6C5CE7, #a29bfe); }
.stat-icon.bg-teal   { background: linear-gradient(135deg, #00CEC9, #55efc4); }
.stat-icon.bg-orange { background: linear-gradient(135deg, #FDCB6E, #e17055); }
.stat-icon.bg-pink   { background: linear-gradient(135deg, #FD79A8, #e84393); }

.stat-value {
    font-size: 1.55rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* ---------------------------------------------------------------
   PROFILE CARD (user/profile.php)
   --------------------------------------------------------------- */
.profile-card {
    padding: 0 0 22px;
    overflow: hidden;
}

.profile-card-banner {
    height: 84px;
    background: var(--brand-gradient);
    margin-bottom: -48px;
}

.profile-card-body {
    padding: 0 20px;
}

.profile-avatar {
    width: 96px;
    height: 96px;
    font-size: 2rem;
    position: relative;
    border: 4px solid var(--bg-surface);
    box-shadow: var(--shadow-md);
}

.profile-mini-stats {
    display: flex;
    border-top: 1px solid var(--border-glass);
    margin: 0 -20px;
    padding: 14px 20px 0;
}

.profile-mini-stats > div {
    flex: 1;
    text-align: center;
}

.profile-mini-stats > div:first-child {
    border-right: 1px solid var(--border-glass);
}

.profile-mini-stat-value {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.profile-mini-stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------
   ACHIEVEMENT BADGES
   --------------------------------------------------------------- */
.achievement-badge {
    text-align: center;
    padding: 16px 10px;
    border-radius: var(--radius-lg);
    transition: transform var(--duration-base) var(--ease-standard);
}

.achievement-badge:hover { transform: translateY(-3px); }

.achievement-badge.locked { opacity: 0.4; filter: grayscale(1); }

.achievement-badge-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--brand-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.4rem;
    margin: 0 auto 8px;
    box-shadow: var(--shadow-sm);
}

.achievement-badge-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
}

.achievement-badge-desc {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------
   PROGRESS BARS (reading history / challenges)
   --------------------------------------------------------------- */
.progress-track {
    height: 8px;
    border-radius: var(--radius-pill);
    background: var(--bg-glass);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--brand-gradient);
    border-radius: var(--radius-pill);
    transition: width var(--duration-slow) var(--ease-standard);
}

/* Bottom navigation (mobile-only floating pill bar) now lives in
 * glass.css - shared with admin.css, see that file for why. */

/* ---------------------------------------------------------------
   MOBILE
   --------------------------------------------------------------- */
@media (max-width: 991.98px) {
    .user-sidebar { display: none; }
    .user-mobile-toggle { display: inline-flex; }
    .user-main { padding: 40px 12px 110px; }
}

/* Phones AND tablets (the whole range where the sidebar is hidden and
   the hamburger takes over - see the max-width: 991.98px block above):
   the topbar used to force the hamburger, greeting text, and icon row
   all onto ONE line, which squeezed the greeting into an awkward
   multi-line wrap on narrower screens. Give the icon row (toggle +
   actions) its own clean top line, and drop the greeting (title only,
   no subtitle) onto a second line below it instead. */
@media (max-width: 991.98px) {
    .user-topbar {
        flex-wrap: wrap;
        padding: 12px 14px;
    }

    .user-topbar-logo { display: flex; order: 1; }
    .user-topbar-actions { order: 2; margin-left: auto; gap: 6px; }
    .user-mobile-toggle { order: 3; }
    .topbar-help-icon { display: none; }

    /* Bigger brand mark, smaller action icons - keeps the row from
       feeling cramped now that it's carrying 5 icons plus the logo. */
    .user-topbar-logo img { height: 40px; }
    .user-topbar-actions .theme-toggle-btn,
    .user-topbar-actions .icon-btn,
    .user-mobile-toggle {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }
    .user-topbar .avatar-circle {
        width: 26px;
        height: 26px;
        font-size: 0.7rem;
    }
    .user-topbar .profile-btn {
        padding: 3px 8px 3px 3px;
        gap: 4px;
    }
    .user-topbar .count-badge {
        min-width: 13px;
        height: 13px;
        font-size: 0.6rem;
        top: 0;
        right: 0;
    }

    .user-greeting {
        order: 4;
        flex-basis: 100%;
    }
#allBooksTabs .book-grid {
	grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
}
    .user-greeting-title {
        font-size: 0.85rem;
        font-weight: 400;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-greeting-subtitle {
        display: none;
    }
}

/* ---------------------------------------------------------------
   MODAL - fade + scale (opt-in via .modal-scale-fade)
   ------------------------------------------------------------------
   Bootstrap's own .modal.fade only slides the dialog vertically -
   this overrides that with a scale+fade "pop in" instead, without
   touching every other modal in the app (e.g. readAgainModal) that
   still uses Bootstrap's default transition. .glass-card on
   .modal-content reuses the same translucent panel style as every
   other card in the app instead of Bootstrap's plain white/light
   default. */
.modal-scale-fade .modal-dialog {
    transform: scale(0.85);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease-out;
}

.modal-scale-fade.show .modal-dialog {
    transform: scale(1);
    opacity: 1;
}

/* ---------------------------------------------------------------
   HELP DESK FLOATING BUTTON - bottom-right corner, every user page
   (see user/includes/footer.php, assets/js/user/help-desk-fab.js).
   Positioned above .bottom-nav on mobile (that bar sits at
   bottom: calc(10px + safe-area) and is roughly 64px tall) so the
   two never overlap - see the max-width: 991.98px override below.
   ------------------------------------------------------------------ */
.help-desk-fab {
    position: fixed;
    right: 20px;
    bottom: calc(24px + env(safe-area-inset-bottom));
    z-index: 1035;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--brand-gradient);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: transform var(--duration-fast) var(--ease-standard);
}

.help-desk-fab:hover { transform: scale(1.06); }
.help-desk-fab:active { transform: scale(0.94); }

.help-desk-fab-menu {
    position: fixed;
    right: 20px;
    bottom: calc(90px + env(safe-area-inset-bottom));
    z-index: 1035;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 215px;
    padding: 10px;
    border-radius: var(--radius-lg);
    background: var(--bg-glass-strong);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity var(--duration-fast) ease, transform var(--duration-fast) ease, visibility var(--duration-fast);
}

.help-desk-fab-menu.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.help-desk-fab-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 500;
    transition: background-color var(--duration-fast) ease;
}

.help-desk-fab-menu-item:hover { background: var(--bg-glass); }
.help-desk-fab-menu-item i { font-size: 1rem; color: var(--brand-primary); width: 18px; text-align: center; }

@media (max-width: 991.98px) {
    .help-desk-fab {
        bottom: calc(92px + env(safe-area-inset-bottom));
        right: 16px;
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
    }

    .help-desk-fab-menu {
        bottom: calc(150px + env(safe-area-inset-bottom));
        right: 16px;
    }
}
