/* ==========================================================================
   Editorial Command Centre — app shell
   docs/design-system.md §8.1 (shell + z-index ladder), §8.4 PageHeader,
   §8.5 Section, §9.17 Rail, §9.18 the one ticking element, §9.19 Topbar,
   §9.20 Command palette.

   Fixed measurements, all from §8.1:
     rail 232px · rail collapsed 68px · rail header h-16 · collapse bar h-11
     topbar h-16 · canvas max-w-[1600px] px-6 py-7 lg:px-8
   Z-index ladder: topbar 20 · rail 30 · overlays 50 · toasts 60 · tooltips 70.
   ========================================================================== */

/* ── §8.1 The shell ─────────────────────────────────────────────────────── */

.ec-shell {
    /* `relative` is load-bearing: it makes the shell a containing block, so an
       absolutely-positioned descendant resolves against it and is clipped by
       overflow-hidden instead of stretching the document and producing a
       second scrollbar. */
    position: relative;
    display: flex;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--paper);
}

.ec-shell__main {
    display: flex;
    min-width: 0;
    flex: 1 1 0%;
    flex-direction: column;
}

.ec-canvas-scroll {
    flex: 1 1 0%;
    overflow-y: auto;
}

.ec-canvas {
    margin-inline: auto;
    width: 100%;
    max-width: 1600px;
    padding: 1.75rem 1.5rem;
}

@media (min-width: 1024px) {
    .ec-canvas { padding-inline: 2rem; }
}

/* ── §9.17 Rail ─────────────────────────────────────────────────────────── */

.ec-rail {
    position: relative;
    z-index: 30;
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    width: 232px;
    background-color: var(--chrome);
    border-right: 1px solid var(--chrome-rule);
}

.ec-rail.is-collapsed { width: 68px; }

/* The rail renders expanded on the server and adopts the stored preference on
   hydration, with the width transition suppressed until then — so adopting the
   preference reads as the initial state rather than an animation nobody asked
   for. */
.ec-rail.is-hydrated {
    transition: width 200ms var(--ease-out-editorial);
}

.ec-rail__header {
    display: flex;
    align-items: center;
    height: 4rem;
    flex-shrink: 0;
    padding-inline: 1.25rem;
    border-bottom: 1px solid var(--chrome-rule);
    overflow: hidden;
}
.ec-rail.is-collapsed .ec-rail__header { padding-inline: 0; justify-content: center; }

/* Collapsed, the wordmark is not merely clipped by the header's overflow — it
   leaves the flow entirely. While it was still laid out, the brand link was
   centred as mark-plus-text, which pushed the mark off-centre and left the
   first letters of the name showing at the rail's edge. */
.ec-rail.is-collapsed .ec-rail__wordmark { display: none; }
.ec-rail.is-collapsed .ec-rail__brand { gap: 0; }

.ec-rail__brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    text-decoration: none;
    min-width: 0;
}

/* The institution's mark at 28px — the same artwork as the browser tab. It
   brings its own light disc, so it needs no plate behind it. */
.ec-rail__mark {
    display: block;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.ec-rail__wordmark {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}
.ec-rail__name {
    font-family: var(--font-serif);
    font-size: 1rem;
    font-weight: 600;
    color: var(--chrome-text-strong);
    white-space: nowrap;
}
.ec-rail__name-dot { color: var(--coral); }
.ec-rail__descriptor {
    font-size: 10px;
    line-height: 1.4;
    letter-spacing: var(--text-label-ls);
    text-transform: uppercase;
    font-weight: 600;
    color: var(--chrome-text-mute);
    white-space: nowrap;
}

.ec-rail__nav {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
    /* `padding: 0` matters: a <ul> carries a 40px default inline padding, which
       pushed every nav item away from the rail's left edge and left the coral
       active marker floating in open space. */
    padding: 0.75rem 0;
    list-style: none;
    margin: 0;
}

.ec-rail__group-label {
    padding: 0.75rem 1.25rem 0.375rem;
    font-size: 10px;
    line-height: 1.4;
    letter-spacing: var(--text-label-ls);
    text-transform: uppercase;
    font-weight: 600;
    color: var(--chrome-text-mute);
    white-space: nowrap;
}
/* collapsed, a group header becomes a hairline divider instead */
.ec-rail.is-collapsed .ec-rail__group-label {
    height: 1px;
    padding: 0;
    margin: 0.625rem 1rem;
    overflow: hidden;
    background-color: var(--chrome-rule);
    color: transparent;
}

.ec-rail__item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-inline: 0.5rem;
    border-radius: var(--radius-md);
    padding: 0.5rem 0.75rem;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    color: var(--chrome-text);
    white-space: nowrap;
    transition: background-color 160ms var(--ease-out-editorial),
                color 160ms var(--ease-out-editorial);
}
.ec-rail__item:hover {
    background-color: color-mix(in srgb, var(--chrome-alt) 60%, transparent);
    color: var(--chrome-text-strong);
}
.ec-rail__item svg {
    /* a deliberate optical adjustment against 14px text */
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--chrome-text-mute);
}

.ec-rail__item.is-active {
    background-color: var(--chrome-alt);
    color: var(--chrome-text-strong);
}
.ec-rail__item.is-active svg { color: var(--coral); }

/* the 2px coral marker */
.ec-rail__item.is-active::before {
    content: "";
    position: absolute;
    left: -0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 1.25rem;
    border-radius: 0 9999px 9999px 0;
    background-color: var(--coral);
}

.ec-rail.is-collapsed .ec-rail__item {
    justify-content: center;
    padding-inline: 0;
}
.ec-rail.is-collapsed .ec-rail__label { display: none; }

.ec-rail__badge {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    margin-left: auto;
    border-radius: 9999px;
    padding: 0.125rem 0.375rem;
    font-size: 11px;
    font-weight: 600;
    background-color: var(--chrome-alt);
    color: var(--chrome-text);
}
.ec-rail__item.is-active .ec-rail__badge {
    background-color: #fff;
    color: var(--coral-strong);
}
/* collapsed, the count degrades to a 6px coral dot */
.ec-rail.is-collapsed .ec-rail__badge {
    position: absolute;
    top: 0.25rem;
    right: 0.5rem;
    width: 6px;
    height: 6px;
    padding: 0;
    font-size: 0;
    background-color: var(--coral);
    color: transparent;
}

.ec-rail__collapse {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    height: 2.75rem;
    flex-shrink: 0;
    border: 0;
    border-top: 1px solid var(--chrome-rule);
    background: none;
    padding-inline: 1.25rem;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--chrome-text-mute);
    cursor: pointer;
    transition: color 160ms var(--ease-out-editorial);
}
.ec-rail__collapse:hover { color: var(--chrome-text-strong); }
.ec-rail__collapse svg { width: 16px; height: 16px; flex-shrink: 0; }
.ec-rail.is-collapsed .ec-rail__collapse {
    justify-content: center;
    padding-inline: 0;
}
.ec-rail.is-collapsed .ec-rail__collapse span { display: none; }

/* ── §9.18 The SLA read at the foot of the rail ─────────────────────────── */

.ec-countdown {
    flex-shrink: 0;
    border-top: 1px solid var(--chrome-rule);
    padding: 1rem;
}
.ec-rail.is-collapsed .ec-countdown { display: none; }

.ec-countdown__label {
    font-size: 9px;
    line-height: 1.4;
    letter-spacing: var(--text-label-ls);
    text-transform: uppercase;
    font-weight: 600;
    color: var(--chrome-text-mute);
}
.ec-countdown__name {
    margin-top: 0.25rem;
    font-family: var(--font-serif);
    font-size: 13px;
    font-weight: 500;
    color: var(--chrome-text-strong);
}
/* Left-aligned with the label and the ticket number above it. It was ranged
   right to sit under the right end of the progress track; with the track gone
   that left it hanging away from everything else in the block. */
.ec-countdown__read {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    margin-top: 0.375rem;
    font-size: 10px;
    color: var(--chrome-text-mute);
}

/* ── §9.19 Topbar ───────────────────────────────────────────────────────── */

.ec-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    height: 4rem;
    flex-shrink: 0;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--rule);
    /* content scrolling under the topbar stays faintly visible, which is what
       makes the shell feel like a window onto a document */
    background-color: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding-inline: 1.5rem;
}

.ec-breadcrumb {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
}
.ec-breadcrumb__current {
    font-family: var(--font-serif);
    font-size: 15px;
    color: var(--ink);
    white-space: nowrap;
}
.ec-breadcrumb__sep { color: var(--ink-faint); }
.ec-breadcrumb__context {
    font-size: var(--text-xs);
    color: var(--ink-mute);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ec-topbar__spacer { margin-left: auto; }

/* the search trigger is a button, not an input — it opens the palette */
.ec-search-trigger {
    display: flex;
    height: 2.25rem;
    width: 14rem;
    align-items: center;
    gap: 0.625rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--rule);
    background-color: var(--surface-alt);
    padding-inline: 0.75rem;
    text-align: left;
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    color: var(--ink-mute);
    cursor: pointer;
    transition: border-color 160ms var(--ease-out-editorial),
                color 160ms var(--ease-out-editorial);
}
.ec-search-trigger:hover {
    border-color: var(--rule-strong);
    color: var(--ink-soft);
}
.ec-search-trigger svg { width: 1rem; height: 1rem; flex-shrink: 0; }
.ec-search-trigger__text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@media (min-width: 1024px) { .ec-search-trigger { width: 18rem; } }

.ec-kbd {
    margin-left: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--rule);
    background-color: var(--surface);
    padding: 0.125rem 0.375rem;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ink-faint);
}

.ec-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 16rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--rule);
    background-color: var(--surface);
    box-shadow: var(--shadow-float);
    animation: rise 240ms var(--ease-out-editorial) both;
    padding: 0.375rem;
    z-index: 50;
}
.ec-menu[hidden] { display: none; }
.ec-menu-wrap { position: relative; }

.ec-menu__item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0.625rem;
    border: 0;
    border-radius: var(--radius-md);
    background: none;
    padding: 0.5rem 0.625rem;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--ink-soft);
    text-decoration: none;
    text-align: left;
    cursor: pointer;
    transition: background-color 160ms var(--ease-out-editorial),
                color 160ms var(--ease-out-editorial);
}
.ec-menu__item:hover { background-color: var(--surface-alt); color: var(--ink); }
.ec-menu__item svg { width: 1rem; height: 1rem; flex-shrink: 0; }

/* destructive intent signalled without a red button sitting there permanently */
.ec-menu__item--danger:hover {
    background-color: var(--crimson-soft);
    color: var(--crimson-strong);
}

.ec-menu__header {
    padding: 0.625rem;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 0.375rem;
}

/* ── §9.20 Command palette ──────────────────────────────────────────────── */

.ec-palette-root {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    /* opens where the eye already is, not centred */
    padding: 1rem 1rem 1rem;
    padding-top: 12vh;
    background-color: color-mix(in srgb, var(--chrome) 45%, transparent);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: fade 180ms var(--ease-out-editorial) both;
}
.ec-palette-root[hidden] { display: none; }

.ec-palette {
    width: 100%;
    max-width: 36rem;
    overflow: hidden;
    /* rounded-xl is used HERE AND NOWHERE ELSE, which is what makes the
       palette feel like a distinct object rather than another dialog */
    border-radius: var(--radius-xl);
    border: 1px solid var(--rule);
    background-color: var(--surface);
    box-shadow: var(--shadow-float);
    animation: rise 240ms var(--ease-out-editorial) both;
}

.ec-palette__query {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    height: 3rem;
    padding-inline: 1rem;
    border-bottom: 1px solid var(--rule);
}
.ec-palette__query svg { width: 1rem; height: 1rem; color: var(--ink-mute); flex-shrink: 0; }
.ec-palette__input {
    flex: 1 1 0%;
    border: 0;
    background: none;
    font-family: var(--font-sans);
    font-size: var(--text-body);
    color: var(--ink);
    outline: none;
}
.ec-palette__input::placeholder { color: var(--placeholder); }

.ec-palette__results {
    max-height: 52vh;
    overflow-y: auto;
    padding-block: 0.375rem;
}
.ec-palette__group {
    padding: 0.5rem 1rem 0.25rem;
    color: var(--ink-mute);
}
.ec-palette__item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0.625rem;
    border: 0;
    background: none;
    padding: 0.5rem 1rem;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--ink-soft);
    text-decoration: none;
    cursor: pointer;
}
.ec-palette__item svg { width: 1rem; height: 1rem; flex-shrink: 0; color: var(--ink-mute); }
.ec-palette__item.is-active {
    background-color: var(--surface-alt);
    color: var(--ink);
}
.ec-palette__item.is-active svg { color: var(--coral); }
.ec-palette__enter { margin-left: auto; color: var(--ink-faint); }
.ec-palette__empty {
    padding: 1.5rem 1rem;
    text-align: center;
    font-size: var(--text-sm);
    color: var(--ink-mute);
}

.ec-palette__footer {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-top: 1px solid var(--rule);
    background-color: var(--surface-alt);
    padding: 0.5rem 1rem;
    font-size: var(--text-xs);
    color: var(--ink-mute);
}
.ec-palette__footer .ec-kbd { margin-left: 0; }

/* ── §8.4 PageHeader ────────────────────────────────────────────────────── */

.ec-page-header {
    border-bottom: 1px solid var(--rule);
    padding-bottom: 1.25rem;
}
.ec-page-header__row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    column-gap: 1.5rem;
    row-gap: 1rem;
}
.ec-page-header__copy { min-width: 0; }
.ec-page-header__eyebrow { color: var(--ink-mute); }
.ec-page-header__title {
    margin: 0.5rem 0 0;
    font-family: var(--font-serif);
    font-size: var(--text-h1);
    line-height: var(--text-h1-lh);
    letter-spacing: var(--text-h1-ls);
    color: var(--ink);
    font-weight: 400;
}
.ec-page-header__meta {
    margin-top: 0.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 0.5rem;
    font-size: var(--text-sm);
    color: var(--ink-soft);
}
.ec-page-header__meta .ec-sep { color: var(--ink-faint); }
.ec-page-header__actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.5rem;
}

/* ── §8.5 Section ───────────────────────────────────────────────────────── */

.ec-section__head {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.ec-section__title { flex-shrink: 0; color: var(--ink); }
.ec-section__rule {
    /* the fading rule: says "this section starts here" without drawing a box */
    flex: 1 1 0%;
    min-width: 1.5rem;
    height: 1px;
    background: linear-gradient(90deg, var(--rule) 0%, transparent 100%);
}
.ec-section__actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.375rem;
}
.ec-section__description {
    margin: 0.5rem 0 0;
    max-width: 68ch;
    font-size: var(--text-sm);
    color: var(--ink-mute);
}
.ec-section__body { margin-top: 1rem; }

/* ── §8.2 Page composition ──────────────────────────────────────────────── */

.ec-page {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;      /* list/detail pages */
    padding-bottom: 1rem;
}
.ec-page--dashboard { gap: 2rem; }

/* ── §8.3 Grid conventions ──────────────────────────────────────────────── */

.ec-grid-3 { display: grid; gap: 1.25rem; }
.ec-grid-2 { display: grid; gap: 1.5rem; }
.ec-grid-cards { display: grid; gap: 1rem; }

@media (min-width: 640px) {
    .ec-grid-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
    .ec-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ec-grid-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
    .ec-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ── Rail as an overlay below lg (§8.3) ─────────────────────────────────── */

.ec-rail-scrim {
    position: fixed;
    inset: 0;
    z-index: 29;
    background-color: color-mix(in srgb, var(--chrome) 35%, transparent);
    animation: fade 180ms var(--ease-out-editorial) both;
}
.ec-rail-scrim[hidden] { display: none; }

.ec-rail__mobile-close { display: none; }

@media (max-width: 1023px) {
    .ec-rail {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        transition: transform 200ms var(--ease-out-editorial);
    }
    .ec-rail.is-open { transform: none; }
    .ec-rail.is-collapsed { width: 232px; }
    .ec-canvas { padding-inline: 1.5rem; }
}

@media (min-width: 1024px) {
    .ec-topbar__menu-toggle { display: none; }
}

/* ── Environment banner, restyled onto the token contract ───────────────── */

.ec-env-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 2rem;
    flex-shrink: 0;
    background-color: var(--amber-soft);
    border-bottom: 1px solid var(--amber-line);
    color: var(--amber-strong);
    font-size: var(--text-xs);
}
.ec-env-banner svg { width: 0.875rem; height: 0.875rem; }

/* The banner sits above the shell, so the shell loses its height. */
body.has-env-banner .ec-shell { height: calc(100dvh - 2rem); }

/* The topbar's notification count sits on the trigger, not in the flow. */
.ec-topbar__count {
    position: absolute;
    top: -2px;
    right: -2px;
    height: auto;
    min-width: 15px;
    padding-inline: 3px;
    justify-content: center;
    color: #fff;
    border-color: transparent;
}

/* ── Legacy page headers, restyled as §8.4 PageHeader ───────────────────────
   The old `dashboard-welcome` block is structurally identical to PageHeader —
   an eyebrow, an h1, a meta line and an action cluster — so it takes the same
   recipe rather than being rewritten in ten templates.

   These rules retire as each remaining page is converted to {% pageheader %}.
   ------------------------------------------------------------------------- */

.dashboard-welcome {
    border-bottom: 1px solid var(--rule);
    padding-bottom: 1.25rem;
    margin-bottom: 1.75rem;
    background: none;
    box-shadow: none;
}
.dashboard-welcome-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    column-gap: 1.5rem;
    row-gap: 1rem;
}
.dashboard-welcome-copy { min-width: 0; }
.dashboard-welcome-copy .label { color: var(--ink-mute); display: block; }
.dashboard-welcome h1,
.dashboard-welcome-copy h1 {
    margin: 0.5rem 0 0;
    font-family: var(--font-serif);
    font-size: var(--text-h1);
    line-height: var(--text-h1-lh);
    letter-spacing: var(--text-h1-ls);
    font-weight: 400;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 0.625rem;
}
.dashboard-welcome h1 svg { width: 1.5rem; height: 1.5rem; color: var(--ink-mute); }
.dashboard-welcome p {
    margin: 0.5rem 0 0;
    font-size: var(--text-sm);
    color: var(--ink-soft);
}
.dashboard-welcome-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.dashboard-welcome-actions form { margin: 0; }

/* ── Standalone error pages (§9.24) ─────────────────────────────────────── */

.ec-error-page {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background-color: var(--paper);
}
.ec-error-page__code { color: var(--ink-faint); margin: 1.25rem 0 0; }
.ec-error-page .ec-state { padding-block: 0; }
.ec-error-page .ec-state__title { margin-top: 0.375rem; }
.ec-error-page__actions {
    margin-top: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}
.ec-error-page__report { margin-top: 2rem; }
