/* JARVIS-164 — the agents-page split.
 *
 * The /agents page is three surfaces behind a subnav: the chat-agents
 * workbench (the design work), the registries (skills + MCP servers), and the
 * gateway (identity/policy). This stylesheet carries the chat-agents
 * composition on top of the shared /static/css/style.css tokens (--surface,
 * --border, --accent, .btn, .badge-*); the registries + gateway surfaces reuse
 * the existing admin table/chip classes unchanged.
 *
 * Namespace: .agents-* (page chrome) and .ca-* (chat-agents workbench).
 * The phone drawer below uses the JARVIS-140/141 idiom from base.html's
 * nav drawer: one node, fixed pane, translateX(-100%) → .open, the shared
 * .popout-scrim, and an 800px breakpoint.
 */

/* ── surface switcher ──────────────────────────────────────────────────── */
.agents-subnav {
    display: flex;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 0.75rem 0 1.25rem;
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
}
.agents-subnav-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.875rem;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: color 0.15s, background 0.15s;
}
.agents-subnav-tab:hover { color: var(--text-bright); background: var(--border-light); }
.agents-subnav-tab.active { color: var(--text-bright); background: var(--accent-muted); }
.agents-subnav-count {
    font-variant-numeric: tabular-nums;
    font-size: 0.75rem;
    opacity: 0.7;
}

/* ── two-column workbench ──────────────────────────────────────────────── */
.ca-cols {
    display: grid;
    grid-template-columns: 296px minmax(0, 1fr);
    gap: 1.25rem;
    margin-top: 1.25rem;
    align-items: start;
}

/* ── left rail ───────────────────────────────────────────────────────────
   The rail is where the two kinds get separated: chat personas are the rich,
   tappable working set; lead identities are a collapsed, read-only pointer to
   where they are actually configured. */
.ca-rail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    position: sticky;
    top: 4.25rem;
}
.ca-rail-search {
    padding: 0.625rem;
    border-bottom: 1px solid var(--border);
}
.ca-rail-search input {
    width: 100%;
    padding: 0.4375rem 0.625rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.8125rem;
    font-family: inherit;
}
.ca-rail-search input:focus { outline: none; border-color: var(--accent); }
.ca-rail-body { max-height: calc(100vh - 12rem); overflow-y: auto; }

.ca-rail-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border-light);
}
.ca-rail-group:first-child { border-top: none; }
.ca-rail-group .ca-count {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    opacity: 0.8;
}
.ca-rail-note {
    padding: 0.375rem 0.75rem 0.625rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.45;
    background: var(--bg);
    border-bottom: 1px solid var(--border-light);
}
.ca-rail-note a { color: var(--accent); text-decoration: none; }
.ca-rail-note a:hover { text-decoration: underline; }
.ca-rail-note code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
}

.ca-agent-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    border-left: 2px solid transparent;
    border-bottom: 1px solid var(--border-light);
    color: inherit;
    text-align: left;
    font: inherit;
    cursor: pointer;
    transition: background 0.12s;
}
.ca-agent-row:hover { background: var(--surface-hover); }
.ca-agent-row.selected {
    background: var(--surface-hover);
    border-left-color: var(--accent);
}
.ca-avatar {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #c4b5fd;
    background: #2a1a3a;
}
.ca-avatar.lead { color: var(--accent); background: #0c2d6b; }
.ca-agent-main { min-width: 0; flex: 1; }
.ca-agent-name {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ca-agent-meta {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ca-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--border);
    flex: 0 0 auto;
}
.ca-dot.on { background: var(--green); }

/* ── detail column ─────────────────────────────────────────────────────── */
.ca-detail { min-width: 0; display: flex; flex-direction: column; gap: 1rem; }

.ca-detail-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.ca-detail-title {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
}
.ca-detail-title h2 {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text-bright);
    margin: 0;
}
.ca-detail-slug {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8125rem;
    color: var(--text-muted);
}
.ca-detail-desc {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin-top: 0.25rem;
    max-width: 70ch;
}

/* At-a-glance strip: the questions the operator opens this page to answer. */
.ca-glance {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.625rem;
}
.ca-glance-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.625rem 0.75rem;
    min-width: 0;
}
.ca-glance-label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 0.1875rem;
}
.ca-glance-value {
    font-size: 0.9375rem;
    color: var(--text-bright);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ca-glance-sub {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

/* ── cards ─────────────────────────────────────────────────────────────── */
.ca-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.ca-card-head {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 0.875rem;
    border-bottom: 1px solid var(--border);
}
.ca-card-head h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-bright);
    margin: 0;
}
.ca-card-head .ca-spacer { margin-left: auto; }
.ca-card-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.ca-card-body { padding: 0.875rem; }
.ca-card-body > p {
    font-size: 0.8125rem;
    color: var(--text-muted);
    line-height: 1.55;
    margin: 0;
}

/* system prompt preview */
.ca-prompt {
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
    line-height: 1.65;
    color: var(--text);
    white-space: pre-wrap;
    max-height: 8.5rem;
    overflow: hidden;
    position: relative;
    mask-image: linear-gradient(to bottom, #000 60%, transparent);
    -webkit-mask-image: linear-gradient(to bottom, #000 60%, transparent);
}
.ca-prompt.expanded {
    max-height: none;
    mask-image: none;
    -webkit-mask-image: none;
}

/* form controls, matching the admin editor idiom */
.ca-field { display: flex; flex-direction: column; gap: 0.3125rem; }
.ca-field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ca-input,
.ca-select {
    width: 100%;
    padding: 0.4375rem 0.625rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.8125rem;
    font-family: inherit;
}
.ca-input:focus, .ca-select:focus { outline: none; border-color: var(--accent); }
.ca-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* skill / scope chips */
.ca-chips { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.ca-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.1875rem 0.5rem;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.ca-chip .x { color: var(--text-muted); cursor: pointer; font-size: 0.875rem; line-height: 1; }
.ca-chip .x:hover { color: var(--red); }
.ca-empty {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-style: italic;
}
.ca-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
}

/* callouts */
.ca-callout {
    display: flex;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    line-height: 1.55;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
}
.ca-callout strong { color: var(--text-bright); font-weight: 600; }
.ca-callout.warn {
    border-color: rgba(210, 153, 34, 0.35);
    background: rgba(210, 153, 34, 0.07);
}
.ca-callout.info {
    border-color: rgba(88, 166, 255, 0.3);
    background: rgba(88, 166, 255, 0.06);
}
.ca-callout-icon { flex: 0 0 auto; line-height: 1.4; }
.ca-callout a { color: var(--accent); text-decoration: none; }
.ca-callout a:hover { text-decoration: underline; }

/* ── mobile: rail becomes a pop-out drawer (JARVIS-140/141 idiom) ─────── */
.ca-mobile-bar { display: none; }

@media (max-width: 800px) {
    .ca-cols { grid-template-columns: 1fr; gap: 0; }
    .ca-rail {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 320px);
        border-radius: 0;
        border-top: none;
        border-bottom: none;
        border-left: none;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        z-index: 150;
        display: flex;
        flex-direction: column;
    }
    .ca-rail.open { transform: translateX(0); }
    .ca-rail-body { max-height: none; flex: 1; }
    .ca-agent-row { padding: 0.625rem 0.75rem; min-height: 44px; }

    .ca-mobile-bar {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        margin: 0.75rem 0 0.875rem;
        padding: 0.375rem;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
    }
    .ca-mobile-bar button {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        min-height: 40px;
        padding: 0 0.75rem;
        background: none;
        border: none;
        border-radius: var(--radius-sm);
        color: var(--text-bright);
        font: inherit;
        font-size: 0.8125rem;
        cursor: pointer;
    }
    .ca-mobile-bar button:hover { background: var(--border-light); }
    .ca-mobile-current {
        margin-left: auto;
        padding-right: 0.5rem;
        font-size: 0.75rem;
        color: var(--text-muted);
        font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* The 4-up glance strip is unreadable at 390px; 2-up keeps each tile
       above the ~150px where the value starts truncating. */
    .ca-glance { grid-template-columns: 1fr 1fr; }
    .ca-row2 { grid-template-columns: 1fr; }
    .ca-detail-head { flex-direction: column; gap: 0.5rem; }
}
@media (prefers-reduced-motion: reduce) {
    .ca-rail { transition: none; }
}
