/* ============================================================================
   Chat
   Staff chat over the platform's data tools (HPP chat on MCP).
   Prefix: ch-
   Design: "Chat Module - UI Directions", frame D (Combined), 2026-08-29.
   Shell: history behind a toolbar disclosure, full-width thread, centred
   780px column. Turn: "You asked" well, tool-trace timeline, answer prose,
   stat strip, data card, follow-up chips, pinned composer.
   Composes hub-* / nv-* / ac-* classes; this file adds layout only.
   ============================================================================ */

.ch-page {
    padding: 0;
    position: relative;
}

.ch-toolbar {
    justify-content: space-between;
    margin-bottom: 0;
}

.ch-toolbar-left,
.ch-toolbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.ch-toolbar-right {
    gap: 8px;
}

.ch-toolbar-left .nv-disclosure {
    margin-left: 6px;
}

/* ── History panel: one float grey, anchored under the toolbar ── */
.ch-history {
    position: absolute;
    top: 70px;
    left: 24px;
    z-index: 200;
    width: 340px;
    max-height: calc(100vh - 62px - 70px - 24px);
    display: flex;
    flex-direction: column;
    padding: 10px;
    background: var(--surface-chrome);
    border: 1px solid var(--ink-line-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
}

.ch-history[hidden] {
    display: none;
}

.ch-history-search {
    min-height: 32px;
    padding: 5px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
}

.ch-history-list {
    margin-top: 6px;
    overflow-y: auto;
    min-height: 0;
}

.ch-history-group {
    padding: 10px 12px 4px;
    color: var(--text-tertiary);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.ch-history-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 38px;
    padding: 0 6px 0 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-system);
    font-size: 0.8125rem;
    text-align: left;
    cursor: pointer;
}

.ch-history-row:hover {
    background: var(--ink-wash);
    color: var(--text-primary);
}

.ch-history-row[aria-current="page"] {
    background: var(--ink-wash-strong);
    color: var(--text-primary);
}

.ch-history-row:focus-visible {
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

.ch-history-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.ch-history-count {
    color: var(--text-tertiary);
    font-size: 0.6875rem;
    font-variant-numeric: tabular-nums;
}

.ch-history-empty {
    padding: 14px 12px;
    color: var(--text-tertiary);
    font-size: 0.8rem;
}

/* ── Thread: scroll region above, pinned footer below ── */
.ch-body {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 62px - 62px);
    min-height: 420px;
}

.ch-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 32px 40px 0;
}

.ch-col {
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 26px;
    padding-bottom: 24px;
}

.ch-foot {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 12px 40px 20px;
}

.ch-foot > * {
    width: 100%;
    max-width: 780px;
}

/* Empty state: prompt and composer as one centred block. */
.ch-body--empty {
    justify-content: center;
}

.ch-body--empty .ch-scroll {
    flex: 0 0 auto;
    overflow: visible;
    padding-top: 0;
}

.ch-body--empty .ch-foot {
    padding-top: 0;
}

.ch-empty {
    width: 100%;
    max-width: 780px;
    margin: 0 auto 6px;
    text-align: center;
}

.ch-empty-title {
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

/* ── User turn: sunken "You asked" well ── */
.ch-q {
    background: var(--surface-field);
    border: 1px solid var(--ink-line);
    border-radius: var(--radius-md);
    padding: 14px 18px;
}

.ch-eyebrow {
    display: flex;
    align-items: baseline;
    gap: 10px;
    color: var(--text-tertiary);
    font-size: 0.65625rem;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
}

.ch-eyebrow-time {
    font-weight: 500;
    letter-spacing: 0.2px;
    text-transform: none;
    font-variant-numeric: tabular-nums;
}

.ch-q-text {
    margin-top: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-line;
}

/* ── Tool-trace timeline ── */
.ch-trace {
    display: flex;
    flex-direction: column;
}

.ch-step {
    position: relative;
    display: flex;
    gap: 14px;
    padding-bottom: 14px;
}

.ch-step::before {
    content: "";
    position: absolute;
    left: 3px;
    top: 14px;
    bottom: 0;
    width: 1px;
    background: var(--ink-line);
}

.ch-step:last-child::before {
    display: none;
}

.ch-step-dot {
    flex: none;
    width: 7px;
    height: 7px;
    margin-top: 5px;
    border-radius: var(--radius-pill);
    background: var(--text-tertiary);
}

.ch-step-body {
    min-width: 0;
}

.ch-step-fn {
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 600;
}

.ch-step-dur {
    color: var(--text-tertiary);
    font-size: 0.65625rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.ch-step--error .ch-step-fn {
    color: var(--status-injured);
}

.ch-step-dur--busy {
    display: inline-block;
    width: 13px;
    height: 13px;
    align-self: center;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--radius-pill);
    animation: ch-spin 0.9s linear infinite;
}

@keyframes ch-spin {
    to { transform: rotate(360deg); }
}

.ch-step-args {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 5px;
    min-height: 20px;
}

.ch-kv {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 8px;
    border-radius: var(--radius-pill);
    background: var(--ink-wash);
    color: var(--text-secondary);
    font-size: 0.65625rem;
    font-variant-numeric: tabular-nums;
}

.ch-kv b {
    margin-right: 4px;
    color: var(--text-tertiary);
    font-size: 0.59375rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

/* ── Answer prose ── */
.ch-ans {
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.7;
}

.ch-ans p {
    margin: 0 0 12px;
}

.ch-ans p:last-child {
    margin-bottom: 0;
}

.ch-ans strong {
    font-weight: 600;
}

.ch-ans ul,
.ch-ans ol {
    margin: 0 0 12px;
    padding-left: 20px;
}

.ch-ans li {
    margin: 2px 0;
}

.ch-ans h1,
.ch-ans h2,
.ch-ans h3,
.ch-ans h4 {
    margin: 12px 0 4px;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
}

.ch-ans code {
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    background: var(--ink-wash);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
}

.ch-ans table {
    margin: 6px 0 12px;
    border-collapse: collapse;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.ch-ans th,
.ch-ans td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--ink-line);
    text-align: left;
    vertical-align: top;
}

.ch-ans th {
    color: var(--text-primary);
    font-weight: 600;
    background: var(--surface-raised);
    border-bottom: 2px solid var(--ink-line-strong);
}

.ch-ans td:not(:first-child),
.ch-ans th:not(:first-child) {
    text-align: right;
}

.ch-ans--error {
    color: var(--status-injured);
}

.ch-ans--stopped {
    color: var(--text-tertiary);
}

/* ── Stat strip ── */
.ch-stats {
    display: flex;
    margin-top: 6px;
    padding: 16px 0 4px;
    border-top: 1px solid var(--ink-line);
}

.ch-stat {
    flex: 1;
    min-width: 0;
    border-left: 1px solid var(--ink-line);
    padding-left: 22px;
}

.ch-stat:first-child {
    border-left: 0;
    padding-left: 0;
}

.ch-stat-v {
    color: var(--text-primary);
    font-size: 1.625rem;
    font-weight: 500;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.ch-stat-v small {
    margin-left: 4px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
}

/* A notable value is ink only: the pole's pink on the numeral and its arrow. */
.ch-stat-v--low {
    color: var(--zscore-low-color);
    font-weight: 600;
}

.ch-stat-v--high {
    color: var(--zscore-high-color);
    font-weight: 600;
}

.ch-stat-k {
    margin-top: 7px;
    color: var(--text-tertiary);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
}

/* ── Data card ── */
.ch-card {
    margin-top: 16px;
    padding: 16px 18px 14px;
    background: var(--surface-raised);
    border: 1px solid var(--ink-line);
    border-radius: var(--radius-md);
}

.ch-card-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.ch-card-title {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
}

.ch-card-meta {
    color: var(--text-tertiary);
    font-size: 0.6875rem;
    font-variant-numeric: tabular-nums;
}

.ch-card-link {
    margin-left: auto;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--accent);
    font-family: var(--font-system);
    font-size: 0.71875rem;
    font-weight: 600;
    cursor: pointer;
}

.ch-card-link:hover {
    color: var(--accent-hover);
}

.ch-card-link:focus-visible {
    outline: 1px solid var(--accent);
    outline-offset: 2px;
}

.ch-card-chart {
    position: relative;
    height: 160px;
    margin-top: 12px;
}

.ch-card-legend {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    color: var(--text-tertiary);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

.ch-card-legend i {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 5px;
    border-radius: 2px;
    vertical-align: -1px;
}

.ch-legend-session {
    background: var(--accent);
    opacity: 0.75;
}

.ch-legend-median {
    height: 0;
    margin-top: 4px;
    border-top: 1.5px dashed var(--reference-gold);
}

.ch-legend-rest {
    background: var(--ink-wash-strong);
}

.ch-peers {
    margin-top: 14px;
    padding-top: 4px;
    border-top: 1px solid var(--ink-line);
}

.ch-peer {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 30px;
    color: var(--text-secondary);
    font-size: 0.78125rem;
}

.ch-peer-name {
    width: 170px;
    color: var(--text-primary);
    font-weight: 500;
}

.ch-peer--me .ch-peer-name {
    font-weight: 700;
}

.ch-peer-track {
    position: relative;
    flex: 1;
    height: 3px;
    border-radius: var(--radius-pill);
    background: var(--ink-wash);
}

.ch-peer-fill {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: var(--radius-pill);
    background: var(--ink-wash-strong);
}

.ch-peer--me .ch-peer-fill {
    background: var(--accent-hover);
}

.ch-peer-v {
    width: 70px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ── Footer: follow-up chips and the composer ── */
.ch-sugg {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ch-composer {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 46px;
    padding: 4px 8px 4px 16px;
    background: var(--surface-field);
    border: 1px solid var(--ink-line-strong);
    border-radius: var(--radius-md);
}

.ch-composer:focus-within {
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

.ch-input {
    flex: 1;
    min-height: 24px;
    max-height: 200px;
    padding: 6px 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    resize: none;
    color: var(--text-primary);
    font-size: 0.84375rem;
    font-weight: 500;
    line-height: 1.5;
}

.ch-input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

.ch-input:hover,
.ch-input:focus {
    border: 0;
    outline: none;
}

/* Send: 32px accent circle. Geometry is the .ac-icon square; only the
   shape rounds. Stop state is the same circle with a square glyph. */
.ch-send {
    border-radius: var(--radius-pill);
}

.ch-send svg {
    width: 14px;
    height: 14px;
}

@media (max-width: 980px) {
    .ch-scroll,
    .ch-foot {
        padding-left: 16px;
        padding-right: 16px;
    }

    .ch-peer-name {
        width: 110px;
    }
}
