/*
 * GPS platform theme layer on top of Tabler 1.6.1 (vendor/tabler, MIT).
 *
 * Every page loads, in this order:
 *   vendor/tabler/css/tabler.min.css, vendor/tabler/css/tabler-themes.min.css,
 *   vendor/tabler-icons/tabler-icons.min.css, css/app.css
 * and sets <html lang="en" data-bs-theme="dark" data-bs-theme-base="slate"> (Tabler's
 * slate greys are the navy palette the Java pages used: #0f172a, #1e293b, #334155).
 *
 * - Colour tokens (--app-*) map onto Tabler's theme variables. Page CSS uses these
 *   instead of hex values, so the pages follow the theme.
 * - The shell (sidebar + top bar) is drawn by common-header.js; its classes start with ch-.
 * - Breakpoints follow Bootstrap: sm 576, md 768, lg 992 (sidebar docks), xl 1200.
 */

:root,
[data-bs-theme] {
    --ch-sidebar-w: 15rem;
    --ch-topbar-h: 56px;

    --app-bg: var(--tblr-body-bg);
    --app-surface: var(--tblr-bg-surface);
    --app-surface-2: var(--tblr-bg-surface-secondary);
    --app-surface-3: var(--tblr-bg-surface-tertiary);
    --app-border: var(--tblr-border-color);
    --app-border-strong: var(--tblr-border-color-translucent);
    --app-text: var(--tblr-body-color);
    --app-text-muted: var(--tblr-secondary);
    --app-text-dim: var(--tblr-tertiary, var(--tblr-secondary));
    --app-primary: var(--tblr-primary);
    --app-primary-soft: rgba(var(--tblr-primary-rgb), .14);
    --app-success: var(--tblr-success);
    --app-warning: var(--tblr-warning);
    --app-danger: var(--tblr-danger);
    --app-info: var(--tblr-info);
    --app-radius: var(--tblr-border-radius);
    --app-shadow: var(--tblr-box-shadow);
    --app-font: var(--tblr-font-sans-serif);
    --app-font-mono: var(--tblr-font-monospace);
}

body {
    font-family: var(--app-font);
    background: var(--app-bg);
    color: var(--app-text);
}

/* ------------------------------------------------------------------ layout */

/* Docked sidebar from lg up: the whole page moves right by its width. */
@media (min-width: 992px) {
    body.ch-layout {
        padding-left: var(--ch-sidebar-w);
    }
}

/* ------------------------------------------------------------------ sidebar */

.ch-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--ch-sidebar-w);
    z-index: 1045;
    display: flex;
    flex-direction: column;
    background: var(--app-surface);
    border-right: 1px solid var(--app-border);
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: transform .2s ease;
}

.ch-sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    height: var(--ch-topbar-h);
    min-height: var(--ch-topbar-h);
    padding: 0 1rem;
    border-bottom: 1px solid var(--app-border);
    color: var(--app-text);
    font-weight: 600;
    font-size: .95rem;
    text-decoration: none;
    white-space: nowrap;
}

.ch-sidebar-brand:hover {
    color: var(--app-text);
    text-decoration: none;
}

.ch-sidebar-brand .ch-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--app-radius);
    background: var(--app-primary);
    color: #fff;
    font-size: 1.15rem;
}

.ch-sidebar-close {
    display: none;
    margin-left: auto;
}

.ch-menu {
    list-style: none;
    margin: 0;
    padding: .5rem .5rem 1rem;
}

.ch-menu-title {
    padding: 1rem .75rem .35rem;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--app-text-muted);
}

.ch-menu a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .5rem .75rem;
    margin: 1px 0;
    border-radius: var(--app-radius);
    color: var(--app-text-muted);
    font-size: .875rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

.ch-menu a .ti {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
}

.ch-menu a:hover {
    background: var(--app-surface-2);
    color: var(--app-text);
}

.ch-menu a.active {
    background: var(--app-primary-soft);
    color: var(--app-primary);
}

.ch-menu .ch-admin-only {
    display: none;
}

body.ch-is-admin .ch-menu .ch-admin-only {
    display: block;
}

.ch-sidebar-foot {
    margin-top: auto;
    padding: .75rem 1rem;
    border-top: 1px solid var(--app-border);
    font-size: .75rem;
    color: var(--app-text-muted);
}

.ch-backdrop {
    display: none;
}

/* Off-canvas below lg: hidden to the left, opened by the menu button. */
@media (max-width: 991.98px) {
    .ch-sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    body.ch-sidebar-open .ch-sidebar {
        transform: none;
        box-shadow: 0 0 40px rgba(0, 0, 0, .45);
    }

    body.ch-sidebar-open .ch-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1040;
        background: rgba(0, 0, 0, .5);
    }

    body.ch-sidebar-open {
        overflow: hidden;
    }

    .ch-sidebar-close {
        display: inline-flex;
    }
}

/* ------------------------------------------------------------------ top bar */

/* #common-header often sits in a page's own flex/grid header row: let it take the row. */
#common-header {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
}

.ch-topbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    height: var(--ch-topbar-h);
    min-height: var(--ch-topbar-h);
    padding: 0 1rem;
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    min-width: 0;
}

.ch-menu-btn {
    display: none;
}

@media (max-width: 991.98px) {
    .ch-menu-btn {
        display: inline-flex;
    }
}

.ch-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--app-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.ch-right {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-left: auto;
    min-width: 0;
}

/* Page-specific controls (dashboard: mode badge, counters, bell, settings). They
   scroll sideways on narrow screens instead of wrapping the bar onto two rows. */
.ch-extra {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.ch-extra::-webkit-scrollbar {
    display: none;
}

.ch-vendor-filter {
    width: auto;
    max-width: 12rem;
}

.ch-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--app-text-muted);
    font-size: .8125rem;
    white-space: nowrap;
}

.ch-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--app-primary-soft);
    color: var(--app-primary);
    font-weight: 600;
    font-size: .8rem;
    flex: none;
}

@media (max-width: 767.98px) {
    .ch-topbar {
        padding: 0 .5rem;
        gap: .4rem;
    }

    #userInfo,
    .ch-logout-label {
        display: none;
    }

    .ch-vendor-filter {
        max-width: 8rem;
    }
}

@media (max-width: 575.98px) {
    .ch-title {
        display: none;
    }

    /* Tabler keeps phone form text at 16px (no zoom on focus); give the select room for
       'All Vendors' now that the title is hidden */
    .ch-vendor-filter {
        max-width: 9.5rem;
    }
}

/* ------------------------------------------------------------------ shared helpers */

/* Wide tables scroll inside their box instead of widening the page. */
.app-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Stack a multi-column page layout below lg. */
@media (max-width: 991.98px) {
    .app-stack-lg {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
    }
}

/* Session expiry dialog (common-header.js) */
.ch-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, .6);
}

.ch-modal-box {
    width: 100%;
    max-width: 24rem;
    padding: 1.75rem 2rem;
    text-align: center;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--tblr-border-radius-lg, 8px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.ch-modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    margin: 0 auto 1rem;
    border-radius: 50%;
    background: rgba(var(--tblr-warning-rgb), .15);
    color: var(--app-warning);
    font-size: 1.5rem;
}
