/* ── App shell: rail, top bar, main column (revamp N1-N7, M1, G12) ──────────
   Version D (docs/roadmap-decisions.md, 2026-10-06): a light rail with
   sentence-case groups and a soft teal active item, search at the top,
   sources and the age of their data at the foot; a thin top bar in the
   main column with the breadcrumb, the freshness chip and the theme.
   Markup: itam/templates/index.html. Behaviour: static/app.js +
   static/lib/source-health.js + static/lib/theme.js. */

body.mc { --rail-w: 224px; }
body.mc.rail-collapsed { --rail-w: 64px; }

/* ── Rail ─────────────────────────────────────────────────────────────── */
.rail {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: var(--z-header);
    width: var(--rail-w);
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    padding: 14px 12px 12px;
    background: var(--rail-bg);
    border-right: 1px solid var(--border);
}

.rail-head { display: flex; align-items: center; gap: var(--sp-2); padding: 0 0 6px 8px; min-height: 36px; }
.rail .brand {
    display: flex; align-items: center; gap: 10px;
    min-width: 0;
    font-family: var(--sans);
    font-size: var(--fs-15);
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--text);
}
.rail .brand img { width: 22px; height: 22px; display: block; object-fit: contain; flex: none; }
.rail .rail-toggle { margin-left: auto; width: 28px; height: 28px; color: var(--text-3); }
.rail .rail-toggle svg { transition: transform var(--dur-med) var(--ease-out); }
body.rail-collapsed .rail .rail-toggle svg { transform: rotate(180deg); }

/* N3: search at the top of the rail, with its shortcut. */
.rail-search {
    display: flex; align-items: center; gap: var(--sp-2);
    width: 100%; height: var(--control-h);
    margin-bottom: 6px;
    padding: 0 8px 0 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--border);
    color: var(--text-3);
    font: inherit;
    font-size: var(--fs-13);
    cursor: pointer;
    white-space: nowrap;
}
.rail-search:hover { box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text-2); }
.rail-search .kbd { margin-left: auto; }

/* The section list scrolls; the foot stays put. */
.rail .top-tabs {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 0 -4px;
    padding: 0 4px 20px;
    scrollbar-width: thin;
    /* A list taller than the screen fades out at the foot, so it reads as
       "scroll for more" rather than cut off. */
    -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 20px), transparent);
    mask-image: linear-gradient(to bottom, black calc(100% - 20px), transparent);
}
.rail .mc-group { display: flex; flex-direction: column; gap: 1px; }
.rail .mc-group-items { display: flex; flex-direction: column; gap: 1px; }

/* N1: group labels in sentence case, quiet; the fold chevron only shows on
   hover or focus, or while the group is folded. */
.rail .mc-sec {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%;
    padding: 10px 10px 4px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    font: inherit;
    font-size: var(--fs-12);
    font-weight: 500;
    color: var(--text-3);
    cursor: pointer;
    text-align: left;
}
.rail .mc-sec:hover { color: var(--text-2); }
.rail .mc-sec-chev { width: 12px; height: 12px; opacity: 0; transition: transform var(--dur-med) var(--ease-out), opacity var(--dur-fast); }
.rail .mc-sec:hover .mc-sec-chev,
.rail .mc-sec:focus-visible .mc-sec-chev,
.rail .mc-sec[aria-expanded="false"] .mc-sec-chev { opacity: 0.8; }
.rail .mc-sec[aria-expanded="false"] .mc-sec-chev { transform: rotate(-90deg); }
html.rail-fold-assets .mc-group[data-group="assets"] .mc-group-items,
html.rail-fold-fleet .mc-group[data-group="fleet"] .mc-group-items,
html.rail-fold-insights .mc-group[data-group="insights"] .mc-group-items,
html.rail-fold-operate .mc-group[data-group="operate"] .mc-group-items,
html.rail-fold-money .mc-group[data-group="money"] .mc-group-items,
html.rail-fold-system .mc-group[data-group="system"] .mc-group-items { display: none; }

.rail .tab-btn {
    position: relative;
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    min-height: 30px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: var(--fs-13);
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--dur-med) var(--ease-out), color var(--dur-med) var(--ease-out);
}
.rail .tab-btn:hover { background: var(--hover); color: var(--text); }
.rail .tab-ico { display: flex; align-items: center; flex: none; color: var(--text-3); }
.rail .tab-ico svg { width: 16px; height: 16px; stroke-width: 1.75; }
.rail .tab-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* Soft teal active item, teal icon, no side bar (G6: teal = selected). */
.rail .tab-btn.active,
.rail .tab-btn[aria-current="page"] { background: var(--accent-dim); color: var(--text); }
.rail .tab-btn.active .tab-ico,
.rail .tab-btn[aria-current="page"] .tab-ico { color: var(--accent); }
.rail .rail-ext { width: 12px; height: 12px; margin-left: auto; color: var(--text-3); opacity: 0; }
.rail .rail-link:hover .rail-ext, .rail .rail-link:focus-visible .rail-ext { opacity: 1; }

/* Small soft badges: orange means "needs action" (G6), money is neutral. */
.rail .mc-badge {
    margin-left: auto;
    padding: 0 7px;
    border-radius: var(--radius-pill);
    font-size: var(--fs-11);
    font-weight: 600;
    line-height: 18px;
    font-variant-numeric: tabular-nums;
    color: var(--warn);
    background: var(--warn-dim);
}
.rail .mc-badge.mc-money { color: var(--text-3); background: transparent; padding: 0; font-weight: 500; }
.mc-badge.bump { animation: badge-pop 0.35s var(--ease-out); }

/* Costs off (production): the entry stays, inert, with a WIP tag. */
.rail .tab-btn.tab-wip { cursor: not-allowed; user-select: none; }
.rail .tab-btn.tab-wip:hover { background: transparent; color: var(--text-2); }
.rail .tab-btn.tab-wip .tab-ico,
.rail .tab-btn.tab-wip .tab-name { opacity: 0.5; }
.rail .tab-wip-overlay {
    margin-left: auto;
    padding: 0 7px;
    border-radius: var(--radius-pill);
    font-size: var(--fs-11);
    font-weight: 600;
    line-height: 18px;
    color: var(--text-3);
    background: var(--sunken);
    box-shadow: inset 0 0 0 1px var(--border);
    pointer-events: none;
}

/* ── Rail foot: sync progress, sources card, account ─────────────────── */
.rail-foot { display: grid; gap: var(--sp-2); padding-top: var(--sp-2); }

/* N2: the sources and the age of their data (DESIGN.md §6). */
.rail-sources {
    display: grid;
    gap: 2px;
    padding: 8px 10px 10px;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--border);
}
.rail-sources-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: 2px; }
.rail-sources-title {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 2px 4px;
    margin-left: -4px;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    font: inherit;
    font-size: var(--fs-12);
    font-weight: 500;
    color: var(--text-3);
    cursor: pointer;
}
.rail-sources-title:hover, .rail-sources-title[aria-expanded="true"] { color: var(--text); }
.rail-sources .pulse-label:empty { display: none; }
.rail-sources .pulse-label { color: var(--warn); font-weight: 500; }
.rail-sources .pulse-label.pulse-failing { color: var(--error); }
.rail-sync-btn { margin-left: auto; }
.rail-sync-btn.syncing svg { animation: spin 1s linear infinite; }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex: none; }
.pulse-dot.stale { background: var(--warn); }
.pulse-dot.error { background: var(--error); }

.src-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.src-row {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--sp-2);
    min-height: 22px;
    font-size: var(--fs-12);
    color: var(--text-2);
}
.src-nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-age { color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* X4: a shape per state, not colour alone: dot = fresh, triangle = behind,
   dash = no data, ring = not configured. */
.src-mk { width: 7px; height: 7px; border-radius: 50%; background: var(--success); justify-self: center; }
.src-row.is-warn, .src-row.is-warn .src-age { color: var(--warn); }
.src-row.is-warn .src-age { font-weight: 600; }
.src-row.is-warn .src-mk {
    width: 0; height: 0; border-radius: 0; background: none;
    border-left: 4.5px solid transparent; border-right: 4.5px solid transparent;
    border-bottom: 8px solid var(--warn);
}
.src-row.is-error, .src-row.is-error .src-age { color: var(--error); }
.src-row.is-error .src-age { font-weight: 600; }
.src-row.is-error .src-mk { width: 9px; height: 2px; border-radius: 1px; background: var(--error); }
.src-row.is-off { color: var(--text-3); }
.src-row.is-off .src-mk { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-3); }

.rail-me { display: flex; align-items: center; gap: 10px; padding: 4px 4px 0 6px; min-width: 0; }
.rail-me-text { min-width: 0; flex: 1; }
.rail-me-name { font-size: var(--fs-13); font-weight: 600; line-height: 16px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-me-role { font-size: var(--fs-12); line-height: 16px; color: var(--text-3); }
.rail-me .icon-btn.has-alert::after {
    content: ''; position: absolute; top: 5px; right: 5px;
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--error); box-shadow: 0 0 0 2px var(--rail-bg);
}
.rail-me .icon-btn.has-alert.stale-alert::after { background: var(--warn); }

/* Sync running: a compact pill above the sources card. */
.sync-progress-pill {
    display: flex; flex-direction: column; align-items: stretch; gap: var(--sp-1);
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--border);
    color: var(--text-2);
    font: inherit;
    font-size: var(--fs-12);
    text-align: left;
    cursor: pointer;
}
.sync-progress-pill[hidden] { display: none; }
.sync-progress-pill:hover { box-shadow: inset 0 0 0 1px var(--accent-border); }
.sync-progress-spinner {
    width: 12px; height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
.sync-progress-src { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-12); color: var(--text-3); }
.sync-progress-src[data-st="ok"] { color: var(--success); }
.sync-progress-src[data-st="error"] { color: var(--error); }
.sync-progress-src[data-st="running"] { color: var(--text-2); }

/* Collapsed rail tooltips (positioned by app.js). */
.rail-tooltip {
    position: fixed;
    z-index: var(--z-tooltip);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    box-shadow: var(--shadow-2), inset 0 0 0 1px var(--border);
    color: var(--text);
    font-size: var(--fs-12);
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
}

/* ── Collapsed rail: a 64px icon strip ───────────────────────────────── */
body.rail-collapsed .rail { padding: 14px 8px 12px; }
body.rail-collapsed .rail-head { flex-direction: column; padding: 0 0 6px; gap: 6px; }
body.rail-collapsed .rail .rail-toggle { margin: 0; }
body.rail-collapsed .brand-name,
body.rail-collapsed .rail-search-label,
body.rail-collapsed .rail-search .kbd,
body.rail-collapsed .rail .tab-name,
body.rail-collapsed .rail .rail-ext,
body.rail-collapsed .rail-sources .src-list,
body.rail-collapsed .rail-sources-title > span:not(.pulse-dot),
body.rail-collapsed .rail-sync-label,
body.rail-collapsed .rail-me .avatar,
body.rail-collapsed .rail-me-text,
body.rail-collapsed #syncProgressPillText,
body.rail-collapsed .sync-progress-list { display: none; }
body.rail-collapsed .rail-search { justify-content: center; padding: 0; }
body.rail-collapsed .rail .tab-btn { justify-content: center; padding: 0; }
body.rail-collapsed .rail .mc-sec {
    height: 1px; padding: 0; margin: 8px 10px 6px;
    background: var(--border); border-radius: 0;
    font-size: 0; pointer-events: none;
}
body.rail-collapsed .rail .mc-sec-chev { display: none; }
body.rail-collapsed .rail .mc-group-items { display: flex !important; }
body.rail-collapsed .rail .mc-badge:not([hidden]),
body.rail-collapsed .rail .tab-wip-overlay {
    position: absolute; top: 5px; right: 10px;
    width: 7px; height: 7px; padding: 0;
    border-radius: 50%; font-size: 0;
    background: var(--warn); box-shadow: none;
}
body.rail-collapsed .rail .mc-badge.mc-money:not([hidden]) { background: var(--text-3); }
body.rail-collapsed .rail-sources { padding: 6px; justify-items: center; }
body.rail-collapsed .rail-sources-head { flex-direction: column; gap: 4px; margin: 0; }
body.rail-collapsed .rail-sources-title { margin: 0; padding: 6px; }
body.rail-collapsed .rail-sync-btn { margin: 0; padding: 4px 6px; }
body.rail-collapsed .rail-me { justify-content: center; padding: 0; }
body.rail-collapsed .sync-progress-pill { align-items: center; padding: 8px 0; }

/* ── Main column ─────────────────────────────────────────────────────── */
.main-col { margin-left: var(--rail-w); min-width: 0; min-height: 100vh; }
.tabs-shell { padding: 20px var(--gutter) 32px; }
/* "Skip to results" / "Skip to filters" point into Investigate: off it their
   targets are hidden, so the links leave the tab order (lib/skip-links.js). */
body:has(#tab-filters[hidden]) .skip-investigate { display: none; }

/* N5: the thin top bar. */
.topbar {
    position: sticky;
    top: 0;
    z-index: calc(var(--z-header) - 1);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    height: var(--topbar-h);
    padding: 0 var(--gutter);
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: var(--fs-13); color: var(--text-3); }
.crumbs .crumb-sep { width: 14px; height: 14px; }
.crumbs .crumb-page { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs .crumb-group { white-space: nowrap; }
.crumbs .crumb-group:empty, .crumbs .crumb-group:empty + .crumb-sep { display: none; }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.mobile-nav-btn { display: none; }

/* E4/N6: data freshness, naming the source. */
.fresh-chip {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    min-width: 0;
    height: 30px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-pill);
    font: inherit;
    font-size: var(--fs-13);
    font-weight: 500;
    color: var(--warn);
    background: var(--warn-dim);
    cursor: pointer;
    white-space: nowrap;
}
.fresh-chip[hidden], .fresh-sync[hidden] { display: none; }
.fresh-chip .fresh-text { overflow: hidden; text-overflow: ellipsis; }
.fresh-chip.is-error { color: var(--error); background: var(--error-dim); }
.fresh-chip:hover { box-shadow: inset 0 0 0 1px currentColor; }

/* Alerts and saved views open under their buttons. */
.topbar-pop { position: relative; }
.topbar .notif-badge {
    position: absolute; top: 2px; right: 1px;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: var(--radius-pill);
    background: var(--error); color: var(--on-accent);
    font-size: var(--fs-10); font-weight: 700; line-height: 16px; text-align: center;
    font-variant-numeric: tabular-nums;
}
.topbar .notif-badge[hidden] { display: none; }
.topbar .header-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    left: auto;
    z-index: var(--z-menu);
    transform-origin: top right;
    animation: menu-in var(--dur-enter) var(--ease-out);
}

/* ── Popovers anchored to the rail foot (Pulse, Options) ─────────────── */
.pulse-panel, .settings-menu {
    position: fixed;
    left: calc(var(--rail-w) + 8px);
    bottom: 12px;
    top: auto; right: auto;
    transform-origin: bottom left;
}
.pulse-panel.open, .settings-menu.open { display: block; animation: menu-in var(--dur-enter) var(--ease-out); }
/* Opened from the top-bar freshness chip: drop down under it instead. */
.pulse-panel[data-anchor="top"] { top: 56px; right: var(--gutter); left: auto; bottom: auto; transform-origin: top right; }

/* P1: menus scale from their origin; transform and opacity only. */
@keyframes menu-in {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes badge-pop {
    0%   { transform: scale(1); }
    45%  { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Laptop tier: a slightly narrower rail. */
@media (min-width: 901px) and (max-width: 1280px) {
    body.mc:not(.rail-collapsed) { --rail-w: 208px; }
}

/* ── Phones and tablets: the rail slides over (M1) ───────────────────── */
.rail-backdrop { display: none; }
@media (max-width: 900px) {
    body.mc, body.mc.rail-collapsed { --rail-w: 248px; }
    .rail {
        transform: translateX(-100%);
        transition: transform var(--dur-enter) var(--ease-out);
        z-index: calc(var(--z-drawer) + 1);
        padding: 14px 12px 12px;
    }
    body.rail-open .rail { transform: none; box-shadow: var(--shadow-3); }
    body.rail-open .rail-backdrop {
        display: block;
        position: fixed; inset: 0;
        z-index: var(--z-drawer);
        background: var(--overlay-bg);
    }
    .main-col { margin-left: 0; }
    .rail .rail-toggle { display: none; }
    .mobile-nav-btn { display: inline-grid; margin-left: -6px; }
    .topbar, .tabs-shell { padding-left: var(--gutter-sm); padding-right: var(--gutter-sm); }
    .tabs-shell { padding-top: 16px; }
    /* The collapsed strip is a desktop affordance: undo it off-canvas. */
    body.rail-collapsed .rail .tab-name,
    body.rail-collapsed .brand-name,
    body.rail-collapsed .rail-search-label,
    body.rail-collapsed .rail-sources .src-list,
    body.rail-collapsed .rail-sources-title > span:not(.pulse-dot),
    body.rail-collapsed .rail-sync-label,
    body.rail-collapsed .rail-me .avatar,
    body.rail-collapsed .rail-me-text { display: revert; }
    body.rail-collapsed .rail-sources .src-list { display: grid; }
    body.rail-collapsed .rail-head { flex-direction: row; padding: 0 0 6px 8px; }
    body.rail-collapsed .rail .tab-btn { justify-content: flex-start; padding: 0 10px; }
    body.rail-collapsed .rail .mc-sec { height: auto; padding: 12px 10px 4px; margin: 0; background: transparent; font-size: var(--fs-12); pointer-events: auto; }
    body.rail-collapsed .rail .mc-badge:not([hidden]) { position: static; width: auto; height: auto; padding: 0 7px; font-size: var(--fs-11); background: var(--warn-dim); }
    body.rail-collapsed .rail-sources { padding: 8px 10px 10px; justify-items: stretch; }
    body.rail-collapsed .rail-sources-head { flex-direction: row; }
    body.rail-collapsed .rail-me { justify-content: flex-start; padding: 4px 4px 0 6px; }
    .pulse-panel, .settings-menu,
    .pulse-panel[data-anchor="top"] {
        left: var(--gutter-sm); right: var(--gutter-sm);
        width: auto;
        top: auto; bottom: 12px;
        z-index: calc(var(--z-drawer) + 2);
    }
}
@media (max-width: 640px) {
    /* The theme lives in Account and options on phones. */
    .topbar-theme { display: none; }
    .crumbs .crumb-group, .crumbs .crumb-sep { display: none; }
    .fresh-sync { display: none; }
    .topbar .header-panel { position: fixed; top: 56px; left: var(--gutter-sm); right: var(--gutter-sm); width: auto; }
}

/* Alerts bell: the line that counts unread alerts the first page left out,
   and the "Show older alerts" button under the list
   (static/lib/notifications.js notShownHtml and notifListHtml). */
.notif-more { padding: 6px 8px; margin-bottom: 4px; font-size: var(--fs-12); color: var(--text-2); border-bottom: 1px solid var(--border-sub); }
.notif-older { display: block; margin: 8px auto 4px; }
