/* App chrome: sidebar + topbar + content. Built from helpmecto's header language
   (glass blur bar, pill nav links, HMC-style brand mark) since helpmecto has no app shell. */

.app { display: grid; grid-template-columns: var(--sidebar-w, 260px) minmax(0, 1fr); min-height: 100vh; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand__mark { width: 28px; height: 28px; color: var(--accent); }
.brand__name { font-weight: 850; font-size: 1.15rem; letter-spacing: .02em; }
.brand__sub { padding-left: 10px; border-left: 1px solid var(--line-2); color: var(--muted); font-size: .8rem; font-weight: 500; }

/* Sidebar */
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; border-right: 1px solid var(--line); background: var(--bg-2); overflow-y: auto; }
.sidebar__brand { display: flex; align-items: center; height: var(--header-h); padding: 0 20px; border-bottom: 1px solid var(--line); flex: none; }
.sidebar__nav { display: grid; gap: 22px; padding: 22px 12px; }
.sidebar__section { display: grid; gap: 2px; }
.sidebar__label { padding: 0 12px 8px; color: var(--muted); font-family: var(--font-mono); font-size: .66rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; }
.sidebar__link { font-size: .92rem; }
.sidebar__foot { margin-top: auto; padding: 16px 20px 20px; border-top: 1px solid var(--line); }
.sidebar__tenant { display: grid; gap: 2px; }
.sidebar__tenant strong { font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 16px; height: var(--header-h); padding: 0 clamp(20px, 3vw, 36px); border-bottom: 1px solid transparent; transition: background .3s, border-color .3s, backdrop-filter .3s; }
.topbar.is-scrolled { background: var(--glass); border-bottom-color: var(--line); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); }
.topbar__title { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text-2); font-size: .92rem; font-weight: 600; }
.topbar__actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.site-switch { position: relative; display: inline-flex; align-items: center; }
.site-switch select { appearance: none; min-height: 38px; padding: 6px 34px 6px 14px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--overlay-3); color: var(--text); font-size: .88rem; font-weight: 600; cursor: pointer; }
.site-switch::after { content: ""; position: absolute; right: 14px; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-2px) rotate(45deg); pointer-events: none; }
.site-switch select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.user-menu { position: relative; }
.user-menu__button { display: inline-flex; align-items: center; gap: 10px; min-height: 38px; padding: 4px 6px 4px 4px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--overlay-3); cursor: pointer; }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); font-family: var(--font-mono); font-size: .78rem; font-weight: 700; }
.user-menu__panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; display: grid; min-width: 240px; padding: 8px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--glass-2); box-shadow: var(--shadow-hud); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); animation: rise .18s var(--ease); }
.user-menu__who { display: grid; gap: 2px; padding: 8px 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.user-menu__who span { color: var(--muted); font-size: .82rem; }

.theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* Test / live environment: switch in the topbar, a hazard-striped bar under it in test mode */
.env-switch button { min-height: 34px; padding: 4px 14px; }
.env-switch button[data-env="test"][aria-selected="true"] { background: var(--test-mode-tint); color: var(--test-mode); box-shadow: inset 0 0 0 1px var(--test-mode-border); }
.env-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 9px clamp(20px, 3vw, 36px); border-bottom: 1px solid var(--test-mode-border);
    background: repeating-linear-gradient(-45deg, var(--test-mode-tint) 0 14px, transparent 14px 28px), var(--bg-2); color: var(--text-2); font-size: .86rem; }
.env-bar strong { color: var(--test-mode); font-family: var(--font-mono); font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; }
.env-bar__link { margin-left: auto; color: var(--test-mode); font-weight: 650; }
.env-badge { border-color: var(--test-mode-border); background: var(--test-mode-tint); color: var(--test-mode); }
.trial-badge[data-expired="true"] { border-color: var(--red-soft); background: var(--red-tint); color: var(--red); }

/* Content */
.main { display: flex; flex-direction: column; min-width: 0; }
.content { width: min(100% - clamp(40px, 6vw, 72px), var(--container)); margin: 0 auto; padding: clamp(24px, 3vw, 40px) 0 80px; }
.page-head { position: relative; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: clamp(24px, 3vw, 36px); }
.page-head h1 { font-size: clamp(1.9rem, 2.8vw, 2.6rem); letter-spacing: -.035em; }
.page-head .lead { margin-top: 12px; font-size: 1.02rem; }
.page-head .eyebrow { margin-bottom: 12px; }
.page-head__actions { display: flex; flex-wrap: wrap; gap: 10px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; margin-bottom: 6px; color: var(--text-2); font-size: .9rem; font-weight: 600; text-decoration: none; }
.back-link:hover { color: var(--accent-text); }

/* The helpmecto page-hero backdrop: orange glow + fading grid, used behind page heads. */
.backdrop { position: absolute; inset: 0 0 auto; height: 420px; z-index: -1; background: radial-gradient(700px 360px at 85% 0%, var(--accent-wash), transparent 70%), linear-gradient(var(--overlay-1) 1px, transparent 1px) 0 0 / 100% 48px, linear-gradient(90deg, var(--overlay-1) 1px, transparent 1px) 0 0 / 48px 100%; mask-image: linear-gradient(#000 30%, transparent); -webkit-mask-image: linear-gradient(#000 30%, transparent); pointer-events: none; }
.main { position: relative; isolation: isolate; }

.boot-screen { display: grid; place-items: center; min-height: 60vh; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }

/* Mobile */
.nav-toggle { display: none; position: relative; width: 44px; height: 44px; flex: none; border: 1px solid var(--line-2); border-radius: 50%; background: transparent; cursor: pointer; }
.nav-toggle span { position: absolute; left: 13px; right: 13px; height: 2px; border-radius: 2px; background: var(--text); transition: transform .3s var(--ease); }
.nav-toggle span:first-child { top: 17px; }
.nav-toggle span:last-child { top: 25px; }
body.nav-open .nav-toggle span:first-child { transform: translateY(4px) rotate(45deg); }
body.nav-open .nav-toggle span:last-child { transform: translateY(-4px) rotate(-45deg); }
.scrim { display: none; }

@media (max-width: 920px) {
    .app { grid-template-columns: minmax(0, 1fr); }
    .topbar { gap: 10px; padding: 0 16px; }
    .topbar__actions { gap: 8px; }
    .site-switch select { max-width: 170px; text-overflow: ellipsis; }
    .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 70; width: 280px; transform: translateX(-100%); transition: transform .35s var(--ease); }
    body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-deep); }
    body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 65; background: #0008; }
    .nav-toggle { display: block; }
    .topbar__title { display: none; }
    .trial-badge, .user-menu__name { display: none; }
    .page-head { flex-direction: column; align-items: flex-start; }
}

/* Focus pages (warehouse edit workspace): the sidebar slides in on demand at every width so the
   editor gets the whole screen, which matters most on tablets. Mirrors the <=920px rules above. */
body.shell-focus .app { grid-template-columns: minmax(0, 1fr); }
body.shell-focus .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 70; width: 280px; transform: translateX(-100%); transition: transform .35s var(--ease); }
body.shell-focus.nav-open .sidebar { transform: none; box-shadow: var(--shadow-deep); }
body.shell-focus.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 65; background: #0008; }
body.shell-focus .nav-toggle { display: block; }
body.shell-focus .content { width: min(100% - clamp(24px, 3vw, 48px), 1920px); padding: 12px 0 32px; }

/* Standalone (no sidebar): auth, onboarding, kiosk. Uses helpmecto's hero grid + glow. */
.standalone { position: relative; min-height: 100vh; overflow: hidden; }
.standalone::before { content: ""; position: absolute; inset: 0; background: linear-gradient(var(--overlay-2) 1px, transparent 1px) 0 0 / 100% 56px, linear-gradient(90deg, var(--overlay-2) 1px, transparent 1px) 0 0 / 56px 100%; mask-image: radial-gradient(ellipse 80% 70% at 60% 30%, #000 30%, transparent 75%); -webkit-mask-image: radial-gradient(ellipse 80% 70% at 60% 30%, #000 30%, transparent 75%); pointer-events: none; }
.standalone__glow { position: absolute; top: -20%; right: -10%; width: 70vw; height: 70vw; max-width: 1000px; max-height: 1000px; background: radial-gradient(circle, var(--accent-wash) 0%, transparent 60%); pointer-events: none; }
.standalone__bar { position: relative; z-index: 2; display: flex; align-items: center; gap: 16px; width: min(100% - 40px, var(--container)); height: var(--header-h); margin: 0 auto; }
.standalone__bar .topbar__actions { margin-left: auto; }
.standalone__body { position: relative; z-index: 1; width: min(100% - 40px, var(--container)); margin: 0 auto; padding: clamp(24px, 5vw, 64px) 0 80px; }

/* Superadmin impersonation: always visible, never mistakable for a customer session. */
.impersonation-bar { position: sticky; top: 0; z-index: 45; display: flex; align-items: center; gap: 12px; padding: 10px clamp(20px, 3vw, 36px); border-bottom: 1px solid var(--accent-border); background: linear-gradient(90deg, var(--accent-wash), var(--accent-tint)), var(--bg-2); color: var(--text); font-size: .9rem; font-weight: 600; }
.impersonation-bar .btn { margin-left: auto; }
.impersonation-bar:not([hidden]) + .topbar { top: 58px; }
