/* ═══════════════════════════════════════════════════════════════════════════════
   SPA Transitions, Skeleton Loading & Native Feel
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─── Page Container ─────────────────────────────────────────────────────────── */
#app {
    position: relative;
    min-height: calc(100vh - 60px);
    overflow-x: hidden;
}

.page-view {
    will-change: transform, opacity;
}

/* ─── iOS-style Page Transitions ─────────────────────────────────────────────── */
.page-enter {
    animation: pageSlideIn 0.32s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.page-exit {
    animation: pageSlideOut 0.28s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 0;
}

/* Back navigation - reverse direction */
.page-enter-back {
    animation: pageSlideInBack 0.32s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.page-exit-back {
    animation: pageSlideOutBack 0.28s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 0;
}

/* Forward: new page slides in from left (RTL) */
@keyframes pageSlideIn {
    from {
        opacity: 0;
        transform: translateX(-60px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pageSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(40px);
    }
}

/* Back: page slides in from right (RTL) */
@keyframes pageSlideInBack {
    from {
        opacity: 0;
        transform: translateX(60px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pageSlideOutBack {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-40px);
    }
}

/* Fade transition for modals/login */
.page-fade-in {
    animation: pageFadeIn 0.3s ease forwards;
}

@keyframes pageFadeIn {
    from { opacity: 0; transform: scale(0.97); }
    to { opacity: 1; transform: scale(1); }
}

/* ─── Skeleton Loading ───────────────────────────────────────────────────────── */
.skeleton {
    background: #e9ecef;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
}

.skeleton-text {
    height: 14px;
    margin-bottom: 10px;
    border-radius: 4px;
}

.skeleton-text.w-75 { width: 75%; }
.skeleton-text.w-50 { width: 50%; }
.skeleton-text.w-30 { width: 30%; }

.skeleton-title {
    height: 22px;
    width: 45%;
    margin-bottom: 16px;
    border-radius: 6px;
}

.skeleton-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.skeleton-stat {
    height: 90px;
    border-radius: 12px;
    margin-bottom: 16px;
}

.skeleton-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid #f0f0f0;
}

.skeleton-row:last-child {
    border-bottom: none;
}

.skeleton-badge {
    width: 60px;
    height: 24px;
    border-radius: 6px;
}

/* ─── Staggered Content Animation ────────────────────────────────────────────── */
.stagger-item {
    opacity: 0;
    transform: translateY(12px);
    animation: staggerIn 0.35s ease forwards;
}

.stagger-item:nth-child(1) { animation-delay: 0.04s; }
.stagger-item:nth-child(2) { animation-delay: 0.08s; }
.stagger-item:nth-child(3) { animation-delay: 0.12s; }
.stagger-item:nth-child(4) { animation-delay: 0.16s; }
.stagger-item:nth-child(5) { animation-delay: 0.20s; }
.stagger-item:nth-child(6) { animation-delay: 0.24s; }
.stagger-item:nth-child(7) { animation-delay: 0.28s; }
.stagger-item:nth-child(8) { animation-delay: 0.32s; }

@keyframes staggerIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Pull-to-Refresh (data only) ────────────────────────────────────────────── */
.ptr-indicator {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(-50px);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: transform 0.3s ease;
    opacity: 0;
    pointer-events: none;
}

.ptr-indicator.active {
    opacity: 1;
    transform: translateX(-50%) translateY(10px);
}

.ptr-indicator.loading {
    opacity: 1;
    transform: translateX(-50%) translateY(10px);
}

.ptr-indicator .ptr-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #C9A961;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.ptr-indicator .ptr-arrow {
    font-size: 16px;
    color: #C9A961;
    transition: transform 0.2s;
}

.ptr-indicator.ready .ptr-arrow {
    transform: rotate(180deg);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Navbar Active Indicator ────────────────────────────────────────────────── */
.navbar-nav .nav-link.active {
    position: relative;
}

.navbar-nav .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    right: 10%;
    height: 3px;
    background: #C9A961;
    border-radius: 3px 3px 0 0;
}

/* ─── Login Page Special (full screen, no navbar) ────────────────────────────── */
body.login-active .navbar,
body.login-active .bottom-nav {
    display: none !important;
}

body.login-active #app {
    min-height: 100vh;
}

body.login-active {
    padding-top: 0 !important;
}

/* ─── Hide navbar on mobile (bottom nav is enough) ───────────────────────────── */
@media (max-width: 991.98px) {
    .navbar .navbar-collapse {
        background: linear-gradient(90deg, #5B6E7F 0%, #4A5A68 100%);
        border-radius: 0 0 12px 12px;
        padding: 8px;
        margin-top: 4px;
    }
}

/* ─── Smooth scroll behavior ─────────────────────────────────────────────────── */
html {
    scroll-behavior: smooth;
}

/* ─── Toast improvements ─────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 70px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 11000;
    width: auto;
    max-width: 90vw;
}

.toast {
    border-radius: 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* ─── Dark mode SPA additions ────────────────────────────────────────────────── */
[data-theme="dark"] .skeleton {
    background: #2d2d2d;
}

[data-theme="dark"] .skeleton::after {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
}

[data-theme="dark"] .skeleton-card {
    background: #1e1e1e;
}

[data-theme="dark"] .ptr-indicator {
    background: #2d2d2d;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* ─── Content appear animation ───────────────────────────────────────────────── */
.content-ready {
    animation: contentAppear 0.25s ease forwards;
}

@keyframes contentAppear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Bottom Navigation Bar (SPA version)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 991.98px) {
    #app { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important; }
}

.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 1050;
    background: #ffffff;
    border-top: 1px solid #e9ecef;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
    display: none;
    direction: rtl;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

@media (max-width: 991.98px) {
    .bottom-nav { display: flex; }
}

.bottom-nav.bottom-nav--hidden {
    transform: translateY(100%);
}

.bottom-nav__items {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    width: 100%;
    padding: 0; margin: 0;
    list-style: none;
    position: relative;
}

.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px 6px;
    text-decoration: none;
    color: #8c9bab;
    font-size: 0.65rem;
    font-weight: 500;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    gap: 2px;
    cursor: pointer;
}

.bottom-nav__item i {
    font-size: 1.2rem;
    transition: transform 0.2s ease, color 0.2s ease;
    line-height: 1;
}

.bottom-nav__item span { line-height: 1; margin-top: 2px; }

.bottom-nav__item:hover,
.bottom-nav__item:focus { color: #5B6E7F; text-decoration: none; }

.bottom-nav__item.active { color: #C9A961; }
.bottom-nav__item.active i { transform: scale(1.1); }

.bottom-nav__item.active::before {
    content: "";
    position: absolute;
    top: 0; left: 25%; right: 25%;
    height: 3px;
    background: linear-gradient(90deg, #C9A961, #D4AF37);
    border-radius: 0 0 3px 3px;
}

.bottom-nav__fab-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.bottom-nav__fab {
    width: 52px; height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #C9A961 0%, #D4AF37 100%);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(201, 169, 97, 0.4);
    cursor: pointer;
    position: relative;
    top: -14px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    z-index: 2;
}

.bottom-nav__fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(201, 169, 97, 0.55);
}

.bottom-nav__fab:active { transform: scale(0.95); }

.bottom-nav__fab.fab--open {
    transform: rotate(45deg);
    background: linear-gradient(135deg, #5B6E7F 0%, #4A5A68 100%);
    box-shadow: 0 4px 16px rgba(91, 110, 127, 0.4);
}

.bottom-nav__popup {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    opacity: 0;
    pointer-events: none;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
    min-width: 170px;
    padding: 8px 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 3;
    direction: rtl;
}

.bottom-nav__popup.popup--visible {
    opacity: 1;
    transform: translateX(-50%) scale(1);
    pointer-events: auto;
}

.bottom-nav__popup::after {
    content: "";
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 12px; height: 12px;
    background: #ffffff;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.05);
}

.bottom-nav__popup-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: #2C3E50;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav__popup-item:hover {
    background: rgba(201, 169, 97, 0.1);
    color: #C9A961;
    text-decoration: none;
}

.bottom-nav__popup-item i {
    font-size: 1rem; width: 20px;
    text-align: center; color: #C9A961;
}

.bottom-nav__badge {
    position: absolute;
    top: 4px;
    right: 50%;
    transform: translateX(calc(50% + 10px));
    min-width: 18px; height: 18px;
    background: #dc3545;
    color: white;
    border-radius: 9px;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}

/* Bottom nav dark mode */
[data-theme="dark"] .bottom-nav {
    background: #1a1a1a;
    border-top-color: #333;
}

[data-theme="dark"] .bottom-nav__item { color: #777; }
[data-theme="dark"] .bottom-nav__item:hover { color: #bbb; }
[data-theme="dark"] .bottom-nav__item.active { color: #C9A961; }

[data-theme="dark"] .bottom-nav__popup {
    background: #2d2d2d;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .bottom-nav__popup::after { background: #2d2d2d; }

[data-theme="dark"] .bottom-nav__popup-item { color: #e0e0e0; }
[data-theme="dark"] .bottom-nav__popup-item:hover { background: rgba(201, 169, 97, 0.15); }
