/* ═══════════════════════════════════════════════════════════════
   Copilot Design Contract
   Site-wide CSS shared by HtmlContentSection (workspace) and
   DynamicBlock (chat). Both surfaces use the same visual language —
   metric grids, status badges, bar tracks, color palette — so
   Claude-authored HTML and structured-block markup look unified.

   Selectors target both:
     .html-content-section  (Pages/Shared/Components/HtmlContentSection.razor)
     .copilot-block         (NWCWebApp2022.Copilot DynamicBlock.razor)
   ═══════════════════════════════════════════════════════════════ */

.html-content-section,
.copilot-block {
    font-size: 0.875rem; /* off-scale — sits between --font-size-md (0.85) and --font-size-base (0.9) */
    line-height: var(--line-height-normal);
    color: var(--bs-body-color);
}

/* ─── Headings (HTML escape hatch) ─── */
.html-content-section h3,
.copilot-block h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin: 0 0 var(--space-sm);
}

.html-content-section h4,
.copilot-block h4 {
    font-size: 0.875rem; /* off-scale */
    font-weight: var(--font-weight-semibold);
    margin: var(--space-md) 0 var(--space-2xs);
    color: var(--tbm-fg-muted);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
}

/* ─── Tables ─── */
.html-content-section table,
.copilot-block table,
.copilot-block-data-table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-sm) 0;
}

.html-content-section th,
.copilot-block th,
.copilot-block-data-table th {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em; /* off-scale, between --letter-spacing-wide and --letter-spacing-wider */
    color: var(--tbm-fg-muted);
    padding: var(--space-2xs) var(--space-sm);
    border-bottom: 1px solid var(--tbm-border);
    text-align: left;
}

.html-content-section td,
.copilot-block td,
.copilot-block-data-table td {
    padding: var(--space-xs) var(--space-sm);
    border-bottom: 1px solid var(--tbm-divider);
    vertical-align: top;
}

.html-content-section tr:last-child td,
.copilot-block tr:last-child td,
.copilot-block-data-table tr:last-child td {
    border-bottom: none;
}

.copilot-block-data-table-wrapper {
    overflow-x: auto;
    margin: 4px 0;
}

.copilot-block-row-actions {
    white-space: nowrap;
    text-align: right;
}

.copilot-block-row-btn {
    font-size: 10px; /* off-scale, finer than --font-size-2xs */
    font-weight: var(--font-weight-semibold);
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid #d1d5db; /* Tailwind gray-300 */
    background: var(--surface-default);
    color: #374151; /* Tailwind gray-700 */
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}

.copilot-block-row-btn:hover:not(:disabled) {
    background: #eff6ff; /* Tailwind blue-50 */
    border-color: #bfdbfe; /* Tailwind blue-200 */
    color: #1d4ed8; /* Tailwind blue-700 */
}

.copilot-block-row-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Dense per-row table actions still need a real tap target on phones, even
   though the table itself already scrolls horizontally — bump the hit area
   without losing the compact desktop density these are meant to have. */
@media (max-width: 767.98px) {
    .copilot-block-row-btn {
        min-height: 32px;
        padding: 6px 10px;
    }
}

/* ─── Action row — shared contract for "a row of Copilot-tool-triggered
   buttons attached to a card or message" (WorkPlanCard header actions,
   DeliverableCardView's Preview/Create/Email/Hold, and any future card).
   Always wraps instead of clipping or letting buttons shrink unpredictably;
   buttons meet the app's --form-input-min-height (44px) touch-target floor
   used elsewhere for form controls. Resting look matches DynamicBlock's own
   .copilot-chip (neutral, accent only on hover/emphasis) so a card's actions
   read as the same family as the chat's follow-up chips. ─── */
.copilot-action-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
}

.copilot-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: var(--form-input-min-height);
    padding: 0.3rem 0.85rem;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    background: var(--surface-default);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.2;
    /* ⚠ NOT `white-space: nowrap`. The row above wraps, which handles a row too wide for
       the card -- but it cannot help a SINGLE button wider than the line, and `nowrap` gives
       such a button a min-content width it can never shrink below, so it pushes out of the
       card instead. Measured 2026-09-08 in the real panel DOM at the 320px minimum width
       (copilot.js clamps the drag there): the action row gets 220px, and "Promote to
       Fermentation Contract" overflowed it by 20px in both themes with nowrap set. Leaving
       this at the initial `normal` costs nothing when a label fits -- flex only shrinks an
       item that is alone on its line -- and wraps instead of overflowing when it does not. */
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.copilot-action-btn:hover:not(:disabled) {
    background: var(--copilot-accent-tint);
    border-color: var(--copilot-accent-soft);
    color: var(--copilot-accent-deep);
}

.copilot-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Primary emphasis — the one call-to-action in a row (e.g. Preview, or an
   already-active toggle like "Saved"/"Promoted"). Accent-tinted at rest
   instead of only on hover. */
.copilot-action-btn.primary {
    border-color: var(--copilot-accent-tint-border);
    background: var(--copilot-accent-tint);
    color: var(--copilot-accent-deep);
}

.copilot-action-btn.primary:hover:not(:disabled) {
    background: var(--copilot-accent-bg);
    border-color: var(--copilot-accent-soft);
}

/* ─── Confirm card — the frame of a chat card that asks the person to
   confirm one change before it is made (LotNoteConfirmBlock, ProposalConfirmBlock).
   Hoisted 2026-10-01 when the second card arrived, so neither scoped file
   repeats it. Chips (nwc-chip) and the action row above are shared too. ─── */
.copilot-confirm-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: var(--space-sm);
    margin: var(--space-xs) 0;
    border: 1px solid var(--copilot-accent-tint-border);
    border-radius: var(--radius-md);
    background: var(--surface-default);
}

.copilot-confirm-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs);
}

/* ─── Metric grid (summary cards) ───
   The floor is the tile's own content, not a fixed 64px. The previous
   `minmax(64px, 1fr)` let a track be NARROWER than the value inside it, and
   `.metric-val` was `white-space: nowrap`, so a long value overflowed its own
   card box. Because each `.metric-card` paints an opaque background in DOM
   order, the next tile then painted OVER the previous tile's overflow --
   which reads as "clipped mid-string" with no ellipsis and no `overflow`
   rule anywhere to explain it. Measured 2026-09-08 on Jeff's Chrome
   (1536x695 CSS px, DPR 1.25, prod Blue, centered Winemaking workspace):
   a 10-analyte lab card got ~72px per tile and every value but the last was
   painted over.

   `min(9rem, 100%)` keeps the floor from itself overflowing a pane narrower
   than the floor -- the copilot rail is user-resizable down past 300px, and
   NO breakpoint in this file can see that, because every media query here
   keys off VIEWPORT width while the pane's width is set by a drag handle.
   auto-fit + a content-sized floor is intrinsic, so it tracks the real pane. */
.html-content-section .metric-grid,
.copilot-block .metric-grid,
.copilot-block-summary-card .metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr));
    gap: var(--space-xs);
    margin: var(--space-sm) 0;
}

.html-content-section .metric-card,
.copilot-block .metric-card,
.copilot-block-summary-card .metric-card {
    min-width: 0;
    background: var(--tbm-neutral-bg);
    border-radius: var(--radius-md);
    padding: var(--space-2xs) var(--space-xs);
    text-align: center;
}

.html-content-section .metric-val,
.copilot-block .metric-val,
.copilot-block-summary-card .metric-val {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    display: block;
    line-height: 1.25;
    overflow-wrap: break-word;
}

.html-content-section .metric-label,
.copilot-block .metric-label,
.copilot-block-summary-card .metric-label {
    display: block;
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wider);
    color: var(--tbm-fg-muted);
    line-height: 1.25;
    overflow-wrap: break-word;
}

/* Sample date + relative age, under the label.
   ⚠ Not decoration. Lab cadence is DAYS, and an undated number sitting beside
   a temperature that moves every few seconds reads as equally live -- the rule
   the tank drawer states at TankManagerModels.cs:242-245 and renders as
   `BRIX · 3D`. This is the chat surface's version of the same pairing, in the
   `.bmb-value / .bmb-prev / .bmb-age` stack shape used by BlockMaturityBoard. */
.html-content-section .metric-sub,
.copilot-block .metric-sub,
.copilot-block-summary-card .metric-sub {
    display: block;
    font-size: var(--font-size-2xs);
    /* ⚠ --tbm-fg-muted, NOT --tbm-fg-faint. Measured 2026-09-08 against
       --tbm-neutral-bg: faint is 2.4:1 light / 3.7:1 dark at this 0.65rem size,
       under the 4.5:1 AA floor -- an unreadable date is the defect this line
       exists to fix. Muted measures 4.7:1 light / 6.2:1 dark. The hierarchy
       against .metric-label comes from size and casing, not from colour. */
    color: var(--tbm-fg-muted);
    line-height: 1.25;
    overflow-wrap: break-word;
}

.copilot-block-summary-title {
    margin: 0 0 var(--space-2xs);
}

/* ─── Status badges ─── */
.html-content-section .status-badge,
.copilot-block .status-badge {
    display: inline-block;
    padding: var(--status-badge-padding);
    border-radius: var(--status-badge-radius);
    font-size: var(--status-badge-font-size);
    font-weight: var(--font-weight-medium);
}

.html-content-section .status-draft,
.copilot-block .status-draft       { background: var(--state-warning-bg); color: var(--state-warning-fg); }
.html-content-section .status-complete,
.copilot-block .status-complete    { background: var(--state-success-bg); color: var(--state-success-fg); }
.html-content-section .status-pending,
.copilot-block .status-pending     { background: var(--state-neutral-bg); color: var(--state-neutral-fg); }

/* ─── Progress / composition bars ─── */
.html-content-section .bar-track,
.copilot-block .bar-track,
.copilot-block-composition .bar-track {
    display: flex;
    height: 8px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--tbm-neutral-bg);
    margin: var(--space-2xs) 0;
}

.html-content-section .bar-fill,
.copilot-block .bar-fill,
.copilot-block-composition .bar-fill {
    height: 100%;
    transition: width 0.3s ease;
}

/* Tableau 10 chart palette — intentional chart-specific palette, leave alone */
.html-content-section .color-1,
.copilot-block .color-1 { background: #4e79a7; }
.html-content-section .color-2,
.copilot-block .color-2 { background: #f28e2b; }
.html-content-section .color-3,
.copilot-block .color-3 { background: #e15759; }
.html-content-section .color-4,
.copilot-block .color-4 { background: #76b7b2; }
.html-content-section .color-5,
.copilot-block .color-5 { background: #59a14f; }

/* ─── Composition legend ─── */
.copilot-block-composition {
    margin: 4px 0 6px;
}

.copilot-block-composition-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.copilot-block-legend-item {
    display: flex;
    align-items: center;
    gap: 3px;
}

.copilot-block-legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 2px;
    vertical-align: middle;
}

/* ─── Action buttons — compact wrapping row, same contract as .copilot-followups
   (both are a row of .copilot-chip pills in the same chat panel; a full-width
   vertical stack here just wasted space for no reason two identical components
   should differ). ─── */
.copilot-block-action-buttons .copilot-block-actions,
.copilot-block-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    margin: 6px 0;
}

.copilot-block-action-buttons .copilot-chip,
.copilot-block-actions .copilot-chip {
    width: auto;
    text-align: center;
    white-space: normal;
    max-width: 100%;
}

/* ─── Summary card bars ─── */
.copilot-block-bars {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}

.copilot-block-bar-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.copilot-block-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 11px; /* off-scale */
    color: var(--tbm-fg-muted);
}

/* ─── Plan-status block ─── */
.copilot-block-plan-status {
    background: #f9fafb; /* Tailwind gray-50 */
    border: 1px solid #e5e7eb; /* Tailwind gray-200 */
    border-radius: var(--radius-lg);
    padding: 10px 12px;
    margin: 4px 0;
}

.copilot-block-plan-steps {
    display: flex;
    align-items: center;
    gap: 0;
}

.copilot-block-plan-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.copilot-block-plan-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #d1d5db; /* Tailwind gray-300 */
    background: var(--surface-default);
    color: #9ca3af; /* Tailwind gray-400 */
    font-size: 11px;
    font-weight: var(--font-weight-bold);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.copilot-block-plan-step.active .copilot-block-plan-circle {
    border-color: #2563eb; /* Tailwind blue-600 */
    background: #2563eb;
    color: var(--white);
}

.copilot-block-plan-step.complete .copilot-block-plan-circle {
    border-color: var(--green-500);
    background: var(--green-500);
    color: var(--white);
    font-size: 12px;
}

.copilot-block-plan-label {
    font-size: 10px;
    font-weight: var(--font-weight-medium);
    color: #6b7280; /* Tailwind gray-500 */
    white-space: nowrap;
}

.copilot-block-plan-step.active .copilot-block-plan-label,
.copilot-block-plan-step.complete .copilot-block-plan-label {
    color: #111827; /* Tailwind gray-900 */
}

.copilot-block-plan-connector {
    flex: 1;
    height: 2px;
    background: #e5e7eb; /* Tailwind gray-200 */
    margin-bottom: 14px;
    min-width: 16px;
}

.copilot-block-plan-connector.filled {
    background: var(--green-500);
}

.copilot-block-plan-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

/* ─── Fallback (unknown type) ─── */
.copilot-block-fallback {
    background: var(--tbm-surface-subtle);
    border: 1px dashed var(--tbm-border);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    margin: 4px 0;
    font-size: 12px;
}

.copilot-block-fallback-title {
    font-weight: var(--font-weight-semibold);
    margin-bottom: 4px;
}

.copilot-block-fallback-json {
    font-size: 11px;
    margin: 0;
    padding: 0;
    background: transparent;
    color: var(--tbm-fg-muted);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ───────────────────────────────────────────────────────────────────────────
   tank-temp-chart — the live SCADA temperature curve inside a chat reply.

   ⛔⛔ COLOURS COME FROM THE --tbm-* TOKENS, NEVER FROM --bs-*. This app ships
   Bootstrap 5.1.0, and --bs-secondary-color / --bs-border-color / --bs-tertiary-bg
   are Bootstrap 5.3 color-mode variables that DO NOT EXIST here. tokens.css defines
   them, but only inside [data-theme="dark"] — so a rule written against them renders
   correctly in dark mode and silently drops in light mode: an undefined var makes the
   declaration invalid at computed-value time, so `stroke` becomes none and the shape
   is DRAWN AND INVISIBLE. Measured on prod 2026-09-04 at 1506x698 CSS / dpr 1.25,
   light mode: the setpoint line, every gridline, the frozen-run dash, the now-rule and
   the card border were all missing, and no test could see it — the elements are in the
   DOM with correct geometry. The --tbm-* set is defined for BOTH themes at :root, and
   is what TankTempGraph.razor.css (the TankBoard drawer) already uses, so pointing here
   is also what makes the two charts read as the same chart.

   ⛔ The hover tooltip is revealed by CSS sibling styling alone. There is no
   @onmousemove on the SVG — on the Blazor Server hosts that would round-trip
   the circuit per mouse move.
   ─────────────────────────────────────────────────────────────────────────── */

.copilot-tank-chart {
    margin: 6px 0;
    border: 1px solid var(--tbm-border);
    border-radius: var(--radius-md);
    background: var(--tbm-surface);
    padding: 8px 10px 10px;
}

.copilot-tank-chart-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.copilot-tank-chart-title {
    font-weight: var(--font-weight-semibold);
    font-size: 13px;
}

.copilot-tank-chart-now {
    font-size: 15px;
    font-weight: var(--font-weight-semibold);
    font-variant-numeric: tabular-nums;
}

.copilot-tank-chart-sp,
.copilot-tank-chart-legend {
    font-size: 11px;
    color: var(--tbm-fg-muted);
}

.copilot-tank-chart-ranges {
    margin-left: auto;
    display: flex;
    gap: 3px;
}

.copilot-tank-chart-chip {
    border: 1px solid var(--tbm-border);
    background: transparent;
    color: var(--tbm-fg-muted);
    border-radius: 999px;
    font-size: 11px;
    line-height: 1;
    padding: 3px 8px;
    cursor: pointer;
}

.copilot-tank-chart-chip:hover:not(:disabled) { background: var(--tbm-surface-subtle); }
.copilot-tank-chart-chip.is-active {
    background: var(--tbm-accent);
    border-color: var(--tbm-accent);
    color: #fff;
}
.copilot-tank-chart-chip:disabled { opacity: .5; cursor: default; }

.copilot-tank-chart-state {
    font-size: 12px;
    color: var(--tbm-fg-muted);
    padding: 14px 2px;
}
.copilot-tank-chart-error { color: var(--tbm-bad-fg); }

.copilot-tank-chart-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.ct-band { pointer-events: none; }
.ct-band-cool  { fill: var(--tbm-cool-band); }
.ct-band-heat  { fill: var(--tbm-heat-band); }
.ct-band-alarm { fill: var(--tbm-alarm); opacity: .08; }
.ct-valve      { fill: var(--tbm-valve); }

.ct-grid { stroke: var(--tbm-grid); stroke-width: 1; }
.ct-axis { fill: var(--tbm-fg-faint); font-size: 10px; }

.ct-temp {
    fill: none;
    stroke: var(--tbm-series-temp);
    stroke-width: 1.8;
    stroke-linejoin: round;
    stroke-linecap: round;
}

/* A frozen run is a verdict the backend computed from the historian — never inferred
   from these points. Dashed so it cannot be mistaken for a measured hold. */
.ct-temp-frozen {
    fill: none;
    stroke: var(--tbm-flat-bg);
    stroke-width: 1.8;
    stroke-dasharray: 3 3;
}

/* A railed RTD. The raw value is preserved rather than clamped, so it must LOOK wrong. */
.ct-temp-fault {
    fill: none;
    stroke: var(--tbm-fault);
    stroke-width: 1.4;
    stroke-dasharray: 2 4;
}
.ct-fault-dot { fill: var(--tbm-fault); }

.ct-setpoint {
    fill: none;
    stroke: var(--tbm-series-setpoint);
    stroke-width: 1.2;
    stroke-dasharray: 5 4;
    opacity: .85;
}

.ct-dot { fill: var(--tbm-series-temp); opacity: .65; }
.ct-dot.is-frozen { fill: var(--tbm-flat-bg); }

.ct-now { stroke: var(--tbm-now); stroke-width: 1; stroke-dasharray: 2 3; opacity: .7; }

.ct-hover-hit { fill: transparent; }
.ct-tip { opacity: 0; pointer-events: none; transition: opacity .08s ease-in; }
.ct-hover:hover .ct-tip { opacity: 1; }
.ct-tip-box { fill: var(--tbm-surface); stroke: var(--tbm-divider); }
.ct-tip-line { fill: var(--tbm-fg); font-size: 11px; }
.ct-tip-muted { fill: var(--tbm-fg-faint); font-size: 10px; }

.copilot-tank-chart-legend {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.ct-key {
    display: inline-block;
    width: 10px;
    height: 3px;
    border-radius: 2px;
    margin-right: 4px;
    vertical-align: middle;
}
.ct-key-temp  { background: var(--tbm-series-temp); }
.ct-key-sp    { background: var(--tbm-series-setpoint); }
.ct-key-cool  { background: var(--tbm-cool); opacity: .25; height: 8px; }
.ct-key-valve { background: var(--tbm-valve); }
.ct-held { color: var(--tbm-fg-muted); font-style: italic; }
