/* ==========================================================================
   BillEase Design System — 3. Layout
   One authenticated shell for every page:
     mobile  : top app bar · content · bottom navigation
     desktop : left navigation rail · top app bar · content
   ========================================================================== */

.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
}

.app-main {
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ---- Top app bar ------------------------------------------------------ */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: calc(var(--topbar-h) + var(--safe-top));
    padding: var(--safe-top) var(--sp-2) 0 var(--sp-2);
    background: rgba(244, 246, 251, 0.9);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid transparent;
    transition: border-color var(--dur-base) var(--ease-standard), box-shadow var(--dur-base) var(--ease-standard);
}

.app-topbar.is-scrolled {
    border-bottom-color: var(--app-border);
    box-shadow: var(--shadow-soft);
}

.app-topbar-title {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 var(--sp-1);
}

.app-topbar-title h1 {
    font-size: 19px;
    font-weight: 750;
    line-height: 1.2;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.app-topbar-title small {
    color: var(--app-text-muted);
    font-size: var(--fs-caption);
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.app-topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    flex: none;
}

.app-topbar .icon-btn {
    background: transparent;
    border-color: transparent;
}

.app-topbar .icon-btn:hover {
    background: var(--app-surface-sunken);
}

.app-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--r-full);
    display: inline-grid;
    place-items: center;
    background: var(--app-primary-container);
    color: var(--app-on-primary-container);
    font-weight: 800;
    font-size: 15px;
    overflow: hidden;
    flex: none;
}

.app-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--app-surface);
}

.app-avatar-link {
    display: inline-grid;
    place-items: center;
    min-width: var(--tap);
    min-height: var(--tap);
    border-radius: var(--r-full);
}

/* ---- Content ---------------------------------------------------------- */
.main-content,
.app-content {
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--sp-2) var(--page-pad) calc(var(--bottom-nav-h) + var(--safe-bottom) + var(--sp-8));
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    flex: 1 0 auto;
}

.app-content--form { max-width: var(--content-form-max); }
.app-content--narrow { max-width: var(--content-narrow-max); }
.app-content--wide { max-width: 1400px; }

.app-content > * {
    margin-top: 0;
    margin-bottom: 0;
}

/* Page header inside content (greeting, hero titles) */
.page-intro {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--sp-3);
    padding-top: var(--sp-1);
}

.page-intro h2 {
    font-size: var(--fs-title);
    font-weight: 800;
}

.page-intro p {
    margin: var(--sp-1) 0 0;
    color: var(--app-text-muted);
    font-size: var(--fs-body-sm);
}

/* ---- Bottom navigation ------------------------------------------------- */
.app-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(var(--nav-count, 5), minmax(0, 1fr));
    align-items: stretch;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding: 6px var(--sp-2) calc(6px + var(--safe-bottom));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--app-border);
    box-shadow: 0 -4px 18px rgba(16, 24, 40, 0.05);
}

.app-bottom-nav a {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: var(--tap);
    color: var(--app-text-muted);
    font-size: 11.5px;
    font-weight: 650;
    letter-spacing: 0.01em;
    text-decoration: none;
    border-radius: var(--r-sm);
    transition: color var(--dur-fast) var(--ease-standard);
}

.app-bottom-nav .nav-ind {
    display: grid;
    place-items: center;
    width: 56px;
    height: 30px;
    border-radius: var(--r-full);
    transition: background-color var(--dur-base) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
}

.app-bottom-nav .nav-ind svg {
    width: 22px;
    height: 22px;
}

.app-bottom-nav a.active {
    color: var(--app-on-primary-container);
}

.app-bottom-nav a.active .nav-ind {
    background: var(--app-primary-container);
    color: var(--app-primary);
}

.app-bottom-nav a:active .nav-ind {
    transform: scale(0.94);
}

/* Central Bill action: tonal-filled, slightly raised — not oversized. */
.app-bottom-nav .nav-bill .nav-ind {
    width: 52px;
    height: 40px;
    margin-top: -8px;
    border-radius: 16px;
    background: var(--app-primary);
    color: var(--app-on-primary);
    box-shadow: 0 6px 16px rgba(var(--app-primary-rgb), 0.32);
}

.app-bottom-nav .nav-bill {
    color: var(--app-text);
}

.app-bottom-nav .nav-bill.active .nav-ind {
    background: var(--app-primary-hover);
    color: var(--app-on-primary);
}

.nav-badge {
    position: absolute;
    top: 2px;
    left: calc(50% + 8px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--r-full);
    background: var(--app-error);
    color: #fff;
    font-size: 10.5px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--app-surface);
}

/* ---- Desktop navigation rail ------------------------------------------ */
.app-sidebar {
    display: none;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-5) var(--sp-4);
    color: var(--app-text);
}

.sidebar-brand .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--app-primary);
    color: var(--app-on-primary);
    font-weight: 800;
    overflow: hidden;
    flex: none;
}

.sidebar-brand .brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--app-surface);
}

.sidebar-brand b {
    display: block;
    font-size: 15px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-brand small {
    color: var(--app-text-muted);
    font-size: var(--fs-caption);
    font-weight: 600;
}

.sidebar-cta {
    margin: 0 var(--sp-4) var(--sp-3);
}

.sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0 var(--sp-3) var(--sp-5);
    scrollbar-width: thin;
}

.sidebar-group + .sidebar-group {
    margin-top: var(--sp-3);
}

.sidebar-group > span {
    display: block;
    padding: var(--sp-2) var(--sp-3) var(--sp-1);
    color: var(--app-text-subtle);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-height: 40px;
    padding: 0 var(--sp-3);
    border-radius: var(--r-full);
    color: var(--app-text-muted);
    font-size: var(--fs-body-sm);
    font-weight: 600;
    transition: background-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}

.sidebar-nav a svg {
    width: 19px;
    height: 19px;
    flex: none;
}

.sidebar-nav a:hover {
    background: var(--app-surface-variant);
    color: var(--app-text);
}

.sidebar-nav a.active {
    background: var(--app-primary-container);
    color: var(--app-on-primary-container);
}

.sidebar-nav a.active svg {
    color: var(--app-primary);
}

.sidebar-nav a .nav-count {
    margin-left: auto;
    min-width: 22px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--r-full);
    background: var(--app-error);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 20px;
    text-align: center;
}

@media (min-width: 1024px) {
    .app-shell {
        display: grid;
        grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    }

    .app-sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        background: var(--app-surface);
        border-right: 1px solid var(--app-border);
    }

    .app-bottom-nav {
        display: none;
    }

    .app-topbar {
        padding: 0 var(--sp-6);
        min-height: 68px;
    }

    .app-topbar-title h1 {
        font-size: var(--fs-title);
    }

    .app-topbar .topbar-menu-btn {
        display: none;
    }

    .main-content,
    .app-content {
        --page-pad: 28px;
        padding-top: var(--sp-3);
        padding-bottom: var(--sp-8);
        gap: var(--sp-5);
    }
}

@media (min-width: 768px) and (max-width: 1023.98px) {
    .main-content,
    .app-content {
        --page-pad: 24px;
    }

    .app-bottom-nav {
        left: 50%;
        right: auto;
        width: min(560px, calc(100% - 32px));
        transform: translateX(-50%);
        bottom: calc(12px + var(--safe-bottom));
        height: var(--bottom-nav-h);
        padding-bottom: 6px;
        border: 1px solid var(--app-border);
        border-radius: var(--r-lg);
        box-shadow: var(--shadow-floating);
    }
}

@media (max-width: 359.98px) {
    :root {
        --page-pad: 12px;
    }

    .app-bottom-nav .nav-ind {
        width: 48px;
    }

    .app-bottom-nav a {
        font-size: 10.5px;
    }
}

/* Public (unauthenticated) shell: auth, storefront, customer pages */
.public-shell {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--app-background);
}

@media print {
    .app-sidebar,
    .app-topbar,
    .app-bottom-nav,
    .toast-region,
    .sheet-layer {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .main-content,
    .app-content {
        max-width: none;
        padding: 0;
    }

    body {
        background: #fff;
    }
}
