/* ==========================================================================
   THE TOPBAR (§9.19) — sticky chrome over the paper canvas
   ==========================================================================
   `bg-surface/85` + `backdrop-blur-md`: content scrolling under the topbar
   stays faintly visible, which is what makes the shell feel like a window
   onto a document rather than a frame around one.

   Fixed at 64px (h-16), matching the rail's wordmark block exactly, so the
   two horizontals line up across the fold.
   ========================================================================== */

.impersonation-banner {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 8px var(--space-5);
    border-bottom: 1px solid var(--amber-line);
    background: var(--amber-soft);
    color: var(--amber-strong);
    font-size: var(--text-xs);
}
.impersonation-banner i { font-size: 14px; }
.impersonation-banner strong { font-weight: var(--font-semibold); }
.impersonation-stop-form { margin-left: auto; }
/* The exit button asked for .btn-light, which no sheet defines, so it fell
   back to the transparent .btn base and read as plain text on the banner. */
.impersonation-banner .btn {
    background: var(--surface);
    border-color: var(--amber-line);
    color: var(--amber-strong);
}
.impersonation-banner .btn:hover {
    background: var(--amber-line);
    border-color: var(--amber-line);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    height: var(--topbar-h);
    flex-shrink: 0;
    padding: 0 var(--space-6);
    border-bottom: 1px solid var(--rule);
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* The rail's own trigger, only below the overlay breakpoint. */
.topbar-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink-soft);
    cursor: pointer;
}

/* The breadcrumb: serif 15px for the section, a faint slash, then
   contextual text. It reads the SAME nav config the rail renders. */
.topbar-breadcrumb {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.topbar-crumb-section {
    font-family: var(--font-serif);
    font-size: 15px;
    font-weight: var(--font-medium);
    color: var(--ink);
    white-space: nowrap;
}

.topbar-crumb-sep { color: var(--ink-faint); }

.topbar-crumb-page {
    font-size: var(--text-xs);
    color: var(--ink-mute);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* The search TRIGGER — a button, not an input. It opens the palette. */
.topbar-search {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 224px;
    height: 36px;
    padding: 0 var(--space-3);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    color: var(--ink-mute);
    font-family: inherit;
    font-size: var(--text-xs);
    text-align: left;
    cursor: pointer;
    transition: border-color var(--dur-colour) var(--ease-out-editorial),
                color var(--dur-colour) var(--ease-out-editorial);
}

.topbar-search:hover {
    border-color: var(--rule-strong);
    color: var(--ink-soft);
}

.topbar-search > i { font-size: 12px; flex-shrink: 0; }

.topbar-search-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A keyboard hint is a machine string, so it is mono (Law 5). */
.topbar-search-kbd {
    flex-shrink: 0;
    padding: 2px 6px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ink-faint);
}

@media (min-width: 1024px) { .topbar-search { width: 288px; } }

.topbar-btn,
.topbar-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--ink-soft);
    font-family: inherit;
    font-size: var(--text-xs);
    cursor: pointer;
    transition: background-color var(--dur-colour) var(--ease-out-editorial),
                border-color var(--dur-colour) var(--ease-out-editorial),
                color var(--dur-colour) var(--ease-out-editorial);
}

.topbar-btn:hover,
.topbar-user:hover {
    background: var(--surface-alt);
    color: var(--ink);
}

.topbar-btn-label { font-weight: var(--font-medium); }
.topbar-btn-caret { font-size: 10px; opacity: .6; }

/* The topbar avatar is the exception to the tint-avatar rule: a solid fill
   with white text, because it sits in chrome (§9.13). */
.topbar-user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--coral-strong);
    color: #fff;
    font-weight: var(--font-semibold);
    font-size: var(--text-xs);
}
.topbar-user-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
}
.topbar-user-name {
    font-weight: var(--font-medium);
    font-size: var(--text-xs);
    color: var(--ink);
}
.topbar-user-role {
    font-size: var(--text-label);
    letter-spacing: var(--text-label-ls);
    text-transform: uppercase;
    font-weight: var(--font-semibold);
    color: var(--ink-mute);
}

.topbar-dropdown { position: relative; }
.topbar-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: var(--z-overlay);
    min-width: 256px;
    padding: 6px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-float);
    display: none;
    animation: rise var(--dur-rise) var(--ease-out-editorial) both;
}
.topbar-dropdown-menu-end { left: auto; right: 0; }
.topbar-dropdown.is-open .topbar-dropdown-menu { display: block; }

.topbar-dropdown-header {
    padding: 8px 10px 6px;
    font-size: var(--text-label);
    line-height: var(--text-label-lh);
    letter-spacing: var(--text-label-ls);
    text-transform: uppercase;
    font-weight: var(--font-semibold);
    color: var(--ink-mute);
}
.topbar-dropdown-form { margin: 0; padding: 0; }
.topbar-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: var(--text-sm);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--dur-colour) var(--ease-out-editorial),
                color var(--dur-colour) var(--ease-out-editorial);
}
.topbar-dropdown-item > i:first-child {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    flex-shrink: 0;
    font-size: 13px;
    color: var(--ink-mute);
}
.topbar-dropdown-item:hover { background: var(--surface-alt); }
.topbar-dropdown-item.is-active {
    background: var(--royal-soft);
    color: var(--royal-strong);
}
.topbar-dropdown-item.is-active > i:first-child { color: var(--royal); }
.topbar-dropdown-item-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.25;
}
.topbar-dropdown-item-label { font-weight: var(--font-medium); }
.topbar-dropdown-item-sub { font-size: var(--text-xs); color: var(--ink-mute); }
.topbar-dropdown-item-check { color: var(--royal); margin-left: auto; }
.topbar-dropdown-divider {
    height: 1px;
    margin: 4px 6px;
    background: var(--rule);
}
/* Destructive intent signalled on hover, so a red control is not sitting
   there permanently. */
.topbar-dropdown-exit:hover {
    background: var(--crimson-soft);
    color: var(--crimson-strong);
}
.topbar-dropdown-exit:hover > i:first-child { color: var(--crimson); }

/* A notification count is a graphic plus a number, so the fill is the base
   tone and the digits are tabular. */
.topbar-notification-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    padding: 1px 4px;
    border-radius: var(--radius-full);
    background: var(--crimson-strong);
    color: #fff;
    font-size: 10px;
    line-height: 1.3;
    font-weight: var(--font-semibold);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 1024px) {
    .topbar-menu-btn { display: inline-flex; }
}

@media (max-width: 768px) {
    .topbar { padding: 0 var(--space-4); }
    .topbar-btn-label,
    .topbar-user-text { display: none; }
}

/* On a phone the search trigger, theme toggle, bell and avatar cannot share
   one non-wrapping row. The palette is still reachable with the shortcut. */
@media (max-width: 640px) {
    .topbar-search { display: none; }
}

/* ==========================================================================
   THE COMMAND PALETTE (§9.20)
   ==========================================================================
   Opens at 12vh, not centred — it should sit where the eye already is.
   `--radius-xl` (14px) is used HERE AND NOWHERE ELSE in the product, which
   is what makes the palette feel like a distinct object rather than another
   dialog. The backdrop is navy at 45%, one step heavier than a dialog's.
   ========================================================================== */

.palette-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 12vh var(--space-4) var(--space-4);
    background: rgb(var(--ink-rgb) / 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: fade var(--dur-fade) var(--ease-out-editorial) both;
}

.palette-backdrop[hidden] { display: none; }

.palette {
    width: 100%;
    max-width: 36rem;
    overflow: hidden;
    border: 1px solid var(--rule);
    border-radius: var(--radius-xl);
    background: var(--surface);
    box-shadow: var(--shadow-float);
    animation: rise var(--dur-rise) var(--ease-out-editorial) both;
}

.palette-query {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 48px;
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--rule);
}

.palette-query-icon { color: var(--ink-faint); font-size: 14px; }

.palette-input {
    flex: 1;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    font-size: var(--text-body);
}

.palette-input:focus { outline: none; box-shadow: none; }

.palette-results {
    max-height: 52vh;
    overflow-y: auto;
    padding: 6px 0;
}

.palette-group[hidden] { display: none; }

.palette-group-title {
    padding: 8px var(--space-4) 4px;
    color: var(--ink-mute);
}

.palette-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px var(--space-4);
    color: var(--ink);
    font-size: var(--text-sm);
    text-decoration: none;
}

.palette-row[hidden] { display: none; }

.palette-row-icon {
    width: 16px;
    flex-shrink: 0;
    text-align: center;
    font-size: 13px;
    color: var(--ink-mute);
}

.palette-row-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-row-enter {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--ink-faint);
    opacity: 0;
}

.palette-row.is-active { background: var(--surface-alt); }
.palette-row.is-active .palette-row-icon { color: var(--coral); }
.palette-row.is-active .palette-row-enter { opacity: 1; }

.palette-empty {
    margin: 0;
    padding: var(--space-8) var(--space-4);
    text-align: center;
    font-size: var(--text-sm);
    color: var(--ink-mute);
}

.palette-empty[hidden] { display: none; }

.palette-footer {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 8px var(--space-4);
    border-top: 1px solid var(--rule);
    background: var(--surface-alt);
    font-size: var(--text-xs);
    color: var(--ink-mute);
}

.palette-footer kbd {
    display: inline-block;
    min-width: 18px;
    margin-right: 3px;
    padding: 1px 4px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: 10px;
    text-align: center;
    color: var(--ink-faint);
}

/* ===== Colour theme toggle — three states (§16) =====
   A segmented radiogroup, not a two-state switch. The active segment is
   the only place in the interface where `shadow-raise` appears at rest,
   because it is standing in for a pressed physical control. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    background: var(--surface-alt);
}

.theme-toggle-option {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-mute);
    cursor: pointer;
    transition: background-color var(--dur-colour) var(--ease-out-editorial),
                color var(--dur-colour) var(--ease-out-editorial),
                box-shadow var(--dur-colour) var(--ease-out-editorial);
}

.theme-toggle-option svg { width: 14px; height: 14px; }

.theme-toggle-option:hover { color: var(--ink); }

.theme-toggle-option[aria-checked="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-raise);
}
