/* ==========================================================================
   quickTAMS — Layout
   Layer 3 of 4. The application shell: sidebar, topbar, content, bottom nav.
   Written with logical properties throughout so the whole shell mirrors
   under dir="rtl" without a second stylesheet.
   ========================================================================== */

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

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    background-color: var(--surface);
    border-inline-end: 1px solid var(--border);
    transition: transform var(--dur-slow) var(--ease-out),
                width var(--dur-slow) var(--ease-out);
}

.sidebar__header {
    display: flex;
    align-items: center;
    height: var(--topbar-h);
    padding-inline: var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    min-width: 0;
    width: 100%;
    gap: var(--space-3);
    color: var(--text);
    font-weight: var(--fw-semibold);
    letter-spacing: var(--tracking-tight);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar__brand:hover { color: var(--text); }

.sidebar__nav {
    flex: 1;
    list-style: none;
    margin: 0;
    padding: var(--space-3) var(--space-3) var(--space-6);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar__section {
    padding: var(--space-5) var(--space-3) var(--space-2);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semibold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    color: var(--text-subtle);
    white-space: nowrap;
}

.sidebar__section:first-child { padding-top: var(--space-2); }

.sidebar__link {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 40px;
    padding: var(--space-2) var(--space-3);
    margin-bottom: 2px;
    border-radius: var(--r-md);
    color: var(--text-muted);
    font-size: var(--fs-base);
    font-weight: var(--fw-medium);
    white-space: nowrap;
    transition: background-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out);
}

.sidebar__link i {
    flex-shrink: 0;
    width: 20px;
    font-size: 1.05rem;
    text-align: center;
    color: var(--text-subtle);
    transition: color var(--dur-fast) var(--ease-out);
}

.sidebar__link:hover {
    background-color: var(--surface-2);
    color: var(--text);
}

.sidebar__link:hover i { color: var(--text-muted); }

.sidebar__link.is-active {
    background-color: var(--accent-soft);
    color: var(--accent-text);
    font-weight: var(--fw-semibold);
}

.sidebar__link.is-active i { color: var(--accent); }

/* A short marker rather than a full-height bar — quieter, still legible. */
.sidebar__link.is-active::before {
    content: "";
    position: absolute;
    inset-inline-start: calc(-1 * var(--space-3));
    inset-block-start: 50%;
    translate: 0 -50%;
    width: 3px;
    height: 18px;
    border-start-end-radius: var(--r-full);
    border-end-end-radius: var(--r-full);
    background-color: var(--accent);
}

.sidebar__badge {
    margin-inline-start: auto;
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semibold);
    color: var(--text-subtle);
}

.sidebar__footer {
    flex-shrink: 0;
    padding: var(--space-3);
    border-top: 1px solid var(--border-subtle);
}

/* ---- Desktop: collapse to an icon rail ---------------------------------- */
@media (min-width: 992px) {
    .app-shell.is-collapsed .sidebar { width: var(--sidebar-rail-w); }

    .app-shell.is-collapsed .sidebar__brand-text,
    .app-shell.is-collapsed .sidebar__link span,
    .app-shell.is-collapsed .sidebar__badge,
    .app-shell.is-collapsed .sidebar__footer .u-rail-hide {
        display: none;
    }

    .app-shell.is-collapsed .sidebar__header,
    .app-shell.is-collapsed .sidebar__link {
        justify-content: center;
        padding-inline: var(--space-2);
    }

    .app-shell.is-collapsed .sidebar__section {
        height: 1px;
        padding: var(--space-3) 0 0;
        margin-inline: var(--space-3);
        overflow: hidden;
        color: transparent;
        border-top: 1px solid var(--border-subtle);
    }

    .app-shell.is-collapsed .main { margin-inline-start: var(--sidebar-rail-w); }
}

/* ==========================================================================
   Main column
   ========================================================================== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-inline-start: var(--sidebar-w);
    transition: margin-inline-start var(--dur-slow) var(--ease-out);
}

.topbar {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: var(--topbar-h);
    padding-inline: var(--space-4);
    background-color: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}

@supports not (backdrop-filter: blur(1px)) {
    .topbar { background-color: var(--surface); }
}

.topbar__spacer { flex: 1; }

.topbar__title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    color: var(--text);
    letter-spacing: var(--tracking-tight);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Square, quiet icon buttons used for toggles in the topbar. */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.05rem;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out);
}

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

.icon-btn:active { background-color: var(--surface-3); }

/* The branch a user is scoped to is load-bearing information here — it
   decides which records they can even see — so it stays visible, not buried
   in the profile menu. */
.branch-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: 30px;
    padding-inline: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    background-color: var(--surface-2);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    white-space: nowrap;
}

.branch-chip__dot {
    width: 6px;
    height: 6px;
    border-radius: var(--r-full);
    background-color: var(--accent);
    flex-shrink: 0;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 38px;
    padding-inline: var(--space-2);
    border-radius: var(--r-md);
    color: var(--text);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out);
}

.user-menu:hover { background-color: var(--surface-2); color: var(--text); }
.user-menu::after { display: none; }

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: var(--r-full);
    background-color: var(--accent-soft);
    color: var(--accent-text);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    letter-spacing: 0;
    text-transform: uppercase;
}

.avatar--lg { width: 40px; height: 40px; font-size: var(--fs-base); }

/* ==========================================================================
   Content area
   ========================================================================== */
.content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin-inline: auto;
    padding: var(--space-6);
}

@media (max-width: 991.98px) {
    .content { padding: var(--space-4); }
}

@media (max-width: 767.98px) {
    .content {
        padding: var(--space-4) var(--space-3);
        /* clear the bottom nav plus the iOS home indicator */
        padding-bottom: calc(var(--bottomnav-h) + var(--space-6) + env(safe-area-inset-bottom));
    }
}

/* ==========================================================================
   Tablet & mobile: sidebar becomes an overlay drawer
   ========================================================================== */
.sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    background-color: var(--overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--dur-base) var(--ease-out),
                visibility var(--dur-base) var(--ease-out);
}

@media (max-width: 991.98px) {
    .main { margin-inline-start: 0; }

    .sidebar {
        box-shadow: var(--shadow-xl);
        transform: translateX(-100%);
    }

    [dir="rtl"] .sidebar { transform: translateX(100%); }

    .app-shell.is-drawer-open .sidebar { transform: translateX(0); }

    .app-shell.is-drawer-open .sidebar-scrim {
        opacity: 1;
        visibility: visible;
    }
}

/* ==========================================================================
   Bottom navigation — phones only
   The five destinations that carry day-to-day counter work.
   ========================================================================== */
.bottom-nav {
    display: none;
    position: fixed;
    inset-inline: 0;
    inset-block-end: 0;
    z-index: var(--z-bottomnav);
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background-color: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--border);
}

@supports not (backdrop-filter: blur(1px)) {
    .bottom-nav { background-color: var(--surface); }
}

.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    height: var(--bottomnav-h);
    padding: 0 var(--space-1);
    border: 0;
    background: transparent;
    color: var(--text-subtle);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-medium);
    text-align: center;
    transition: color var(--dur-fast) var(--ease-out);
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav__item i { font-size: 1.2rem; line-height: 1; }

.bottom-nav__item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bottom-nav__item.is-active { color: var(--accent-text); }
.bottom-nav__item:active { color: var(--accent); }

/* Centre action — the single most frequent task gets a raised affordance. */
.bottom-nav__fab {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-inline: var(--space-1);
    border: 0;
    border-radius: var(--r-lg);
    background-color: var(--accent);
    color: var(--on-accent);
    font-size: 1.35rem;
    box-shadow: var(--shadow-md);
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav__fab:hover,
.bottom-nav__fab:focus { color: var(--on-accent); }
.bottom-nav__fab:active { background-color: var(--accent-active); }

@media (max-width: 767.98px) {
    .bottom-nav { display: flex; align-items: stretch; }
}

/* ==========================================================================
   Login
   ========================================================================== */
.auth {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: var(--space-4);
    background-color: var(--canvas);
    /* A single soft accent wash — enough to feel considered, quiet enough
       to stay out of the way at 6am on a counter monitor. */
    background-image:
        radial-gradient(60rem 30rem at 50% -10%, var(--accent-soft), transparent 70%);
}

.auth__card {
    width: 100%;
    max-width: 400px;
}

.auth__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-6);
    text-align: center;
}

/* Uploaded company logo on the sign-in card — replaces the mark + app-name
   lockup, like it does in the sidebar and on printed documents. */
.auth__logo {
    display: block;
    max-height: 96px;
    max-width: 260px;
    object-fit: contain;
}

.auth__title {
    font-size: var(--fs-xl);
    font-weight: var(--fw-semibold);
    letter-spacing: var(--tracking-tight);
    margin: 0;
}

.auth__subtitle {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    margin: 0;
}

.auth__panel {
    padding: var(--space-6);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
}

.auth__footer {
    margin-top: var(--space-5);
    text-align: center;
    font-size: var(--fs-xs);
    color: var(--text-subtle);
}

@media (max-width: 575.98px) {
    .auth__panel { padding: var(--space-5) var(--space-4); }
}
