/* Reusable widget styles. Defined ONCE — pages compose, never redefine.
 *
 * Component list (grows as PRs land):
 *
 *  PR1:  .btn, .btn--primary, .btn--ghost, .btn--danger, .btn--icon,
 *        .input, .field, .field__label, .field__hint,
 *        .policy-list, .banner, .card, .card--elevated, .pill
 *  PR2+: card variants, dropdown, drawer, modal
 *  PR5:  composer, sub-agent-card, tool-row, callout
 */

/* ── Buttons ──────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    /* One shared control height for every button — without it, padded
       text buttons (~39px) and the fixed icon squares drift apart and
       read as two different control sizes side by side. */
    height: 38px;
    padding: 0 16px;
    border-radius: var(--r-md);
    border: 1px solid transparent;
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.2;
    transition: background-color 120ms ease, border-color 120ms ease,
                color 120ms ease, opacity 120ms ease;
    user-select: none;
}

/* Many "buttons" are really <a> elements — kill the global prose-link
   underline on hover for anything with button geometry. An underline
   on a bordered/filled control reads as a rendering glitch. */
.btn:hover,
.btn:focus {
    text-decoration: none;
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn--primary {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}
.btn--primary:hover:not(:disabled) {
    background: var(--primary-h);
    border-color: var(--primary-h);
    text-decoration: none;
}

.btn--ghost {
    background: transparent;
    color: var(--ink-muted);
    border-color: var(--border);
}
.btn--ghost:hover:not(:disabled) {
    background: var(--surface-3);
    color: var(--ink);
    border-color: var(--border);
}

/* Soft / tinted — a primary-coloured fill at low intensity. Sits between
   ghost (quiet) and primary (loud): used for a meaningful-but-secondary
   action you still want to read as "on brand" (e.g. Check for new alerts). */
.btn--soft {
    background: var(--primary-tint);
    color: var(--primary);
    border-color: transparent;
}
.btn--soft:hover:not(:disabled) {
    background: color-mix(in srgb, var(--primary) 16%, var(--surface));
    color: var(--primary-h);
}

.btn--danger {
    background: var(--surface);
    color: var(--danger);
    border-color: var(--danger);
}
.btn--danger:hover:not(:disabled) {
    background: var(--danger-tint);
}

.btn--icon {
    /* Square at the shared .btn control height. */
    width: 38px;
    padding: 0;
    border-radius: var(--r-md);
    border-color: var(--border);
}

.btn--block {
    width: 100%;
}

/* ── Tooltip ──────────────────────────────────────────────────────
   Styled, instant replacement for the native ``title`` bubble (which is
   unstyled and lags ~1s before showing). Add ``data-tooltip="…"`` to any
   element — keep ``aria-label`` alongside for screen readers, and DROP
   the ``title`` attr so the OS tooltip doesn't double up. Pure CSS, so
   CSP-safe. The host needs a positioning context; we set it here. The
   bubble floats above the element and centres on it. Requires the host's
   container to not clip overflow (the /home card doesn't). */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) translateY(2px);
    padding: 4px 8px;
    border-radius: var(--r-sm);
    background: var(--ink);
    color: #fff;
    font-size: var(--text-xs);
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 120ms ease, transform 120ms ease;
    z-index: 40;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Placement variant: bubble BELOW the element. For hosts that sit at
   the top edge of a clipping container (e.g. the investigate page's
   workbench bar inside .workspace { overflow: hidden }), where the
   default above-the-element bubble gets cut off. */
[data-tooltip][data-tooltip-pos="bottom"]::after {
    bottom: auto;
    top: calc(100% + 6px);
    transform: translateX(-50%) translateY(-2px);
}
[data-tooltip][data-tooltip-pos="bottom"]:hover::after,
[data-tooltip][data-tooltip-pos="bottom"]:focus-visible::after {
    transform: translateX(-50%) translateY(0);
}

/* ── Form fields ──────────────────────────────────────────────── */

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field__label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--ink);
}

.field__label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.field__label-action {
    font-size: var(--text-xs);
    color: var(--ink-muted);
    text-decoration: none;
}

.field__label-action:hover {
    color: var(--primary);
    text-decoration: none;
}

.field__hint {
    font-size: var(--text-xs);
    color: var(--ink-muted);
}

.input {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: var(--text-base);
    line-height: 1.4;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.input:focus,
.input:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.input--error {
    border-color: var(--danger);
}

.input::placeholder {
    color: var(--muted-2);
}

/* Input with a trailing icon button (e.g. show/hide password). The
 * button is absolutely positioned over the right edge; padding-right
 * on the input keeps typed text from sliding under it. */
.field__input-wrap {
    position: relative;
}

.field__input-wrap .input {
    padding-right: 40px;
}

.field__eye-btn {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink-muted);
    padding: 0;
    transition: color 120ms ease;
}

.field__eye-btn:hover {
    color: var(--ink);
}

/* ── Password policy hint list (used on landing) ───────────────── */

.policy-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px var(--s-3);
}

/* A satisfied rule turns green with a ✓ and stays visible — no
 * per-item disappearing act (it read as glitchy). The whole list
 * eases away together once every rule is met, handled by the
 * caller's CSS toggling the parent `is-validating` class. */
.policy-list__item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-xs);
    color: var(--ink-muted);
    transition: color 200ms ease;
}

.policy-list__item::before {
    content: "○";
    font-size: 14px;
    color: var(--muted-2);
    display: inline-block;
    width: 14px;
    text-align: center;
    transition: color 200ms ease;
}

/* Met — colour shifts to success and the ○ swaps to a ✓ that pops
 * in. Transitions handle the colour ramp on the text. */
.policy-list__item--met {
    color: var(--success);
}

.policy-list__item--met::before {
    content: "✓";
    color: var(--success);
    animation: rule-met-pop 250ms ease;
}

@keyframes rule-met-pop {
    0%   { transform: scale(1);   }
    40%  { transform: scale(1.4); }
    100% { transform: scale(1);   }
}

/* ── Banners / inline messages ─────────────────────────────────── */

.banner {
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: var(--text-sm);
}

.banner--error {
    background: var(--danger-tint);
    border-color: #fecaca;
    color: var(--danger);
}

.banner--info {
    background: var(--info-tint);
    border-color: #bfdbfe;
    color: var(--info);
}

.banner--success {
    background: var(--success-tint);
    border-color: #a7f3d0;
    color: var(--success);
}

/* ── Cards ────────────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s-5);
}

.card--elevated {
    box-shadow: var(--shadow-md);
    border-color: var(--border-soft);
}

/* ── Pills / badges ───────────────────────────────────────────── */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: var(--r-pill);
    font-size: var(--text-xs);
    font-weight: 500;
    background: var(--surface-3);
    color: var(--ink-muted);
}

.pill--primary { background: var(--primary-soft); color: var(--primary); }
.pill--success { background: var(--success-soft); color: var(--success); }
.pill--danger  { background: var(--danger-soft);  color: var(--danger); }
.pill--warn    { background: var(--warn-soft);    color: var(--warn); }
.pill--info    { background: var(--info-soft);    color: var(--info); }

/* ── Runs menu (previous-runs dropdown) ──────────────────────────────
   Shared by the /home alert row and the investigate-page banner. Native
   <details> disclosure — no JS, CSP-safe. Summary is a small button
   (icon glyph + run count); the list is an absolutely-positioned popover.
   Colours come from tokens so it adopts each page's palette (the
   investigate page overrides surface/ink inside #workspace). */
.runs-menu {
    position: relative;
    display: inline-flex;
}
.runs-menu__summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    /* Override .btn--icon's fixed 32px square so icon + count fit. */
    width: auto;
    min-width: 32px;
    padding: 0 8px;
}
.runs-menu__summary::-webkit-details-marker { display: none; }
.runs-menu__count {
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1;
}
.runs-menu__list {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 30;
    min-width: 220px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.12));
}
.runs-menu__label {
    margin: 2px 8px 6px;
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-muted);
}
.runs-menu__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: 8px;
    border-radius: var(--r-sm, 6px);
    text-decoration: none;
    color: inherit;
}
.runs-menu__item:hover { background: var(--surface-3); text-decoration: none; }
.runs-menu__item[aria-current="page"] { background: var(--primary-soft); }
.runs-menu__verdict {
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--surface-3);
    color: var(--ink);
    white-space: nowrap;
}
.runs-menu__verdict--latest        { background: var(--primary-soft); color: var(--primary); }
.runs-menu__verdict--malicious,
.runs-menu__verdict--true_positive { background: var(--danger-soft);  color: var(--danger); }
.runs-menu__verdict--benign,
.runs-menu__verdict--false_positive{ background: var(--success-soft); color: var(--success); }
.runs-menu__when {
    flex-shrink: 0;
    font-size: var(--text-xs);
    color: var(--ink-muted);
}

/* ── Modals (overlay dialogs) ──────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal__scrim {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.modal__panel {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    width: min(720px, 92vw);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    animation: modal-in 160ms ease-out;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal__header {
    padding: var(--s-4) var(--s-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal__title {
    font-size: var(--text-lg);
}

.modal__body {
    padding: var(--s-4) var(--s-5);
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}

.modal__footer {
    padding: var(--s-3) var(--s-5);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--s-3);
}

.modal__textarea {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    min-height: 240px;
    resize: vertical;
}

.modal__pre {
    margin: 0;
    padding: var(--s-3);
    background: var(--surface-3);
    border-radius: var(--r-md);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-soft);
    overflow-y: auto;
    max-height: 60vh;
}

/* Soft recommended-path callout inside a modal body — a calm tinted box
   that nudges toward the preferred action without reading as a warning. */
.modal__tip {
    display: flex;
    align-items: flex-start;
    gap: var(--s-2);
    padding: var(--s-3);
    background: var(--primary-tint);
    border-radius: var(--r-md);
    font-size: var(--text-sm);
    line-height: 1.5;
    color: var(--text-soft);
}
.modal__tip svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin-top: 1px;
    color: var(--primary);
}
.modal__tip strong { color: var(--primary); font-weight: 600; }

/* ── Page hero (shared) ─────────────────────────────────────────────
 * One hero pattern for the primary surfaces (home, connections,
 * schedule, memory): 24px/600/-0.01em title + muted base-size lede,
 * left-aligned. Pages add their own BEM class alongside for layout
 * hooks but MUST NOT redefine the type — that's how the four pages
 * drifted apart in the first place. */
.page-hero {
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
}

.page-hero__title {
    font-size: var(--text-2xl);
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
}

.page-hero__lede {
    color: var(--ink-muted);
    line-height: 1.55;
    margin: 0;
}

/* ── Alert content (shared) ─────────────────────────────────────────
 * Hero card + raw payload for an alert. Rendered by the standalone
 * /alert/<id> page AND injected into the /home right-side drawer via
 * GET /api/alerts/<id>/content, so the styles must be shared (here),
 * not page-scoped. See ui/templates/components/_alert_content.html. */
.alert-content {
    display: flex;
    flex-direction: column;
    gap: var(--s-5);
}

.alert-detail__hero {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}

.alert-detail__hero-head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
}

.alert-detail__title {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--ink);
}

.alert-detail__meta {
    display: flex;
    align-items: center;
    gap: var(--s-2);
}

.alert-detail__summary {
    color: var(--ink);
    line-height: 1.5;
    margin: 0;
}

.alert-detail__summary-label {
    font-weight: 600;
    margin-right: var(--s-2);
}

.alert-detail__status {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    color: var(--ink-muted);
    font-size: var(--text-sm);
}

/* ── Status indicator + verdict badge (shared) ──────────────────────
 * Used by /home alert rows AND the alert-content fragment above, so
 * they live here rather than pages/home.css. The investigate page
 * redefines .status-dot in its own stream.css (loads later, wins). */

/* Status — mirrors the investigate-page workbench dot:
   10px dot + 3px soft-colour halo ring. */
.status {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-weight: 500;
}
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: var(--r-pill);
    background: var(--muted-2);
    box-shadow: 0 0 0 3px var(--surface-3);
    flex-shrink: 0;
    transition: background 200ms ease, box-shadow 200ms ease;
}
.status-dot.is-running { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); animation: status-pulse 1.6s ease-in-out infinite; }
.status-dot.is-done    { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.status-dot.is-stopped { background: var(--warn);    box-shadow: 0 0 0 3px var(--warn-soft); }
.status-dot.is-error   { background: var(--danger);  box-shadow: 0 0 0 3px var(--danger-soft); }
@keyframes status-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* Verdict badge — the answer. Only rendered on completed runs. Soft
   tinted fill + faint same-hue border; the icon inherits text colour. */
.verdict {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: var(--r-md);
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
    background: var(--surface-3);
    color: var(--ink-muted);
    border: 1px solid var(--border);
}
.verdict svg { width: 15px; height: 15px; flex-shrink: 0; }
.verdict--malicious { background: var(--danger-soft);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.verdict--benign    { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.verdict--uncertain { background: var(--warn-soft);    color: var(--warn);    border-color: color-mix(in srgb, var(--warn) 22%, transparent); }

.alert-detail__actions {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    flex-wrap: wrap;
    margin-top: var(--s-2);
}

/* Inline form wrapping a button so it sits flush with its neighbour. */
.alert-detail__rerun-form {
    display: inline-flex;
    margin: 0;
}

.alert-detail__raw-title {
    font-size: var(--text-lg);
    margin: 0 0 var(--s-3) 0;
}

.alert-detail__raw-body {
    background: var(--surface-alt, #f6f6f7);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-4);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--ink);
    overflow-x: auto;
    white-space: pre;
    max-height: 600px;
    overflow-y: auto;
}

/* ── Drawer (shared singleton) ──────────────────────────────────────
 * Right-side slide-in panel. Markup is ui/templates/components/_drawer.html
 * (one #drawer-root per page); JS is ui/static/js/components/drawer.js.
 * Used by onboarding (connection form) and /home ("View alert" content).
 * Onboarding-specific form bits stay in pages/onboarding.css. */
.drawer {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    justify-content: flex-end;
}

.drawer__scrim {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.drawer__panel {
    position: relative;
    width: min(480px, 100vw);
    height: 100vh;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: drawer-in 200ms ease-out;
}

/* Roomier variant for content-heavy bodies (e.g. the alert JSON
   payload). Opt in per open() via {wide:true}. Wide enough to read a
   raw payload comfortably while still leaving the alert list visible. */
.drawer__panel--wide {
    width: min(760px, 94vw);
}

@keyframes drawer-in {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}

.drawer__header {
    padding: var(--s-4) var(--s-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--s-3);
}

.drawer__logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: var(--r-sm);
    flex-shrink: 0;
}

.drawer__title {
    font-size: var(--text-lg);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.drawer__body {
    flex: 1;
    overflow-y: auto;
    padding: var(--s-5);
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
}

/* Chromeless variant — no header bar, just a floating × over the
   content. Opt in per open() via {chromeless:true} for bodies that
   carry their own title (e.g. the /home alert drawer). */
.drawer__close-float {
    display: none;
    position: absolute;
    top: var(--s-3);
    right: var(--s-3);
    z-index: 1;
    background: var(--surface);
}

.drawer__panel--chromeless .drawer__header {
    display: none;
}

.drawer__panel--chromeless .drawer__close-float {
    display: inline-flex;
}

/* Clear the floating × (top var(--s-3) + 32px button) so nothing
   tucks under it. */
.drawer__panel--chromeless .drawer__body {
    padding-top: var(--s-9);
}

/* ── Skeleton loaders ───────────────────────────────────────────────
 * Content-shaped shimmer placeholders shown while a fragment loads
 * (e.g. the alert drawer). Far less jarring than a faint "Loading…"
 * line in an empty panel. .skeleton is the shimmer primitive; the
 * --line / --block / --pill modifiers shape it. */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--border) 25%,
        var(--surface-3, #f1f3f8) 50%,
        var(--border) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--r-sm);
}

.skeleton--line {
    height: 0.85em;
    margin-bottom: var(--s-2);
}

.skeleton--pill {
    height: 22px;
    width: 64px;
    border-radius: 999px;
}

.skeleton--block {
    height: 220px;
    border-radius: var(--r-md);
}

@keyframes skeleton-shimmer {
    0%   { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* Layout wrapper mirroring the alert-content shape so the skeleton
   occupies roughly the same regions as the real fragment. */
.alert-skeleton {
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
}

.alert-skeleton__head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
}

@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; }
}

/* ── Select / dropdown (shared) ─────────────────────────────────────
 * One canonical themed dropdown for every <select> in the app (home
 * filters, schedule cadence, …). Native open list renders light via
 * the root color-scheme; this styles the closed control to match our
 * inputs (same --r-md, border, focus ring) with a consistent chevron.
 * Add the `.select` class to a <select>; page CSS only does layout. */
.select {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background-color: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: var(--text-sm);
    line-height: 1.4;
    padding: var(--s-2) var(--s-7) var(--s-2) var(--s-3);
    cursor: pointer;
    transition: border-color 120ms ease, box-shadow 120ms ease;
    background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='12'%20viewBox='0%200%2012%2012'%20fill='none'%3E%3Cpath%20d='M2%204.5l4%204%204-4'%20stroke='%2364748b'%20stroke-width='1.6'%20stroke-linecap='round'%20stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--s-3) center;
}

.select:hover {
    border-color: var(--ink-muted);
}

.select:focus,
.select:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ── Custom dropdown (themed <select> replacement) ──────────────────
 * Native <select> open lists are OS-drawn and can't be themed by CSS,
 * so we enhance them (ui/static/js/components/select.js) into a real
 * DOM menu we fully control. The native <select> stays as the value
 * source (hidden once enhanced); without JS it falls back to the
 * CSS-styled native control above. */
.custom-select {
    position: relative;
    display: inline-block;
}

.custom-select--block {
    display: block;
    width: 100%;
}

/* Native select is the source of truth but invisible once enhanced. */
.custom-select select {
    display: none;
}

.custom-select__trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-2);
    width: 100%;
    padding: var(--s-2) var(--s-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: var(--text-sm);
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.custom-select__trigger:hover {
    border-color: var(--ink-muted);
}

.custom-select__trigger:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.custom-select__trigger:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.custom-select__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select__arrow {
    display: inline-flex;
    color: var(--muted-2);
    flex: none;
    transition: transform 120ms ease;
}

.custom-select.open .custom-select__arrow {
    transform: rotate(180deg);
}

.custom-select__menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    width: max-content;
    max-width: min(320px, 90vw);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    padding: var(--s-1);
    z-index: 50;
}

.custom-select.open .custom-select__menu {
    display: block;
}

/* Search box (rendered by select.js only when the option count exceeds
   the no-scroll capacity). Sits above the scrolling list, so it stays
   put while the list scrolls. */
.custom-select__search {
    padding: var(--s-1) var(--s-1) var(--s-2);
}

.custom-select__search-input {
    width: 100%;
    padding: var(--s-2) var(--s-3);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
    font-size: var(--text-sm);
}

.custom-select__search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

/* The scrolling region. max-height = 7 items × 36px, matched to
   SEARCH_THRESHOLD in select.js: a list that scrolls (>7) always has a
   search box, and a list that fits (≤7) never does. */
.custom-select__list {
    max-height: 252px;
    overflow-y: auto;
}

.custom-select__item {
    display: flex;
    align-items: center;
    min-height: 36px;
    box-sizing: border-box;
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-sm);
    font-size: var(--text-sm);
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}

.custom-select__item.is-hidden {
    display: none;
}

.custom-select__item:hover {
    background: var(--surface-3);
}

.custom-select__item.selected {
    background: var(--primary-tint);
    color: var(--primary-h);
    font-weight: 600;
}

.custom-select__empty {
    padding: var(--s-2) var(--s-3);
    font-size: var(--text-sm);
    color: var(--ink-muted);
}

/* ════════════════════════════════════════════════════════════════════
   Action items (docs/action-items-plan-v3.md §5; mockups/v3/)
   Strip cards (.ai-card), rail (.ai-rail/.ai-rit), overflow menu
   (.ai-menu), chips. Shared by /home and /actions — defined once here.
   ════════════════════════════════════════════════════════════════════ */

:root {
    --ai-teal: #0d9488;
    --ai-teal-soft: rgba(13, 148, 136, 0.1);
    --ai-violet: #7c3aed;
    --ai-violet-soft: rgba(124, 58, 237, 0.1);
}

.btn--xs {
    height: 30px;
    padding: 0 12px;
    font-size: var(--text-xs);
    font-weight: 600;
}

/* ── strip ── */
.ai-strip {
    margin-bottom: var(--s-6);
}
.ai-strip__band {
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 2px 9px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--danger);
}
.ai-strip__band--input {
    color: #b45309;
}
.ai-strip__band--input .ai-strip__all {
    color: #b45309;
}
.ai-strip__line {
    flex: 1;
    height: 1px;
    background: var(--border-soft);
}
.ai-strip__all {
    color: var(--danger);
    font-weight: 600;
    font-size: var(--text-xs);
    text-decoration: none;
}
.ai-strip__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--s-3);
}
@media (max-width: 1000px) {
    .ai-strip__grid {
        grid-template-columns: 1fr;
    }
}
.ai-card {
    display: flex;
    flex-direction: column;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 120ms, transform 120ms;
}
.ai-card {
    position: relative;
}
.ai-card:hover,
.ai-card:focus-within {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    /* the hover transform creates a stacking context — without a
       z-index the open kebab menu paints UNDER later sections. */
    z-index: 60;
}
/* White surface (design review 2026-07-10): the lane color lives in
   the 4px stripe + the label ONLY — a tinted wash lowers text
   contrast and smears the signal across the card. */
.ai-card--urgent {
    border-left-color: var(--danger);
}
.ai-card--decide {
    border-left-color: var(--warn);
}
/* Ink primary on strip cards: one calm, maximum-contrast anchor that
   never hue-clashes with the lane accents. Scoped to cards — the
   product-wide primary stays indigo. */
.ai-card .btn--primary {
    background: #111827;
    border-color: #111827;
}
.ai-card .btn--primary:hover {
    background: #1f2937;
    border-color: #1f2937;
}
.ai-card__head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 7px;
}
.ai-card__src {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.ai-card--urgent .ai-card__src {
    color: var(--danger);
}
.ai-card--decide .ai-card__src {
    color: #b45309;
}
.ai-card__ago {
    margin-left: auto;
    font-size: 11px;
    color: var(--muted-2);
    font-family: var(--font-mono);
}
.ai-card__title {
    font-weight: 650;
    font-size: var(--text-base);
    letter-spacing: -0.01em;
    line-height: 1.35;
}
.ai-card__title code {
    font-size: 0.9em;
}
.ai-card__gist {
    font-size: var(--text-sm);
    color: var(--ink-muted);
    margin-top: 4px;
    flex: 1;
    /* Cards render title + gist only, at the mock's size — clamp the
       gist so a long one can't balloon the card (2026-07-10). */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.ai-card__gist b {
    color: var(--text-soft);
    font-weight: 600;
}
.ai-card__actions {
    display: flex;
    gap: var(--s-2);
    margin-top: 11px;
    position: relative;
}
.ai-card__kebab {
    margin-left: auto;
    width: 26px;
    height: 26px;
    border: 0;
    background: transparent;
    border-radius: var(--r-md);
    color: var(--muted-2);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    font-weight: 700;
}
.ai-card__kebab:hover {
    background: var(--surface-3);
    color: var(--ink);
}

/* ── overflow menu ── */
.ai-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 1000;
    min-width: 160px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
    padding: 4px;
}
.ai-menu__item {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: var(--text-sm);
    padding: 7px 10px;
    border-radius: var(--r-sm);
    cursor: pointer;
    color: var(--ink);
}
.ai-menu__item:hover {
    background: var(--surface-3);
}
.ai-menu__dismiss {
    display: flex;
    gap: 6px;
    padding: 6px;
    border-top: 1px solid var(--border-soft);
    margin-top: 4px;
}
.ai-menu__reason {
    flex: 1;
    min-width: 0;
    height: 30px;
    font-size: var(--text-xs);
}

/* ── chips ── */
.ai-chip {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: var(--r-pill);
}
.ai-chip--progress {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-soft);
    background: var(--surface-3);
}
.ai-chip__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink);
    animation: ai-chipdot 1.8s ease-in-out infinite;
}
@keyframes ai-chipdot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}
.ai-chip--stalled {
    color: #b45309;
    background: color-mix(in srgb, var(--warn) 14%, var(--surface));
}
.ai-chip--aging {
    color: var(--muted-2);
    background: var(--surface-3);
}
.ai-chip--recurred {
    color: var(--ai-teal);
    background: var(--ai-teal-soft);
}

/* ── rail ── */
.ai-rail {
    position: sticky;
    top: calc(var(--topbar-h) + var(--s-4));
    align-self: start;
    display: block;
}
.ai-railbox {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 14px 6px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 26px;
}
.ai-rg {
    margin-bottom: 26px;
}
.ai-railbox .ai-rg {
    margin-bottom: 22px;
}
.ai-railbox .ai-rg:last-child {
    margin-bottom: 10px;
}
.ai-rgh {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 2px 10px;
    font-weight: 650;
    font-size: var(--text-base);
    letter-spacing: -0.01em;
}
.ai-rgh__sp {
    flex: 1;
}
.ai-rgh__link {
    font-size: var(--text-xs);
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}
.ai-rits {
    display: grid;
    gap: 8px;
    /* Pin the implicit column to the container width: without this,
       grid sizes the column to the cards' max-content and a nowrap
       meta line pushes every card past the railbox edge. */
    grid-template-columns: minmax(0, 1fr);
}
.ai-rit {
    min-width: 0;
    display: flex;
    gap: 11px;
    align-items: center;
    padding: 11px 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 120ms;
}
.ai-railbox .ai-rit {
    background: var(--bg);
    box-shadow: none;
}
.ai-rit:hover {
    box-shadow: var(--shadow-md);
}
.ai-rit__icon {
    flex: none;
    width: 26px;
    height: 26px;
    border-radius: var(--r-md);
    display: grid;
    place-items: center;
}
.ai-rit--tune .ai-rit__icon {
    background: var(--ai-teal-soft);
    color: var(--ai-teal);
}
.ai-rit--fix .ai-rit__icon {
    background: var(--ai-violet-soft);
    color: var(--ai-violet);
}
.ai-rit__x {
    flex: 1;
    min-width: 0;
}
.ai-rit__t {
    font-weight: 600;
    font-size: var(--text-sm);
    line-height: 1.35;
    /* Headline surface (mockups/v3 .rit): the card is a one-glance
       pointer into the review modal, never the content itself. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.ai-rit__m {
    font-size: var(--text-xs);
    color: var(--ink-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-rit__go {
    flex: none;
}
.ai-rit__check {
    flex: none;
    color: var(--success);
}
.ai-rit--zz .ai-rit__check {
    color: var(--muted-2);
}
.ai-learnbox {
    font-size: var(--text-sm);
    color: var(--ink-muted);
    line-height: 1.55;
    background: var(--bg);
    border-radius: var(--r-lg);
    padding: var(--s-4);
}
.ai-learnbox b {
    color: var(--text-soft);
}
.ai-learnbox--quiet {
    color: var(--muted-2);
}
.ai-learnbar {
    height: 6px;
    border-radius: var(--r-pill);
    background: var(--surface-3);
    margin-top: 10px;
    overflow: hidden;
}
.ai-learnbar i {
    display: block;
    height: 100%;
    border-radius: var(--r-pill);
    background: linear-gradient(
        90deg,
        var(--ai-teal),
        color-mix(in srgb, var(--ai-teal) 40%, var(--surface))
    );
}

/* ── sources ── */
.ai-sources {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    padding: 4px 14px;
}
.ai-srow {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-top: 1px solid var(--border-soft);
    font-size: var(--text-sm);
}
.ai-srow:first-child {
    border-top: 0;
}
.ai-srow__name {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-dot {
    flex: none; /* a long provider name must never crush the dot */
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.ai-srow__st {
    flex: none;
    white-space: nowrap;
}
.ai-dot--ok {
    background: var(--success);
}
.ai-dot--warn {
    background: var(--warn);
}
.ai-srow__st--ok {
    color: var(--success);
    font-size: var(--text-xs);
    font-weight: 600;
}
.ai-srow__st--warn {
    color: var(--warn);
    font-size: var(--text-xs);
    font-weight: 600;
}

/* ── tune review modal body (mockups/v3/tune_review*.html; the modal
   shell is the standard .modal component above) ── */
.ai-review-modal .modal__panel {
    max-width: 620px;
}
.ai-review-modal .modal__body {
    display: grid;
    gap: 12px;
    /* The base .modal__body is a flex:1 slot in the panel column;
       grid's default align-content:stretch distributes any leftover
       height as blank bands into every auto row (empty space under
       the claim, inside the what-changes boxes). Rows hug content. */
    align-content: start;
}
.rv-claim {
    font-size: var(--text-sm);
    color: var(--ink-muted);
    margin: 0;
}
.rv-claim b {
    color: var(--ink);
}
.rv-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}
.rv-tbl td {
    padding: 7px 0;
    border-bottom: 1px solid var(--border-soft);
}
.rv-tbl td:first-child {
    color: var(--ink-muted);
    width: 150px;
    font-size: var(--text-xs);
}
.rv-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    /* Each box hugs ITS OWN text — a short "what doesn't" must not
       inflate to match a long "what changes" (or vice versa). */
    align-items: start;
}
.rv-w {
    padding: 10px 12px;
    border-radius: var(--r-md);
    font-size: var(--text-xs);
    line-height: 1.55;
}
.rv-w--yes {
    background: var(--success-soft);
    border: 1px solid color-mix(in srgb, var(--success) 30%, var(--border));
}
.rv-w--yes b {
    color: var(--success);
}
.rv-w--no {
    background: var(--surface-3);
    border: 1px solid var(--border);
}
.rv-w--no b {
    color: var(--ink-muted);
}
.rv-lbl {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ai-teal);
}
.rv-fact {
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    font-size: var(--text-sm);
    line-height: 1.55;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink);
    resize: vertical;
}
.rv-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.rv-tag {
    font-size: 10px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--ai-teal);
    background: var(--ai-teal-soft);
    padding: 1px 8px;
    border-radius: 999px;
}
.rv-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.rv-chip {
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    padding: 7px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-soft);
    cursor: pointer;
}
.rv-chip--on {
    border-color: var(--ai-teal);
    background: var(--ai-teal-soft);
    color: var(--ai-teal);
    box-shadow: inset 0 0 0 1px var(--ai-teal);
}
.rv-own {
    display: flex;
    gap: 8px;
}
.rv-detail {
    flex: 1;
    box-sizing: border-box;
    font: inherit;
    font-size: var(--text-sm);
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink);
}
.ai-review-modal__footer {
    justify-content: flex-start;
}
.ai-review-modal__sp {
    flex: 1;
}

/* ── known-noise bar on the alerts list (plan §3.3.1) ── */
.ai-noise {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--r-lg);
    margin-bottom: var(--s-3);
}
.ai-noise__icon {
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: var(--r-md);
    background: var(--ai-teal-soft);
    color: var(--ai-teal);
    display: grid;
    place-items: center;
}
.ai-noise__text {
    flex: 1;
    font-size: var(--text-sm);
    color: var(--ink-muted);
}
.ai-noise__text b {
    color: var(--text-soft);
    font-weight: 650;
}

/* ── strip extras: storm chip, all-clear band, START HERE card (plan
   §5.1 states; mockups/v3/home_state_*) ── */
.ai-strip__more {
    font-weight: 700;
    color: var(--ink-muted);
    text-decoration: none;
}
.ai-allclear {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: color-mix(in srgb, var(--success) 6%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--success) 30%, var(--border));
    border-left: 4px solid var(--success);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--s-6);
}
.ai-allclear__ic {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--success-soft);
    color: var(--success);
    display: grid;
    place-items: center;
}
.ai-allclear__t {
    font-weight: 650;
}
.ai-allclear__m {
    font-size: var(--text-sm);
    color: var(--ink-muted);
    margin-top: 1px;
}
.ai-allclear__sp {
    flex: 1;
}
.ai-allclear__link {
    color: var(--success);
    font-weight: 600;
    font-size: var(--text-sm);
    text-decoration: none;
}
.ai-strip__band--start {
    color: var(--primary);
}
.ai-strip__grid--single {
    grid-template-columns: 1fr;
}
.ai-card--start {
    border-left-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 4%, var(--surface));
    flex-direction: row;
    align-items: center;
    gap: 16px;
}
.ai-card__starticon {
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: var(--r-md);
    background: var(--primary-soft);
    color: var(--primary);
    display: grid;
    place-items: center;
}
.ai-card__startbody {
    flex: 1;
}
.ai-card__actions--start {
    margin-top: 0;
}

.rv-samples a {
    color: var(--primary);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    margin-right: 8px;
}

/* ── tags chip editor (review modal) ── */
/* Bare chip row (mockups/v3 .rv-tags) — no box: the chips ARE the
   surface, the inline input reveals itself only when typing. */
.rv-tagedit {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
.rv-tagchip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 650;
    font-family: var(--font-mono);
    color: var(--ai-teal);
    background: var(--ai-teal-soft);
    padding: 2px 4px 2px 9px;
    border-radius: 999px;
    max-width: 100%;
}
.rv-tagchip__x {
    border: 0;
    background: transparent;
    color: inherit;
    opacity: 0.55;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 999px;
}
.rv-tagchip__x:hover {
    opacity: 1;
}
.rv-tagedit__input {
    flex: 1;
    min-width: 90px;
    border: 0;
    outline: none;
    font: inherit;
    font-size: var(--text-xs);
    color: var(--ink);
    background: transparent;
    padding: 2px;
}
.ai-rit--handled[data-handled-link] {
    cursor: pointer;
}

/* Reasoning: 2 lines by default, "show more" reveals the rest. */
.rv-reason {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.rv-reason--open {
    display: block;
    -webkit-line-clamp: unset;
}
.rv-reason__more {
    border: 0;
    background: transparent;
    padding: 0;
    margin-top: 2px;
    color: var(--primary);
    font-size: var(--text-xs);
    font-weight: 600;
    cursor: pointer;
}

/* Evidence cases: count first, the full list on demand (a 29-link
   two-column wall dominated the modal). */
.rv-cases > summary {
    cursor: pointer;
    color: var(--primary);
    font-size: var(--text-sm);
    font-weight: 600;
    list-style: none;
}
.rv-cases > summary::-webkit-details-marker {
    display: none;
}
.rv-cases[open] > summary {
    margin-bottom: 6px;
}
.rv-samples--list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow: auto;
}

/* Modal footer snooze options (Snooze always asks HOW). */
.rv-snooze {
    display: inline-flex;
    gap: 6px;
}
