/* ============================================================================
   layout.css — Page shell, sidebar, header, page wrappers, grid scaffolding.
   ============================================================================ */

/* ─── APP SHELL ───────────────────────────────────────────────────────── */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
    background: var(--surface-0);
}

.app-shell__sidebar {
    background: var(--surface-1);
    border-right: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    z-index: var(--z-sticky);
}

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

/* Mobile: sidebar becomes a drawer + bottom-tab bar replaces nav */
@media (max-width: 1023px) {
    .app-shell { grid-template-columns: 1fr; }
    .app-shell__sidebar {
        position: fixed;
        top: 0; left: 0;
        width: min(280px, 80vw);
        transform: translateX(-100%);
        transition: transform var(--motion-base);
        z-index: var(--z-drawer);
        box-shadow: var(--shadow-xl);
    }
    .app-shell[data-drawer-open='true'] .app-shell__sidebar { transform: translateX(0); }
    .app-shell[data-drawer-open='true']::after {
        content: '';
        position: fixed; inset: 0;
        background: var(--surface-overlay);
        backdrop-filter: blur(4px);
        z-index: calc(var(--z-drawer) - 1);
        animation: fade-in var(--motion-base);
    }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ─── SIDEBAR ─────────────────────────────────────────────────────────── */

.sidebar {
    padding: var(--sp-5) var(--sp-4);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar__brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-2);
    padding: 0 var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--sp-4);
}
.sidebar__brand img { height: 28px; width: auto; opacity: 0.92; }
.sidebar__brand-meta {
    display: block;
    font-family: var(--font-body);
    font-weight: var(--fw-regular);
    font-size: 0.7rem;
    color: var(--text-tertiary);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.sidebar__nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar__section {
    margin-top: var(--sp-4);
}
.sidebar__section-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    padding: 0 var(--sp-3) var(--sp-2);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-3);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    line-height: 1.2;
    transition: background var(--motion-fast), color var(--motion-fast);
    position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item .bi {
    font-size: 18px;
    flex-shrink: 0;
    opacity: 0.85;
}
.nav-item__badge {
    margin-left: auto;
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    padding: 1px 6px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    color: var(--text-on-accent);
    line-height: 1.4;
    min-width: 18px;
    text-align: center;
}

.nav-item--active {
    background: var(--surface-2);
    color: var(--text-primary);
}
.nav-item--active::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 8px; bottom: 8px;
    width: 3px;
    border-radius: var(--radius-pill);
    background: var(--accent);
    box-shadow: 0 0 8px rgba(230, 92, 0, 0.5);
}

.sidebar__footer {
    margin-top: var(--sp-5);
    padding-top: var(--sp-4);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}
.sidebar__user-name {
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text-primary);
    line-height: 1.2;
}
.sidebar__user-meta {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    line-height: 1.4;
    margin-top: 2px;
}
.sidebar__logout {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: var(--text-tertiary);
    padding: var(--sp-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--motion-fast), color var(--motion-fast);
}
.sidebar__logout:hover { color: var(--text-primary); background: var(--surface-2); }

/* ─── HEADER ──────────────────────────────────────────────────────────── */

.app-header {
    height: var(--header-h);
    padding: 0 var(--sp-6);
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(11, 11, 12, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
}

.app-header__menu-btn {
    display: none;
    background: transparent;
    border: 0;
    color: var(--text-primary);
    width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}
.app-header__menu-btn:hover { background: var(--surface-2); }

@media (max-width: 1023px) {
    .app-header { padding: 0 var(--sp-4); }
    .app-header__menu-btn { display: inline-flex; }
}

.app-header__title {
    font-size: var(--fs-base);
    font-weight: var(--fw-medium);
    color: var(--text-primary);
}
.app-header__crumb {
    color: var(--text-tertiary);
    font-size: var(--fs-sm);
}

.app-header__right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

/* ─── PAGE ──────────────────────────────────────────────────────────── */

.page {
    padding: var(--sp-6) var(--sp-6);
    max-width: var(--container);
    margin: 0 auto;
    width: 100%;
    flex: 1;
}
.page--narrow { max-width: var(--container-narrow); }
.page--wide   { max-width: min(1600px, 96vw); }

@media (max-width: 768px) {
    .page { padding: var(--sp-5) var(--sp-4); }
}

/* Mobile bottom tab bar — used by client portal on small screens */
@media (max-width: 768px) {
    .app-shell__main { padding-bottom: var(--bottom-tab-h); }
}

.bottom-tabs {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bottom-tab-h);
    background: rgba(11, 11, 12, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-subtle);
    z-index: var(--z-sticky);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-tabs__inner {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: 100%;
}
.bottom-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-tertiary);
    font-size: 10px;
    font-weight: var(--fw-medium);
    text-decoration: none;
    transition: color var(--motion-fast);
}
.bottom-tab .bi { font-size: 22px; line-height: 1; }
.bottom-tab--active { color: var(--accent-text); }
.bottom-tab--active .bi { filter: drop-shadow(0 0 6px var(--accent-soft)); }

@media (max-width: 768px) {
    .bottom-tabs { display: block; }
}

/* ─── GRID HELPERS ────────────────────────────────────────────────────── */

.grid           { display: grid; gap: var(--sp-5); }
.grid--2        { grid-template-columns: repeat(2, 1fr); }
.grid--3        { grid-template-columns: repeat(3, 1fr); }
.grid--4        { grid-template-columns: repeat(4, 1fr); }
.grid--auto     { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

@media (max-width: 1023px) {
    .grid--3, .grid--4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
}

.stack          { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack--sm      { gap: var(--sp-2); }
.stack--lg      { gap: var(--sp-6); }
.row            { display: flex; align-items: center; gap: var(--sp-3); }
.row--between   { justify-content: space-between; }
.row--end       { justify-content: flex-end; }
.row--wrap      { flex-wrap: wrap; }

.spacer         { flex: 1; }

/* ─── PAGE HEADER ─────────────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--sp-4);
    margin-bottom: var(--sp-6);
    flex-wrap: wrap;
}
.page-header__title {
    font-family: var(--font-display);
    font-size: var(--fs-3xl);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    letter-spacing: var(--tracking-tight);
    line-height: 1.1;
    margin: 0;
}
.page-header__eyebrow {
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    color: var(--text-tertiary);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--sp-2);
}
.page-header__subtitle {
    color: var(--text-secondary);
    margin-top: var(--sp-2);
    font-size: var(--fs-base);
    line-height: var(--lh-body);
    max-width: 60ch;
}
.page-header__actions {
    display: flex;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

/* ─── AUTH LAYOUT (no sidebar) ────────────────────────────────────────── */

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
    background:
        radial-gradient(ellipse 70% 50% at 70% 0%,  rgba(230, 92, 0, 0.10), transparent 60%),
        radial-gradient(ellipse 60% 45% at 20% 90%, rgba(110, 168, 255, 0.05), transparent 60%),
        var(--surface-0);
}

.auth-shell__inner {
    margin: auto;
    width: 100%;
    max-width: 460px;
    padding: var(--sp-7) var(--sp-5);
}

.auth-card {
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--sp-7);
    box-shadow: var(--shadow-xl);
}
@media (max-width: 480px) {
    .auth-card { padding: var(--sp-5); border-radius: var(--radius-lg); }
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3);
    margin-bottom: var(--sp-6);
    text-align: center;
}
.auth-brand img { height: 36px; width: auto; }
.auth-brand__tag {
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    color: var(--text-tertiary);
    font-weight: var(--fw-semibold);
}

.auth-card__title {
    font-family: var(--font-display);
    font-size: var(--fs-2xl);
    font-weight: var(--fw-semibold);
    text-align: center;
    margin-bottom: var(--sp-2);
}
.auth-card__subtitle {
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: var(--sp-6);
    font-size: var(--fs-sm);
}

/* Margin/padding helpers (use sparingly) */
.mt-0 { margin-top: 0 !important; }
.mt-2 { margin-top: var(--sp-2) !important; }
.mt-3 { margin-top: var(--sp-3) !important; }
.mt-4 { margin-top: var(--sp-4) !important; }
.mt-5 { margin-top: var(--sp-5) !important; }
.mt-6 { margin-top: var(--sp-6) !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--sp-2) !important; }
.mb-3 { margin-bottom: var(--sp-3) !important; }
.mb-4 { margin-bottom: var(--sp-4) !important; }
.mb-5 { margin-bottom: var(--sp-5) !important; }
.mb-6 { margin-bottom: var(--sp-6) !important; }
.text-center { text-align: center; }
.w-full { width: 100%; }
