/* ========================================
   APP LAYOUT CHROME
   Styles moved out of the always-mounted layout components (MainLayout, NavMenu, PageTransitionWrapper,
   NavigationLoadingOverlay, ToastDismissAll, NotificationDisplay).
   ======================================== */

/* ---------- Layout/ToastDismissAll.razor ---------- */
.lbsa-toast-dismiss-all {
    position: fixed;
    top: 14px;
    right: 24px;
    z-index: calc(var(--z-toast) + 1);
    pointer-events: auto;
}

.lbsa-toast-dismiss-all-button {
    min-height: 30px;
    padding: 5px 11px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    background: rgba(31, 41, 55, 0.94);
    color: #fff;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.24);
    cursor: pointer;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1;
}

.lbsa-toast-dismiss-all-button:hover,
.lbsa-toast-dismiss-all-button:focus-visible {
    background: #111827;
    outline: 2px solid rgba(96, 165, 250, 0.9);
    outline-offset: 2px;
}

.lbsa-toast-dismiss-all ~ #mud-snackbar-container {
    top: 58px !important;
}

.lbsa-mud-toast-clickable {
    cursor: pointer;
}

.lbsa-assistance-request-toast {
    position: fixed !important;
    right: 20px;
    bottom: 20px;
    width: min(400px, calc(100vw - 32px));
    z-index: var(--z-toast);
}

@media (max-width: 600px) {
    .lbsa-assistance-request-toast {
        right: 16px;
        bottom: 16px;
    }

    .lbsa-toast-dismiss-all {
        top: 10px;
        right: 16px;
    }

    .lbsa-toast-dismiss-all ~ #mud-snackbar-container {
        top: 52px !important;
    }
}

/* ---------- Layout/NavMenu.razor ---------- */
.nav-menu {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--lbsa-bg-secondary);
}

.nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--lbsa-border-color);
}

.nav-header h3 {
    color: var(--color-primary); /* Teal theme color */
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-header h3 i {
    color: var(--color-primary);
}

.nav-close-btn {
    background: transparent;
    border: 1px solid rgba(var(--color-primary-rgb), 0.3);
    color: var(--color-primary);
    padding: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.nav-close-btn:hover {
    background: rgba(var(--color-primary-rgb), 0.1);
    border-color: rgba(var(--color-primary-rgb), 0.5);
}

.nav-close-btn i {
    font-size: 1.25rem;
}

.nav-section {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--lbsa-text-muted);
    text-transform: uppercase;
    margin-top: 1rem;
    border-top: 1px solid var(--lbsa-border-color);
    padding-top: 1rem;
}

.nav-section:first-of-type {
    margin-top: 0.5rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-top: 1px solid var(--lbsa-border-color);
    cursor: pointer;
    transition: background-color 0.2s ease;
    position: relative;
}

.user-info:hover {
    background-color: rgba(var(--color-primary-rgb), 0.1);
}

.profile-arrow {
    margin-left: auto;
    font-size: 0.875rem;
    color: var(--lbsa-text-muted);
    transition: transform 0.2s ease;
}

.user-info:hover .profile-arrow {
    transform: translateX(2px);
    color: var(--lbsa-primary);
}

.user-info i {
    font-size: 1.5rem;
    color: var(--lbsa-primary);
}

.user-name {
    font-weight: 500;
    color: var(--lbsa-text-primary);
    font-size: 0.875rem;
}

.user-org {
    font-size: 0.75rem;
    color: var(--lbsa-text-secondary);
}

.logout-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--lbsa-danger);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 500;
    transition: background 0.2s ease;
}

.logout-btn:hover {
    background: #d32f2f;
}

.nav-item .badge {
    margin-left: auto;
    font-size: 0.625rem;
    padding: 0.125rem 0.375rem;
}

/* ---------- Shared/PageTransitionWrapper.razor ---------- */
.page-transition-wrapper {
    position: relative;
    width: 100%;
    min-height: 100%;
    max-width: 100%;
    overflow-x: clip;
    /* No fixed height - allow content to grow and scroll */
}

.page-content {
    width: 100%;
    min-height: 100%;
    max-width: 100%;
    transform-origin: center;
    backface-visibility: hidden;
    /* No fixed height - allow content to grow and scroll */
}

/* Initial state */
.page-preparing {
    opacity: 0;
    transform: translate3d(14px, 0, 0);
    will-change: transform, opacity;
}

/* Visible state - explicitly no transform to avoid creating containing block for fixed elements */
.page-visible {
    opacity: 1;
    transform: none !important; /* Must override animation fill states */
    will-change: auto !important; /* Reset will-change */
}

/* Initial load animation */
.page-initial-load {
    animation: initialLoad 0.26s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes initialLoad {
    from {
        opacity: 0;
        transform: translate3d(0, 10px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

/* Slide in from right (forward navigation) */
.page-slide-in-right {
    animation: slideInRight 0.24s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideInRight {
    from {
        transform: translate3d(18px, 0, 0);
        opacity: 0;
    }
    to {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
}

/* Slide in from left (backward navigation) */
.page-slide-in-left {
    animation: slideInLeft 0.24s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideInLeft {
    from {
        transform: translate3d(-18px, 0, 0);
        opacity: 0;
    }
    to {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
}

/* Slide out to left (forward navigation) */
.page-slide-out-left {
    animation: slideOutLeft 0.16s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes slideOutLeft {
    from {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
    to {
        transform: translate3d(-12px, 0, 0);
        opacity: 0;
    }
}

/* Slide out to right (backward navigation) */
.page-slide-out-right {
    animation: slideOutRight 0.16s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes slideOutRight {
    from {
        transform: translate3d(0, 0, 0);
        opacity: 1;
    }
    to {
        transform: translate3d(12px, 0, 0);
        opacity: 0;
    }
}

/* Fade animations for replace navigation */
.page-fade-in {
    animation: fadeIn 0.2s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.page-fade-out {
    animation: fadeOut 0.14s ease forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .page-slide-in-right,
    .page-slide-in-left {
        animation-duration: 0.2s;
    }

    .page-slide-out-left,
    .page-slide-out-right {
        animation-duration: 0.14s;
    }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .page-content {
        animation: none !important;
        transition: opacity 0.2s ease !important;
    }

    .page-slide-in-right,
    .page-slide-in-left,
    .page-slide-out-left,
    .page-slide-out-right,
    .page-fade-in,
    .page-fade-out {
        animation: none !important;
    }

    .page-preparing {
        opacity: 0;
        transform: none;
    }

    .page-visible {
        opacity: 1;
        transform: none;
    }
}

/* ---------- Shared/NavigationLoadingOverlay.razor ---------- */
.navigation-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-navigation-overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

.navigation-overlay.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.navigation-spinner-container {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    animation: slideUp 0.3s ease;
}

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

.navigation-spinner {
    display: block !important;
}

.navigation-spinner .e-spinner-pane {
    stroke: var(--color-primary) !important;
}

.loading-text {
    color: var(--color-primary);
    margin: 0;
    font-size: 1.1rem;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .navigation-overlay,
    .navigation-spinner-container {
        animation: none;
        transition: none;
    }
}

/* ---------- Layout/NotificationDisplay.razor (scoped to .notification-container; its .btn rules used to leak app-wide) ---------- */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: var(--z-toast);
    max-width: 400px;
    width: 100%;
    pointer-events: none;
}

:where(.notification-container) .notification {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    margin-bottom: 12px;
    overflow: hidden;
    position: relative;
    transition: transform 0.3s ease;
    pointer-events: auto;
    touch-action: pan-x;
    user-select: none;
}

:where(.notification-container) .notification.notification-assistance-request {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: min(400px, calc(100vw - 32px));
    margin: 0;
    z-index: 1060;
}

@media (max-width: 600px) {
    :where(.notification-container) .notification.notification-assistance-request {
        right: 16px;
        bottom: 16px;
    }
}

:where(.notification-container) .notification-progress {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: rgba(0, 0, 0, 0.1);
    z-index: 1;
}

:where(.notification-container) .notification-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
    width: 0%;
}

:where(.notification-container) .notification-close-touch {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    transition: all 0.2s ease;
}

:where(.notification-container) .notification-close-touch:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: scale(1.1);
}

:where(.notification-container) .notification-close-touch:active {
    transform: scale(0.95);
}

:where(.notification-container) .close-icon {
    font-size: 18px;
    font-weight: bold;
    color: #666;
    line-height: 1;
}

:where(.notification-container) .notification-content {
    padding: 16px 50px 16px 16px;
}

:where(.notification-container) .notification-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
    color: #333;
}

:where(.notification-container) .notification-icon {
    font-size: 18px;
}

:where(.notification-container) .notification-message {
    color: #666;
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 8px;
}

:where(.notification-container) .notification-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

:where(.notification-container) .notification-timeout-disabled {
    margin-top: 8px;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
}

:where(.notification-container) .notification-timeout-disabled small {
    color: #888;
    font-size: 12px;
}

:where(.notification-container) .swipe-hint {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

:where(.notification-container) .swipe-hint.show {
    opacity: 1;
}

/* Notification type styling */
:where(.notification-container) .notification-error {
    border-left: 4px solid #dc3545;
}

:where(.notification-container) .notification-warning {
    border-left: 4px solid #ffc107;
}

:where(.notification-container) .notification-success {
    border-left: 4px solid #28a745;
}

:where(.notification-container) .notification-info {
    border-left: 4px solid #17a2b8;
}

:where(.notification-container) .notification-critical {
    box-shadow: 0 8px 32px rgba(220, 53, 69, 0.3);
    border: 2px solid #dc3545;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .notification-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

    :where(.notification-container) .notification-close-touch {
        width: 36px;
        height: 36px;
        top: 6px;
        right: 6px;
    }

    :where(.notification-container) .close-icon {
        font-size: 20px;
    }
}

/* Button styles */
:where(.notification-container) .btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 36px;
    min-width: 36px;
}

:where(.notification-container) .btn-sm {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 28px;
}

:where(.notification-container) .btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

:where(.notification-container) .btn-primary:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

:where(.notification-container) .btn-outline {
    background: transparent;
    color: var(--color-primary);
    border-color: var(--color-primary);
}

:where(.notification-container) .btn-outline:hover {
    background: var(--color-primary);
    color: white;
}

/* ---------- Layout/MainLayout.razor ---------- */
.app-layout {
    height: 100dvh;
    min-height: 100vh;
    overflow: hidden;
}

.app-layout .app-nav-sidebar {
    z-index: var(--z-nav-drawer) !important;
    width: min(250px, 75vw) !important;
    max-width: 75vw !important;
    min-width: 0 !important;
    background: var(--lbsa-bg-primary) !important;
    border-right: 1px solid rgba(var(--color-primary-rgb), 0.22);
}

/* Only the navigation drawer's own scrim sits just below the drawer; other MudBlazor overlays keep their defaults. */
.app-layout .mud-drawer-overlay.mud-overlay-drawer {
    z-index: var(--z-nav-drawer-overlay) !important;
}

.app-main {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    overflow: hidden;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--lbsa-bg-secondary);
    border-bottom: 1px solid var(--lbsa-border-color);
    flex-shrink: 0;
    min-width: 0;
}

.app-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    width: 100%;
    min-width: 0;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.app-content--map {
    overflow: hidden !important;
    padding: 0 !important;
    scrollbar-gutter: auto !important;
    width: 100% !important;
    max-width: 100% !important;
}

.lbsa-container-fluid {
    width: 100%;
    max-width: 1720px;
    margin: 0 auto;
    padding: 1rem var(--page-gutter-desktop, 1.25rem) calc(1.5rem + env(safe-area-inset-bottom));
    min-width: 0;
}

.lbsa-container-fluid--map {
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 100%;
    overflow: hidden;
}

.app-content--map,
.app-content--map .lbsa-container-fluid--map,
.app-content--map .lbsa-container-fluid--map .page-transition-wrapper,
.app-content--map .lbsa-container-fluid--map .page-content {
    height: 100% !important;
    min-height: 0 !important;
}

.lbsa-container-fluid--map .page-transition-wrapper,
.lbsa-container-fluid--map .page-content {
    height: 100% !important;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.app-menu-button {
    border: 1px solid rgba(var(--color-primary-rgb), 0.2);
    border-radius: 6px;
    background: rgba(var(--color-primary-rgb), 0.08);
    width: 38px;
    height: 38px;
}



.header-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.app-header h2 {
    margin: 0;
    color: var(--lbsa-text-primary);
    font-size: 1.25rem;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .app-header h2 {
        font-size: 0.95rem;
    }

    .header-logo {
        height: 32px;
    }

    /* Keep consistent content gutters on mobile to avoid edge collisions */
    .app-content {
        padding: 0 !important;
        margin: 0 !important;
        scrollbar-gutter: auto !important;
    }

    .lbsa-container-fluid {
        padding: var(--page-gutter-mobile, 0.55rem) var(--page-gutter-mobile, 0.55rem) calc(1rem + env(safe-area-inset-bottom)) !important;
        margin: 0 auto !important;
    }

    .lbsa-container-fluid--map {
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Header with minimal padding */
    .app-header {
        padding: 0.65rem 0.55rem !important;
    }
}

@media (max-width: 420px) {
    .app-header h2 {
        font-size: 0.86rem;
    }

    .header-logo {
        height: 28px;
    }

    .header-left {
        gap: 0.45rem;
    }
}

/* Connection Status Overlay */
.connection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-connection-overlay);
}

.connection-content {
    text-align: center;
    color: white;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.connection-content--modal {
    width: min(92vw, 380px);
    min-height: 230px;
    background: rgba(18, 22, 27, 0.94);
    border: 1px solid rgba(var(--color-primary-rgb), 0.28);
    border-radius: 8px;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.42);
}

.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.connection-spinner {
    display: block !important;
    margin: 0 auto;
}

.connection-content h4 {
    color: var(--color-primary);
    margin: 1rem 0 0 0;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.connection-content p {
    color: rgba(255, 255, 255, 0.72);
    margin: 0.35rem 0 1.1rem;
    line-height: 1.35;
}

.connection-actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
}

.connection-actions .mud-button-root {
    width: 100%;
}

/* Forced password change uses the shared dialog shell and cannot be dismissed. */
.forced-password-change-dialog .password-change-intro {
    margin: 0 0 1.15rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.forced-password-change-dialog .password-change-field {
    margin-bottom: 1rem;
}

.forced-password-change-dialog .password-change-field label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 650;
}

.forced-password-change-dialog .password-change-error {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    margin: 0;
    padding: 0.7rem 0.8rem;
    border: 1px solid rgba(var(--color-danger-rgb), 0.34);
    border-radius: 8px;
    background: rgba(var(--color-danger-rgb), 0.1);
    color: #ff8a80;
    font-size: 0.85rem;
}

.forced-password-change-dialog .dark-input .mud-input-outlined-border {
    border-color: rgba(var(--color-primary-rgb), 0.25) !important;
}

.forced-password-change-dialog .dark-input .mud-input-slot {
    color: rgba(255, 255, 255, 0.92) !important;
    padding-left: 0.55rem !important;
}

.forced-password-change-dialog .lbsa-mobile-dialog-footer .mud-button-root {
    width: 100%;
    min-height: 44px;
}

