/* ==========================================================================
   Layout: app shell (one top bar for every role), page container, responsive drawer
   ========================================================================== */
.app-topbar {
    position: sticky; top: 0; z-index: 900; isolation: isolate;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: var(--space-4);
    padding: 0 var(--space-5);
    border-bottom: 1px solid var(--border);
}
/* the frosted background lives on a pseudo-element: a backdrop-filter on the bar itself would trap the
   position:fixed mobile drawer inside the 60px header (it becomes the containing block) */
.app-topbar::before {
    content: ""; position: absolute; inset: 0; z-index: -1;
    background: var(--surface); /* fallback for browsers without color-mix() */
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: saturate(1.4) blur(14px);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.app-brand { display: flex; align-items: center; gap: var(--space-3); flex: 0 0 auto; }
.app-brand img { height: 34px; width: auto; display: block; }
.wordmark { display: inline-flex; align-items: center; gap: 10px; color: var(--primary); font: 800 1.25rem/1 var(--font-sans); letter-spacing: -.02em; }
.wordmark svg { width: 32px; height: 32px; }
.wordmark__text { color: var(--text); } .wordmark__text b { color: var(--primary); font-weight: 800; }
.auth-hero .wordmark { color: #fff; } .auth-hero .wordmark__text, .auth-hero .wordmark__text b { color: #fff; }
.auth-hero .wordmark svg rect { fill: #4f46e5; }
.app-brand .corner-logo { height: 34px; max-width: 120px; object-fit: contain; border-left: 1px solid var(--border); padding-left: var(--space-3); }
.app-brand .corner-logo[src$="/.png"], .app-brand .corner-logo:not([src]) { display: none; }

.app-nav { display: flex; align-items: center; gap: 2px; flex: 1 1 auto; min-width: 0; }
.nav-item {
    display: inline-flex; align-items: center; gap: 8px;
    height: 36px; padding: 0 12px;
    color: var(--text-2); font-weight: 550; font-size: .9rem; white-space: nowrap;
    background: transparent; border: 0; border-radius: var(--radius-sm); cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary); }
.nav-item.is-active svg { opacity: 1; }

.app-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; flex: 0 0 auto; }
.icon-btn {
    width: 38px; height: 38px; display: inline-grid; place-items: center;
    color: var(--text-2); background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn svg { width: 20px; height: 20px; }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }

/* dropdown (user menu + "More" group) */
.dropdown { position: relative; }
.dropdown-panel {
    position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; z-index: 950;
    padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-3);
    opacity: 0; visibility: hidden; transform: translateY(-4px); transition: all var(--t) var(--ease);
}
.dropdown.is-open > .dropdown-panel { opacity: 1; visibility: visible; transform: none; }
.dropdown-panel.left { right: auto; left: 0; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; color: var(--text); background: transparent;
    border: 0; border-radius: var(--radius-sm); cursor: pointer; font: inherit; font-size: .9rem; text-align: left; }
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.menu-item svg { width: 17px; height: 17px; color: var(--text-muted); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-head { padding: 10px 12px 8px; }
.menu-head b { display: block; } .menu-head small { color: var(--text-muted); }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; border: 1px solid var(--border); border-radius: var(--radius-pill);
    background: var(--surface); cursor: pointer; font: inherit; color: var(--text); }
.user-chip:hover { border-color: var(--primary); }
.avatar { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: var(--on-primary); font-weight: 700; font-size: .78rem; }
.user-chip .who { text-align: left; line-height: 1.15; }
.user-chip .who b { display: block; font-size: .82rem; } .user-chip .who small { color: var(--text-muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }

/* secondary toolbar (workspace tools for the module editor) */
.app-toolbar {
    position: sticky; top: var(--topbar-h); z-index: 800;
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2);
    padding: 8px var(--space-5);
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

/* page container */
.page { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--space-5); }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: var(--space-5); }
.page-head h2 { margin: 0; font-size: 1.4rem; }
.page-head .spacer { flex: 1; }
.app-footer { padding: var(--space-5); text-align: center; color: var(--text-muted); font-size: .8rem; }

/* burger + drawer (mobile) */
.burger { display: none; }
.drawer-backdrop { position: fixed; inset: 0; z-index: 940; background: var(--backdrop); opacity: 0; visibility: hidden; transition: opacity var(--t); }
@media (max-width: 960px) {
    .app-topbar { padding: 0 var(--space-3); gap: var(--space-2); }
    .burger { display: inline-grid; }
    .app-nav {
        position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 320px); height: 100dvh; z-index: 960; padding-top: max(var(--space-5), env(safe-area-inset-top));
        flex-direction: column; align-items: stretch; gap: 4px; padding: var(--space-5) var(--space-3);
        background: var(--surface); border-right: 1px solid var(--border); box-shadow: var(--shadow-3);
        transform: translateX(-102%); transition: transform var(--t) var(--ease); overflow-y: auto;
    }
    .app-nav .nav-item { height: 44px; font-size: 1rem; }
    body.nav-open .app-nav { transform: none; }
    body.nav-open .drawer-backdrop { opacity: 1; visibility: visible; }
    body.nav-open .app-topbar { z-index: 970; } /* the menu lives inside the top bar: it must stack above the dimming backdrop */
    .user-chip .who { display: none; }
    .user-chip { padding: 4px; }
    .app-toolbar { padding: 8px var(--space-3); overflow-x: auto; flex-wrap: nowrap; }
    .page { padding: var(--space-4) var(--space-3); }
    .app-brand .corner-logo { display: none; }
}
@media (max-width: 520px) { .app-brand img.brand-logo { height: 28px; } }

/* ---------- admin pages that overlay the editor area ---------- */
.page--overlay { position: absolute; left: 0; right: 0; z-index: 20; min-height: calc(100vh - var(--topbar-h)); background: var(--bg); }
.page-panel { max-width: var(--content-max); margin: var(--space-5) auto; }
.impersonate-bar { display: flex; align-items: center; justify-content: center; gap: var(--space-3); padding: 6px var(--space-4); font-size: .85rem; font-weight: 600; color: #fff; background: var(--warning); }
.impersonate-bar button { color: #fff; background: rgba(0, 0, 0, .25); border: 0; border-radius: var(--radius-pill); padding: 3px 12px; font: inherit; cursor: pointer; }

/* ---------- mobile drawer extras ---------- */
.nav-drawer-head, .nav-drawer-foot { display: none; }
@media (max-width: 960px) {
    .nav-drawer-head { display: flex; align-items: center; justify-content: space-between; margin: -4px 4px 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
    .nav-drawer-head .wordmark { font-size: 1.15rem; }
    .nav-drawer-head .icon-btn { font-size: 1.7rem; line-height: 1; }
    .nav-drawer-foot { display: flex; flex-direction: column; gap: 4px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
    .nav-drawer-user { display: flex; align-items: center; gap: 12px; padding: 8px 12px 12px; } .nav-drawer-user b { display: block; } .nav-drawer-user small { color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-size: .7rem; }
    .nav-item.is-danger { color: var(--danger); }
    .app-nav { padding-bottom: max(var(--space-4), env(safe-area-inset-bottom)); }
    /* the Tools group expands inline inside the drawer instead of floating */
    .app-nav .dropdown { width: 100%; } .app-nav .dropdown > .nav-item { width: 100%; justify-content: flex-start; }
    .app-nav .dropdown-panel { position: static; display: none; min-width: 0; padding: 2px 0 6px 28px; background: transparent; border: 0; box-shadow: none; opacity: 1; visibility: visible; transform: none; }
    .app-nav .dropdown.is-open > .dropdown-panel { display: block; }
    .app-nav .menu-item { height: 42px; font-size: .95rem; }
}

.nav-item { text-decoration: none; } a.menu-item { text-decoration: none; }
