/*
 * The app frame: sidebar, top bar, the view area, the page toolbar and the layout grids views share.
 * Phone first: an off-canvas drawer under a top bar; an icon rail from 600 px; the full sidebar
 * from 1024 px; wider gutters from 1440 px.
 */

.shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
    min-height: 100dvh;
}

/* Sidebar: a drawer on phones. */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-drawer);
    display: flex;
    flex-direction: column;
    width: min(86vw, 300px);
    border-right: 1px solid var(--border);
    background: var(--surface-1);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--duration) var(--ease), visibility 0s linear var(--duration);
}

.shell[data-nav="open"] .sidebar {
    transform: none;
    visibility: visible;
    transition: transform var(--duration) var(--ease);
}

.shell-scrim {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-drawer) - 1);
    background: var(--scrim);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--topbar-height);
    padding: 0 var(--space-3) 0 var(--space-5);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--touch);
    color: var(--text);
    text-decoration: none;
}

.brand-mark {
    width: 28px;
    height: 28px;
    flex: none;
}

.brand-mark .plate {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2.5;
}

.brand-mark .dot {
    fill: var(--accent);
}

.brand-word {
    font-size: var(--text-md);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.nav {
    flex: 1;
    padding: var(--space-3) var(--space-2);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.nav-list {
    display: grid;
    gap: 2px;
}

.nav-group + .nav-group {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}

.nav-group-label {
    display: block;
    padding: var(--space-2) var(--space-3);
}

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--touch);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--text-sm);
    text-decoration: none;
}

.nav-link .icon {
    color: var(--text-muted);
}

.nav-link:hover {
    background: var(--surface-hover);
}

.nav-link[aria-current="page"] {
    background: var(--accent-soft);
    font-weight: 700;
}

.nav-link[aria-current="page"] .icon {
    color: var(--accent);
}

.nav-link[aria-current="page"]::before {
    content: "";
    position: absolute;
    inset: 10px auto 10px 0;
    width: 3px;
    border-radius: var(--radius-pill);
    background: var(--accent);
}

.sidebar-foot {
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.sidebar-foot .sidebar-customer {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-foot strong {
    display: block;
    overflow: hidden;
    color: var(--text);
    font-size: var(--text-sm);
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Main column and top bar */
.shell-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--topbar-height);
    padding: 0 var(--space-2) 0 var(--space-2);
    border-bottom: 1px solid var(--border);
    background: var(--surface-0);
}

.topbar-brand .brand-word {
    font-size: var(--text-base);
}

.breadcrumb {
    flex: 1;
    min-width: 0;
}

.breadcrumb ol {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    overflow: hidden;
    color: var(--text-muted);
    font-size: var(--text-xs);
    white-space: nowrap;
}

.breadcrumb li {
    display: flex;
    align-items: center;
    min-width: 0;
}

.breadcrumb li:not(:last-child) {
    display: none;
}

.breadcrumb li + li::before {
    content: "/";
    margin-right: var(--space-1);
}

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

.breadcrumb [aria-current="page"] {
    display: block;
    overflow: hidden;
    color: var(--text);
    font-weight: 700;
    text-overflow: ellipsis;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-left: auto;
}

.bell {
    position: relative;
}

.bell-dot {
    position: absolute;
    top: 10px;
    right: 11px;
    width: 8px;
    height: 8px;
    border: 2px solid var(--surface-0);
    border-radius: 50%;
    background: var(--positive);
    box-sizing: content-box;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--touch);
    padding: 0 var(--space-1);
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    text-align: right;
}

.user-chip:hover {
    background: var(--surface-hover);
}

.user-text {
    display: none;
    line-height: 1.25;
}

.user-name {
    display: block;
    font-size: var(--text-sm);
    font-weight: 700;
}

.user-email {
    display: block;
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.avatar {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex: none;
    overflow: hidden;
    border: 1px solid var(--border-control);
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text);
    font-size: var(--text-xs);
    font-weight: 700;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* The view area and what views lay out inside it */
.view {
    --view-padding: var(--space-4);
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--view-padding);
}

.view:focus {
    outline: none;
}

.view-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.view-title {
    font-size: var(--text-lg);
}

.view-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.view-toolbar .toolbar-end {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

.stack {
    display: grid;
    gap: var(--space-4);
}

/* The KPI row scrolls sideways inside itself when the tiles do not fit, never the page. */
.kpi-row {
    container-type: inline-size;
    display: grid;
    grid-auto-columns: minmax(220px, 1fr);
    grid-auto-flow: column;
    gap: var(--space-3);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    padding-bottom: var(--space-1);
}

.kpi-row > * {
    scroll-snap-align: start;
}

.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
}

/* The boot skeleton: drawn by index.php before any script runs. */
.skeleton {
    display: block;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-hover) 50%, var(--surface-2) 100%);
    background-size: 200% 100%;
    animation: skeleton-wave 1.4s ease-in-out infinite;
}

.skeleton-line {
    height: 0.8em;
    margin: 0.35em 0;
}

.skeleton-block {
    height: 120px;
    border-radius: var(--radius);
}

.boot-card {
    padding: var(--space-5);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-1);
}

@keyframes skeleton-wave {
    from {
        background-position: 100% 0;
    }
    to {
        background-position: -100% 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
    }
}

/* Tablet: an icon rail; the drawer, its scrim and the menu button go away. */
@media (min-width: 600px) {
    .shell {
        grid-template-columns: var(--rail-width) minmax(0, 1fr);
    }

    .sidebar,
    .shell[data-nav="open"] .sidebar {
        position: sticky;
        top: 0;
        width: auto;
        height: 100vh;
        height: 100dvh;
        transform: none;
        visibility: visible;
        transition: none;
    }

    .shell-scrim,
    .topbar-menu,
    .topbar-brand,
    .sidebar-close {
        display: none;
    }

    .sidebar-brand {
        justify-content: center;
        padding: 0;
    }

    .sidebar .brand-word,
    .nav-label,
    .nav-group-label,
    .sidebar-foot {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .nav-link {
        justify-content: center;
        padding: var(--space-2);
    }

    .topbar {
        padding: 0 var(--space-4) 0 var(--space-6);
    }

    .breadcrumb li:not(:last-child) {
        display: flex;
        flex: none;
    }

    .user-text {
        display: block;
    }

    .view {
        --view-padding: var(--space-6);
    }
}

/* Desktop: the full sidebar with labels. */
@media (min-width: 1024px) {
    .shell {
        grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    }

    .sidebar-brand {
        justify-content: flex-start;
        padding: 0 var(--space-5);
    }

    .sidebar .brand-word,
    .nav-label,
    .nav-group-label,
    .sidebar-foot {
        position: static;
        width: auto;
        height: auto;
        overflow: visible;
        clip: auto;
        white-space: normal;
    }

    .nav-group-label {
        white-space: nowrap;
    }

    .nav-link {
        justify-content: flex-start;
        padding: var(--space-2) var(--space-3);
    }

    .grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1440px) {
    .view {
        --view-padding: var(--space-8);
    }

    .kpi-row {
        grid-auto-columns: minmax(240px, 1fr);
    }
}

@media print {
    .sidebar,
    .topbar,
    .shell-scrim,
    .skip-link {
        display: none !important;
    }

    .shell {
        display: block;
    }
}

/* Onboarding: the first screen of a person with no business. */
.onboarding {
    display: grid;
    gap: var(--space-4);
    max-width: 640px;
    margin: 0 auto;
}

.onboarding-form {
    gap: var(--space-4);
}
