/* Dashboard shell — role-aware, customizable. Gridstack provides the grid;
   this file styles the widget tile, edit mode, add-widget panel, and modal.

   Direction B ("Modern SaaS console", docs/ui-retemplate-PLAN.md): hairline
   borders carry the structure, elevation is reserved for surfaces that genuinely
   float, one accent does the emphasis. Every colour here resolves to a token
   from input.css so the page follows the colour scheme.

   No `var(--token, #fallback)` pairs. This file used to carry them and three
   had drifted onto token names that do not exist — `--bg-grouped-primary`,
   `--background`, `--tint` — so the add-widget panel, the config picker and a
   focus ring silently painted their light-mode fallbacks in dark mode. A bare
   var() fails visibly instead of quietly rendering the wrong scheme. */

.dash-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.dash-save-state {
  font-size: var(--text-footnote);
  color: var(--label-secondary);
  margin-right: var(--space-1);
  min-width: 80px;
  text-align: right;
}

/* Dashboard action menu — icon-triggered popup that hosts the
   Customize / Add widget / Reset / Done actions. */
.dash-menu { position: relative; }

.dash-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-md);
  color: var(--label-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.dash-menu-trigger:hover {
  background: var(--fill3);
  color: var(--label);
}
.dash-menu-trigger[aria-expanded="true"] {
  background: var(--fill2);
  color: var(--label);
  border-color: var(--separator-opaque);
}
.dash-menu-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dash-menu-popup {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  padding: var(--space-1);
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dash-menu-popup[hidden] { display: none; }

.dash-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: var(--text-callout);
  font-weight: 500;
  color: var(--label);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.dash-menu-item[hidden] { display: none; }
.dash-menu-item:hover  { background: var(--fill3); }
.dash-menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.dash-menu-item svg { color: var(--label-secondary); flex-shrink: 0; }
.dash-menu-item:hover svg { color: var(--label); }

/* "Done" — the one emphasised action in the menu. accent-ink, not accent:
   the raw brand hue fails AA as text (see the token table in the plan). */
.dash-menu-item-primary       { color: var(--accent-ink); }
.dash-menu-item-primary svg,
.dash-menu-item-primary:hover svg { color: var(--accent-ink); }

.dash-hint {
  margin: 0 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--yellow-tint);
  border-left: 3px solid var(--orange);
  border-radius: var(--radius-sm);
  font-size: var(--text-footnote);
  color: var(--label);
}

/* Getting-started panel. Was nine inline style attributes on the page; the
   progress fill was `--green`, which read as a status colour rather than as
   the one accent doing the emphasis on this screen. */
.ob-panel { position: relative; }
.ob-dismiss {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  border: 0;
  background: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--label-secondary);
}
.ob-dismiss:hover { color: var(--label); }
.ob-title {
  margin: 0 0 var(--space-1);
  font-size: var(--text-headline);
  font-weight: 600;
  color: var(--label);
}
.ob-subtitle {
  margin: 0 0 var(--space-3);
  color: var(--label-secondary);
  font-size: var(--text-footnote);
}
.ob-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.ob-track {
  flex: 1;
  min-width: 160px;
  height: 6px;
  background: var(--fill3);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.ob-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s var(--spring);
}
.ob-count {
  font-size: var(--text-footnote);
  font-weight: 600;
  color: var(--label);
  white-space: nowrap;
}

.dash-grid-wrapper {
  position: relative;
  min-height: 200px;
}

.dash-empty {
  text-align: center;
  padding: var(--space-10) var(--space-5);
  color: var(--label-secondary);
}
.dash-empty p { margin: 0 0 var(--space-3); }

/* Gridstack tile = widget tile. Hairline border, no resting shadow. */
.grid-stack-item-content {
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, box-shadow 0.15s;
}
/* Edit mode reads as "these are handles now": accent hairline plus a tint ring,
   rather than the grey border + drop shadow it used to lift with. */
.grid-stack.dash-edit .grid-stack-item-content {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--separator);
  flex: 0 0 auto;
  cursor: default;
}
.grid-stack.dash-edit .widget-header { cursor: move; }
.widget-title {
  font-size: var(--text-callout);
  font-weight: 600;
  color: var(--label);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.widget-actions {
  display: flex;
  gap: var(--space-1);
  align-items: center;
}
.widget-action-btn {
  background: transparent;
  border: 0;
  color: var(--label-tertiary);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  line-height: 0;
}
.widget-action-btn:hover { background: var(--fill3); color: var(--label); }
.widget-action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.widget-remove-btn { display: none; color: var(--red); font-weight: 700; font-size: 18px; }
.grid-stack.dash-edit .widget-remove-btn { display: inline-flex; }

/* In-header config picker (rendered by widgets that expose configOptions). */
.widget-config-select {
  font-size: var(--text-caption1);
  padding: 2px 22px 2px var(--space-2);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-sm);
  background-color: var(--bg-elevated);
  color: var(--label);
  cursor: pointer;
  max-width: 140px;
  appearance: auto;
}
.widget-config-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.widget-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-footnote);
}
.widget-body.is-loading,
.widget-body.is-empty,
.widget-body.is-error {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--label-secondary);
}
.widget-body.is-error { color: var(--red); }

.widget-body .widget-kpi-value {
  font-size: var(--text-large-title);
  font-weight: 700;
  color: var(--label);
  line-height: 1.1;
}
.widget-body .widget-kpi-label {
  font-size: var(--text-caption1);
  color: var(--label-secondary);
  margin-top: var(--space-1);
}
.widget-body .widget-kpi-sub {
  font-size: var(--text-caption2);
  color: var(--label-tertiary);
  margin-top: 6px;
}
.widget-body .widget-kpi-block {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; width: 100%;
}

.widget-body table.widget-list {
  width: 100%;
  border-collapse: collapse;
}
.widget-body table.widget-list th,
.widget-body table.widget-list td {
  padding: 6px var(--space-2);
  text-align: left;
  border-bottom: 1px solid var(--separator);
}
.widget-body table.widget-list th {
  font-size: var(--text-caption2);
  text-transform: uppercase;
  color: var(--label-tertiary);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.widget-body table.widget-list tr:last-child td { border-bottom: 0; }

.widget-body .widget-chart-wrap { position: relative; height: 100%; min-height: 120px; }
.widget-body .widget-map-wrap   { position: relative; height: 100%; min-height: 200px; }

/* ── Cell descriptors (renderCell in dashboard-widget-base.js) ──────────
   Status pills, progress bars and severity stripes let list widgets encode
   state in form, not just text. Fills come from the status hues, small text
   from the --status-*-ink tokens (the fills can't legally carry 11px text). */
.widget-cell-muted { color: var(--label-tertiary); }

.widget-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-caption2);
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.widget-pill i {
  width: 6px; height: 6px;
  border-radius: 999px;
  background: currentColor;
  flex: none;
}
.widget-pill-ok      { background: var(--green-tint);  color: var(--status-ok-ink); }
.widget-pill-info    { background: var(--blue-tint);   color: var(--status-info-ink); }
.widget-pill-warn    { background: var(--orange-tint); color: var(--status-warn-ink); }
.widget-pill-crit    { background: var(--red-tint);    color: var(--status-crit-ink); }
.widget-pill-neutral { background: var(--fill3);       color: var(--label-secondary); }

.widget-progress-wrap {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 80px;
}
.widget-progress {
  flex: 1 1 auto;
  height: 5px;
  min-width: 48px;
  border-radius: 999px;
  background: var(--fill3);
  overflow: hidden;
}
.widget-progress i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent-solid);
}
.widget-progress-ok i   { background: var(--green); }
.widget-progress-warn i { background: var(--orange); }
.widget-progress-crit i { background: var(--red); }
.widget-progress-label {
  font-size: var(--text-caption2);
  color: var(--label-secondary);
  font-variant-numeric: tabular-nums;
}

.widget-body table.widget-list tr.wrow-sev-warn td:first-child { box-shadow: inset 2px 0 0 var(--orange); }
.widget-body table.widget-list tr.wrow-sev-crit td:first-child { box-shadow: inset 2px 0 0 var(--red); }

/* ── Widget states (skeleton / empty / error) ───────────────────────────
   Designed states replace the raw "Loading…" / "HTTP 500: …" text dumps. */
.widget-skeleton {
  align-self: stretch;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}
.widget-skeleton-bar {
  height: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--fill4) 25%, var(--fill2) 50%, var(--fill4) 75%);
  background-size: 200% 100%;
  animation: widget-shimmer 1.4s linear infinite;
}
@keyframes widget-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .widget-skeleton-bar { animation: none; background: var(--fill4); }
}

.widget-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  max-width: 260px;
}
.widget-state-icon {
  width: 36px; height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--fill3);
  color: var(--label-secondary);
}
.widget-state-icon.is-ok   { background: var(--green-tint); color: var(--status-ok-ink); }
.widget-state-icon.is-crit { background: var(--red-tint);   color: var(--status-crit-ink); }
.widget-state-title {
  font-size: var(--text-footnote);
  font-weight: 600;
  color: var(--label);
}
.widget-state-hint {
  font-size: var(--text-caption1);
  color: var(--label-secondary);
  overflow-wrap: anywhere;
}
.widget-retry-btn {
  margin-top: var(--space-1);
  font: inherit;
  font-size: var(--text-caption1);
  font-weight: 600;
  color: var(--label);
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-md);
  padding: 5px 14px;
  cursor: pointer;
}
.widget-retry-btn:hover { background: var(--fill4); }
.widget-retry-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── KPI strip host ─────────────────────────────────────────────────────
   The .kpis component (styles.css) is display:grid, which beats the
   [hidden] attribute — reassert. Tiles are built by dashboard-header.js. */
.dash-kpis[hidden] { display: none; }

/* ── Recommended-layout banner ──────────────────────────────────────────
   Presented while the user is on a role default (layout source==='default').
   Accent-tinted, hairline-bordered; the accent rail marks it as guidance,
   not a warning (that's what .dash-hint's orange is for). */
.dash-default-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--accent-tint);
  border: 1px solid var(--separator-opaque);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-size: var(--text-footnote);
}
/* display:flex would defeat the hidden attribute — reassert it. */
.dash-default-banner[hidden] { display: none; }
.dash-default-banner .ddb-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--label-secondary);
}
.dash-default-banner .ddb-text b { color: var(--label); font-weight: 600; }
.ddb-btn {
  font: inherit;
  font-size: var(--text-caption1);
  font-weight: 600;
  color: var(--accent-on-solid);
  background: var(--accent-solid);
  border: none;
  border-radius: var(--radius-md);
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.ddb-btn:hover { background: var(--accent-solid-hover); }
.ddb-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ddb-dismiss {
  font-size: var(--text-title3);
  line-height: 1;
  color: var(--label-tertiary);
  background: none;
  border: none;
  padding: 2px 6px;
  cursor: pointer;
}
.ddb-dismiss:hover { color: var(--label); }
.ddb-dismiss:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

/* Add-widget panel */
.dash-add-panel {
  position: fixed;
  top: 0; right: 0;
  width: 360px;
  height: 100vh;
  background: var(--bg-elevated);
  border-left: 1px solid var(--separator-opaque);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
}
.dash-add-panel[hidden] { display: none; }
.dash-add-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--separator);
}
.dash-add-panel-header h2 {
  margin: 0;
  font-size: var(--text-headline);
  font-weight: 600;
  color: var(--label);
}
.dash-add-close {
  background: transparent; border: 0; cursor: pointer;
  font-size: 24px; line-height: 1; color: var(--label-secondary);
}
.dash-add-close:hover { color: var(--label); }
.dash-add-search {
  margin: var(--space-3) var(--space-4);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-callout);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--label);
}
.dash-add-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
.dash-add-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 var(--space-4) var(--space-4);
}
.dash-add-loading { color: var(--label-secondary); text-align: center; padding: var(--space-5) 0; }
.dash-add-category {
  margin-top: 18px;
  font-size: var(--text-caption2);
  text-transform: uppercase;
  color: var(--label-tertiary);
  font-weight: 700;
  letter-spacing: 0.05em;
}
.dash-add-widget {
  display: flex;
  flex-direction: column;
  padding: var(--space-3) var(--space-4);
  margin: var(--space-2) 0;
  border-radius: var(--radius-md);
  background: var(--bg-grouped-secondary);
  cursor: pointer;
  border: 1px solid var(--separator);
  transition: border-color 0.15s, background 0.15s;
}
.dash-add-widget:hover {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.dash-add-widget[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.dash-add-widget .title { font-weight: 600; font-size: var(--text-callout); color: var(--label); margin-bottom: 2px; }
.dash-add-widget .desc  { font-size: var(--text-caption1); color: var(--label-secondary); }
.dash-add-widget .in-use { font-size: var(--text-caption2); color: var(--green); margin-top: var(--space-1); }
.dash-add-widget .unavailable { font-size: var(--text-caption2); color: var(--label-secondary); margin-top: var(--space-1); }

/* Modal */
.dash-modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.dash-modal[hidden] { display: none; }
.dash-modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 420px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow-lg);
}
.dash-modal-card h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-title3);
  font-weight: 600;
  color: var(--label);
}
.dash-modal-card p  { margin: 0 0 18px; color: var(--label-secondary); }
.dash-modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }

/* `.btn-danger` is deliberately NOT redeclared here. This file used to carry
   its own copy, and because it loads after styles.css that copy won every
   button on this page — the same duplicate-selector debt the retemplate plan
   documents. The shared component in input.css handles it. */

/* Refresh spinner inside widget header */
.widget-action-btn.is-spinning svg { animation: dash-spin 0.8s linear infinite; }
@keyframes dash-spin { to { transform: rotate(360deg); } }
