/* ============================================================
   Dashboard (Home) — health donut, distribution bars, alerts
   summary, needs-attention list, richer stat tiles; plus the
   server-list (Fleet) filter extras.
   Colours come from the app.css tokens so both themes work.
   ============================================================ */

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

/* ---------- Header refresh cluster ---------- */
.fleet-header .header-actions:has(.dash-refresh) { flex-wrap: wrap; justify-content: flex-end; }
.dash-refresh {
    display: inline-flex; align-items: center; gap: 8px;
    padding-right: 10px; margin-right: 2px;
    border-right: 1px solid var(--border);
}
.dash-updated { font-family: var(--mono); font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.dash-refresh-btn { padding: 5px 9px; font-size: 14px; line-height: 1; }
.dash-refresh-btn .spin { display: inline-block; animation: spin 0.8s linear infinite; }
.dash-auto {
    display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
    font-family: var(--mono); font-size: 11px; color: var(--text-dim); user-select: none;
}
.dash-auto input { accent-color: var(--accent); margin: 0; }

/* ---------- Stat tiles (buttons) ---------- */
.dash-tiles { margin-bottom: 18px; }
.stat-grid button.stat {
    font: inherit; color: inherit; text-align: left; width: 100%;
    display: block; cursor: pointer;
}
.stat-grid button.stat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.stat-ico {
    position: absolute; top: 14px; right: 14px;
    color: var(--text-faint); opacity: 0.85; line-height: 0;
    transition: color .15s ease;
}
.stat-ok .stat-ico { color: var(--accent); }
.stat-warn .stat-ico { color: var(--amber); }
.stat-crit .stat-ico { color: var(--red); }
.stat-sub {
    margin-top: 6px;
    font-family: var(--mono); font-size: 10.5px; color: var(--text-dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-meter {
    margin-top: 8px; height: 4px; border-radius: 4px;
    background: var(--panel-hi); overflow: hidden;
}
.stat-meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s ease; }
.stat.active {
    box-shadow: 0 0 0 1px var(--accent), 0 0 18px var(--accent-glow);
    background: color-mix(in srgb, var(--accent) 6%, var(--panel));
}
.stat.active .stat-ico { color: var(--accent); }

/* ---------- Overview grid ---------- */
.dash-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.15fr);
    gap: 14px;
    margin-bottom: 28px;
}
.dash-span { grid-column: 1 / -1; min-width: 0; }
.dash-panel { min-width: 0; display: flex; flex-direction: column; }
.dash-span > .dash-panel { height: 100%; }
.dash-panel-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin-bottom: 12px;
}
.dash-panel-head h2 { margin: 0; font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.14em; }
.dash-sub-head { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--border); }
.dash-link, .dash-link-btn {
    font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em;
    color: var(--accent); white-space: nowrap;
}
.dash-link-btn {
    background: none; border: 1px solid transparent; border-radius: 20px;
    padding: 3px 10px; cursor: pointer;
}
.dash-link-btn:hover, .dash-link-btn.on { border-color: var(--accent-dim); background: var(--accent-glow); }
.dash-link-btn:focus-visible, .dash-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dash-more {
    align-self: flex-start; margin-top: 10px;
    background: none; border: none; padding: 2px 0; cursor: pointer;
    font-family: var(--mono); font-size: 11px; color: var(--accent);
}
.dash-more:hover { text-decoration: underline; }
.dash-quiet {
    display: flex; align-items: center; gap: 10px;
    padding: 14px; border-radius: 8px;
    background: var(--green-bg); color: var(--text-dim); font-size: 13px;
}
.dash-quiet-ico {
    display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
    background: var(--green); color: var(--panel); font-weight: 700; font-size: 12px; flex: none;
}

/* ---------- Health donut ---------- */
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut { width: 132px; height: 132px; flex: none; transform: rotate(-90deg); overflow: visible; }
.donut text { transform: rotate(90deg); transform-origin: 60px 60px; text-anchor: middle; }
.donut-track { fill: none; stroke: var(--panel-hi); stroke-width: 13; }
.donut-seg {
    fill: none; stroke-width: 13; cursor: pointer;
    transition: stroke-width .15s ease, opacity .15s ease;
}
.donut-seg:hover { stroke-width: 16; }
.donut.has-on .donut-seg:not(.on) { opacity: 0.3; }
.donut-seg.on { stroke-width: 16; }
.seg-ok { stroke: var(--green); }
.seg-warn { stroke: var(--amber); }
.seg-critical { stroke: var(--red); }
.seg-unknown { stroke: var(--text-faint); }
.donut-num { font-family: var(--mono); font-size: 21px; font-weight: 600; fill: var(--text); }
.donut-cap { font-family: var(--mono); font-size: 8.5px; letter-spacing: 0.14em; text-transform: uppercase; fill: var(--text-faint); }

.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 150px; display: grid; gap: 2px; }
.legend-row {
    width: 100%; display: grid; grid-template-columns: 12px 1fr auto 38px; align-items: center; gap: 8px;
    padding: 6px 8px; border-radius: 6px; border: 1px solid transparent;
    background: none; color: var(--text); font: inherit; font-size: 12.5px; text-align: left; cursor: pointer;
}
.legend-row:hover:not(:disabled) { background: var(--panel-2); border-color: var(--border); }
.legend-row.on { background: var(--panel-hi); border-color: var(--accent-dim); }
.legend-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.legend-row:disabled { opacity: 0.45; cursor: default; }
.legend-num { font-family: var(--mono); font-weight: 600; }
.legend-pct { font-family: var(--mono); font-size: 11px; color: var(--text-faint); text-align: right; }
.sw { width: 10px; height: 10px; border-radius: 3px; background: var(--text-faint); }
.sw-ok { background: var(--green); }
.sw-warn { background: var(--amber); }
.sw-critical { background: var(--red); }

/* ---------- Distribution bars ---------- */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.bar-row {
    width: 100%; display: grid; grid-template-columns: minmax(70px, 38%) 1fr 30px; align-items: center; gap: 10px;
    padding: 5px 6px; border-radius: 6px; border: 1px solid transparent;
    background: none; color: var(--text); font: inherit; font-size: 12px; text-align: left; cursor: pointer;
}
.bar-row:hover:not(:disabled) { background: var(--panel-2); border-color: var(--border); }
.bar-row.on { background: var(--panel-hi); border-color: var(--accent-dim); }
.bar-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.bar-row:disabled { opacity: 0.45; cursor: default; }
.bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }
.bar-track { height: 8px; border-radius: 6px; background: var(--panel-hi); overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 2px; border-radius: 6px; background: var(--accent); transition: width .4s ease; }
.bar-fill.tone-ok { background: var(--green); }
.bar-fill.tone-warn { background: var(--amber); }
.bar-fill.tone-crit { background: var(--red); }
.bar-fill.tone-dim { background: var(--text-faint); }
.bar-num { font-family: var(--mono); font-weight: 600; text-align: right; }

/* ---------- Alerts summary ---------- */
.sev-pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.sev-pill {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    padding: 9px 11px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--border); background: var(--panel-2); color: var(--text-dim); font: inherit; text-align: left;
    transition: border-color .15s ease, transform .15s ease;
}
.sev-pill:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--border-hi); }
.sev-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sev-pill:disabled { cursor: default; }
.sev-pill-num { font-family: var(--mono); font-size: 20px; font-weight: 600; line-height: 1.1; color: var(--text); }
.sev-pill-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; }
.sev-pill-critical:not(.zero) { border-color: color-mix(in srgb, var(--red) 55%, transparent); background: var(--red-bg); }
.sev-pill-critical:not(.zero) .sev-pill-num { color: var(--red); }
.sev-pill-warning:not(.zero) { border-color: color-mix(in srgb, var(--amber) 55%, transparent); background: var(--amber-bg); }
.sev-pill-warning:not(.zero) .sev-pill-num { color: var(--amber); }
.sev-pill-info:not(.zero) .sev-pill-num { color: var(--accent); }
.sev-pill.zero { opacity: 0.55; }
.sev-pill.on { box-shadow: 0 0 0 1px var(--accent); border-color: var(--accent); }

.alert-feed { list-style: none; margin: 0; padding: 0; }
.alert-feed li {
    display: grid; grid-template-columns: 10px minmax(0, 1fr); gap: 10px; align-items: start;
    padding: 8px 2px; border-bottom: 1px solid var(--border);
}
.alert-feed li:last-child { border-bottom: none; }
.alert-feed .sev-dot { margin-top: 5px; }
.alert-feed-msg { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-feed-meta { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); display: flex; gap: 5px; flex-wrap: wrap; }
.alert-feed-meta a { font-weight: 500; }

/* ---------- Needs attention ---------- */
.attn-list {
    list-style: none; margin: 0; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 8px;
}
.attn-row {
    display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 12px; align-items: center;
    padding: 10px 12px; border-radius: 8px;
    border: 1px solid var(--border); border-left: 3px solid var(--text-faint);
    background: var(--panel-2);
    transition: border-color .15s ease, background .15s ease;
}
.attn-row:hover { background: var(--panel-hi); border-color: var(--border-hi); }
.attn-row.attn-crit { border-left-color: var(--red); }
.attn-row.attn-warn { border-left-color: var(--amber); }
.attn-score {
    display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
    font-family: var(--mono); font-size: 12px; font-weight: 700;
    background: var(--panel-hi); color: var(--text-dim);
}
.attn-crit .attn-score { background: var(--red-bg); color: var(--red); }
.attn-warn .attn-score { background: var(--amber-bg); color: var(--amber); }
.attn-name { font-weight: 600; font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attn-reasons { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.attn-reasons .chip { font-size: 9.5px; padding: 1px 7px; }
.attn-actions { display: flex; gap: 6px; }
.attn-actions .btn { text-decoration: none; }
.attn-actions .btn-scan { min-width: 56px; justify-content: center; }

/* ---------- Server table extras ---------- */
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; }
.filter-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 20px; cursor: pointer;
    border: 1px solid var(--accent-dim); background: var(--accent-glow); color: var(--accent);
    font-family: var(--mono); font-size: 11px;
}
.filter-chip:hover { border-color: var(--accent); }
.filter-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dash-noresults {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 18px; border: 1px dashed var(--border-hi); border-radius: var(--radius);
}
.dash-noresults p { margin: 0; }
.dash-table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.dash-table-wrap .fleet-table { min-width: 860px; }
.chip-alert { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); background: var(--red-bg); text-decoration: none; }
.chip-alert:hover { border-color: var(--red); text-decoration: none; }
.dash-age { font-size: 10px; color: var(--text-faint); }
.dash-age.stale { color: var(--amber); }
.dash-bulk { height: 3px; border-radius: 3px; background: var(--panel-hi); overflow: hidden; margin: 2px 0 6px; }
.dash-bulk > span { display: block; height: 100%; background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); transition: width .3s ease; }

/* ---------- Empty state ---------- */
.dash-empty { text-align: center; padding: 44px 20px; }
.dash-empty h2 { color: var(--text); letter-spacing: 0.04em; text-transform: none; font-size: 17px; margin: 14px 0 6px; }
.dash-empty p { max-width: 460px; margin: 0 auto 18px; }
.dash-empty-art { width: 64px; height: 64px; fill: none; stroke: var(--accent); stroke-width: 1.6; }
.dash-empty-art circle { fill: var(--accent); stroke: none; }
.dash-empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Skeleton ---------- */
.skel {
    border-radius: 6px;
    background: linear-gradient(90deg, var(--panel-2) 0%, var(--panel-hi) 50%, var(--panel-2) 100%);
    background-size: 200% 100%;
    animation: dash-shimmer 1.3s ease-in-out infinite;
}
.skel-num { width: 46%; height: 28px; }
.skel-line { width: 70%; height: 10px; margin-top: 12px; }
.skel-line.w40 { width: 40%; margin: 0 0 14px; }
.skel-block { height: 120px; }
.skel-row { height: 34px; margin: 6px 0; }
.dash-skeleton .stat-grid { margin-bottom: 18px; }
@keyframes dash-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
    .skel, .dash-refresh-btn .spin { animation: none; }
    .stat-meter > span, .bar-fill, .dash-bulk > span { transition: none; }
}

/* ---------- Home: tiles are links into /fleet?filter=… ---------- */
.stat-grid a.stat { display: block; color: inherit; text-decoration: none; }
.stat-grid a.stat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.header-actions a.btn, .dash-empty-actions a { text-decoration: none; display: inline-flex; align-items: center; }
.home-lower {
    display: grid; gap: 14px; margin-bottom: 28px;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.4fr) minmax(0, 1fr);
}
.home-lower .cmd-code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.home-ep {
    display: flex; align-items: baseline; gap: 10px; padding: 6px 0;
    color: inherit; text-decoration: none;
}
.home-ep-num { font-family: var(--mono); font-size: 30px; font-weight: 600; color: var(--accent); }
.home-ep.down .home-ep-num { color: var(--red); }
.home-ep-label { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.home-ep:hover .home-ep-label { color: var(--text); }

/* ---------- Fleet: compact quick-filter chips ---------- */
.posture-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.posture-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 20px; cursor: pointer;
    border: 1px solid var(--border); background: var(--panel); color: var(--text-dim);
    font: inherit; font-family: var(--mono); font-size: 11px;
}
.posture-chip:hover { border-color: var(--border-hi); color: var(--text); }
.posture-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.posture-chip-n { color: var(--text); font-weight: 600; }
.posture-chip.warn .posture-chip-n { color: var(--amber); }
.posture-chip.crit .posture-chip-n { color: var(--red); }
.posture-chip.on { border-color: var(--accent-dim); background: var(--accent-glow); color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .dash-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .home-lower { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .home-lower > :nth-child(2) { grid-column: 1 / -1; order: 3; }
    .dash-grid > .dash-panel:nth-child(3) { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
    .dash-grid, .home-lower { grid-template-columns: minmax(0, 1fr); }
    .dash-refresh { border-right: none; padding-right: 0; }
    #servers.section-head { flex-wrap: wrap; }
    #servers.section-head .search-input { max-width: none; min-width: 0; width: 100%; }
}
@media (max-width: 480px) {
    .attn-row { grid-template-columns: 30px minmax(0, 1fr); }
    .attn-actions { grid-column: 2; }
    .donut-wrap { justify-content: center; }
    .stat-ico { display: none; }
}
