/* App shell: sidebar (>= lg) / off-canvas drawer + top bar + bottom tab bar (< lg).
   Markup: templates/base.html, components/navigation/sidebar.html. */

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-frame {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.app-main {
    flex: 1;
    width: 100%;
    padding-top: clamp(1.25rem, 0.8rem + 1.6vw, 2.25rem);
    padding-bottom: 3rem;
}

.app-container {
    width: 100%;
    max-width: var(--app-container-max);
    margin-inline: auto;
    padding-inline: var(--app-container-gutter);
}

/* Bootstrap's .container (standalone pages) shares the app edges. */
.container {
    max-width: var(--app-container-max);
    padding-inline: var(--app-container-gutter);
}

/* ---------- Brand ---------- */
.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    color: var(--app-text-strong);
    font-family: var(--app-font-display);
    font-size: 1.02rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-decoration: none;
}

.app-brand:hover {
    color: var(--app-text-strong);
}

.app-brand-mark {
    display: grid;
    flex: none;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.6rem;
    background: linear-gradient(145deg, #1a3a66, #0b1c33);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.app-brand-mark img {
    width: 1.45rem;
    height: 1.45rem;
}

[data-bs-theme="light"] .app-brand-mark {
    background: linear-gradient(145deg, #e8f0ff, #d6e3fb);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.14);
}

/* ---------- Sidebar ---------- */
.app-sidebar {
    --bs-offcanvas-width: min(20rem, 86vw);
    --bs-offcanvas-bg: var(--app-sidebar);
    --bs-offcanvas-border-color: var(--app-border);
    --bs-offcanvas-color: var(--app-text);
}

.app-sidebar .offcanvas-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--app-border);
}

.app-sidebar-inner {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 1.25rem;
    min-height: 0;
    padding: 1.1rem 0.85rem 0.85rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.app-sidebar-brand {
    padding: 0 0.35rem;
}

.app-sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.app-sidebar-heading {
    margin: 0 0 0.3rem;
    padding: 0 0.6rem;
    color: var(--app-subtle);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.app-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 2.25rem;
    padding: 0.4rem 0.6rem;
    border-radius: var(--app-radius-sm);
    color: var(--app-muted);
    font-weight: 550;
    text-decoration: none;
    transition: background 0.15s var(--app-ease), color 0.15s var(--app-ease);
}

.app-nav-link .app-icon {
    flex: none;
    width: 1.1rem;
    height: 1.1rem;
}

.app-nav-link > span:not(.app-pill):not(.app-nav-dot):not(.app-nav-recent-mark) {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-nav-link:hover {
    color: var(--app-text-strong);
    background: var(--app-surface-2);
}

.app-nav-link.is-active {
    color: var(--app-text-strong);
    background: var(--app-primary-soft);
}

.app-nav-link.is-active .app-icon {
    color: var(--app-primary-text);
}

.app-nav-link.is-active::before {
    position: absolute;
    top: 0.45rem;
    bottom: 0.45rem;
    left: -0.85rem;
    width: 3px;
    content: "";
    border-radius: 0 3px 3px 0;
    background: var(--app-primary);
}

.app-nav-dot {
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--app-subtle);
}

.app-nav-dot--ok { background: var(--app-ok); }
.app-nav-dot--warning { background: var(--app-warning); }
.app-nav-dot--danger { background: var(--app-danger); box-shadow: 0 0 0 3px var(--app-danger-soft); }

.app-nav-recent .app-nav-link {
    min-height: 2rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.app-nav-recent-mark {
    display: grid;
    flex: none;
    place-items: center;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 0.3rem;
    color: var(--app-muted);
    background: var(--app-surface-3);
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
}

.app-sidebar-spacer {
    flex: 1;
}

.app-sidebar-account {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.75rem;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    background: var(--app-surface);
}

.app-account-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.app-avatar {
    display: grid;
    flex: none;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(145deg, var(--app-primary), #1e3a8a);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.app-account-name {
    flex: 1;
    min-width: 0;
    line-height: 1.25;
}

.app-account-name strong {
    display: block;
    overflow: hidden;
    color: var(--app-text-strong);
    font-size: 0.875rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-account-name small {
    display: block;
    overflow: hidden;
    color: var(--app-muted);
    font-size: 0.75rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar-account form {
    margin: 0;
}

/* Theme switch: three-way segmented control (System / Hell / Dunkel). */
.app-theme-switch {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.2rem;
    padding: 0.2rem;
    border-radius: var(--app-radius-sm);
    background: var(--app-inset);
    box-shadow: inset 0 0 0 1px var(--app-border);
}

.app-theme-switch button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    height: 1.85rem;
    padding: 0;
    border: 0;
    border-radius: 0.35rem;
    color: var(--app-muted);
    background: transparent;
    font-size: 0.75rem;
    font-weight: 550;
    transition: background 0.15s var(--app-ease), color 0.15s var(--app-ease);
}

.app-theme-switch button:hover {
    color: var(--app-text-strong);
}

.app-theme-switch button[aria-pressed="true"] {
    color: var(--app-text-strong);
    background: var(--app-surface-3);
    box-shadow: var(--app-shadow-sm);
}

[data-bs-theme="light"] .app-theme-switch button[aria-pressed="true"] {
    background: #fff;
}

.app-theme-switch .app-icon {
    width: 0.95rem;
    height: 0.95rem;
}

/* ---------- Top bar (mobile + public pages) ---------- */
.app-topbar,
.navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--app-topbar-height);
    padding: 0.5rem var(--app-container-gutter);
    border-bottom: 1px solid var(--app-border);
    background: color-mix(in srgb, var(--app-bg) 86%, transparent);
    backdrop-filter: saturate(1.4) blur(14px);
}

.navbar > .app-container {
    padding-inline: 0;
}

.navbar-brand {
    color: var(--app-text-strong);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.app-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
}

.app-icon-button {
    display: inline-grid;
    flex: none;
    place-items: center;
    width: 2.35rem;
    height: 2.35rem;
    padding: 0;
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-sm);
    color: var(--app-text);
    background: var(--app-surface);
    transition: background 0.15s var(--app-ease), border-color 0.15s var(--app-ease);
}

.app-icon-button:hover {
    border-color: var(--app-border-strong);
    color: var(--app-text-strong);
    background: var(--app-surface-2);
}

.app-icon-button .app-icon {
    width: 1.15rem;
    height: 1.15rem;
}

.app-icon-button--ghost {
    border-color: transparent;
    background: transparent;
}

/* ---------- Bottom tab bar (mobile, customers) ---------- */
.app-tabbar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    display: grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    height: calc(var(--app-tabbar-height) + env(safe-area-inset-bottom, 0px));
    padding: 0.35rem 0.35rem env(safe-area-inset-bottom, 0px);
    border-top: 1px solid var(--app-border);
    background: color-mix(in srgb, var(--app-sidebar) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(14px);
}

.app-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0;
    border: 0;
    border-radius: var(--app-radius-sm);
    color: var(--app-muted);
    background: transparent;
    font-size: 0.7rem;
    font-weight: 600;
    text-decoration: none;
}

.app-tab .app-icon {
    width: 1.3rem;
    height: 1.3rem;
}

.app-tab.is-active {
    color: var(--app-primary-text);
}

.app-tab.is-active .app-icon {
    filter: drop-shadow(0 0 10px var(--app-primary-ring));
}

.app-shell--tabbar .app-main {
    padding-bottom: calc(var(--app-tabbar-height) + 2.5rem);
}

.app-shell--tabbar .app-footer {
    padding-bottom: calc(var(--app-tabbar-height) + 1rem);
}

/* ---------- Footer ---------- */
.app-footer {
    padding-block: 1.25rem;
    border-top: 1px solid var(--app-border);
    color: var(--app-muted);
    font-size: 0.8125rem;
}

.app-footer a {
    color: var(--app-muted);
    text-decoration: none;
}

.app-footer a:hover {
    color: var(--app-text-strong);
}

/* ---------- Desktop: persistent sidebar ---------- */
@media (min-width: 992px) {
    .app-shell--sidebar {
        display: grid;
        grid-template-columns: var(--app-sidebar-width) minmax(0, 1fr);
    }

    .app-sidebar-col {
        position: sticky;
        top: 0;
        height: 100vh;
        border-right: 1px solid var(--app-border);
        background: var(--app-sidebar);
    }

    .app-sidebar {
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    .app-shell--sidebar .app-topbar,
    .app-tabbar {
        display: none;
    }

    .app-shell--tabbar .app-main {
        padding-bottom: 3rem;
    }

    .app-shell--tabbar .app-footer {
        padding-bottom: 1.25rem;
    }
}
