/* ============================================================
   Elitma site shell — themes and layout (owner: shell)
   Loaded after vars.css / elitma.css / main.css, before areas/*.css.

   1. Tokens that never change with the theme (sizes, brand hue)
   2. Light theme: framework variables + shell variables
   3. Dark theme: same variables, dark values
   4. App layout (logged in): sidebar, topbar, main, footer
   5. Collapsed sidebar (desktop) and drawer (mobile, < 900px)
   6. Shared bits other areas may use: .empty-state, form errors, kbd
   7. Shortcuts dialog, preview page helpers
   8. Public layout (guests): top navbar, footer (D-014)
   9. Page tabs (.shell-tabs) and menu counters

   Rule: colors exist ONLY in sections 2 and 3, as variables. Every rule
   below reads var(--...). The framework components (cards, tables,
   buttons, badges, flashes...) follow the theme because sections 2-3
   redefine the variables they already use.
   ============================================================ */


/* ── 1. Theme-independent tokens ─────────────────────────── */
:root {
    /* THE accent. Change the hue (0-360) to rebrand the whole site:
       every accent shade in both themes is derived from these two. */
    --app-accent-h: 174;
    --app-accent-s: 64%;

    --app-sidebar-w:           240px;
    --app-sidebar-w-collapsed: 64px;
    --app-sidebar-current:     var(--app-sidebar-w);
    --app-drawer-w:            min(300px, 86vw);
    --app-topbar-h:            56px;
    --app-content-max:         1200px;
    --app-page-pad:            var(--space-8);
    --app-nav-item-h:          34px;
    --app-nav-icon:            19px;
    --app-public-nav-h:        64px;
    --app-brand-mark:          26px;
    --app-avatar:              30px;
    --app-iconbtn:             32px;

    /* Calmer heading scale than the framework default (Linear-like). */
    --font-size-4xl: 2rem;
    --letter-spacing-tight: -0.02em;
}


/* ── 2. Light theme ───────────────────────────────────────── */
/* :root too, so a page without JS (data-theme="system") still gets a theme. */
:root,
html[data-theme="light"] {
    color-scheme: light;

    /* Accent */
    --color-primary:         hsl(var(--app-accent-h) var(--app-accent-s) 28%);
    --color-primary-hover:   hsl(var(--app-accent-h) var(--app-accent-s) 23%);
    --color-primary-active:  hsl(var(--app-accent-h) var(--app-accent-s) 19%);
    --color-primary-light:   hsl(var(--app-accent-h) 42% 72%);
    --color-primary-lighter: hsl(var(--app-accent-h) 55% 94%);
    --color-primary-dark:    hsl(var(--app-accent-h) 70% 19%);

    --color-secondary:       #4b5260;
    --color-secondary-hover: #3a404c;
    --color-secondary-light: #d4d7dd;
    --color-secondary-dark:  #2b3039;

    /* Surfaces */
    --color-bg:           #f7f8fa;
    --color-bg-card:      #ffffff;
    --color-bg-muted:     #f9fafb;
    --color-bg-elevated:  #ffffff;
    --color-bg-overlay:   rgba(12, 14, 18, 0.45);

    /* Text */
    --color-text:            #121419;
    --color-text-muted:      #585f6b;
    --color-text-light:      #8a909b;
    --color-text-on-primary: #ffffff;
    --color-text-on-secondary: #ffffff;
    --color-text-on-primary-light: var(--color-primary-dark);

    /* Borders */
    --color-border:        #e4e6ea;
    --color-border-strong: #d0d4db;

    /* Buttons (danger/success darkened: white text needs >= 4.5:1) */
    --color-btn-primary-text:       var(--color-text-on-primary);
    --color-btn-outline-hover-text: var(--color-text-on-primary);
    --color-btn-ghost-text:         var(--color-text-muted);
    --color-btn-ghost-hover-bg:     #eef0f3;
    --color-btn-danger-bg:          #d42a2a;
    --color-btn-danger-text:        #ffffff;
    --color-btn-danger-hover:       #b21f1f;
    --color-btn-success-bg:         #047857;
    --color-btn-success-text:       #ffffff;
    --color-btn-success-hover:      #065f46;

    /* States */
    --color-success:        #059669;
    --color-success-bg:     #e3f6ee;
    --color-success-border: #b5e6d0;
    --color-success-text:   #065f46;
    --color-error:          #dc2626;
    --color-error-bg:       #fdecec;
    --color-error-border:   #f7c9c9;
    --color-error-text:     #991b1b;
    --color-warning:        #d97706;
    --color-warning-bg:     #fdf3e1;
    --color-warning-border: #f4dbab;
    --color-warning-text:   #8a4b08;

    /* Forms */
    --color-input-bg:           #ffffff;
    --color-input-border:       var(--color-border-strong);
    --color-input-focus-shadow: hsl(var(--app-accent-h) var(--app-accent-s) 40% / 0.18);

    /* Table */
    --color-table-header-bg:   var(--color-bg-muted);
    --color-table-header-text: #3b414c;
    --color-table-row-hover:   #f6f7f9;
    --color-table-stripe:      #fafbfc;

    /* Badges */
    --color-badge-default-bg:   #eef0f3;
    --color-badge-default-text: #4b5260;
    --color-status-closed-bg:   #eef0f3;

    /* Shadows: softer than the framework default */
    --shadow-xs: 0 1px 2px rgba(16, 18, 24, 0.05);
    --shadow-sm: 0 1px 2px rgba(16, 18, 24, 0.06), 0 1px 1px rgba(16, 18, 24, 0.03);
    --shadow-md: 0 8px 20px rgba(16, 18, 24, 0.08), 0 2px 6px rgba(16, 18, 24, 0.04);
    --shadow-xl: 0 24px 48px rgba(16, 18, 24, 0.16);

    /* ── Shell ── */
    --app-sidebar-bg:           #f1f2f4;
    --app-sidebar-border:       #e2e4e8;
    --app-sidebar-text:         #464c58;
    --app-sidebar-text-strong:  #121419;
    --app-sidebar-muted:        #676d78;
    --app-sidebar-icon:         #676d78;
    --app-sidebar-hover-bg:     rgba(18, 20, 25, 0.055);
    --app-sidebar-active-bg:    #ffffff;
    --app-sidebar-active-text:  #121419;
    --app-sidebar-active-icon:  var(--color-primary);
    --app-sidebar-active-shadow: 0 1px 2px rgba(16, 18, 24, 0.08), 0 0 0 1px rgba(16, 18, 24, 0.04);
    --app-scrollbar:            rgba(18, 20, 25, 0.18);

    --app-topbar-bg:            rgba(247, 248, 250, 0.86);
    --app-topbar-border:        #e4e6ea;
    --app-hover-bg:             rgba(18, 20, 25, 0.055);
    --app-iconbtn-text:         #585f6b;
    --app-iconbtn-text-hover:   #121419;

    --app-brand-mark-bg:        var(--color-primary);
    --app-brand-mark-text:      var(--color-text-on-primary);
    --app-avatar-bg:            hsl(var(--app-accent-h) 32% 87%);
    --app-avatar-text:          hsl(var(--app-accent-h) 70% 20%);

    --app-segment-bg:           rgba(18, 20, 25, 0.06);
    --app-segment-active-bg:    #ffffff;
    --app-segment-active-text:  #121419;

    --app-kbd-bg:               #f3f4f6;
    --app-kbd-border:           #d0d4db;
    --app-kbd-text:             #121419;

    --app-focus-ring:           hsl(var(--app-accent-h) var(--app-accent-s) 36%);
    --app-error-ring:           rgba(220, 38, 38, 0.16);
    --app-empty-icon-bg:        #eef0f3;

    --app-footer-bg:            #f1f2f4;
    --app-nav-link:             #464c58;
    --app-nav-link-hover:       #121419;
}


/* ── 3. Dark theme ────────────────────────────────────────── */
html[data-theme="dark"] {
    color-scheme: dark;

    /* Accent: lighter shades, dark text on top */
    --color-primary:         hsl(var(--app-accent-h) 58% 50%);
    --color-primary-hover:   hsl(var(--app-accent-h) 58% 58%);
    --color-primary-active:  hsl(var(--app-accent-h) 58% 44%);
    --color-primary-light:   hsl(var(--app-accent-h) 40% 30%);
    --color-primary-lighter: hsl(var(--app-accent-h) 40% 13%);
    --color-primary-dark:    hsl(var(--app-accent-h) 62% 72%);

    --color-secondary:       #2c2f36;
    --color-secondary-hover: #373a42;
    --color-secondary-light: #3a3e46;
    --color-secondary-dark:  #1f2126;

    /* Surfaces */
    --color-bg:           #0f1013;
    --color-bg-card:      #16171b;
    --color-bg-muted:     #1a1c20;
    --color-bg-elevated:  #1c1e23;
    --color-bg-overlay:   rgba(0, 0, 0, 0.6);

    /* Text */
    --color-text:            #e6e8eb;
    --color-text-muted:      #9ca2ac;
    --color-text-light:      #6e747e;
    --color-text-on-primary: hsl(var(--app-accent-h) 80% 8%);
    --color-text-on-secondary: #e6e8eb;
    --color-text-on-primary-light: var(--color-primary-dark);

    /* Borders */
    --color-border:        #25272d;
    --color-border-strong: #34373e;

    /* Buttons */
    --color-btn-primary-text:       var(--color-text-on-primary);
    --color-btn-secondary-text:     #e6e8eb;
    --color-btn-outline-hover-text: var(--color-text-on-primary);
    --color-btn-ghost-text:         #a8aeb7;
    --color-btn-ghost-hover-bg:     #202227;
    --color-btn-danger-bg:          #c42525;
    --color-btn-danger-text:        #ffffff;
    --color-btn-danger-hover:       #a81d1d;
    --color-btn-success-bg:         #047857;
    --color-btn-success-text:       #ffffff;
    --color-btn-success-hover:      #065f46;

    /* States */
    --color-success:        #34d399;
    --color-success-bg:     #0e2a20;
    --color-success-border: #1b4a37;
    --color-success-text:   #7ee2b8;
    --color-error:          #f87171;
    --color-error-bg:       #2c1417;
    --color-error-border:   #5b2328;
    --color-error-text:     #fca5a5;
    --color-warning:        #fbbf24;
    --color-warning-bg:     #2a200d;
    --color-warning-border: #57421a;
    --color-warning-text:   #fcd34d;

    /* Forms */
    --color-input-bg:           #111216;
    --color-input-border:       #34373e;
    --color-input-focus-shadow: hsl(var(--app-accent-h) 58% 50% / 0.25);

    /* Table */
    --color-table-header-bg:   #1a1c20;
    --color-table-header-text: #c7ccd3;
    --color-table-row-hover:   #1b1d22;
    --color-table-stripe:      #18191d;

    /* Badges */
    --color-badge-default-bg:   #25272d;
    --color-badge-default-text: #b9bec6;
    --color-status-closed-bg:   #25272d;

    /* Shadows: dark UIs need darker, not lighter, shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45), 0 1px 1px rgba(0, 0, 0, 0.3);
    --shadow:    0 4px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 32px rgba(0, 0, 0, 0.55);
    --shadow-xl: 0 28px 56px rgba(0, 0, 0, 0.6);

    /* ── Shell ── */
    --app-sidebar-bg:           #0b0c0e;
    --app-sidebar-border:       #1d1f24;
    --app-sidebar-text:         #a3a9b3;
    --app-sidebar-text-strong:  #eceef1;
    --app-sidebar-muted:        #7d838e;
    --app-sidebar-icon:         #7d838e;
    --app-sidebar-hover-bg:     rgba(255, 255, 255, 0.05);
    --app-sidebar-active-bg:    rgba(255, 255, 255, 0.08);
    --app-sidebar-active-text:  #f3f4f6;
    --app-sidebar-active-icon:  var(--color-primary);
    --app-sidebar-active-shadow: none;
    --app-scrollbar:            rgba(255, 255, 255, 0.14);

    --app-topbar-bg:            rgba(15, 16, 19, 0.82);
    --app-topbar-border:        #1f2126;
    --app-hover-bg:             rgba(255, 255, 255, 0.06);
    --app-iconbtn-text:         #9ca2ac;
    --app-iconbtn-text-hover:   #eceef1;

    --app-brand-mark-bg:        var(--color-primary);
    --app-brand-mark-text:      var(--color-text-on-primary);
    --app-avatar-bg:            hsl(var(--app-accent-h) 30% 20%);
    --app-avatar-text:          hsl(var(--app-accent-h) 60% 78%);

    --app-segment-bg:           rgba(255, 255, 255, 0.05);
    --app-segment-active-bg:    #2a2d33;
    --app-segment-active-text:  #f3f4f6;

    --app-kbd-bg:               #1d1f24;
    --app-kbd-border:           #34373e;
    --app-kbd-text:             #e6e8eb;

    --app-focus-ring:           hsl(var(--app-accent-h) 58% 56%);
    --app-error-ring:           rgba(248, 113, 113, 0.2);
    --app-empty-icon-bg:        #1d1f24;

    --app-footer-bg:            #0b0c0e;
    --app-nav-link:             #a3a9b3;
    --app-nav-link-hover:       #eceef1;
}


/* ── 4. App layout (logged in) ────────────────────────────── */

body.shell-root {
    display:          block;
    min-height:       100vh;
    background-color: var(--color-bg);
}

/* Keyboard focus is always visible. Inputs keep the framework ring. */
:where(a, button, summary, [tabindex]):focus-visible {
    outline:        2px solid var(--app-focus-ring);
    outline-offset: 2px;
}

.shell-skip {
    position:         absolute;
    left:             var(--space-4);
    top:              calc(-1 * var(--space-16));
    z-index:          var(--z-toast);
    padding:          var(--space-2) var(--space-4);
    border-radius:    var(--radius-md);
    background-color: var(--color-primary);
    color:            var(--color-text-on-primary);
    font-size:        var(--font-size-sm);
    font-weight:      var(--font-weight-semibold);
}
.shell-skip:focus { top: var(--space-3); color: var(--color-text-on-primary); }

/* Icon button (sidebar, topbar, dialog) */
.shell-iconbtn {
    display:          inline-flex;
    align-items:      center;
    justify-content:  center;
    flex-shrink:      0;
    width:            var(--app-iconbtn);
    height:           var(--app-iconbtn);
    border:           none;
    border-radius:    var(--radius-md);
    background:       transparent;
    color:            var(--app-iconbtn-text);
    transition:       background-color var(--transition), color var(--transition);
}
.shell-iconbtn:hover { background-color: var(--app-hover-bg); color: var(--app-iconbtn-text-hover); }

/* Sidebar */
.shell-sidebar {
    position:         fixed;
    top:              0;
    bottom:           0;
    left:             0;
    z-index:          var(--z-sidebar);
    width:            var(--app-sidebar-current);
    display:          flex;
    flex-direction:   column;
    background-color: var(--app-sidebar-bg);
    border-right:     1px solid var(--app-sidebar-border);
    overflow:         hidden;
    transition:       width var(--transition-medium);
}

.shell-sidebar__head {
    display:     flex;
    align-items: center;
    gap:         var(--space-2);
    height:      var(--app-topbar-h);
    padding:     0 var(--space-3) 0 var(--space-4);
    flex-shrink: 0;
}

.shell-brand {
    display:        flex;
    align-items:    center;
    gap:            var(--space-3);
    flex:           1;
    min-width:      0;
    color:          var(--app-sidebar-text-strong);
    font-size:      var(--font-size-base);
    font-weight:    var(--font-weight-semibold);
    letter-spacing: -0.01em;
    border-radius:  var(--radius-md);
}
.shell-brand:hover { color: var(--app-sidebar-text-strong); }

.shell-brand__mark {
    display:          grid;
    place-items:      center;
    flex-shrink:      0;
    width:            var(--app-brand-mark);
    height:           var(--app-brand-mark);
    border-radius:    var(--radius-md);
    background-color: var(--app-brand-mark-bg);
    color:            var(--app-brand-mark-text);
    font-size:        var(--font-size-sm);
    font-weight:      var(--font-weight-bold);
}
.shell-brand__text { white-space: nowrap; overflow: hidden; }

.shell-sidebar__close { display: none; }

.shell-nav {
    flex:            1;
    overflow-x:      hidden;
    overflow-y:      auto;
    padding:         var(--space-2) var(--space-3) var(--space-4);
    scrollbar-width: thin;
    scrollbar-color: var(--app-scrollbar) transparent;
}

.shell-nav__section + .shell-nav__section { margin-top: var(--space-5); }

/* The heading is a button: it folds the section away (D-022). It keeps the
   look of the old <p>, so nothing moves on the page. */
.shell-nav__label {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    gap:             var(--space-2);
    width:           100%;
    margin:          0 0 var(--space-1);
    padding:         var(--space-1) var(--space-3);
    border:          0;
    border-radius:   var(--radius-md);
    background:      none;
    color:           var(--app-sidebar-muted);
    font-family:     inherit;
    font-size:       var(--font-size-xs);
    font-weight:     var(--font-weight-medium);
    letter-spacing:  0.02em;
    white-space:     nowrap;
    text-align:      left;
    cursor:          pointer;
    transition:      background-color var(--transition), color var(--transition);
}
.shell-nav__label:hover { background: var(--app-sidebar-hover-bg); color: var(--app-sidebar-text); }

.shell-nav__chevron {
    flex-shrink: 0;
    font-size:   var(--app-nav-icon);
    transition:  transform var(--transition);
}
/* Closed: the arrow points right (left in a right-to-left language). */
.shell-nav__label[aria-expanded="false"] .shell-nav__chevron { transform: rotate(-90deg); }
[dir="rtl"] .shell-nav__label[aria-expanded="false"] .shell-nav__chevron { transform: rotate(90deg); }

.shell-nav__list {
    display:        flex;
    flex-direction: column;
    gap:            1px;
}
/* A folded section (D-022). Without this the `hidden` attribute does nothing:
   the rule above is an author rule and beats the browser's own
   `[hidden] { display: none }`, so the list stayed visible. */
.shell-nav__list[hidden] { display: none; }

.shell-nav__link {
    display:       flex;
    align-items:   center;
    gap:           var(--space-3);
    height:        var(--app-nav-item-h);
    padding:       0 var(--space-3);
    border-radius: var(--radius-md);
    color:         var(--app-sidebar-text);
    font-size:     var(--font-size-sm);
    font-weight:   var(--font-weight-medium);
    white-space:   nowrap;
    transition:    background-color var(--transition), color var(--transition);
}
.shell-nav__link .icon {
    flex-shrink: 0;
    font-size:   var(--app-nav-icon);
    color:       var(--app-sidebar-icon);
    transition:  color var(--transition);
}
.shell-nav__link:hover {
    background-color: var(--app-sidebar-hover-bg);
    color:            var(--app-sidebar-text-strong);
}
.shell-nav__link:hover .icon { color: var(--app-sidebar-text-strong); }
/* The sidebar clips overflow: draw the focus ring inside the item. */
.shell-nav__link:focus-visible { outline-offset: -2px; }

.shell-nav__link.is-active {
    background-color: var(--app-sidebar-active-bg);
    color:            var(--app-sidebar-active-text);
    box-shadow:       var(--app-sidebar-active-shadow);
}
.shell-nav__link.is-active .icon {
    color:                   var(--app-sidebar-active-icon);
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

.shell-nav__text { overflow: hidden; text-overflow: ellipsis; }

/* An action in the menu (Log out: a POST form, D-044) wears the look of the
   links around it, none of the browser's button chrome. Weaker than :hover
   and .is-active, which still colour it. */
button.shell-nav__link {
    width:      100%;
    border:     0;
    background: none;
    text-align: start;
}

/* Sidebar bottom: account, session links, theme */
.shell-sidebar__foot {
    display:        flex;
    flex-direction: column;
    gap:            var(--space-2);
    flex-shrink:    0;
    padding:        var(--space-3);
    border-top:     1px solid var(--app-sidebar-border);
}

.shell-user {
    display:     flex;
    align-items: center;
    gap:         var(--space-3);
    min-width:   0;
    padding:     var(--space-1) var(--space-2);
}

.shell-user__avatar {
    display:          grid;
    place-items:      center;
    flex-shrink:      0;
    width:            var(--app-avatar);
    height:           var(--app-avatar);
    border-radius:    var(--radius-full);
    background-color: var(--app-avatar-bg);
    color:            var(--app-avatar-text);
    font-size:        var(--font-size-xs);
    font-weight:      var(--font-weight-semibold);
}

.shell-user__meta {
    display:        flex;
    flex-direction: column;
    min-width:      0;
    line-height:    1.3;
}
.shell-user__name {
    overflow:      hidden;
    text-overflow: ellipsis;
    white-space:   nowrap;
    color:         var(--app-sidebar-text-strong);
    font-size:     var(--font-size-sm);
    font-weight:   var(--font-weight-semibold);
}
.shell-user__kind {
    color:     var(--app-sidebar-muted);
    font-size: var(--font-size-xs);
}

.shell-theme {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    gap:             var(--space-2);
    padding:         var(--space-1) var(--space-1) 0 var(--space-3);
}
.shell-theme__label {
    color:     var(--app-sidebar-muted);
    font-size: var(--font-size-xs);
}
.shell-theme__options {
    display:          inline-flex;
    gap:              2px;
    padding:          2px;
    border-radius:    var(--radius-md);
    background-color: var(--app-segment-bg);
}
.shell-theme__btn {
    display:       grid;
    place-items:   center;
    width:         30px;
    height:        26px;
    border:        none;
    border-radius: var(--radius);
    background:    transparent;
    color:         var(--app-sidebar-icon);
    transition:    background-color var(--transition), color var(--transition);
}
.shell-theme__btn .icon { font-size: 17px; }
.shell-theme__btn:hover { color: var(--app-sidebar-text-strong); }
.shell-theme__btn[aria-pressed="true"] {
    background-color: var(--app-segment-active-bg);
    color:            var(--app-segment-active-text);
    box-shadow:       var(--shadow-xs);
}

.shell-overlay { display: none; }

/* Right column: topbar + page + footer */
.shell-body {
    display:        flex;
    flex-direction: column;
    min-width:      0;
    min-height:     100vh;
    margin-left:    var(--app-sidebar-current);
    transition:     margin-left var(--transition-medium);
}

.shell-topbar {
    position:         sticky;
    top:              0;
    z-index:          var(--z-nav);
    display:          flex;
    align-items:      center;
    gap:              var(--space-3);
    height:           var(--app-topbar-h);
    padding:          0 var(--app-page-pad);
    background-color: var(--app-topbar-bg);
    border-bottom:    1px solid var(--app-topbar-border);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    backdrop-filter:  saturate(1.4) blur(10px);
}

.shell-topbar__menu { display: none; margin-left: calc(-1 * var(--space-2)); }

.shell-crumbs { flex: 1; min-width: 0; }
.shell-crumbs ol {
    display:     flex;
    align-items: center;
    gap:         var(--space-1);
    min-width:   0;
    font-size:   var(--font-size-sm);
}
.shell-crumbs__item {
    display:     flex;
    align-items: center;
    gap:         var(--space-1);
    min-width:   0;
    color:       var(--color-text-muted);
    white-space: nowrap;
}
.shell-crumbs__item a { color: var(--color-text-muted); border-radius: var(--radius-sm); }
.shell-crumbs__item a:hover { color: var(--color-text); }
.shell-crumbs__sep { font-size: 16px; color: var(--color-text-light); }
.shell-crumbs__current {
    display:       block;
    overflow:      hidden;
    text-overflow: ellipsis;
    color:         var(--color-text);
    font-weight:   var(--font-weight-semibold);
}

.shell-topbar__actions {
    display:     flex;
    align-items: center;
    gap:         var(--space-2);
    flex-shrink: 0;
}

/* The framework's `main` is a centred 1200px column: the shell wants the
   whole right column, with the page centred inside .shell-page. */
.shell-main {
    flex:      1;
    width:     100%;
    max-width: none;
    margin:    0;
    padding:   var(--app-page-pad);
}
.shell-main:focus { outline: none; }
.shell-page { max-width: var(--app-content-max); margin: 0 auto; }

.shell-footer {
    display:         flex;
    flex-wrap:       wrap;
    align-items:     center;
    justify-content: space-between;
    gap:             var(--space-3);
    padding:         var(--space-5) var(--app-page-pad);
    border-top:      1px solid var(--color-border);
    color:           var(--color-text-muted);
    font-size:       var(--font-size-xs);
}
.shell-footer__links { display: flex; flex-wrap: wrap; gap: var(--space-4); }
.shell-footer a { color: var(--color-text-muted); }
.shell-footer a:hover { color: var(--color-text); }


/* ── 5a. Collapsed sidebar (desktop only) ─────────────────── */
@media (min-width: 900px) {
    html.shell-collapsed { --app-sidebar-current: var(--app-sidebar-w-collapsed); }

    .shell-collapsed .shell-brand__text,
    .shell-collapsed .shell-nav__text,
    .shell-collapsed .shell-user__meta,
    .shell-collapsed .shell-theme__label { display: none; }

    /* Brand mark and expand button no longer fit side by side in 64px. */
    .shell-collapsed .shell-sidebar__head {
        flex-direction: column;
        justify-content: center;
        height:         auto;
        padding:        var(--space-3) 0 var(--space-2);
    }
    .shell-collapsed .shell-brand { flex: none; }

    .shell-collapsed .shell-nav { padding-left: var(--space-3); padding-right: var(--space-3); }
    .shell-collapsed .shell-nav__link { justify-content: center; padding: 0; }

    /* Section titles become thin separators. */
    .shell-collapsed .shell-nav__label {
        height:           1px;
        margin:           0 var(--space-2) var(--space-3);
        padding:          0;
        overflow:         hidden;
        font-size:        0;
        background-color: var(--app-sidebar-border);
        cursor:           default;
    }
    .shell-collapsed .shell-nav__label:hover { background-color: var(--app-sidebar-border); }
    .shell-collapsed .shell-nav__chevron { display: none; }

    /* A separator cannot be clicked open again, so a folded section still shows
       its icons while the sidebar is narrow (D-022). */
    .shell-collapsed .shell-nav__list[hidden] { display: flex; }

    /* The counter becomes a dot on the icon (the number is still read out). */
    .shell-collapsed .shell-nav__badge {
        position:  absolute;
        top:       5px;
        right:     9px;
        min-width: 8px;
        height:    8px;
        padding:   0;
        font-size: 0;
    }

    .shell-collapsed .shell-sidebar__foot { align-items: center; padding: var(--space-3) var(--space-2); }
    .shell-collapsed .shell-nav__list--foot { width: 100%; }
    .shell-collapsed .shell-user { padding: 0; }
    .shell-collapsed .shell-theme { padding: 0; }
    .shell-collapsed .shell-theme__options { flex-direction: column; }
}


/* ── 5b. Drawer (mobile / narrow windows) ─────────────────── */
@media (max-width: 899.98px) {
    :root { --app-page-pad: var(--space-4); }

    /* Off-canvas; visibility:hidden keeps its links out of the Tab order
       while closed (a translated-away panel would still be focusable). */
    .shell-sidebar {
        z-index:    var(--z-modal);
        width:      var(--app-drawer-w);
        transform:  translateX(-100%);
        visibility: hidden;
        transition: transform var(--transition-medium), visibility 0s linear var(--transition-medium);
    }
    html.shell-drawer-open .shell-sidebar {
        transform:  none;
        visibility: visible;
        box-shadow: var(--shadow-xl);
        transition: transform var(--transition-medium), visibility 0s;
    }

    .shell-sidebar__collapse { display: none; }
    .shell-sidebar__close    { display: inline-flex; }

    .shell-overlay {
        display:          block;
        position:         fixed;
        inset:            0;
        z-index:          calc(var(--z-modal) - 1);
        background-color: var(--color-bg-overlay);
        opacity:          0;
        pointer-events:   none;
        transition:       opacity var(--transition-medium);
    }
    html.shell-drawer-open .shell-overlay { opacity: 1; pointer-events: auto; }
    html.shell-drawer-open body { overflow: hidden; }

    .shell-body { margin-left: 0; }
    .shell-topbar__menu { display: inline-flex; }
    .shell-topbar__help { display: none; }
    .shell-footer { flex-direction: column; align-items: flex-start; }
}

/* Phones: only the current page title in the topbar. */
@media (max-width: 599.98px) {
    .shell-crumbs__item:not(.shell-crumbs__current) { display: none; }
    .shell-main { padding-top: var(--space-5); }
    h1 { font-size: var(--font-size-2xl); }
}

@media (prefers-reduced-motion: reduce) {
    .shell-sidebar, .shell-body, .shell-overlay { transition: none; }
}


/* ── 6. Shared bits for every area ────────────────────────── */

/* Empty state: <div class="empty-state"> icon / title / text / actions */
.empty-state {
    display:        flex;
    flex-direction: column;
    align-items:    center;
    gap:            var(--space-2);
    padding:        var(--space-12) var(--space-6);
    text-align:     center;
}
.empty-state--page {
    justify-content: center;
    min-height:      calc(100vh - var(--app-topbar-h) - var(--space-20) * 2);
}
.empty-state__icon {
    display:          grid;
    place-items:      center;
    width:            64px;
    height:           64px;
    margin-bottom:    var(--space-2);
    border-radius:    var(--radius-full);
    background-color: var(--app-empty-icon-bg);
    color:            var(--color-text-muted);
    font-size:        32px;
}
.empty-state__code {
    margin:         0;
    color:          var(--color-primary);
    font-size:      var(--font-size-sm);
    font-weight:    var(--font-weight-semibold);
    letter-spacing: 0.12em;
}
.empty-state__title {
    margin:      0;
    color:       var(--color-text);
    font-size:   var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
}
h1.empty-state__title { font-size: var(--font-size-2xl); }
.empty-state__text {
    max-width: 420px;
    margin:    0;
    color:     var(--color-text-muted);
}
.empty-state__actions {
    display:         flex;
    flex-wrap:       wrap;
    justify-content: center;
    gap:             var(--space-3);
    margin-top:      var(--space-4);
}

/* Field with an error: <div class="form-group form-group--error"> + .form-error */
.form-group--error input,
.form-group--error select,
.form-group--error textarea,
[aria-invalid="true"] { border-color: var(--color-error); }
.form-group--error input:focus,
.form-group--error select:focus,
.form-group--error textarea:focus,
[aria-invalid="true"]:focus { border-color: var(--color-error); box-shadow: 0 0 0 3px var(--app-error-ring); }

kbd {
    display:          inline-block;
    min-width:        24px;
    padding:          1px var(--space-2);
    border:           1px solid var(--app-kbd-border);
    border-bottom-width: 2px;
    border-radius:    var(--radius-sm);
    background-color: var(--app-kbd-bg);
    color:            var(--app-kbd-text);
    font-family:      var(--font-family-mono);
    font-size:        var(--font-size-xs);
    line-height:      1.6;
    text-align:       center;
}


/* ── 7. Shortcuts dialog, preview page ────────────────────── */

.shell-dialog {
    /* The global reset zeroes margins, which would pin the modal top-left. */
    margin:           auto;
    width:            min(440px, calc(100vw - var(--space-8)));
    padding:          var(--space-6);
    border:           1px solid var(--color-border);
    border-radius:    var(--radius-lg);
    background-color: var(--color-bg-elevated);
    color:            var(--color-text);
    box-shadow:       var(--shadow-xl);
}
.shell-dialog::backdrop { background-color: var(--color-bg-overlay); }

.shell-dialog__head {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    margin-bottom:   var(--space-4);
}
.shell-dialog__title { margin: 0; font-size: var(--font-size-lg); }
.shell-dialog__hint { margin-top: var(--space-4); color: var(--color-text-muted); font-size: var(--font-size-xs); }

.shell-keys { display: flex; flex-direction: column; }
.shell-keys__row {
    display:     flex;
    align-items: center;
    gap:         var(--space-4);
    padding:     var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
    font-size:   var(--font-size-sm);
}
.shell-keys__row:last-child { border-bottom: none; }
.shell-keys__row dt { flex: 0 0 48px; }
.shell-keys__row dd { color: var(--color-text-muted); }

.ui-preview__section { margin-bottom: var(--space-10); }
.ui-preview__title {
    margin-bottom:  var(--space-3);
    color:          var(--color-text-muted);
    font-size:      var(--font-size-xs);
    font-weight:    var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.ui-preview__row {
    display:     flex;
    flex-wrap:   wrap;
    align-items: center;
    gap:         var(--space-3);
}


/* ── 8. Public layout (guests) ────────────────────────────── */
/* A normal website: navbar on top, content, footer. The navbar is as tall as
   --app-topbar-h here, so everything that offsets by it (sticky blocks,
   full-height empty states) keeps working in both layouts. */
.shell-root--public { --app-topbar-h: var(--app-public-nav-h); }
/* Column so the footer sits at the bottom of short pages (body.shell-root
   in section 4 says display:block, hence the same specificity here). */
body.shell-root--public {
    display:        flex;
    flex-direction: column;
}

.site-nav {
    position:         sticky;
    top:              0;
    z-index:          var(--z-nav);
    background-color: var(--app-topbar-bg);
    border-bottom:    1px solid var(--app-topbar-border);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    backdrop-filter:  saturate(1.4) blur(10px);
}
.site-nav__inner {
    display:     flex;
    align-items: center;
    gap:         var(--space-6);
    max-width:   calc(var(--app-content-max) + 2 * var(--app-page-pad));
    height:      var(--app-public-nav-h);
    margin:      0 auto;
    padding:     0 var(--app-page-pad);
}

.site-nav__brand,
.site-nav__brand:hover,
.site-footer__brand,
.site-footer__brand:hover { flex: none; color: var(--color-text); }
.site-nav__brand .shell-brand__text { font-size: var(--font-size-lg); letter-spacing: -0.02em; }

.site-nav__menu {
    display:     flex;
    flex:        1;
    align-items: center;
    gap:         var(--space-6);
    min-width:   0;
}
.site-nav__links { flex: 1; min-width: 0; }
.site-nav__list  { display: flex; align-items: center; gap: var(--space-1); }

.site-nav__link {
    display:       inline-flex;
    align-items:   center;
    height:        36px;
    padding:       0 var(--space-3);
    border-radius: var(--radius-md);
    color:         var(--app-nav-link);
    font-size:     var(--font-size-sm);
    font-weight:   var(--font-weight-medium);
    white-space:   nowrap;
    transition:    background-color var(--transition), color var(--transition);
}
.site-nav__link:hover { background-color: var(--app-hover-bg); color: var(--app-nav-link-hover); }
.site-nav__link.is-active { color: var(--color-text); background-color: var(--app-hover-bg); }

.site-nav__actions {
    display:     flex;
    align-items: center;
    gap:         var(--space-2);
    flex:        none;
}
/* The theme switcher sits in the bar: no visible label (it keeps its name
   for screen readers), and no sidebar padding. */
.shell-theme--bar { padding: 0; margin-right: var(--space-2); }
.shell-theme--bar .shell-theme__label {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.site-nav__toggle { display: none; margin-left: auto; }

.shell-main--public { padding-top: var(--space-10); padding-bottom: var(--space-16); }
/* The public footer is tall: a full-height empty state (404, maintenance)
   would push it off screen, so it only fills part of the window here. */
.shell-root--public .empty-state--page { min-height: 55vh; }

/* Footer */
.site-footer {
    margin-top:       auto;
    background-color: var(--app-footer-bg);
    border-top:       1px solid var(--color-border);
    color:            var(--color-text-muted);
    font-size:        var(--font-size-sm);
}
.site-footer__inner {
    max-width: calc(var(--app-content-max) + 2 * var(--app-page-pad));
    margin:    0 auto;
    padding:   var(--space-12) var(--app-page-pad) var(--space-6);
}
.site-footer__top {
    display:               grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap:                   var(--space-10);
    padding-bottom:        var(--space-10);
}
/* More specific than `.site-footer a` below, which would grey the brand out. */
.site-footer a.site-footer__brand,
.site-footer a.site-footer__brand:hover { display: inline-flex; margin-bottom: var(--space-3); color: var(--color-text); }
.site-footer__tagline { max-width: 36ch; margin: 0; color: var(--color-text-muted); line-height: 1.6; }
.site-footer__cols {
    display:               grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap:                   var(--space-6);
}
.site-footer__title {
    margin:      0 0 var(--space-3);
    color:       var(--color-text);
    font-size:   var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
}
.site-footer__col ul { display: flex; flex-direction: column; gap: var(--space-2); }
.site-footer a { color: var(--color-text-muted); }
.site-footer a:hover { color: var(--color-text); }
.site-footer__bottom {
    display:         flex;
    flex-wrap:       wrap;
    justify-content: space-between;
    gap:             var(--space-2) var(--space-6);
    padding-top:     var(--space-5);
    border-top:      1px solid var(--color-border);
    font-size:       var(--font-size-xs);
}

/* Phones and small tablets: the links and actions fold behind the menu
   button. Only when JS runs (html.js): without it the menu simply wraps
   under the brand, so nothing is ever unreachable. */
@media (max-width: 767.98px) {
    :root { --app-page-pad: var(--space-4); }

    .site-nav__inner { flex-wrap: wrap; height: auto; min-height: var(--app-public-nav-h); gap: 0 var(--space-4); }
    .site-nav__brand { height: var(--app-public-nav-h); }
    .site-nav__menu {
        flex-basis:     100%;
        flex-direction: column;
        align-items:    stretch;
        gap:            var(--space-4);
        padding:        var(--space-2) 0 var(--space-4);
    }
    .site-nav__list { flex-direction: column; align-items: stretch; }
    .site-nav__link { height: 44px; }
    .site-nav__actions { flex-wrap: wrap; }
    .site-nav__actions .btn { flex: 1 1 auto; justify-content: center; }
    .shell-theme--bar { flex-basis: 100%; margin: 0 0 var(--space-1); justify-content: flex-start; }

    html.js .site-nav__toggle { display: inline-flex; }
    html.js .site-nav__menu {
        position:         absolute;
        top:              100%;
        left:             0;
        right:            0;
        display:          none;
        padding:          var(--space-3) var(--app-page-pad) var(--space-5);
        background-color: var(--color-bg-elevated);
        border-bottom:    1px solid var(--color-border);
        box-shadow:       var(--shadow-md);
    }
    html.js.site-nav-open .site-nav__menu { display: flex; }

    .shell-main--public { padding-top: var(--space-6); padding-bottom: var(--space-10); }
    .site-footer__inner { padding-top: var(--space-10); }
    .site-footer__top { grid-template-columns: 1fr; gap: var(--space-8); padding-bottom: var(--space-8); }
}


/* ── 9. Page tabs and menu counters ───────────────────────── */
/* Second-level navigation of an area (Nav::TABS): real links, one page per
   tab, so each tab has its own URL and works without JS. */
.shell-tabs {
    margin-bottom: var(--space-6);
    border-bottom: 1px solid var(--color-border);
    overflow-x:    auto;
    scrollbar-width: none;
}
.shell-tabs::-webkit-scrollbar { display: none; }
.shell-tabs__list { display: flex; gap: var(--space-1); }
.shell-tabs__link {
    display:       inline-flex;
    align-items:   center;
    gap:           var(--space-2);
    padding:       var(--space-3) var(--space-3);
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color:         var(--color-text-muted);
    font-size:     var(--font-size-sm);
    font-weight:   var(--font-weight-medium);
    white-space:   nowrap;
    transition:    color var(--transition), border-color var(--transition);
}
.shell-tabs__link .icon { font-size: 18px; }
.shell-tabs__link:hover { color: var(--color-text); border-bottom-color: var(--color-border-strong); }
.shell-tabs__link.is-active { color: var(--color-text); border-bottom-color: var(--color-primary); }
.shell-tabs__link.is-active .icon { color: var(--color-primary); }
.shell-tabs__link:focus-visible { outline-offset: -2px; }

/* Counter pill (unread notifications) on a sidebar item or a tab */
.shell-nav__link { position: relative; }
.shell-nav__badge,
.shell-tabs__badge {
    display:          inline-grid;
    place-items:      center;
    min-width:        20px;
    height:           20px;
    padding:          0 6px;
    border-radius:    var(--radius-full);
    background-color: var(--color-primary);
    color:            var(--color-text-on-primary);
    font-size:        11px;
    font-weight:      var(--font-weight-semibold);
    line-height:      1;
}
.shell-nav__badge { margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
    .site-nav__link, .shell-tabs__link { transition: none; }
}
