/* ------------------------------------------------------------------
   Kafka Live Metrics Dashboard
   Plain CSS — Flexbox & Grid, no external frameworks
   ------------------------------------------------------------------ */

:root {
    --color-bg: #f3f6fb;
    --color-surface: #ffffff;
    --color-surface-muted: #f8fafc;
    --color-border: #e2e8f0;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-primary: #2563eb;
    --color-primary-soft: #dbeafe;
    --color-success: #059669;
    --color-success-soft: #d1fae5;
    --color-failure: #dc2626;
    --color-failure-soft: #fee2e2;
    --color-warning: #d97706;
    --color-warning-soft: #fef3c7;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --font-sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --space-xs: 0.5rem;
    --space-sm: 0.75rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 2.5rem;
    --max-width: 1200px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--color-text);
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.08), transparent 28rem),
        linear-gradient(180deg, #eef2ff 0%, var(--color-bg) 18rem, var(--color-bg) 100%);
    line-height: 1.5;
}

.dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ------------------------------------------------------------------
   Header
   ------------------------------------------------------------------ */

.dashboard-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
}

.dashboard-title {
    margin: 0;
    font-size: clamp(1.5rem, 2.5vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
}

.connection-panel {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-surface-muted);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.connection-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 7rem;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.status-disconnected {
    color: var(--color-warning);
    background: var(--color-warning-soft);
    border: 1px solid #fcd34d;
}

.status-connected {
    color: var(--color-success);
    background: var(--color-success-soft);
    border: 1px solid #6ee7b7;
}

/* ------------------------------------------------------------------
   Main layout
   ------------------------------------------------------------------ */

.dashboard-main {
    flex: 1;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg) var(--space-2xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    scroll-padding-top: 7.5rem;
}

/* ------------------------------------------------------------------
   Dashboard tabs
   ------------------------------------------------------------------ */

.dashboard-tabs {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    min-width: 0;
}

.dashboard-tablist {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.4rem;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}

.dashboard-tab {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.95rem;
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 650;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.dashboard-tab:hover {
    color: var(--color-text);
    background: var(--color-surface-muted);
}

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

.dashboard-tab.is-active {
    color: var(--color-primary);
    background: var(--color-primary-soft);
    border-color: #bfdbfe;
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: var(--color-failure);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.dashboard-tabpanel {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    min-width: 0;
}

.dashboard-tabpanel[hidden] {
    display: none;
}

/* ------------------------------------------------------------------
   R&D hierarchy (temporary validation tab)
   ------------------------------------------------------------------ */

.rnd-hierarchy-section .section-header code {
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.rnd-findings {
    margin: 0 var(--space-lg) var(--space-lg);
    padding: var(--space-md) var(--space-lg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
}

.rnd-findings-title {
    margin: 0 0 var(--space-sm);
    font-size: 0.9375rem;
    font-weight: 700;
}

.rnd-findings-list {
    margin: 0;
    padding-left: 1.25rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    line-height: 1.55;
}

.rnd-findings-list .rnd-finding-warn {
    color: var(--color-warning);
    font-weight: 600;
}

.rnd-findings-list .rnd-finding-ok {
    color: var(--color-success);
}

.rnd-hierarchy-tree {
    padding: 0 var(--space-lg) var(--space-lg);
}

.rnd-channel,
.rnd-profile,
.rnd-job {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    margin-bottom: var(--space-sm);
    overflow: hidden;
}

.rnd-channel > summary,
.rnd-profile > summary,
.rnd-job > summary {
    cursor: pointer;
    list-style: none;
    padding: 0.75rem 1rem;
    font-weight: 650;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: baseline;
}

.rnd-channel > summary::-webkit-details-marker,
.rnd-profile > summary::-webkit-details-marker,
.rnd-job > summary::-webkit-details-marker {
    display: none;
}

.rnd-channel > summary::before,
.rnd-profile > summary::before,
.rnd-job > summary::before {
    content: "▸";
    color: var(--color-text-muted);
    margin-right: 0.35rem;
}

.rnd-channel[open] > summary::before,
.rnd-profile[open] > summary::before,
.rnd-job[open] > summary::before {
    content: "▾";
}

.rnd-channel-body,
.rnd-profile-body,
.rnd-job-body {
    padding: 0 0.75rem 0.75rem 1.25rem;
    border-top: 1px solid var(--color-border);
}

.rnd-meta-chip {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.rnd-profile,
.rnd-job {
    margin-top: 0.5rem;
}

.rnd-run-table-wrap {
    overflow-x: auto;
    margin-top: 0.5rem;
}

.rnd-run-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.rnd-run-table th,
.rnd-run-table td {
    padding: 0.5rem 0.65rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: middle;
}

.rnd-run-table th {
    color: var(--color-text-muted);
    font-weight: 650;
    white-space: nowrap;
}

.rnd-empty {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    padding: var(--space-md);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.section-header {
    padding: var(--space-lg) var(--space-lg) 0;
}

.section-title {
    margin: 0;
    padding-bottom: var(--space-md);
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
}

.metrics-meta {
    margin: var(--space-sm) 0 0;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.metrics-error {
    margin: var(--space-sm) 0 0;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    background: var(--color-failure-soft);
    color: var(--color-failure);
    font-size: 0.875rem;
    font-weight: 600;
}

/* ------------------------------------------------------------------
   Global metrics cards
   ------------------------------------------------------------------ */

.global-metrics-section {
    padding-bottom: var(--space-lg);
}

.global-metrics-section .metrics-grid {
    align-items: stretch;
}

.global-metrics-section .metric-card {
    container-type: inline-size;
    container-name: global-metric;
    height: 100%;
    min-height: 7.5rem;
}

/* Keep Global Metrics values on one line; scale with card width. */
.global-metrics-section .metric-value {
    display: block;
    width: 100%;
    max-width: 100%;
    margin-top: auto;
    white-space: nowrap;
    overflow: hidden;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
    line-height: 1.15;
    font-size: clamp(0.95rem, 11cqi, 1.85rem);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--space-md);
    padding: var(--space-lg);
}

.metric-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--space-sm);
    min-width: 0;
    min-height: 120px;
    padding: var(--space-md) var(--space-lg);
    overflow: hidden;
    background: linear-gradient(180deg, var(--color-surface-muted) 0%, var(--color-surface) 100%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.metric-label {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    margin: 0;
    max-width: 100%;
    font-size: clamp(1.05rem, 1.6vw + 0.55rem, 1.85rem);
    font-weight: 700;
    line-height: 1.2;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
}

.metric-success {
    color: var(--color-success);
}

.metric-failure {
    color: var(--color-failure);
}

/* ------------------------------------------------------------------
   Overview — Requires Attention (UI placeholder)
   ------------------------------------------------------------------ */

.overview-attention-section {
    padding-bottom: var(--space-lg);
}

.overview-attention-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-lg);
}

.overview-attention-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: linear-gradient(180deg, var(--color-surface-muted) 0%, var(--color-surface) 100%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--color-border);
}

.overview-attention-card[data-severity="critical"] {
    border-left-color: var(--color-failure);
}

.overview-attention-card[data-severity="warning"] {
    border-left-color: var(--color-warning);
}

.overview-attention-card[data-severity="healthy"] {
    border-left-color: var(--color-success);
}

.overview-attention-card__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm) var(--space-md);
}

.overview-attention-severity {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.overview-attention-severity--critical {
    background: var(--color-failure-soft);
    color: var(--color-failure);
    border: 1px solid #fecaca;
}

.overview-attention-severity--warning {
    background: var(--color-warning-soft);
    color: var(--color-warning);
    border: 1px solid #fde68a;
}

.overview-attention-severity--healthy {
    background: var(--color-success-soft);
    color: var(--color-success);
    border: 1px solid #a7f3d0;
}

.overview-attention-channel {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-text);
}

.overview-attention-reason {
    margin: 0;
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    background: rgba(15, 23, 42, 0.04);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    line-height: 1.35;
}

.overview-attention-card[data-severity="critical"] .overview-attention-reason {
    border-color: rgba(220, 38, 38, 0.25);
    background: rgba(220, 38, 38, 0.06);
    color: #991b1b;
}

.overview-attention-card[data-severity="warning"] .overview-attention-reason {
    border-color: rgba(217, 119, 6, 0.28);
    background: rgba(217, 119, 6, 0.08);
    color: #92400e;
}

.attention-channel-reason {
    margin: 0;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface-muted);
    color: var(--color-text);
    font-size: 0.875rem;
    line-height: 1.4;
}

.overview-attention-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-md);
    margin: 0;
}

.overview-attention-stat {
    min-width: 0;
}

.overview-attention-stat dt {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.overview-attention-stat dd {
    margin: 0.25rem 0 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    word-break: break-word;
}

.overview-attention-card__actions {
    display: flex;
    justify-content: flex-end;
}

.overview-attention-empty {
    margin: 0;
    padding: 0.25rem 0;
}

.overview-attention-details-btn {
    appearance: none;
    border: 1px solid var(--color-border);
    background: var(--color-primary-soft);
    color: var(--color-primary);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.9rem;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 650;
    cursor: pointer;
}

.overview-attention-details-btn:disabled {
    cursor: not-allowed;
    opacity: 0.75;
}

.attention-channel-modal-panel {
    width: min(760px, 100%);
    max-height: min(90vh, 900px);
    overflow: auto;
}

.attention-channel-range-meta {
    margin: 0.25rem 0 0;
}

.attention-channel-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.attention-channel-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-md);
}

.attention-channel-summary-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.attention-channel-name {
    font-weight: 700;
    font-size: 1.05rem;
    word-break: break-word;
}

.attention-channel-hierarchy-block {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.attention-channel-hierarchy-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
}

.attention-channel-hierarchy {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
    padding: 0.65rem 0.75rem;
    max-height: 18rem;
    overflow: auto;
}

.attention-hierarchy-profile,
.attention-hierarchy-job {
    margin: 0.15rem 0;
}

.attention-hierarchy-profile > summary,
.attention-hierarchy-job > summary {
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
}

.attention-hierarchy-job-list,
.attention-hierarchy-run-list {
    margin: 0.25rem 0 0.35rem 1rem;
    padding: 0;
    list-style: none;
}

.attention-hierarchy-run {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.65rem;
    padding: 0.2rem 0;
    font-size: 0.8rem;
}

.attention-hierarchy-run .mono-cell {
    font-size: 0.78rem;
}

.attention-channel-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.65rem;
    margin-top: 0.25rem;
}

.attention-channel-primary-btn,
.attention-channel-secondary-btn {
    appearance: none;
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.9rem;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}

.attention-channel-secondary-btn {
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
}

.attention-channel-primary-btn {
    border: 1px solid #1d4ed8;
    background: #2563eb;
    color: #fff;
}

.attention-channel-primary-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.attention-channel-primary-btn:not(:disabled):hover {
    background: #1d4ed8;
}

.rnd-channel--focus > summary {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

@media (max-width: 900px) {
    .overview-attention-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .attention-channel-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .overview-attention-stats {
        grid-template-columns: 1fr;
    }

    .overview-attention-card__actions {
        justify-content: stretch;
    }

    .overview-attention-details-btn {
        width: 100%;
    }

    .attention-channel-summary {
        grid-template-columns: 1fr;
    }
}

/* ------------------------------------------------------------------
   Overview — Channel Health
   ------------------------------------------------------------------ */

.channel-health-section {
    padding-bottom: var(--space-lg);
}

.channel-health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-md);
    padding: var(--space-lg);
    align-items: stretch;
}

.channel-health-card {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    min-width: 0;
    min-height: 8.5rem;
    height: 100%;
    padding: 0.85rem 1rem;
    text-align: left;
    appearance: none;
    font: inherit;
    color: inherit;
    cursor: pointer;
    background: linear-gradient(180deg, var(--color-surface-muted) 0%, var(--color-surface) 100%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--color-border);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.channel-health-card:hover,
.channel-health-card:focus-visible {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    outline: none;
}

.channel-health-card:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.channel-health-card[data-severity="critical"] {
    border-left-color: var(--color-failure);
}

.channel-health-card[data-severity="warning"] {
    border-left-color: var(--color-warning);
}

.channel-health-card[data-severity="healthy"] {
    border-left-color: var(--color-success);
}

.channel-health-card__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.55rem;
}

.channel-health-channel {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.25;
    word-break: break-word;
}

.channel-health-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem 0.75rem;
    margin: 0;
}

.channel-health-stat dt {
    margin: 0;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.channel-health-stat dd {
    margin: 0.1rem 0 0;
    font-size: 0.9rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.channel-health-empty {
    margin: 0;
    grid-column: 1 / -1;
}

@media (max-width: 560px) {
    .channel-health-grid {
        grid-template-columns: 1fr;
    }
}

/* ------------------------------------------------------------------
   Historical / Run Analytics time-range bar (page-level, sticky)
   ------------------------------------------------------------------ */

.historical-range-bar,
.dashboard-range-bar {
    position: sticky;
    top: 3.6rem;
    z-index: 40;
    margin: 0;
    padding: 0;
    background:
        linear-gradient(
            180deg,
            rgba(243, 246, 251, 0.98) 0%,
            rgba(243, 246, 251, 0.96) 70%,
            rgba(243, 246, 251, 0.88) 100%
        );
    border-top: 1px solid transparent;
    backdrop-filter: blur(6px);
}

.historical-range-bar__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.historical-range-bar__text {
    flex: 1 1 16rem;
    min-width: 0;
}

.historical-range-bar__label {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--color-text);
}

.historical-range-bar__selected {
    margin: 0.35rem 0 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-primary);
}

.historical-range-bar__hint {
    margin: 0.35rem 0 0;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    line-height: 1.4;
}

.time-range-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.range-btn {
    appearance: none;
    border: 1px solid var(--color-border);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.8rem;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.range-btn:hover {
    border-color: #bfdbfe;
    color: var(--color-primary);
    background: var(--color-primary-soft);
}

.range-btn.is-active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #ffffff;
}

.filtered-range-section {
    scroll-margin-top: 7.5rem;
}

.operational-section .metrics-meta {
    max-width: 48rem;
}

.attention-reason {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    line-height: 1.4;
    max-width: 28rem;
}

.range-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 0.4rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid #bfdbfe;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
    vertical-align: middle;
}

.run-details-range-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
}

/* ------------------------------------------------------------------
   Historical trends
   ------------------------------------------------------------------ */

.trends-section {
    padding-bottom: var(--space-lg);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-lg);
    padding: var(--space-lg);
}

.chart-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: linear-gradient(180deg, var(--color-surface-muted) 0%, var(--color-surface) 100%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.chart-title {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--color-text);
}

.chart-canvas-wrap {
    position: relative;
    width: 100%;
    height: 260px;
}

.chart-canvas-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-canvas-wrap-tall {
    height: 340px;
}

.chart-subtitle {
    margin: 0 0 var(--space-sm);
}

/* ------------------------------------------------------------------
   Run analytics
   ------------------------------------------------------------------ */

.run-analytics-section {
    padding-bottom: var(--space-lg);
}

.metrics-meta-sep {
    margin: 0 0.35rem;
}

.run-analytics-controls {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.5fr);
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg) 0;
    align-items: end;
}

.control-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.run-analytics-search input {
    width: 100%;
    box-sizing: border-box;
    min-height: 2.5rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    font-size: 0.875rem;
}

.run-analytics-search input:focus {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    outline-offset: 1px;
    border-color: var(--color-primary);
}

.filter-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.filter-btn {
    appearance: none;
    border: 1px solid var(--color-border);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.75rem;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.filter-btn:hover {
    border-color: #bfdbfe;
    color: var(--color-primary);
    background: var(--color-primary-soft);
}

.filter-btn.is-active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #ffffff;
}

.run-analytics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-lg);
    padding: var(--space-lg);
}

.run-analytics-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-width: 0;
    padding: var(--space-md);
    background: linear-gradient(180deg, var(--color-surface-muted) 0%, var(--color-surface) 100%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.table-wrapper-compact {
    padding: 0;
    overflow-x: auto;
}

.mono-cell {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.run-id-link {
    appearance: none;
    border: 0;
    background: none;
    padding: 0;
    margin: 0;
    max-width: 14rem;
    color: var(--color-primary);
    font: inherit;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: bottom;
}

.run-id-link:hover,
.run-id-link:focus-visible {
    color: #1d4ed8;
}

/* ------------------------------------------------------------------
   Run details modal
   ------------------------------------------------------------------ */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--space-xl) var(--space-md);
    overflow-y: auto;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(920px, 100%);
    margin: auto;
    padding: var(--space-lg);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-md);
}

.modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.modal-close {
    appearance: none;
    border: 1px solid var(--color-border);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-sm);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--color-text);
    border-color: #cbd5e1;
}

.run-details-meta {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-md);
}

/* ------------------------------------------------------------------
   Run health badges
   ------------------------------------------------------------------ */

.health-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.2;
    white-space: nowrap;
}

.health-badge__dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    flex: 0 0 auto;
}

.health-badge--monitoring {
    color: #475569;
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.health-badge--monitoring .health-badge__dot {
    background: #94a3b8;
}

.health-badge--healthy {
    color: #047857;
    background: var(--color-success-soft);
    border-color: #6ee7b7;
}

.health-badge--healthy .health-badge__dot {
    background: var(--color-success);
}

.health-badge--warning {
    color: #b45309;
    background: var(--color-warning-soft);
    border-color: #fcd34d;
}

.health-badge--warning .health-badge__dot {
    background: var(--color-warning);
}

.health-badge--critical {
    color: #b91c1c;
    background: var(--color-failure-soft);
    border-color: #fca5a5;
}

.health-badge--critical .health-badge__dot {
    background: var(--color-failure);
}

.health-explanation {
    margin: 0;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface-muted);
    color: var(--color-text);
    font-size: 0.875rem;
    line-height: 1.45;
}

.health-explanation--monitoring {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}

.health-explanation--healthy {
    background: var(--color-success-soft);
    border-color: #6ee7b7;
    color: #065f46;
}

.health-explanation--warning {
    background: var(--color-warning-soft);
    border-color: #fcd34d;
    color: #92400e;
}

.health-explanation--critical {
    background: var(--color-failure-soft);
    border-color: #fca5a5;
    color: #991b1b;
}

.run-details-meta-item {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
    padding: var(--space-md);
    background: var(--color-surface-muted);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.run-details-meta-item .mono-cell,
#runDetailsRunId,
#runDetailsJobId,
#runDetailsLastUpdated {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.run-details-metrics {
    padding: 0;
}

.run-details-metrics .metric-card {
    min-height: 96px;
}

.run-details-chart-card {
    margin: 0;
    min-width: 0;
}

body.modal-open {
    overflow: hidden;
}

/* ------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------ */

.run-metrics-section,
.recent-messages-section {
    padding-bottom: var(--space-lg);
}

.run-metrics-details {
    padding-bottom: 0;
}

.run-metrics-summary {
    list-style: none;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-lg);
    cursor: pointer;
    user-select: none;
}

.run-metrics-summary::-webkit-details-marker {
    display: none;
}

.run-metrics-summary .section-title {
    border-bottom: none;
    padding-bottom: 0;
}

.run-metrics-summary-text {
    min-width: 0;
    flex: 1 1 auto;
}

.run-metrics-summary-meta {
    margin-top: var(--space-sm);
}

.run-metrics-independence-hint {
    margin-top: 0.25rem;
    font-size: 0.8125rem;
}

.run-metrics-chevron {
    flex: 0 0 auto;
    width: 1.75rem;
    height: 1.75rem;
    margin-top: 0.15rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-muted);
    position: relative;
}

.run-metrics-chevron::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0.45rem;
    height: 0.45rem;
    border-right: 2px solid var(--color-text-muted);
    border-bottom: 2px solid var(--color-text-muted);
    transform: translate(-50%, -65%) rotate(45deg);
    transition: transform 0.15s ease;
}

.run-metrics-details[open] .run-metrics-chevron::before {
    transform: translate(-50%, -35%) rotate(225deg);
}

.run-metrics-summary:hover {
    background: rgba(37, 99, 235, 0.03);
}

.run-metrics-body {
    padding-bottom: var(--space-lg);
}

.run-metrics-section > .section-header + .run-metrics-body {
    border-top: 1px solid var(--color-border);
}

.run-metrics-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg) 0;
}

.run-metrics-search {
    flex: 1 1 18rem;
    max-width: 28rem;
}

.run-metrics-search input {
    width: 100%;
    box-sizing: border-box;
    min-height: 2.5rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    font-size: 0.875rem;
}

.run-metrics-search input:focus {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    outline-offset: 1px;
    border-color: var(--color-primary);
}

.table-wrapper {
    padding: var(--space-lg);
    overflow-x: auto;
}

.table-wrapper-wide {
    max-width: 100%;
}

.data-table-wide {
    min-width: 2200px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.data-table thead {
    background: var(--color-surface-muted);
}

.data-table th,
.data-table td {
    padding: 0.9rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9375rem;
}

.data-table th {
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.04);
}

.data-table td.empty-row {
    text-align: center;
    color: var(--color-text-muted);
    font-weight: 600;
    padding: 1.5rem 1rem;
}

.data-table td {
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.data-table td.mono {
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

/* Empty state placeholder rows can be styled later via JS */
.data-table tbody:empty::after {
    content: "No data yet";
    display: block;
    padding: var(--space-xl);
    text-align: center;
    color: var(--color-text-muted);
}

/* ------------------------------------------------------------------
   Footer
   ------------------------------------------------------------------ */

.dashboard-footer {
    margin-top: auto;
    padding: var(--space-lg);
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.dashboard-footer p {
    margin: 0;
}

/* ------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------ */

@media (max-width: 1200px) {
    .metrics-grid,
    .run-details-metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .run-details-meta {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .metrics-grid,
    .run-details-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .charts-grid,
    .run-analytics-grid,
    .run-details-meta,
    .run-analytics-controls {
        grid-template-columns: 1fr;
    }

    .run-id-link {
        max-width: 10rem;
    }
}

@media (max-width: 640px) {
    .header-content,
    .dashboard-main {
        padding-left: var(--space-md);
        padding-right: var(--space-md);
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .connection-panel {
        width: 100%;
        justify-content: space-between;
    }

    .metrics-grid,
    .run-details-metrics {
        grid-template-columns: 1fr;
    }

    .metric-card {
        min-height: auto;
        padding: var(--space-md);
    }

    .global-metrics-section .metric-card {
        min-height: 6.5rem;
    }

    .metric-value {
        font-size: clamp(1.15rem, 5vw, 1.6rem);
    }

    .global-metrics-section .metric-value {
        font-size: clamp(1.05rem, 8cqi, 1.6rem);
        white-space: nowrap;
        overflow-wrap: normal;
        word-break: normal;
    }

    .modal-panel {
        padding: var(--space-md);
    }

    .historical-range-bar {
        top: 4.75rem;
        padding-top: var(--space-sm);
        padding-bottom: var(--space-sm);
    }

    .historical-range-bar__inner {
        padding: var(--space-md);
    }

    .time-range-selector {
        width: 100%;
        justify-content: stretch;
    }

    .range-btn {
        flex: 1 1 auto;
        text-align: center;
    }

    .filtered-range-section {
        scroll-margin-top: 11rem;
    }

    .dashboard-main {
        scroll-padding-top: 11rem;
    }

    .run-id-link {
        max-width: 8.5rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.75rem;
        font-size: 0.875rem;
    }
}
