/* Layout Components - NavMenu and MainLayout */

/* Main Page Layout */
.page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    background: var(--bg-primary);
}

.main-content article {
    min-height: calc(100vh - 60px);
}

/* Navigation Bar */
.navbar-top {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
    box-shadow: 0 12px 32px -18px rgba(18, 21, 46, 0.55);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: white !important;
    text-decoration: none;
    display: flex;
    align-items: center;
    transition: opacity 0.2s;
}

@media (hover: hover) {
    .navbar-brand:hover {
        opacity: 0.9;
    }
}

.brand-badge {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.25);
    color: white;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    letter-spacing: 0.5px;
    vertical-align: middle;
}

.navbar-toggler {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.75rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.navbar-links {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex: 1;
    justify-content: space-between;
    margin-left: 3rem;
}

.navbar-links.collapse {
    display: flex;
}

.nav-main,
.nav-auth {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link {
    color: white !important;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: all 0.2s;
    font-weight: 500;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

@media (hover: hover) {
    .nav-link:hover {
        background: rgba(255, 255, 255, 0.15);
    }
}

.nav-link.active {
    background: rgba(255, 255, 255, 0.25);
}

/* Active timer animation - Scanning & Pulse */
.nav-link-animated {
    position: relative;
    overflow: hidden;
}

/* Pulsing Icon */
.nav-link-animated span[class^="bi-"],
.nav-link-animated span[class*=" bi-"] {
    color: #4ade80 !important;
    animation: navIconPulse 2s ease-in-out infinite;
    display: inline-block;
    /* Ensure transform works */
}

@keyframes navIconPulse {

    0%,
    100% {
        transform: scale(1);
        text-shadow: 0 0 5px rgba(74, 222, 128, 0.3);
    }

    50% {
        transform: scale(1.15);
        text-shadow: 0 0 12px rgba(74, 222, 128, 0.6);
    }
}

/* Scanning Underline */
.nav-link-animated::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg,
            transparent 0%,
            #4ade80 50%,
            transparent 100%);
    background-size: 200% 100%;
    animation: navScanLine 2.5s linear infinite;
    opacity: 0.9;
}

@keyframes navScanLine {
    0% {
        background-position: 150% 0;
    }

    100% {
        background-position: -50% 0;
    }
}

@media (prefers-reduced-motion: reduce) {

    .nav-link-animated span[class^="bi-"],
    .nav-link-animated span[class*=" bi-"],
    .nav-link-animated::after {
        animation: none;
    }

    .nav-link-animated {
        border-bottom: 2px solid #4ade80;
    }
}

.nav-badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.25);
    color: white;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    letter-spacing: 0.5px;
}

.nav-dropdown {
    position: relative;
}

.dropdown-toggle::after {
    content: none;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.5rem;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 18px 36px -24px rgba(24, 28, 54, 0.45);
    min-width: 180px;
    overflow: hidden;
    z-index: 1001;
    display: block;
}

.dropdown-menu.collapse {
    display: none !important;
}

.dropdown-item {
    color: var(--text-primary) !important;
    padding: 0.75rem 1rem;
    display: block;
    text-decoration: none;
    transition: background 0.2s;
}

@media (hover: hover) {
    .dropdown-item:hover {
        background: var(--hover-bg);
    }
}

.dropdown-item.active {
    background: rgba(124, 105, 255, 0.12);
    color: var(--accent-primary) !important;
}

.logout-form {
    margin: 0;
}

/* Premium Link in Nav */
.nav-link-premium {
    color: white !important;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: 0.938rem;
    display: flex;
    align-items: center;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.15);
    border: 1.5px solid rgba(255, 255, 255, 0.3);
}

@media (hover: hover) {
    .nav-link-premium:hover {
        background: rgba(255, 255, 255, 0.25);
        border-color: rgba(255, 255, 255, 0.5);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

.nav-link-premium .bi-star-fill {
    color: #ffd700;
}

@media (max-width: 768px) {
    .premium-text {
        display: none;
    }

    .nav-link-premium {
        padding: 0.5rem;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        justify-content: center;
    }

    .nav-link-premium .me-2 {
        margin-right: 0 !important;
    }
}

/* Modern Icon Buttons */
.icon-button {
    background: transparent;
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

@media (hover: hover) {
    .icon-button:hover {
        background: rgba(255, 255, 255, 0.15);
    }
}

.icon-button:active {
    background: rgba(255, 255, 255, 0.25);
}

.icon-button svg {
    fill: white;
    opacity: 0.95;
}

.apps-button svg circle {
    transition: all 0.2s ease;
}

@media (hover: hover) {
    .apps-button:hover svg circle {
        opacity: 0.9;
    }
}

/* Apps Menu */
.apps-dropdown {
    position: relative;
}


.apps-menu {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    min-width: 320px;
    overflow: hidden;
    z-index: 1001;
    display: block;
    animation: menuSlideIn 0.2s ease;
    border: 1px solid var(--border-light);
}

.apps-menu.collapse {
    display: none !important;
}

/* Apps menu header with close button */
.apps-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
}

.apps-header-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.apps-close-btn {
    display: none;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

@media (hover: hover) {
    .apps-close-btn:hover {
        background: var(--hover-bg);
        color: var(--text-primary);
    }
}

.apps-header {
    padding: 16px 20px 12px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.apps-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 12px 20px 20px;
}

.app-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 12px;
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

@media (hover: hover) {
    .app-item:hover {
        background: var(--hover-bg);
        transform: translateY(-2px);
    }
}

.app-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin-bottom: 10px;
    transition: transform 0.2s ease;
    color: white;
}

@media (hover: hover) {
    .app-item:hover .app-icon {
        transform: scale(1.05);
    }
}

.calorie-icon {
    background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
}

.grocery-icon {
    background: linear-gradient(135deg, #4caf50 0%, #66bb6a 100%);
}

.gym-icon {
    background: linear-gradient(135deg, #e53935 0%, #ef5350 100%);
}

.habit-icon {
    background: linear-gradient(135deg, #5c6bc0 0%, #7986cb 100%);
}

.budget-icon {
    background: linear-gradient(135deg, #66bb6a 0%, #81c784 100%);
}

.study-icon {
    background: linear-gradient(135deg, #ffa726 0%, #ffb74d 100%);
}

.app-name {
    font-size: 0.813rem;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.3;
}

/* Apps Section Divider */
.apps-section-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 16px;
}

.apps-section-header {
    padding: 12px 20px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Disabled App Items */
.app-item-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

@media (hover: hover) {
    .app-item-disabled:hover {
        background: none;
        transform: none;
    }
}

/* User Avatar and Menu */
.user-dropdown {
    position: relative;
}

.user-avatar-button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    transition: opacity 0.2s ease;
}

@media (hover: hover) {
    .user-avatar-button:hover {
        opacity: 0.9;
    }
}

.user-avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
}

@media (hover: hover) {
    .user-avatar-button:hover .user-avatar-circle {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        transform: scale(1.05);
    }
}

.user-initial {
    font-size: 0.938rem;
    font-weight: 600;
    color: var(--accent-primary);
    user-select: none;
}

.btn-signin {
    background: white;
    color: var(--accent-primary);
    padding: 0.5rem 1.25rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.938rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

@media (hover: hover) {
    .btn-signin:hover {
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        transform: translateY(-1px);
        color: var(--accent-primary);
    }
}

/* User Menu Dropdown */
.user-menu {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    min-width: 320px;
    overflow: hidden;
    z-index: 1001;
    display: block;
    animation: menuSlideIn 0.2s ease;
    border: 1px solid var(--border-light);
}

.user-menu.collapse {
    display: none !important;
}

.user-menu-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-tertiary);
}

.user-avatar-large {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-initial-large {
    font-size: 1.75rem;
    font-weight: 600;
    color: white;
    user-select: none;
}

.user-info-text {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-plan-badge {
    font-size: 0.688rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    color: #1a1a1a;
    padding: 3px 8px;
    border-radius: 6px;
    margin-top: 6px;
    display: inline-block;
    box-shadow: 0 2px 6px rgba(255, 215, 0, 0.3);
}

.user-menu-divider {
    height: 1px;
    background: var(--border-light);
    margin: 8px 0;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.2s ease;
    font-size: 0.938rem;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

@media (hover: hover) {
    .user-menu-item:hover {
        background: var(--hover-bg);
    }
}

.user-menu-item .bi {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

.logout-item {
    color: #dc3545 !important;
}

.logout-item .bi {
    color: #dc3545 !important;
}

@media (hover: hover) {
    .logout-item:hover {
        background: rgba(220, 53, 69, 0.1);
    }
}

.theme-toggle-item {
    justify-content: space-between;
    cursor: pointer;
    background: transparent;
    border-radius: 8px;
    transition: background 0.2s ease;
}

@media (hover: hover) {
    .theme-toggle-item:hover {
        background: var(--hover-bg);
    }
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    margin-left: auto;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch .toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    border-radius: 24px;
    transition: all 0.3s ease;
}

.toggle-switch .toggle-slider:before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--accent-gradient);
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(20px);
}

@media (hover: hover) {
    .toggle-switch:hover .toggle-slider {
        opacity: 0.9;
    }
}

@keyframes menuSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Navigation - triggers at 1200px to handle trackers with many nav items */
@media (max-width: 1200px) {
    .navbar-container {
        /* No flex-wrap - prevent line breaks */
    }

    .navbar-toggler {
        display: block;
        order: 10;
    }

    /* Nav-auth stays visible, positioned before toggler */
    .nav-auth {
        order: 5;
        margin-left: auto;
        margin-right: 0.5rem;
    }

    /* Collapsible nav links */
    .navbar-links {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        background: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        margin: 0;
        padding: 1rem;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        order: 20;
        width: 100%;
    }

    .navbar-links.collapse {
        display: none;
    }

    .navbar-links.is-open {
        display: flex;
    }

    .nav-main {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        width: 100%;
    }

    .nav-link {
        width: 100%;
        text-align: left;
        padding: 0.75rem 1rem;
    }

    .dropdown-menu {
        position: static;
        box-shadow: none;
        background: rgba(255, 255, 255, 0.1);
        margin-top: 0;
        margin-left: 1rem;
    }

    .navbar-links .dropdown-item {
        color: white !important;
    }

    @media (hover: hover) {
        .navbar-links .dropdown-item:hover {
            background: rgba(255, 255, 255, 0.15);
        }
    }

    .navbar-links .dropdown-item.active {
        background: rgba(255, 255, 255, 0.25);
    }

    /* Fullscreen apps menu on mobile */
    .apps-menu {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        z-index: 9999;
        overflow-y: auto;
        animation: appsMenuSlideUp 0.25s ease;
    }

    @keyframes appsMenuSlideUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .apps-menu-header {
        padding: 1.25rem 1.5rem;
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        background: var(--card-bg);
        z-index: 10;
    }

    .apps-header-title {
        font-size: 1.25rem;
        text-transform: none;
        letter-spacing: normal;
        color: var(--text-primary);
    }

    .apps-close-btn {
        display: flex;
        width: 44px;
        height: 44px;
        font-size: 1.25rem;
    }

    .apps-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
        padding: 1.5rem;
    }

    .app-item {
        padding: 1.5rem 1rem;
    }

    .app-icon {
        width: 56px;
        height: 56px;
        font-size: 1.5rem;
    }

    .app-name {
        font-size: 0.95rem;
        margin-top: 0.75rem;
    }

    .apps-section-header {
        padding: 0.75rem 1.5rem;
    }

    .apps-section-divider {
        margin: 0.5rem 1.5rem;
    }

    /* User menu adjustments */
    .user-menu {
        position: fixed;
        top: 60px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: calc(100% - 2rem);
        max-width: 400px;
        animation: userMenuSlideIn 0.2s ease;
    }

    @keyframes userMenuSlideIn {
        from {
            opacity: 0;
            transform: translateX(-50%) translateY(-8px);
        }
        to {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
    }
}

/* Print Styles */
@media print {

    .navbar-top,
    .app-footer {
        display: none !important;
    }
}

/* ========================================
   Progressive Mobile Responsive Navbar
   ======================================== */

/* Mobile auth section - hidden by default */
.nav-auth-mobile {
    display: none;
}

/* Mobile user name next to avatar - hidden by default */
.user-name-mobile {
    display: none;
}

/* At 1200px: Show mobile auth section in collapsed menu */
@media (max-width: 1200px) {
    .nav-auth-mobile {
        display: flex;
        flex-direction: column;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
        margin-top: 1rem;
        padding-top: 1rem;
    }

    /* Hide mobile-specific items by default - only show when hidden from top bar */
    .nav-link-premium-mobile,
    .user-dropdown-mobile,
    .btn-signin-mobile {
        display: none;
    }
}

/* At 500px: Hide premium button from top bar, show in mobile menu */
@media (max-width: 500px) {
    .nav-auth > .nav-link-premium {
        display: none;
    }

    .nav-link-premium-mobile {
        display: flex !important;
    }
}

/* At 420px: Hide user dropdown/signin from top bar, show in mobile menu */
@media (max-width: 420px) {
    .nav-auth > .user-dropdown,
    .nav-auth > .btn-signin {
        display: none;
    }

    .user-dropdown-mobile {
        display: block !important;
    }

    .btn-signin-mobile {
        display: flex !important;
    }

    /* Style the mobile user button with name */
    .user-dropdown-mobile .user-avatar-button {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
        padding: 0.5rem 0;
    }

    .user-name-mobile {
        display: block;
        color: white;
        font-weight: 500;
        font-size: 1rem;
    }

    /* Fullscreen user menu on mobile */
    .user-dropdown-mobile .user-menu {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        z-index: 1010;
        overflow-y: auto;
        transform: none;
        animation: userMenuSlideUp 0.25s ease;
    }

    @media (hover: hover) {
        /* Ensure menu items have hover states */
        .user-dropdown-mobile .user-menu-item:hover {
            background: var(--hover-bg);
        }
    }

    .user-dropdown-mobile .user-menu-item:active {
        background: var(--bg-secondary);
    }

    @keyframes userMenuSlideUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Show close button on mobile user menu */
    .user-dropdown-mobile .user-menu-close-btn {
        display: flex;
    }

    /* Adjust header for fullscreen */
    .user-dropdown-mobile .user-menu-header {
        padding-top: 3rem;
    }
}

/* Close button for mobile user menu - hidden by default */
.user-menu-close-btn {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

@media (hover: hover) {
    .user-menu-close-btn:hover {
        background: var(--hover-bg);
        color: var(--text-primary);
    }
}

/* Pricing Toggle Dark Mode */
body.dark-theme .pricing-toggle {
    background: #374151 !important;
}

/* Prevent iOS Safari auto-zoom on input focus */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px !important;
    }
}