/* Dashboard, charts and instance cards (Phase 9.14). Chart colours are the --viz tokens (validated with the dataviz palette
   checker against the light and dark surfaces); status marks reuse the --sev tokens and always carry an icon or text. */
:root {
  --viz-1: #008f8f;
  --viz-2: #d9482a;
  --viz-muted: #8fa1a7;
  --viz-track: #e3eaec;
  --viz-hatch: #b9c6ca;
  --on-viz-1: #000;
  --on-viz-muted: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --viz-1: #00a9a2; --viz-2: #d95926; --viz-muted: #5f7a80; --viz-track: #1e353b; --viz-hatch: #3c5a61; --on-viz-1: var(--on-fill); --on-viz-muted: #fff; }
}
:root[data-theme="dark"] { --viz-1: #00a9a2; --viz-2: #d95926; --viz-muted: #5f7a80; --viz-track: #1e353b; --viz-hatch: #3c5a61; --on-viz-1: var(--on-fill); --on-viz-muted: #fff; }

/* tone classes, shared by charts and cards: fills and (suffix -text) text colours */
.tone-error { background: var(--sev-error); stroke: var(--sev-error); }
.tone-warn { background: var(--sev-warn); stroke: var(--sev-warn); }
.tone-info { background: var(--sev-info); stroke: var(--sev-info); }
.tone-good, .tone-brand { background: var(--viz-1); stroke: var(--viz-1); }
.tone-1 { background: var(--viz-1); fill: var(--viz-1); }
.tone-2 { background: var(--viz-2); fill: var(--viz-2); }
.tone-muted { background: var(--viz-muted); stroke: var(--viz-muted); }
.tone-hatch { background: repeating-linear-gradient(135deg, var(--viz-hatch) 0 3px, transparent 3px 6px); stroke: var(--viz-hatch); }
.tone-error-text { color: var(--sev-error); }
.tone-warn-text { color: var(--sev-warn); }
.tone-info-text { color: var(--sev-info); }
.tone-good-text, .tone-brand-text { color: var(--brand); }
svg .tone-error, svg .tone-warn, svg .tone-info, svg .tone-good, svg .tone-brand, svg .tone-muted, svg .tone-hatch { background: none; }
svg .tone-1, svg .tone-2 { background: none; }

.view-dashboard { max-width: 90rem; }

/* stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.stat-card { display: flex; flex-direction: column; gap: 0.2rem; padding: 0.85rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--elev-1); color: var(--text); text-decoration: none; border-top: 3px solid var(--border); transition: border-color 0.12s, box-shadow 0.12s; }
a.stat-card:hover, a.stat-card:focus-visible { border-color: var(--tone, var(--brand)); box-shadow: var(--elev-2); }
.stat-card.tone-error { --tone: var(--sev-error); border-top-color: var(--sev-error); background: var(--surface); stroke: none; }
.stat-card.tone-warn { --tone: var(--sev-warn); border-top-color: var(--sev-warn); background: var(--surface); stroke: none; }
.stat-card.tone-good { --tone: var(--viz-1); border-top-color: var(--viz-1); background: var(--surface); stroke: none; }
.stat-card.tone-neutral { border-top-color: var(--border); }
.stat-label { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.stat-label .icon { width: 1rem; height: 1rem; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 0.8rem; min-height: 2.2em; }

/* chart cards */
.chart-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--space-3); }
.chart-grid > .span-2 { grid-column: span 2; }
.chart-grid > .span-3 { grid-column: span 3; }
.chart-grid > .span-4 { grid-column: span 4; }
.chart-grid > .span-6 { grid-column: 1 / -1; }
@media (max-width: 78rem) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid > .span-2, .chart-grid > .span-3 { grid-column: span 1; }
  .chart-grid > .span-4 { grid-column: span 2; }
}
@media (max-width: 40rem) {
  .stat-grid, .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .chart-grid > .span-4 { grid-column: auto; }
}
.chart-card { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.9rem 1rem 0.8rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--elev-1); min-width: 0; }
.chart-title { margin: 0; font-size: 1rem; }
.chart-sub { margin: -0.3rem 0 0; color: var(--muted); font-size: 0.8rem; }
.chart-subhead { margin: 0.6rem 0 0; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.chart-note { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.8rem; }
.viz-empty { color: var(--muted); margin: 0.5rem 0; }
.viz-table { margin-top: auto; padding-top: 0.4rem; font-size: 0.8rem; }
.viz-table summary { color: var(--muted); width: max-content; }
.viz-table table { margin-top: 0.4rem; }

/* donut + legends */
.donut-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; }
.donut-ring { position: relative; width: 9.5rem; height: 9.5rem; flex: none; }
.donut { width: 100%; height: 100%; }
.donut-track { stroke: var(--viz-track); }
.donut-arc { background: none; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; }
.donut-value { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.donut-label { max-width: 5.5rem; margin-top: 0.15rem; color: var(--muted); font-size: 0.7rem; line-height: 1.2; }
.viz-legend { display: grid; gap: 0.3rem; margin: 0; padding: 0; list-style: none; flex: 1; min-width: 9rem; }
.viz-legend-row { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin-top: 0.5rem; }
.legend-row { display: flex; align-items: center; gap: 0.5rem; color: var(--text); text-decoration: none; padding: 0.15rem 0.3rem; border-radius: 6px; }
a.legend-row:hover { background: var(--hover); }
.legend-swatch { width: 0.7rem; height: 0.7rem; border-radius: 3px; flex: none; }
.legend-icon { display: inline-flex; align-items: center; justify-content: center; width: 1rem; height: 1rem; }
.legend-icon .icon { width: 0.85rem; height: 0.85rem; }
.legend-name { flex: 1; }
.legend-count { font-weight: 700; font-variant-numeric: tabular-nums; }
.viz-legend-row .legend-name { flex: none; font-size: 0.8rem; color: var(--muted); }
.viz-legend-row li { display: flex; align-items: center; gap: 0.4rem; }

/* bars */
.bar-list { display: grid; gap: 0.35rem; margin: 0; padding: 0; list-style: none; }
.bar-row { display: grid; grid-template-columns: minmax(8rem, 15rem) 1fr 2.2rem; align-items: center; gap: 0.6rem; }
.bar-label { color: var(--text); text-decoration: none; font-size: 0.85rem; display: flex; align-items: center; gap: 0.3rem; min-width: 0; }
a.bar-label:hover { text-decoration: underline; }
.bar-icon { display: inline-flex; align-items: center; justify-content: center; width: 1rem; height: 1rem; flex: none; }
.bar-track { height: 0.9rem; background: var(--viz-track); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-row .bar-sync { width: var(--icon-md); height: var(--icon-md); }
.bar-row:has(.bar-sync) { grid-template-columns: 1.6rem minmax(7rem, 13rem) 1fr 2.2rem; }

/* stacked bars */
.stack-list { display: grid; gap: 0.6rem; margin: 0; padding: 0; list-style: none; }
.stack-row { display: grid; grid-template-columns: 5.5rem 1fr; align-items: center; gap: 0.75rem; }
.stack-label { font-weight: 600; font-size: 0.85rem; }
.stack-bar { display: flex; gap: 2px; min-height: 1.5rem; }
.stack-seg { display: flex; align-items: center; justify-content: center; min-width: 0.6rem; border-radius: 4px; color: #fff; font-size: 0.75rem; font-weight: 700; text-decoration: none; font-variant-numeric: tabular-nums; }
.stack-seg.tone-good { color: var(--on-viz-1); }
.stack-seg.tone-error, .stack-seg.tone-warn, .stack-seg.tone-info { color: var(--surface); }
.stack-seg.tone-muted { color: var(--on-viz-muted); }
.stack-seg.tone-hatch { color: var(--text); }
a.stack-seg:hover { filter: brightness(1.12); }
.stack-seg-small { font-size: 0; }
.stack-note { color: var(--muted); font-size: 0.8rem; align-self: center; }

/* columns */
.columns { width: 100%; height: auto; overflow: visible; }
.columns .grid-line { stroke: var(--border); stroke-width: 1; }
.columns .axis-text { fill: var(--muted); font-size: 8px; }
.columns .value-text { fill: var(--text); font-size: 9px; font-weight: 700; }
.columns .col { stroke: none; }

/* lists */
.urgent-list { display: grid; gap: 0.5rem; }
.urgent-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.7rem; }
.urgent-main { min-width: 0; }
.urgent-row { min-height: 3rem; }
.urgent-main .badges { margin-top: 0.2rem; flex-direction: row; flex-wrap: wrap; }
.urgent-main .urgent-badges { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; gap: 0.2rem 0.4rem; align-items: start; }
.urgent-badges > li { margin: 0 !important; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.urgent-more { color: var(--muted); font-size: 0.78rem; font-weight: 700; cursor: help; }
.urgent-name { color: var(--text); font-weight: 600; text-decoration: none; }
.urgent-name:hover { text-decoration: underline; }
.urgent-count { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }

/* instance cards (Instances page) */
.instance-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: var(--space-3); margin: 0.25rem 0 var(--space-4); }
.instance-card { display: flex; flex-direction: column; gap: 0.35rem; align-items: stretch; padding: 0.8rem 0.9rem; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--elev-1); cursor: pointer; }
.instance-card:hover { border-color: var(--muted); background: var(--surface); }
.instance-card.is-selected { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand), var(--elev-1); }
.instance-card.is-down { border-style: dashed; }
.ic-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.ic-name { font-size: 1.1rem; font-weight: 700; }
.ic-tier { padding: 0 0.5rem; border-radius: var(--radius-pill); background: var(--hover); color: var(--muted); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.ic-host { color: var(--muted); font-size: 0.78rem; overflow-wrap: anywhere; }
.ic-state { font-size: 0.8rem; font-weight: 600; color: var(--text); }
.ic-state.is-bad, .ic-error { color: var(--sev-error); }
.ic-error { font-size: 0.8rem; overflow-wrap: anywhere; }
.ic-stats { display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.75rem; margin: 0.25rem 0 0; font-size: 0.82rem; }
.ic-stats dt { color: var(--muted); }
.ic-stats dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.ic-bar { display: flex; gap: 2px; height: 0.45rem; margin-top: 0.4rem; }
.ic-seg { border-radius: 3px; min-width: 4px; }

/* instance release line and drift note */
.ic-release { font-size: 0.85rem; font-weight: 600; }
.ic-drift { margin-left: 0.4rem; padding: 0 0.4rem; border-radius: var(--radius-pill); background: color-mix(in srgb, var(--sev-warn) 14%, transparent); color: var(--sev-warn); font-size: 0.7rem; font-weight: 700; }
.ic-drift.is-behind { background: color-mix(in srgb, var(--sev-error) 12%, transparent); color: var(--sev-error); }

/* instance details panel */
.instance-details { margin: 0 0 var(--space-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--elev-1); }
.instance-details > summary { padding: 0.65rem 1rem; font-weight: 700; }
.id-title { flex: none; }
.id-oneline { margin-left: 0.5rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.instance-details[open] .id-oneline { display: none; }
.id-body { padding: 0 1rem 0.9rem; }
.id-open { display: inline-block; margin-bottom: 0.4rem; }
.id-unavailable { color: var(--muted); font-size: 0.85rem; }
.instance-details .facts { margin-bottom: 0.4rem; }

/* Apps section of the Instances page: title and Export on one line, folds like the details panel */
.apps-section { margin: 0 0 var(--space-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--elev-1); }
.apps-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; padding: 0.4rem 1rem; }
.apps-section > .detail-sub { margin: 0; padding: 0 1rem 0.6rem; }
.apps-body > .detail-sub, .apps-body > .notice, .apps-body > .state { margin: 0.4rem 1rem 0.8rem; }
.view-instances .apps-section .table-scroll { border: 0; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-lg) var(--radius-lg); background: none; box-shadow: none; }
.apps-toggle { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.1rem; border: 0; background: none; color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.apps-head .export-menu { margin-left: auto; }
.view-instances .apps-section { flex: 1; display: flex; flex-direction: column; min-height: min(20rem, 50vh); }
.view-instances .apps-section:has(.apps-body[hidden]) { flex: none; min-height: 0; }
.apps-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view-instances .apps-section .table-scroll { flex: 1; min-height: 0; overflow: auto; }
.apps-body[hidden] { display: none; }

/* Welcome card (demo data showing) */
.get-started { margin: 0 0 var(--space-4); padding: 0.9rem 1.1rem; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand, var(--focus)); border-radius: var(--radius-lg); box-shadow: var(--elev-1); }
.get-started-title { margin: 0 0 0.2rem; font-size: 1.05rem; }
.get-started-steps { margin: 0.4rem 0 0.6rem; padding-left: 1.3rem; }
.get-started-steps li { margin: 0.25rem 0; }
.get-started-steps li.is-done strong { color: var(--muted); }
.get-started-actions { display: flex; align-items: center; gap: 0.75rem; }
.get-started-steps .detail-sub { display: block; margin: 0; }

/* Source control: Git host chips and the single problems line */
.host-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.35rem; margin: 0.3rem 0 0; }
.host-chips > li, .host-chips > li + li { display: flex; margin: 0; line-height: 1; }
.host-chip { display: inline-flex; align-items: center; gap: 0.35rem; height: 1.6rem; box-sizing: border-box; line-height: 1; padding: 0 0.55rem; border: 1px solid var(--border); border-radius: 999px; color: var(--text); text-decoration: none; font-size: 0.8rem; background: var(--surface); }
.host-chip:hover { background: var(--hover); }
.host-chip.has-problem { border-color: var(--sev-warn); }
.host-count { font-weight: 700; font-variant-numeric: tabular-nums; }
.host-chip .src-icon, .host-chip .sev-mark { width: 0.9rem; height: 0.9rem; flex: none; display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.host-chip .src-icon svg { width: 100%; height: 100%; }
.git-problems { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }

/* Oldest stashes: two columns on wide screens */
.stash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem 2rem; }
@media (max-width: 70rem) { .stash-grid { grid-template-columns: minmax(0, 1fr); } }
.urgent-count.is-old { color: var(--sev-warn); font-weight: 700; }
.stash-old { color: var(--sev-warn); font-weight: 700; }
