:root {
    --navbar-height: 60px;
    --navbar-title-bg: rgba(0, 123, 255, 0.8);
    --navbar-shadow: 3px 3px 5px rgba(0, 0, 0, 0.5);
    --navbar-mobile-breakpoint: 600px;
    --primary-color: #4a90e2;
    --primary-color-dark: #357abd;
}

/* Main navbar container */
.navbar {
    height: var(--navbar-height);
    width: 100%;
    background: transparent;
    margin: 0;
    padding: 0;
    overflow: visible;
}

/* Content wrapper using grid layout */
.navbar-content {
    height: 100%;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
    position: relative;
    padding: 0 15px;
    box-sizing: border-box;
    overflow: visible;
}

/* Title styling */
.navbar-title {
    grid-column: 2;
    font-size: 32px;
    font-family: 'Segoe UI', sans-serif;
    font-weight: bold;
    color: white;
    text-shadow: var(--navbar-shadow);
    padding: 0 20px 8px 20px;
    border-radius: 0 0 15px 15px;
    background: var(--navbar-title-bg);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-top: none; /* No top border since it's at the top of the page */
    transition: transform 0.3s ease;
    text-align: center;
    z-index: 999;
    position: relative;
    overflow: hidden;
}

.navbar-title a {
    color: inherit;
    text-decoration: none;
    display: block;
    position: relative;
    z-index: 2;
}

.navbar-title:hover {
    transform: scale(1.01);
}

.navbar-title::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
    transition: left 0.6s ease-out;
    z-index: 1;
}

.navbar-title:hover::before {
    left: 100%;
}

/* Auth container (login/profile) */
.auth-container {
    grid-column: 3;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: var(--navbar-height);
    z-index: 50000 !important; /* Force container above all content */
    padding-right: 15px;
    position: relative;
}

/* Universal button styles */
.action-button, .login-button {
    background: var(--primary-color);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    text-align: center;
}

.action-button:hover, .login-button:hover {
    background: var(--primary-color-dark);
    transform: scale(1.05);
}

/* Login specific styles */
.login-container {
    position: relative;
    z-index: 50001 !important; /* Force login container above all content */
}

.login-button {
    background: #fff;
    color: #333;
    border: 2px solid var(--primary-color);
    padding: 12px 28px;
    font-size: 18px;
}

.login-button:hover {
    background: #e3f0ff;
    color: var(--primary-color-dark);
    border-color: var(--primary-color-dark);
}

/* Login dropdown */
.login-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    background: white !important;
    border-radius: 8px;
    padding: 8px;
    display: none;
    z-index: 999999 !important; /* Extremely high z-index */
    min-width: 240px;
    border: 1px solid rgba(0,0,0,0.1);
    isolation: isolate !important; /* Create new stacking context */
}

.login-dropdown.show {
    display: block;
}

/* Login options */
.login-option {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: #333;
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.2s ease;
    margin: 4px 0;
}

.login-option img {
    width: 20px;
    height: 20px;
    margin-right: 12px;
}

.login-option:hover { background: #f8f9fa; }
.login-option.google:hover { background: #f1f3f4; }
.login-option.github:hover { background: #24292e; color: white; }
.login-option.microsoft:hover { background: #2f2f2f; color: white; }

/* Avatar and profile dropdown */
.avatar-container {
    position: relative;
    display: flex;
    align-items: center;
    height: 100%;
    z-index: 50001 !important; /* Force avatar container above all content */
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    margin: 0;
    border: 2px solid white;
    transition: transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.user-avatar:hover {
    transform: scale(1.05);
}

/* Profile dropdown */
.logout-dropdown.simple-menu {
    position: absolute !important;
    top: calc(100% + 8px) !important;
    right: 0 !important;
    width: 220px;
    background: #fff !important;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    padding: 12px 10px 8px 10px;
    z-index: 999999 !important; /* Extremely high z-index */
    display: none;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
    box-sizing: border-box;
    min-width: 200px;
    max-width: 280px;
    isolation: isolate !important; /* Create new stacking context */
}

.avatar-container.open .logout-dropdown.simple-menu {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.dropdown-display-name {
    font-weight: 600;
    color: #333;
    padding: 8px 16px;
    margin-bottom: 8px;
    text-align: center;
    font-size: 16px;
}

.logout-dropdown .action-button {
    display: block;
    width: calc(100% - 44px);
    margin: 0 8px 8px 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
}

.logout-dropdown .logout-btn {
    background: #dc3545;
}

.logout-dropdown .logout-btn:hover {
    background: #c82333;
}

/* Page Credits Widget */
.page-credits-container {
    grid-column: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    height: var(--navbar-height);
    z-index: 50001 !important; /* Force credits container above all content */
    padding-left: 15px;
    position: relative;
}

.page-credits-widget {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    border: 1px solid rgba(74, 144, 226, 0.3);
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
    cursor: pointer;
    user-select: none;
}

.page-credits-widget:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
}

.credits-display {
    padding: 8px 12px;
    min-width: 80px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
}

.credit-line {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary-color);
    text-align: center;
}

.credit-count {
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

.credit-type {
    font-size: 11px;
    opacity: 0.85;
    letter-spacing: 0.3px;
    line-height: 1;
    white-space: nowrap;
}

/* Credits dropdown */
.credits-dropdown.simple-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 220px;
    background: #fff !important;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    padding: 12px 10px 8px 10px;
    z-index: 999999 !important; /* Extremely high z-index */
    display: none;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
    box-sizing: border-box;
    min-width: 200px;
    max-width: 280px;
    isolation: isolate !important; /* Create new stacking context */
}

.page-credits-container.open .credits-dropdown.simple-menu {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.credit-detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    margin: 2px 0;
    font-size: 13px;
    border-radius: 6px;
    background: rgba(0,0,0,0.06);
}

.credit-detail .detail-value {
    color: var(--primary-color);
    font-weight: 600;
}

.credit-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 8px 16px;
    border-top: 1px solid #eee;
    font-size: 14px;
    font-weight: 600;
    background: rgba(74, 144, 226, 0.05);
    border-radius: 6px;
}

.credit-total .detail-value {
    color: #333;
}

.credits-dropdown.simple-menu .action-button {
    width: 60%;
    margin: 8px auto 0 auto;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    display: block;
    text-align: center;
}

/* "What is ScribbleScan?" link for non-authenticated users */
.what-is-scribblescan-container {
    grid-column: 1; /* Position in the first column of the navbar grid */
    display: flex;
    align-items: center; /* Vertically center the link */
    justify-content: flex-start; /* Align to the left */
    height: var(--navbar-height); /* Match navbar height */
    padding-left: 15px; /* Default padding, aligned with .page-credits-container and .auth-container */
    position: relative;
    z-index: 1000; /* Adjusted to be below modals (e.g. modal z-index 9999) */
}

/* Styling for the "What is ScribbleScan?" link in the navbar, using .action-button for base */
.action-button.what-is-scribblescan-navbar-override {
    background-color: #6c757d; /* Specific gray background */
    color: white;
    border: none; /* Override .action-button border */
    padding: 10px 16px;   /* Match Sign In button default padding */
    font-size: 15px;     /* Match Sign In button default font-size */
    font-weight: 600;    /* Match Sign In button font-weight */
    /* border-radius will be inherited from .action-button (8px) */
    /* text-decoration: none will be inherited */
    /* cursor: pointer will be inherited */
    /* position: relative, overflow: hidden for shine effect inherited from .action-button */
    /* transition: all 0.2s ease inherited from .action-button for background */
    /* display: inline-flex, align-items: center, justify-content: center inherited from .action-button */
    gap: 0; /* No gap needed for simple text link */
    line-height: normal; /* Ensure consistent line height */
}

.action-button.what-is-scribblescan-navbar-override:hover {
    background-color: #5a6268; /* Specific hover background */
    color: white; /* Ensure text remains white */
    transform: scale(1.05); /* Standard hover transform, inherited from .action-button:hover or can be explicit */
    /* Shine effect on hover is handled by .action-button::before styles in base.css */
}


/* Mobile Responsive - Consolidated */
@media (max-width: 685px) {
    .navbar {
        width: 100vw;
        max-width: 100%;
    }
    
    .navbar-content {
        padding: 0 6px; /* Reduced further for equal spacing */
        grid-template-columns: auto 1fr auto; /* Center title between edge elements */
    }
    
    .navbar-title {
        font-size: 25px;
        padding: 0 16px 8px 16px;
        margin-bottom: 5px;
        width: max-content; /* Size to content */
        margin-left: auto;   /* Center the block */
        margin-right: auto;  /* Center the block */
    }

    .navbar-title a {
        display: block;
        text-align: center;
    }

    .auth-container {
        padding-right: 3px; /* Match left side spacing */
        overflow: visible;
        display: flex;
        align-items: center;
        height: var(--navbar-height);
        margin: 0;
    }
    
    /* Unified button scaling - match base.css */
    .action-button, .login-button {
        padding: 8px 14px !important;
        font-size: 14px !important;
    }
    .action-button.what-is-scribblescan-navbar-override { /* Responsive override */
        padding: 8px 14px !important;
        font-size: 14px !important;
    }

    .user-avatar {
        width: 40px; /* Larger */
        height: 40px;
        transform: scale(0.9); /* Less aggressive scaling */
    }
    
    .avatar-container {
        position: relative;
        z-index: 50001 !important; /* Force above all content on mobile */
        height: auto;
    }
    
    .logout-dropdown.simple-menu {
        width: 200px;
        margin-top: 5px;
        z-index: 999999 !important; /* Extremely high z-index for mobile */
        right: 0 !important; /* Reset mobile positioning */
    }

    /* Page credits mobile adjustments */
    .page-credits-container {
        padding-left: 3px; /* Match right side spacing */
        overflow: visible;
        display: flex;
        align-items: center;
        height: var(--navbar-height);
        margin: 0;
    }
    
    .page-credits-widget {
        transform: scale(1.0); /* Full size, no scaling down */
        transform-origin: left center; /* Scale from left edge */
    }
    .what-is-scribblescan-container { padding-left: 3px; } /* Symmetry adjustment */
    .credits-display {
        padding: 8px 12px; /* Larger padding */
        min-width: 75px; /* Increased significantly */
    }
    
    .credit-count {
        font-size: 16px; /* Much larger - back to desktop size */
    }
    
    .credit-type {
        font-size: 12px; /* Much larger */
    }
}

/* Small-medium mobile - intermediate sizing */
@media (max-width: 550px) {
    .navbar-content {
        padding: 0 4px; /* Equal spacing from edges */
    }
    
    .navbar-title {
        font-size: 24.5px;
        padding: 0 14px 6px 14px;
    }
    
    /* Intermediate button scaling - between 685px and 450px styles */
    .action-button, .login-button {
        padding: 7px 12px !important;
        font-size: 13px !important;
    }
    .action-button.what-is-scribblescan-navbar-override { /* Responsive override */
        padding: 7px 12px !important;
        font-size: 13px !important;
    }

    .user-avatar {
        width: 38px; /* Slightly larger */
        height: 38px;
        transform: scale(0.85);
    }

    .page-credits-container {
        padding-left: 2px; /* Match right spacing */
    }
    
    .auth-container {
        padding-right: 2px; /* Match left spacing */
    }
    
    .page-credits-widget {
        transform: scale(0.95); /* Less scaling */
    }
    .what-is-scribblescan-container { padding-left: 2px; } /* Symmetry adjustment */
    .credits-display {
        padding: 7px 11px; /* Larger */
        min-width: 70px; /* Larger */
    }
    
    .credit-count {
        font-size: 15px; /* Much larger */
    }
    
    .credit-type {
        font-size: 11.5px; /* Much larger */
    }
}

/* Extra small screens - unified scaling */
@media (max-width: 450px) {
    .navbar-content {
        padding: 0 3px; /* Equal spacing from edges */
    }
    
    .navbar-title {
        font-size: 24px;
        padding: 0 12px 5px 12px;
    }
    
    /* Match button scaling from base.css */
    .action-button, .login-button {
        padding: 7px 11px !important;
        font-size: 12.5px !important;
    }
    .action-button.what-is-scribblescan-navbar-override { /* Responsive override */
        padding: 7px 11px !important;
        font-size: 12.5px !important;
    }

    .user-avatar {
        width: 36px; /* Larger */
        height: 36px;
        transform: scale(0.8); /* Less aggressive */
    }

    .page-credits-container {
        padding-left: 1px; /* Match right spacing */
    }
    
    .auth-container {
        padding-right: 1px; /* Match left spacing */
    }
    
    .page-credits-widget {
        transform: scale(0.9); /* Less scaling */
        transform-origin: left center;
    }
    .what-is-scribblescan-container { padding-left: 1px; } /* Symmetry adjustment */
    .credits-display {
        padding: 6px 10px; /* Larger */
        min-width: 65px; /* Larger */
    }
    
    .credit-count {
        font-size: 14px; /* Much larger */
    }
    
    .credit-type {
        font-size: 11px; /* Much larger */
    }

    .logout-dropdown.simple-menu {
        max-width: 85vw;
    }
}

/* Extra small mobile - covers 350-450px range */
@media (max-width: 400px) {
    .navbar-content {
        padding: 0 2px; /* Equal minimal spacing from edges */
    }
    
    .navbar-title {
        font-size: 23px;
        padding: 0 10px 4px 10px;
    }
    
    .action-button, .login-button {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
    .action-button.what-is-scribblescan-navbar-override { /* Responsive override */
        padding: 6px 10px !important;
        font-size: 12px !important;
    }

    .user-avatar {
        width: 34px; /* Larger than before */
        height: 34px;
        transform: scale(0.75); /* Less aggressive */
    }

    .page-credits-container {
        padding-left: 1px; /* Match right spacing exactly */
    }
    
    .auth-container {
        padding-right: 1px; /* Match left spacing exactly */
    }
    
    .page-credits-widget {
        transform: scale(0.85); /* Less scaling */
        transform-origin: left center;
    }
    .what-is-scribblescan-container { padding-left: 1px; } /* Symmetry adjustment, stays 1px */
    .credits-display {
        padding: 5px 9px; /* Larger padding */
        min-width: 60px; /* Larger width */
    }
    
    .credit-count {
        font-size: 13px; /* Much larger - was 11.5px */
    }
    
    .credit-type {
        font-size: 10px; /* Larger - was 9.5px */
    }
    
    /* Dropdown buttons also scale consistently */
    .logout-dropdown .action-button {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
}

/* Secondary info button in dropdown menu */
.logout-dropdown .secondary-info-btn {
    display: block;
    width: calc(100% - 44px); /* Match other dropdown buttons */
    margin: 8px 8px 8px 8px; /* Standard margin, no extra spacing */
    padding: 8px 12px; /* Match other dropdown buttons exactly */
    font-size: 13px; /* Match other dropdown buttons */
    font-weight: 500; /* Match other dropdown buttons */
    background-color: #6c757d !important; /* Gray secondary button */
    border: none !important; /* Remove any borders */
    position: relative;
}

/* Separator line between logout and about/legal */
.logout-dropdown .dropdown-separator {
    height: 1px;
    background-color: #d1d3d4;
    margin: 12px 16px;
    border: none;
    opacity: 0.6;
}

.logout-dropdown .secondary-info-btn:hover {
    background-color: #5a6268 !important;
    transform: scale(1.05); /* Match the standard button hover effect */
}