/* Base Layout CSS - Fluent Up Application
 * This file contains only layout structure styles (navbar, footer, content areas)
 * Theme customization is in bootstrap-theme.css
 * App-specific components are in app-components.css
 */

/* ============================================
   Body and Layout Structure
   ============================================ */

body {
    min-height: 100dvh; /* Dynamic viewport height for Android */
    min-height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Fixed height to prevent body scrolling */
    height: 100vh; /* Fallback for older browsers */
    color: var(--bs-body-color);
    /* Removed transition:all - no properties transition on body element */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent body-level scrolling - scrollbar appears on main-content */
    /* Android text rendering optimizations */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body:not(.base-auth):not(.base-focus){
    padding-top: 4.375rem; /* Account for fixed header - responsive rem units */
}
body.base-auth{
    padding-top: 0.625rem;
}

/* Body with footer */
body.has-footer {
    padding-bottom: 5rem; /* Account for fixed footer */
}

/* Body with progress bar */
body.has-progress {
    padding-bottom: 4.8125rem; /* Account for progress bar */
}

/* Body with both footer and progress bar */
body.has-footer.has-progress {
    padding-bottom: 9.8125rem; /* Account for both footer and progress bar */
}

.body-content {
    padding: calc(var(--bs-spacer) * 2); /* 2rem = 2 * --bs-spacer */
    text-align: left;
    overflow: visible; /* No scrolling - parent main-content handles scrolling */
    overflow-wrap: break-word; /* Break long words to prevent overflow */
    word-wrap: break-word; /* Legacy support */
    min-width: 0; /* Allow flex item to shrink */
    max-width: 100%; /* Prevent overflow */
}

/* Story content container - ensure proper text wrapping */
#storyContent {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
}

/* ============================================
   Fixed Header (Navbar)
   ============================================ */

/* Optimized navbar - solid background with opacity for better performance */
.navbar.fixed-top {
    background: var(--bs-primary-transparent, rgba(0, 52, 89, 0.95)) !important;
    padding-top: 0.3rem;
    padding-right: 0.7rem;
    padding-bottom: 0.3rem;
    padding-left: 0.7rem;
    /* Fallback for browsers without safe-area-inset support */
    padding: 0.3rem 0.7rem;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100vw; /* Prevent horizontal overflow */
    box-sizing: border-box;
}

.navbar-brand {
    color: white !important;
    font-weight: var(--bs-font-weight-semibold, 600);
    font-size: calc(var(--bs-font-size-base, 1rem) * 1.5);
}

.navbar-toggler {
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 var(--bs-focus-ring-width) rgba(255, 255, 255, var(--bs-focus-ring-opacity));
}

.navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 1%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

.navbar-nav .nav-link {
    color: rgba(255, 255, 255, 0.9) !important;
    font-weight: var(--bs-font-weight-normal, 400);
    padding: calc(var(--bs-spacer) * 0.5) var(--bs-spacer);
    transition: transform 0.2s ease;
}

.navbar-nav .nav-link:hover {
    color: white !important;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: var(--bs-border-radius);
}

/* ============================================
   Main Content Area
   ============================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex item to shrink below content size */
    overflow-y: auto; /* Enable scrolling at main-content level */
    overflow-x: hidden; /* Prevent horizontal scrolling */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS/Android */
}

/* Add padding-bottom to main-content when footer is visible to prevent scrollbar behind footer */
/* body.has-footer .main-content {
    padding-bottom: 5rem; /* Match body padding-bottom to account for footer height */
} */

/* When both footer and progress bar are present */
body.has-footer.has-progress .main-content {
    padding-bottom: 9.8125rem; /* Account for both footer and progress bar */
}

.main-content .container-fluid {
    display: flex;
    flex-direction: column;
    flex: 1;
    /*min-height: 0;
    height: 100%; */
    width: 100%; /* Ensure full width */
}

/* Optimized main content card - solid background with opacity for better performance */
.main-content .card {
    background: rgba(var(--bs-body-bg-rgb), 0.98);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible; /* Allow content to flow - scrolling handled by main-content */
    flex: 1;
    min-height: 0; /* Allow flex item to shrink below content size */
    width: 100%; /* Ensure full width */
}

[data-bs-theme="dark"] .main-content .card {
    background: rgba(var(--bs-body-bg-rgb), 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.main-content .card:hover {
    transform: translateY(-2px);
}

/* ============================================
   Fixed Footer
   ============================================ */

/* Optimized footer - solid background with opacity for better performance */
footer.fixed-bottom {
    background: var(--bs-primary-transparent, rgba(0, 52, 89, 0.95)) !important;
    /* padding-top: 1rem;
    padding-right: 0px;
    padding-bottom: 1rem;
    padding-left: 0px; */
    /* Fallback for browsers without safe-area-inset support */
    /* padding: 1rem 0; */
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100vw; /* Prevent horizontal overflow */
    box-sizing: border-box;
}

.footer-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-weight: var(--bs-font-weight-medium, 500);
    transition: transform 0.3s ease;
    min-width: 120px;
    min-height: 44px; /* Minimum touch target for Android */
    /* Android touch optimization */
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.3);
    touch-action: manipulation;
}

.footer-btn:hover {
    transform: translateY(-1px);
}

.footer-btn.active {
    background: rgba(255, 255, 255, 0.9);
    color: var(--bs-primary);
    border-color: white;
}

/* ============================================
   Loading Overlay
   ============================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100vw; /* Prevent horizontal overflow */
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--bs-zindex-toast, 1080);
    box-sizing: border-box;
}

.loading-overlay.show {
    display: flex;
}

/* ============================================
   List Group (Minimal overrides)
   ============================================ */

.list-group-item {
    color: var(--bs-body-color);
    border: none !important;
    border-radius: 0 !important;
    padding: calc(var(--bs-spacer) * 0.5) var(--bs-spacer);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    background: transparent;
    border-bottom: 1px solid rgba(var(--bs-body-color-rgb), 0.05);
    margin: 0;
    text-decoration: none;
    outline: none;
    box-shadow: var(--bs-box-shadow-sm);
}

[data-bs-theme="dark"] .list-group-item {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.list-group-item:link {
    color: var(--bs-body-color);
    text-decoration: none;
}

.list-group-item:focus {
    outline: 0 0 0 0.2rem var(--bs-focus-ring-color);
    outline-offset: -2px;
}

.list-group-item:hover {
    background: var(--bs-secondary-bg);
    transform: translateX(4px);
    color: var(--bs-primary);
}

.list-group-item:active {
    transform: translateX(2px);
    background: var(--bs-tertiary-bg);
    color: var(--bs-secondary);
}

.list-group-item:last-child {
    border-bottom: none;
}

.list-group-item .item-content {
    display: flex;
    align-items: center;
    flex: 1;
}

.list-group-item .item-icon {
    margin-right: var(--bs-border-radius-lg);
    font-size: var(--bs-font-size-lg, 1.125rem);
}

.list-group-item .item-text {
    flex: 1;
}

.list-group-item .item-progress {
    margin-left: var(--bs-spacer);
    font-size: var(--bs-font-size-sm, 0.875rem);
    font-weight: var(--bs-font-weight-medium, 500);
    color: var(--bs-secondary-color);
    min-width: 60px;
    text-align: right;
}

.list-group-item .item-progress.progress-high {
    color: var(--bs-success);
}

.list-group-item:hover .item-text {
    color: var(--bs-primary);
}

.list-group-item:active .item-text {
    color: var(--bs-secondary);
}

/* Subtle ripple effect for links */
.list-group-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bs-primary);
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    border-radius: var(--bs-border-radius-sm);
}

.list-group-item:hover::before {
    opacity: 0.08;
}

.list-group-item:active::before {
    opacity: 0.15;
    transition: opacity 0.1s ease;
}

/* List group container styling */
.list-group {
    border-radius: 0px;
    overflow: hidden;
    border: none;
    box-shadow: none;
}

[data-bs-theme="dark"] .list-group {
    background: var(--bs-body-bg);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: var(--bs-box-shadow);
}

/* First and last item styling */
.list-group-item:first-child {
    border-top-left-radius: var(--bs-border-radius);
    border-top-right-radius: var(--bs-border-radius);
}

.list-group-item:last-child {
    border-bottom: none;
    border-bottom-left-radius: var(--bs-border-radius);
    border-bottom-right-radius: var(--bs-border-radius);
}

/* ============================================
   Modal (Minimal overrides)
   ============================================ */


/* Semi-transparent header for modals - optimized without blur */
.modal-custom .modal-header {
    background: var(--bs-primary-transparent, rgba(0, 52, 89, 0.95));
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    color: white;
}

/* Modal content optimization */
.modal-custom .modal-content {
    backface-visibility: hidden;
    transform: translateZ(0);
}

.modal-content{
    border:none;
}

.modal-custom .btn-close {
    filter: invert(1);
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.modal-custom .btn-close:hover {
    opacity: 1;
}

/* Modal icon variations */
.modal-icon-info {
    color: var(--bs-info);
}

.modal-icon-success {
    color: var(--bs-success);
}

.modal-icon-warning {
    color: var(--bs-warning);
}

.modal-icon-error {
    color: var(--bs-danger);
}

.modal-icon-question {
    color: rgba(var(--bs-primary-rgb), 0.7); /* Lighter primary color */
}

/* ============================================
   Form Controls (Minimal overrides)
   ============================================ */

/* Password input padding for toggle button */
#password,
#password2 {
    padding-right: calc(var(--bs-spacer) * 3) !important;
}

/* Password toggle button hover */
button[data-target]:hover {
    color: var(--bs-primary) !important;
}

/* ============================================
   Dark Mode Specific Overrides
   ============================================ */

[data-bs-theme="dark"] p,
[data-bs-theme="dark"] li {
    color: var(--bs-secondary-color) !important;
}

[data-bs-theme="dark"] .card-title {
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .form-label {
    color: var(--bs-body-color);
}

/* Dark mode icon color for bi-question-square-fill */
[data-bs-theme="dark"] .bi-question-square-fill {
    color: white;
}

/* ============================================
   Custom Scrollbar
   ============================================ */

/* Global scrollbar styles for modals, dropdowns, etc. */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bs-secondary-bg, #f1f1f1);
    border-radius: 10px; /* Custom scrollbar, keep specific value */
}

::-webkit-scrollbar-thumb {
    background: var(--bs-primary);
    border-radius: 10px; /* Custom scrollbar, keep specific value */
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bs-secondary);
}

/* Main content scrollbar - primary scrolling area */
.main-content::-webkit-scrollbar {
    width: 8px; /* Slightly wider for better visibility on mobile */
}

.main-content::-webkit-scrollbar-track {
    background: var(--bs-secondary-bg, #f1f1f1);
    border-radius: 10px;
}

.main-content::-webkit-scrollbar-thumb {
    background: var(--bs-primary);
    border-radius: 10px;
}

.main-content::-webkit-scrollbar-thumb:hover {
    background: var(--bs-secondary);
}

/* ============================================
   High DPI / Retina Display Optimizations
   ============================================ */

/* High-DPI devices (2x and above) - All platforms */
/* Standard resolution-based media query */
@media screen and (min-resolution: 192dpi),
       screen and (min-resolution: 2dppx),
       screen and (-webkit-min-device-pixel-ratio: 2) {
    /* Ensure text is crisp on high-DPI screens */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }

    /* Improve touch target visibility */
    button, a, input, select, textarea {
        -webkit-tap-highlight-color: rgba(0, 52, 89, 0.2);
    }

    /* Ensure borders render crisply on high DPI */
    .navbar-toggler,
    .list-group-item,
    .card,
    .modal-content,
    .btn {
        /* Use device pixel ratio for crisp borders */
        border-image: none;
        border-image-width: 1;
        -webkit-border-image: none;
    }

    /* Optimize scrollbar for high DPI */
    ::-webkit-scrollbar {
        width: 8px; /* Slightly wider for better visibility on high DPI */
    }
}

/* Very High-DPI devices (3x and above) - iPhone Retina HD, etc. */
@media screen and (min-resolution: 288dpi),
       screen and (min-resolution: 3dppx),
       screen and (-webkit-min-device-pixel-ratio: 3) {
    /* Enhanced text rendering for very high DPI */
    body {
        -webkit-font-smoothing: subpixel-antialiased;
        text-rendering: optimizeLegibility;
    }

    /* Ensure borders are crisp on very high DPI */
    .navbar-toggler,
    .list-group-item,
    .card,
    .modal-content,
    .btn,
    .footer-btn {
        border-image: none;
        border-image-width: 1;
        -webkit-border-image: none;
    }

    /* Optimize scrollbar for very high DPI */
    ::-webkit-scrollbar {
        width: 10px;
    }
}

/* Ultra High-DPI devices (4x and above) */
@media screen and (min-resolution: 384dpi),
       screen and (min-resolution: 4dppx),
       screen and (-webkit-min-device-pixel-ratio: 4) {
    /* Maximum quality text rendering */
    body {
        -webkit-font-smoothing: subpixel-antialiased;
        text-rendering: optimizeLegibility;
    }

    /* Ensure all borders render properly */
    * {
        border-image-width: 1;
    }
}

/* Android Chrome/Edge specific fixes */
@supports (-webkit-appearance: none) {
    /* Fix for Android viewport units - HyperOS compatibility */
    html {
        height: -webkit-fill-available;
    }

    body {
        min-height: -webkit-fill-available;
        min-height: 100dvh; /* Dynamic viewport height for Android */
        min-height: 100vh; /* Fallback for older browsers */
        height: -webkit-fill-available;
        height: 100dvh;
        height: 100vh;
        overflow: hidden; /* Prevent body-level scrolling - scrollbar appears on main-content */
    }

    /* Enable scrolling on main-content for Android */
    .main-content {
        overflow-y: auto; /* Enable scrolling at main-content level */
        overflow-x: hidden; /* Prevent horizontal scrolling */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on Android */
    }

    /* Fix for fixed elements on Android */
    .navbar.fixed-top,
    footer.fixed-bottom,
    .progress-container-fixed,
    .loading-overlay {
        position: fixed;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
    }
}

/* ============================================
   Mobile Optimizations
   ============================================ */

@media (max-width: 768px) {
    /* Android HyperOS specific viewport fixes */
    html {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
        text-size-adjust: 100%;
        height: 100%;
        height: -webkit-fill-available;
    }

    body {
        min-height: 100%;
        min-height: -webkit-fill-available;
        min-height: 100dvh;
        min-height: 100vh;
        height: 100%;
        height: -webkit-fill-available;
        height: 100dvh;
        height: 100vh;
        overflow: hidden; /* Prevent body-level scrolling - scrollbar appears on main-content */
        width: 100%;
        max-width: 100vw;
        position: relative;
    }

    body:not(.base-auth):not(.base-focus){
        padding-top: 3.75rem;
    }

    /* Mobile body with footer */
    body.has-footer {
        padding-bottom: 4.375rem;
    }

    /* Mobile body with progress bar */
    body.has-progress {
        padding-bottom: 4.1875rem;
    }

    /* Mobile body with both footer and progress bar */
    body.has-footer.has-progress {
        padding-bottom: 8.5625rem;
    }

    .navbar-brand {
        font-size: var(--bs-font-size-xl, 1.25rem);
    }

    .main-content {
        flex: 1;
        min-height: 0; /* Allow flex item to shrink below content size */
        overflow-y: auto; /* Enable scrolling at main-content level on mobile */
        overflow-x: hidden; /* Prevent horizontal scrolling */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS/Android */
    }

    /* Add padding-bottom to main-content when footer is visible on mobile
    body.has-footer .main-content {
        padding-bottom: 4.375rem;
    } */

    /* When both footer and progress bar are present on mobile */
    body.has-footer.has-progress .main-content {
        padding-bottom: 8.5625rem; /* Account for both footer and progress bar on mobile */
        margin-top: 0.5rem;
    }

    .main-content .card {
        padding: calc(var(--bs-spacer) * 0.5);
    }

    .footer-btn {
        min-width: auto; /* Allow buttons to shrink on mobile */
        max-width: 100%; /* Prevent overflow */
        flex: 1 1 auto; /* Allow flexible sizing */
        font-size: calc(var(--bs-font-size-base, 1rem) * 0.9);
        padding: calc(var(--bs-spacer) * 0.5) calc(var(--bs-spacer) * 0.75);
    }

    .body-content {
        padding: calc(var(--bs-spacer) * 0.8);
        overflow: visible; /* No scrolling - parent main-content handles scrolling */
        min-width: 0; /* Allow flex item to shrink */
        max-width: 100%; /* Prevent overflow */
    }

    /* Ensure story content doesn't overflow */
    #storyContent {
        min-width: 0;
        max-width: 100%;
        overflow-x: hidden; /* Prevent horizontal overflow */
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .container-fluid {
        padding: 0 0.5rem; /* Minimum 8px padding for Android */
        overflow-x: visible; /* Allow content to extend when needed */
    }

    /* Ensure main content doesn't clip on mobile */
    .main-content .card {
        overflow-x: visible;
        max-width: 100%;
    }

    /* Mobile responsive modal - Bootstrap handles most of this, keep only custom overrides */
    .modal-custom .modal-header {
        padding: var(--bs-spacer);
    }
}

/* ============================================
   Very Small Mobile Devices (320px - 480px)
   ============================================ */

@media (max-width: 480px) {
    /* Further reduce footer button size for very small screens */
    .footer-btn {
        min-width: auto;
        padding: calc(var(--bs-spacer) * 0.4) calc(var(--bs-spacer) * 0.8);
        font-size: calc(var(--bs-font-size-base, 1rem) * 0.85);
    }

    /* Ensure fixed elements don't cause horizontal overflow */
    .navbar.fixed-top,
    footer.fixed-bottom,
    .progress-container-fixed,
    .loading-overlay {
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100vw; /* Prevent overflow */
    }

    /* Reduce container padding on very small screens */
    .container-fluid {
        padding: 0 0.25rem; /* Minimum 4px padding */
    }

    .body-content {
        padding: calc(var(--bs-spacer) * 0.8);
    }
}

/* ============================================
   Utility Overrides
   ============================================ */

.row > * {
    margin-top: unset !important;
}


.fluid-focus {
    padding: 0;
}

.fluid-focus .card-focus {
    padding: 0;
}

.logo-img{
    height: auto;
    max-width: 140px;
}