/* ============================================
   DASHBOARD - eCharts Views
   Controls, chart containers, drill-down panel
   ============================================ */

/* On dashboard pages the chart sizes itself to the viewport, so drop the global
   .main min-height (which assumes a one-row header) to keep the footer from being
   pushed below the fold. Scoped via :has() so the Home page is unaffected. */
.main:has([data-heatmap-config]) {
    min-height: 0;
    padding-bottom: 0.5rem;
}

/* Chart container - chart elements float directly over the page background.
   Height is set by JS (chart-heatmap.js) to fit the viewport so the environment
   header row and toolbar stay pinned while overflowing rows scroll inside the plot. */
.dashboard-chart-container {
    position: relative;
    width: 100%;
    min-height: 360px;
    border: none;
    background: transparent;
    box-shadow: none;
}

/* Controls toolbar */
.dashboard-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px var(--color-shadow-soft);
}

.dashboard-controls-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 1 1 0;
    min-width: 0;
    justify-content: flex-start;
}

.dashboard-controls-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1 1 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Control buttons */
.ctrl-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-surface-elevated);
    color: var(--color-ink-soft);
    cursor: pointer;
    transition: var(--transition-fast);
}

.ctrl-btn:hover {
    background: var(--color-surface-soft);
    border-color: var(--color-border-strong);
    color: var(--color-accent);
}

.ctrl-btn.active {
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    border-color: var(--color-accent);
}

/* Dashboard buttons */
.dashboard-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: var(--radius);
    border: 2px solid var(--color-border);
    background: var(--color-surface-elevated);
    color: var(--color-ink-soft);
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.dashboard-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
    background: rgba(12, 93, 150, 0.04);
}

.dashboard-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dashboard-btn.active {
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    border-color: var(--color-accent);
}

/* Dashboard selects */
.dashboard-select {
    padding: 0.35rem 0.6rem;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: var(--radius);
    border: 2px solid var(--color-border);
    background: var(--color-surface-elevated);
    color: var(--color-ink-soft);
    cursor: pointer;
    transition: var(--transition-fast);
}

.dashboard-select:hover,
.dashboard-select:focus {
    border-color: var(--color-accent);
    outline: none;
}

/* Dashboard refresh group */
.dashboard-refresh {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* Dashboard search refinement */
.dashboard-search {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    position: relative;
    flex: 0 1 280px;
    min-width: 180px;
}

.dashboard-search input {
    padding: 0.35rem 0.6rem 0.35rem 1.8rem;
    font-size: 0.82rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-elevated);
    color: var(--color-ink);
    width: 100%;
    transition: var(--transition-fast);
}

.dashboard-search input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(12, 93, 150, 0.08);
    outline: none;
}

.dashboard-search i.fa-search {
    position: absolute;
    left: 0.6rem;
    color: var(--color-muted);
    font-size: 0.8rem;
    pointer-events: none;
}

.dashboard-search .search-clear {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--color-muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.2rem;
}

/* Compare results modal */
.compare-summary {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
}

.compare-summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.9rem;
}

.compare-summary-row + .compare-summary-row {
    border-top: 1px solid var(--color-border);
}

.compare-summary-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-ink-soft);
}

.compare-summary-value {
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.compare-summary-value.match { color: #16a34a; }
.compare-summary-value.mismatch { color: #dc2626; }
.compare-summary-label .fa-check-circle { color: #16a34a; }
.compare-summary-label .fa-exclamation-circle { color: #dc2626; }

.compare-diff-heading {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
    color: var(--color-ink);
}

.compare-diff-table-wrap {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.compare-diff-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.compare-diff-table th {
    position: sticky;
    top: 0;
    background: var(--color-surface-soft);
    text-align: left;
    padding: 0.45rem 0.6rem;
    font-weight: 600;
    color: var(--color-ink-soft);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.compare-diff-table td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--color-border);
}

.compare-diff-table tbody tr:last-child td {
    border-bottom: none;
}

.compare-diff-app { font-weight: 600; color: var(--color-ink); }

.compare-diff-ver {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--color-ink-soft);
    text-align: center;
    white-space: nowrap;
}

.compare-all-match {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: #16a34a;
    font-weight: 600;
    font-size: 0.9rem;
}

.compare-all-match .fa-check-circle { color: #16a34a; }

/* Info bar between controls and chart */
.dashboard-info-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--color-muted);
    flex-wrap: wrap;
}

.dashboard-info-bar .info-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    background: var(--color-surface-soft);
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--color-ink-soft);
}

.dashboard-info-bar .info-badge i {
    font-size: 0.72rem;
    color: var(--color-muted);
}

.dashboard-info-bar .info-badge.warn {
    background: var(--color-warn-bg);
    color: var(--color-warn-text);
}

/* Compare control pill — the single compare/clear action in the info bar.
   Idle/1-selected: passive guidance. Ready (2+): primary call-to-action.
   Active: clear-comparison state. */
.dashboard-info-bar .info-badge.compare-hint {
    border: 1px solid transparent;
    background: rgba(12, 93, 150, 0.1);
    color: var(--color-accent);
    font-family: inherit;
    cursor: default;
    transition: var(--transition-fast);
}

.dashboard-info-bar .info-badge.compare-hint i {
    color: var(--color-accent);
}

/* Ready to compare: looks like a primary button and invites a click. */
.dashboard-info-bar .info-badge.compare-hint.is-ready {
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(12, 93, 150, 0.3);
}

.dashboard-info-bar .info-badge.compare-hint.is-ready i {
    color: var(--color-accent-contrast);
}

.dashboard-info-bar .info-badge.compare-hint.is-ready:hover,
.dashboard-info-bar .info-badge.compare-hint.is-ready:focus-visible {
    background: var(--color-accent-hover);
    outline: none;
}

/* Active comparison: click to clear. */
.dashboard-info-bar .info-badge.compare-hint.is-active {
    background: var(--color-surface-elevated);
    color: var(--color-ink-soft);
    border-color: var(--color-border-strong);
    cursor: pointer;
}

.dashboard-info-bar .info-badge.compare-hint.is-active i {
    color: var(--color-ink-soft);
}

.dashboard-info-bar .info-badge.compare-hint.is-active:hover,
.dashboard-info-bar .info-badge.compare-hint.is-active:focus-visible {
    border-color: var(--color-accent);
    color: var(--color-accent);
    outline: none;
}

.dashboard-info-bar .info-badge.compare-hint.is-active:hover i,
.dashboard-info-bar .info-badge.compare-hint.is-active:focus-visible i {
    color: var(--color-accent);
}

.info-spacer {
    flex: 1;
}

.dashboard-info-bar .date-range-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    padding: 0.2rem 0.6rem;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--color-ink-soft);
    transition: var(--transition-fast);
}

.dashboard-info-bar .date-range-trigger:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

/* Drill-down panel */
.drilldown-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 90vw;
    height: 100vh;
    background: var(--color-surface-elevated);
    border-left: 1px solid var(--color-border);
    box-shadow: -4px 0 16px var(--color-shadow-strong);
    z-index: 1060;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.drilldown-panel.open {
    transform: translateX(0);
}

.drilldown-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-hover) 100%);
    color: white;
}

.drilldown-panel-header h3 {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drilldown-panel-close {
    background: none;
    border: none;
    color: white;
    opacity: 0.8;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem;
}

.drilldown-panel-close:hover {
    opacity: 1;
}

.drilldown-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.drilldown-card {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-elevated);
    transition: var(--transition-fast);
}

.drilldown-card:hover {
    border-color: var(--color-border-strong);
    box-shadow: 0 2px 4px var(--color-shadow-soft);
}

.drilldown-card .env-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-muted-strong);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.35rem;
}

.drilldown-card .version {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--color-ink);
    margin-bottom: 0.25rem;
}

.drilldown-card .meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--color-muted);
}

.drilldown-card .status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 600;
}

.drilldown-card .status-badge.succeeded {
    background: var(--heatmap-succeeded-bg);
    color: var(--heatmap-succeeded);
}

.drilldown-card .status-badge.succeeded-with-issues {
    background: var(--heatmap-issues-bg);
    color: var(--heatmap-issues);
}

.drilldown-card .status-badge.pending {
    background: var(--heatmap-pending-bg);
    color: var(--heatmap-pending);
}

.drilldown-card .status-badge.unknown {
    background: var(--heatmap-unknown-bg);
    color: var(--heatmap-unknown);
}

.drilldown-card .status-badge.failed {
    background: var(--heatmap-failed-bg);
    color: var(--heatmap-failed);
}

/* Backdrop */
.drilldown-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    z-index: 1059;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.drilldown-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Refresh control */
.refresh-control {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-elevated);
    font-size: 0.78rem;
    color: var(--color-muted);
}

.refresh-control select {
    border: none;
    background: transparent;
    font-size: 0.78rem;
    color: var(--color-ink-soft);
    padding: 0;
    cursor: pointer;
}

/* Compare mode */
.compare-active .dashboard-chart-container {
    border-color: var(--color-accent);
}

/* Date range */
.date-range-display {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    background: var(--color-surface-soft);
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    color: var(--color-ink-soft);
    cursor: pointer;
}

/* Stats modal */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    text-align: center;
}

.stat-card .stat-value {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-ink);
}

.stat-card .stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    margin-top: 0.2rem;
}

/* Responsive */
@media (max-width: 767px) {
    .dashboard-controls {
        padding: 0.5rem;
        gap: 0.5rem;
        justify-content: flex-start;
    }

    /* Flatten the left/right zones so every control becomes a sibling in one
       wrapping flex row, flowing inline as a grid instead of stacking each on
       its own line. (display: contents removes the wrapper boxes from layout.) */
    .dashboard-controls-left,
    .dashboard-controls-right {
        display: contents;
    }

    /* Search grows to fill the row; the dropdown/buttons sit inline beside it
       and wrap below only when there isn't room. */
    .dashboard-search {
        flex: 1 1 160px;
        min-width: 140px;
    }

    .dashboard-select,
    .dashboard-btn,
    .dashboard-refresh {
        flex: 0 0 auto;
    }

    .dashboard-chart-container {
        min-height: 320px;
    }

    .drilldown-panel {
        width: 100%;
    }

    /* Keep info badges inline and wrapping (flex grid), not a vertical stack. */
    .dashboard-info-bar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.4rem 0.5rem;
    }

    /* The spacer would push the date trigger onto its own line — collapse it so
       the date pill wraps naturally with the other badges. */
    .dashboard-info-bar .info-spacer {
        display: none;
    }
}

/* Invisible hit-zone layer over the heatmap axes. Each .axis-hit-zone covers the
   entire header cell (column strip for xAxis, row strip for yAxis) so the hover
   tooltip and the compare-toggle click target match the full column/row, not
   just the rotated label glyphs. */
.axis-hit-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

.axis-hit-zone {
    position: absolute;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    pointer-events: auto;
    overflow: visible;
    /* Defensive: keep the button visually invisible but discoverable to AT. */
    appearance: none;
    -webkit-appearance: none;
}

.axis-hit-zone:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
    border-radius: 4px;
}

/* Floating tooltip for rotated env headers / truncated app names on the heatmap
   axes. Driven by chart-interactions.js mouseover on axisLabel events. */
.axis-label-tip {
    position: absolute;
    display: none;
    z-index: 1080;
    pointer-events: none;
    max-width: 320px;
    padding: 4px 8px;
    background: rgba(31, 41, 55, 0.95);
    color: #ffffff;
    font-size: 12px;
    line-height: 1.3;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

html[data-theme="dark"] .axis-label-tip {
    background: rgba(15, 23, 42, 0.96);
    color: #e8f1fb;
    border: 1px solid rgba(255, 255, 255, 0.08);
}
