/* ============================================================
 * Linear context shells — settings/admin contextual sidebar
 * + page chrome adapted from sample_ui/admin-linear.html.
 *
 * Loaded after linear.css. Adds:
 *   - .linear-sidebar--context modifier (replaces main nav with
 *     a context-specific nav: back link, title, search, sections,
 *     foot)
 *   - .linear-page-head with .linear-tag pill
 *   - .linear-page-sub subtitle line
 *   - .linear-qa-grid quick-action cards
 *   - .linear-dist-row distribution bars
 *   - .linear-health-row live-status rows
 *   - .linear-env-pill, .linear-icon-btn--context
 * ============================================================ */

/* ---------- CONTEXT SIDEBAR ---------- */
.linear-sidebar--context {
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 0;
    gap: 0;
    overflow-y: auto;
}

.linear-sidebar-back {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 12.5px;
    color: var(--fg-muted);
    border-bottom: 1px solid var(--border);
    height: 49px;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    text-decoration: none;
}
.linear-sidebar-back:hover { background: var(--bg-subtle); color: var(--fg); }
.linear-sidebar-back .linear-sidebar-back-arrow {
    font-size: 13px;
    color: var(--fg-faint);
    line-height: 1;
}
.linear-sidebar-back-label {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    gap: 1px;
    min-width: 0;
}
.linear-sidebar-back-label small {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--fg-faint);
}
.linear-sidebar-back-label strong {
    font-weight: 500;
    font-size: 13px;
    color: inherit;
}

.linear-sidebar-title {
    padding: 14px 16px 6px;
    display: flex;
    align-items: center;
    gap: 9px;
}
.linear-sidebar-title-icon {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    background: var(--fg);
    color: var(--bg);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.linear-sidebar-title-icon svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.linear-sidebar-title h2 {
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -0.012em;
    color: var(--fg);
    margin: 0;
}
.linear-sidebar-title-badge {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 500;
}

.linear-sidebar-search {
    padding: 6px 12px;
}
.linear-sidebar-search-trigger {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px 6px 28px;
    font-size: 12.5px;
    color: var(--fg-subtle);
    text-align: left;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: border-color 0.15s;
    font-family: inherit;
    cursor: pointer;
}
.linear-sidebar-search-trigger:hover { border-color: var(--border-strong); }
.linear-sidebar-search-trigger::before {
    content: '';
    position: absolute;
    left: 9px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>") no-repeat center / contain;
}
.linear-sidebar-search-trigger kbd {
    font-family: var(--font-mono);
    font-size: 10.5px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    color: var(--fg-subtle);
}

.linear-sidebar--context .linear-sidebar-section {
    padding: 8px 8px 4px;
    gap: 0;
}
.linear-sidebar--context .linear-sidebar-label {
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--fg-faint);
    text-transform: uppercase;
    padding: 8px 8px 4px;
}
.linear-sidebar--context .linear-nav-item {
    margin-bottom: 1px;
}
.linear-sidebar--context .linear-nav-item.active {
    background: var(--surface-active);    /* was hardcoded #ececec — white-ish pill in dark mode. Now flips via the token. */
    color: var(--fg);
    font-weight: 500;
    box-shadow: inset 2px 0 0 var(--accent);    /* match the base .linear-nav-item.active rule in linear.css so the orange stripe shows on contextual sidebars too */
}

.linear-sidebar-foot {
    margin-top: auto;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 12.5px;
}
/* Avatar + name area is a single link to ``settings.profile``. Styled
   to keep the original row layout (no underline, inherits colour),
   but lights up on hover/focus so it reads as interactive. */
.linear-sidebar-foot-profile {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: inherit;
    padding: 4px 6px;
    margin: -4px -6px;
    border-radius: 5px;
    transition: background-color 0.12s ease;
}
.linear-sidebar-foot-profile:hover,
.linear-sidebar-foot-profile:focus-visible {
    background: var(--bg-subtle);
    color: inherit;
    text-decoration: none;
}
.linear-sidebar-foot-profile:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.linear-sidebar-foot-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--accent-line);
    display: grid;
    place-items: center;
    font-size: 10.5px;
    font-weight: 600;
    flex-shrink: 0;
}
/* Role-tinted avatar modifiers — see ``sidebar_user_foot.html`` for the
   role-to-class map. Default (no modifier) keeps the accent orange. */
.linear-sidebar-foot-avatar--danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: var(--danger-line);
}
.linear-sidebar-foot-avatar--info {
    background: var(--info-soft);
    color: var(--info);
    border-color: var(--info-line);
}
.linear-sidebar-foot-avatar--good {
    background: var(--good-soft);
    color: var(--good);
    border-color: var(--good-line);
}
.linear-sidebar-foot-avatar--warn {
    background: var(--warn-soft);
    color: var(--warn);
    border-color: var(--warn-line);
}
.linear-sidebar-foot-avatar--purple {
    background: var(--purple-soft);
    color: var(--purple);
    border-color: var(--purple-line);
}
.linear-sidebar-foot-avatar--neutral {
    background: var(--bg-subtle);
    color: var(--fg-subtle);
    border-color: var(--border);
}
.linear-sidebar-foot-who {
    line-height: 1.2;
    flex: 1;
    min-width: 0;
}
.linear-sidebar-foot-who strong {
    font-weight: 500;
    display: block;
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.linear-sidebar-foot-who span {
    font-size: 11px;
    color: var(--fg-subtle);
}
.linear-sidebar-foot-gear {
    color: var(--fg-faint);
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    line-height: 1;
}
.linear-sidebar-foot-gear:hover { color: var(--fg); }

/* ---------- ENV PILL (top-right of topbar) ---------- */
.linear-env-pill {
    font-family: var(--font-mono);
    font-size: 10.5px;
    background: var(--bg-subtle);
    color: var(--fg-muted);
    padding: 2px 7px;
    border-radius: 3px;
    letter-spacing: 0.02em;
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.linear-env-pill::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--good);
}

/* ---------- PAGE HEAD (variant with tag) ---------- */
.linear-page-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.linear-page-title-row h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.022em;
    color: var(--fg);
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}
.linear-tag {
    font-size: 11px;
    font-family: var(--font-mono);
    font-weight: 500;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 2px 7px;
    border-radius: 3px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.linear-page-title-row .linear-page-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.linear-page-sub {
    font-size: 13px;
    color: var(--fg-subtle);
    margin-bottom: 24px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.linear-page-sub .mono { font-family: var(--font-mono); }
.linear-page-sub .dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--fg-faint);
}
.linear-live {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--good);
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.linear-live::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--good);
    animation: linear-live-pulse 1.6s ease-in-out infinite;
}
@keyframes linear-live-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
    .linear-live::before { animation: none; }
}

/* ---------- QA GRID (quick-action cards) ---------- */
.linear-qa-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.linear-qa-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    text-decoration: none;
    color: inherit;
}
.linear-qa-card:hover {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}
.linear-qa-card-icon {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: var(--bg-subtle);
    display: grid;
    place-items: center;
    color: var(--fg-muted);
    flex-shrink: 0;
}
.linear-qa-card-icon svg { width: 14px; height: 14px; }
.linear-qa-card-body {
    min-width: 0;
    flex: 1;
}
.linear-qa-card-body h4 {
    font-size: 13px;
    font-weight: 500;
    color: var(--fg);
    letter-spacing: -0.01em;
    margin: 0 0 1px 0;
}
.linear-qa-card-body p {
    font-size: 11.5px;
    color: var(--fg-subtle);
    letter-spacing: -0.005em;
    margin: 0;
}
.linear-qa-card-arrow {
    color: var(--fg-faint);
    font-size: 12px;
    margin-left: auto;
    align-self: center;
    transition: color var(--transition-fast), transform var(--transition-fast);
}
.linear-qa-card:hover .linear-qa-card-arrow {
    color: var(--fg-muted);
    transform: translateX(1px);
}

/* ---------- DEFINITION ROWS (key/value pairs) ---------- */
.linear-defs {
    list-style: none;
    margin: 0;
    padding: 0;
}
.linear-def-row {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 16px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--divider, var(--border));
    align-items: center;
}
.linear-def-row:last-child { border-bottom: none; }
.linear-def-key {
    font-size: 12.5px;
    color: var(--fg-subtle);
}
.linear-def-val {
    font-size: 13px;
    color: var(--fg);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.linear-def-val .mono { font-family: var(--font-mono); }
.linear-def-val--muted { color: var(--fg-faint); font-style: italic; }

/* ---------- DISTRIBUTION ROWS ---------- */
.linear-dist-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--divider, var(--border));
}
.linear-dist-row:last-child { border-bottom: none; }
.linear-dist-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.linear-dist-row-head-left {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--fg);
}
.linear-dist-swatch {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    flex-shrink: 0;
    /* Templates pass the per-role colour as `style="--swatch:#hex"` —
       falls back to the muted token when no swatch is supplied. */
    background: var(--swatch, var(--fg-faint));
}
.linear-dist-row-head-right {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--fg-subtle);
    display: flex;
    gap: 8px;
    align-items: baseline;
}
.linear-dist-row-head-right .count {
    color: var(--fg);
    font-weight: 500;
    font-size: 12.5px;
}
.linear-dist-bar {
    height: 4px;
    background: var(--bg-subtle);
    border-radius: 2px;
    overflow: hidden;
}
.linear-dist-bar-fill {
    height: 100%;
    border-radius: 2px;
    /* Templates pass `style="--swatch:#hex; --pct:N%"` — both are pure
       data, no styling. The bar reads them via var() to colour itself
       and to set its width. */
    background: var(--swatch, var(--fg-faint));
    width: var(--pct, 0%);
    transition: width 0.5s ease;
}

/* ---------- HEALTH ROWS ---------- */
.linear-health-row {
    padding: 12px 14px;
    border-bottom: 1px solid var(--divider, var(--border));
}
.linear-health-row:last-child { border-bottom: none; }
.linear-health-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.linear-health-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--fg);
}
.linear-health-status {
    font-size: 11.5px;
    font-family: var(--font-mono);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    letter-spacing: 0.01em;
}
.linear-health-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.linear-health-status--good { color: var(--good); }
.linear-health-status--warn { color: var(--warn); }
.linear-health-status--info { color: var(--info); }
.linear-health-bar {
    height: 3px;
    background: var(--bg-subtle);
    border-radius: 2px;
    overflow: hidden;
}
.linear-health-bar-fill {
    height: 100%;
    border-radius: 2px;
    /* Templates pass the dynamic width via `style="--pct:N%"`. The
       colour modifier (--good/--warn/--info) supplies the background. */
    width: var(--pct, 0%);
}
.linear-health-bar-fill--good { background: var(--good); }
.linear-health-bar-fill--warn { background: var(--warn); }
.linear-health-bar-fill--info { background: var(--info); }
.linear-health-meta {
    font-size: 11.5px;
    font-family: var(--font-mono);
    color: var(--fg-subtle);
    margin-top: 4px;
    letter-spacing: -0.01em;
}

/* ---------- BADGE INSIDE CARD HEAD ---------- */
.linear-card-head-badge {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--fg-subtle);
    background: var(--bg-subtle);
    border-radius: 3px;
    padding: 1px 5px;
    font-weight: 500;
    margin-left: 6px;
}

/* ---------- RICH STAT (admin-linear sample style) ----------
   Larger than .linear-stat — shows label + menu, large value with
   optional fraction, delta pill (up/down/flat/warn), foot caption. */
.linear-stat-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}
.linear-stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color 0.15s;
}
.linear-stat-card:hover { border-color: var(--border-strong); }
.linear-stat-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.linear-stat-card-label {
    font-size: 12px;
    color: var(--fg-muted);
    font-weight: 500;
    letter-spacing: -0.005em;
    display: flex;
    align-items: center;
    gap: 6px;
}
.linear-stat-card-label .linear-icon { width: 13px; height: 13px; color: var(--fg-faint); }
.linear-stat-card-menu {
    color: var(--fg-faint);
    font-size: 14px;
    line-height: 0;
    cursor: pointer;
    background: transparent;
    border: 0;
    padding: 0;
}
.linear-stat-card-value-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.linear-stat-card-value {
    font-size: 28px;
    font-weight: 500;
    letter-spacing: -0.03em;
    color: var(--fg);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.linear-stat-card-value-frac {
    font-size: 18px;
    color: var(--fg-faint);
    font-weight: 400;
}
.linear-stat-card-delta {
    font-size: 11.5px;
    font-weight: 500;
    font-family: var(--font-mono);
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 5px;
    border-radius: 3px;
}
.linear-stat-card-delta--up   { color: var(--good);   background: var(--good-soft); }
.linear-stat-card-delta--warn { color: var(--warn);   background: var(--warn-soft); }
.linear-stat-card-delta--flat { color: var(--fg-subtle); background: var(--bg-subtle); }
.linear-stat-card-foot {
    font-size: 11.5px;
    color: var(--fg-subtle);
    font-family: var(--font-mono);
    letter-spacing: -0.01em;
}

/* ---------- RICH STAT — sparkline variant ----------
   Adds a slim canvas slot under the value-row + footer (or a small
   .linear-stat-card-mini-meta block). Used on the home dashboard. */
.linear-stat-card--with-sparkline { gap: 6px; }
.linear-stat-card-spark {
    width: 100%;
    height: 28px;
    margin-top: 2px;
}
.linear-stat-card-spark canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Auto-fit stat row — used when the count of cards isn't a clean
   multiple of 4 (e.g. the home dashboard's 7 KPIs). */
.linear-stat-row--auto {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

/* "This week" event row hover (used by the dashboard upcoming-events panel). */
.linear-week-event {
    transition: background var(--transition-fast);
}
.linear-week-event:hover { background: var(--surface-hover); }

/* Footer link inside a stat-card (small ghost-style "View all NCRs →"). */
.linear-stat-card-link {
    font-size: 11.5px;
    color: var(--fg-muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    transition: color var(--transition-fast);
}
.linear-stat-card-link:hover { color: var(--fg); }

/* ---------- TWO-PANEL GRID (dist + health side by side) ---------- */
.linear-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
@media (max-width: 1100px) {
    .linear-stat-row { grid-template-columns: repeat(2, 1fr); }
    .linear-grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .linear-stat-row { grid-template-columns: 1fr; }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1100px) {
    .linear-qa-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
    .linear-qa-grid { grid-template-columns: 1fr; }
    .linear-def-row { grid-template-columns: 1fr; gap: 4px; }
    .linear-page-title-row { flex-direction: column; align-items: flex-start; gap: 12px; }
}
