/*
 * PURPOSE: App Shell and Global Navigation styles.
 * RESPONSIBILITY: Layout for header, sidebar, bottom navigation, drawers, and generic modals.
 * WHAT MUST NOT BE PUT HERE: Component styles (buttons/cards), module layouts, dashboard layout.
 */

/* --- APP SHELL LAYOUT (MOBILE FIRST) --- */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background-color: var(--color-surface-white);
    border-bottom: 1px solid var(--color-border-light);
    flex-shrink: 0;
    z-index: 10;
}

.header-brand {
    font-family: var(--font-heading);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-lg);
    color: var(--color-primary);
}

.header-progress-placeholder {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    display: none; /* Hidden on small screens */
}

.settings-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--space-xs);
    color: var(--color-text-main);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}

.settings-btn:hover {
    background-color: var(--color-surface-light);
}

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.app-sidebar {
    display: none; /* Hidden on mobile */
}

.app-main {
    flex: 1;
    overflow-y: auto;
    background-color: var(--color-bg-base);
    padding-bottom: 80px; /* Safe space for mobile bottom nav */
}

.app-main:focus:not(:focus-visible) {
    outline: none; /* Prevent visible outline on programmatic focus after route change */
}

/* --- MOBILE BOTTOM NAVIGATION --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: var(--color-surface-white);
    border-top: 1px solid var(--color-border-light);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: var(--space-xs) 0;
    z-index: 20;
    padding-bottom: calc(var(--space-xs) + env(safe-area-inset-bottom, 0px));
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    transition: color 0.2s ease;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: var(--font-body);
    min-width: 44px;
    min-height: 44px;
}

.bottom-nav-item svg {
    margin-bottom: 4px;
}

.bottom-nav-item[aria-current="page"],
.bottom-nav-item.active {
    color: var(--color-action);
}

.bottom-nav-item:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

/* --- NAVIGATION MENU ITEMS (Sidebar & Drawer) --- */
.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    text-decoration: none;
    color: var(--color-text-main);
    font-weight: var(--font-weight-medium);
    border-radius: var(--radius-sm);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.nav-link:hover {
    background-color: var(--color-surface-light);
}

.nav-link[aria-current="page"] {
    background-color: var(--color-brand-soft-pink);
    color: var(--color-action);
    font-weight: var(--font-weight-semibold);
    border-left: 4px solid var(--color-action);
}

.nav-separator {
    height: 1px;
    background-color: var(--color-border-light);
    margin: var(--space-md) 0;
}

/* --- DRAWER (MOBILE) --- */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: rgba(38, 50, 56, 0.5);
    z-index: 30;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.drawer-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.module-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;.module-drawer
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    background-color: var(--color-surface-white);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-modal);
}

.module-drawer.is-open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border-light);
}

.drawer-title {
    margin: 0;
    font-size: var(--font-size-lg);
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-main);
    min-width: 44px;
    min-height: 44px;
}

.icon-btn:hover {
    background-color: var(--color-surface-light);
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

/* --- GENERIC MODAL (SETTINGS & MESSAGES) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: rgba(38, 50, 56, 0.5);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--color-surface-white);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.2s ease;
}

.modal-overlay.is-open .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border-light);
}

.modal-title {
    margin: 0;
    font-size: var(--font-size-lg);
}

.modal-body {
    padding: var(--space-lg);
}

.modal-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* --- SETTINGS & RESET MODAL SPECIFICS --- */
.settings-storage-note {
    font-size: var(--font-size-xs);
    margin-top: var(--space-xs);
}

.settings-reset-section {
    margin-top: var(--space-md);
}

.settings-reset-button {
    width: 100%;
    color: var(--color-status-danger);
    border-color: var(--color-status-danger);
    background-color: transparent;
}

.settings-reset-button:hover:not(:disabled) {
    background-color: var(--color-status-danger-bg);
    border-color: var(--color-status-danger);
}

.reset-dialog-title {
    color: var(--color-status-danger);
}

.reset-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.reset-danger-action {
    color: var(--color-status-danger);
    border-color: var(--color-status-danger);
    background-color: transparent;
}

.reset-danger-action:hover:not(:disabled) {
    background-color: var(--color-status-danger-bg);
    border-color: var(--color-status-danger);
}

/* --- ROUTE PLACEHOLDERS --- */
.route-empty-state {
    min-height: 50vh;
}

.route-empty-state .card {
    text-align: center;
}

/* --- DESKTOP LAYOUT --- */
@media (min-width: 1024px) {
    .app-sidebar {
        display: block;
        width: 280px;
        background-color: var(--color-surface-white);
        border-right: 1px solid var(--color-border-light);
        overflow-y: auto;
        padding: var(--space-md);
        flex-shrink: 0;
    }

    .bottom-nav {
        display: none;
    }

    .app-main {
        padding-bottom: 0; /* Remove mobile safe space */
    }

    .header-progress-placeholder {
        display: block;
    }
}

/* =========================================================
   FREE MULA — iOS Safari scroll stability
   Avoid nested 100dvh scrolling which can create a temporary
   blank/dead area above the fixed bottom navigation when the
   Safari browser chrome expands/collapses.
   ========================================================= */
@media (max-width: 767px) {
    @supports (-webkit-touch-callout: none) {
        html,
        body {
            min-height: 100%;
            height: auto;
        }

        .app-layout {
            height: auto;
            min-height: 100svh;
            min-height: 100dvh;
            overflow: visible;
        }

        .app-body {
            flex: none;
            min-height: 0;
            overflow: visible;
        }

        .app-main {
            overflow-y: visible;
            min-height: 0;
            padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
        }
    }
}
