/* Spaceshift dashboard - reusable components: KPI cards, charts, filters,
   the slide-over drawer, toast, sortable headers, export button, shortcuts
   modal, batch action bar, inline copy/search, storage bar. Split from
   dashboard.css. */

/* ---- KPI cards ---------------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-3);
}

.kpi-card {
  position: relative;
  background: linear-gradient(180deg, var(--surface-raised), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-4);
  overflow: hidden;
  transition: border-color var(--ease), transform var(--ease);
}
.kpi-card:hover { border-color: var(--border-strong); }
.kpi-card::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(120px 60px at 100% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent);
  pointer-events: none;
}
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.kpi-icon {
  width: 26px; height: 26px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  flex: none;
}
.kpi-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-2);
}
.kpi-value {
  margin-top: var(--sp-2);
  font-size: var(--text-stat);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi-sub { margin-top: 3px; font-size: var(--text-xs); color: var(--text-3); }
.kpi-unit { font-size: 0.5em; color: var(--text-3); margin-left: 4px; }
.cost-delta { color: var(--text-3); font-size: var(--text-xs); }
.kpi-card.warn { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }
.kpi-card.warn .kpi-value { color: var(--red); }
.kpi-card.warn .kpi-icon { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }

/* Back-compat: the plain stat cards used on pages without full KPI styling. */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-3); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--sp-3) var(--sp-4); }
.stat .l { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-2); }
.stat .n { margin-top: var(--sp-1); font-size: var(--text-stat); font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat.warn { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }
.stat.warn .n { color: var(--red); }

/* ---- Charts ------------------------------------------------------------- */

.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-4);
}
.chart-card h2 { font-size: var(--text-md); }
.chart-card .section-note { margin-bottom: var(--sp-2); }
.chart-legend { display: flex; gap: var(--sp-4); margin-top: var(--sp-2); font-size: var(--text-xs); color: var(--text-2); flex-wrap: wrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chart-legend i.dot-green { background: var(--green); }
.chart-legend i.dot-amber { background: var(--amber); }
.chart-legend i.dot-red { background: var(--red); }
.chart-empty { display: flex; align-items: center; justify-content: center; height: 220px; color: var(--text-3); font-size: var(--text-sm); }

/* Inline percentage meters inside table cells. */
.meter {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-width: 84px;
}
.meter-track { flex: 1; height: 5px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; min-width: 48px; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--green); width: 0; }
/* Discrete 5%-step width classes - JS sets one of these rather than an
   inline style="width:", which the dashboard's CSP (no style-src
   'unsafe-inline') blocks even for script-set el.style mutations. */
.meter-fill.p0, .dist-segment.p0, .setup-progress-fill.p0 { width: 0%; }
.meter-fill.p5, .dist-segment.p5, .setup-progress-fill.p5 { width: 5%; }
.meter-fill.p10, .dist-segment.p10, .setup-progress-fill.p10 { width: 10%; }
.meter-fill.p15, .dist-segment.p15, .setup-progress-fill.p15 { width: 15%; }
.meter-fill.p20, .dist-segment.p20, .setup-progress-fill.p20 { width: 20%; }
.meter-fill.p25, .dist-segment.p25, .setup-progress-fill.p25 { width: 25%; }
.meter-fill.p30, .dist-segment.p30, .setup-progress-fill.p30 { width: 30%; }
.meter-fill.p35, .dist-segment.p35, .setup-progress-fill.p35 { width: 35%; }
.meter-fill.p40, .dist-segment.p40, .setup-progress-fill.p40 { width: 40%; }
.meter-fill.p45, .dist-segment.p45, .setup-progress-fill.p45 { width: 45%; }
.meter-fill.p50, .dist-segment.p50, .setup-progress-fill.p50 { width: 50%; }
.meter-fill.p55, .dist-segment.p55, .setup-progress-fill.p55 { width: 55%; }
.meter-fill.p60, .dist-segment.p60, .setup-progress-fill.p60 { width: 60%; }
.meter-fill.p65, .dist-segment.p65, .setup-progress-fill.p65 { width: 65%; }
.meter-fill.p70, .dist-segment.p70, .setup-progress-fill.p70 { width: 70%; }
.meter-fill.p75, .dist-segment.p75, .setup-progress-fill.p75 { width: 75%; }
.meter-fill.p80, .dist-segment.p80, .setup-progress-fill.p80 { width: 80%; }
.meter-fill.p85, .dist-segment.p85, .setup-progress-fill.p85 { width: 85%; }
.meter-fill.p90, .dist-segment.p90, .setup-progress-fill.p90 { width: 90%; }
.meter-fill.p95, .dist-segment.p95, .setup-progress-fill.p95 { width: 95%; }
.meter-fill.p100, .dist-segment.p100, .setup-progress-fill.p100 { width: 100%; }
.meter[data-level="warning"] .meter-fill { background: var(--amber); }
.meter[data-level="critical"] .meter-fill { background: var(--red); }
.meter-value { font-variant-numeric: tabular-nums; font-size: var(--text-xs); color: var(--text-2); min-width: 2.5em; text-align: right; }
.detail-modal-meta { font-size: var(--text-sm); color: var(--text-2); margin-bottom: var(--sp-2); }
.time-presets-label { font-size: var(--text-xs); color: var(--text-3); margin-right: 4px; }
.detail-link { cursor: pointer; text-decoration: underline dotted; }

/* ---- Filters ---------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.filters input,
.filters select,
.config-value-input {
  font: inherit;
  font-size: var(--text-sm);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 10px;
  line-height: 1.3;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.filters input:focus,
.filters select:focus,
.config-value-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.filters input[type="search"] { flex: 1; min-width: 220px; }
.filters select { min-width: 130px; }
.filters .count {
  margin-left: auto;
  font-size: var(--text-sm);
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---- Slide-over drawer (Alpine.js) --------------------------------------- */

.drawer-overlay {
  position: fixed; inset: 0;
  background: color-mix(in srgb, black 55%, transparent);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--ease);
}
.drawer-overlay.is-open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(420px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.4);
  z-index: 41;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
.drawer.is-open { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.drawer-title { font-size: var(--text-lg); font-weight: 650; font-family: var(--font-mono); word-break: break-all; }
.drawer-subtitle { margin-top: 2px; font-size: var(--text-xs); color: var(--text-3); }
.drawer-close {
  flex: none;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
}
.drawer-close:hover { background: var(--surface-2); color: var(--text); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-5); }
.drawer-section-title { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin-bottom: var(--sp-2); }
.drawer-field {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}
.drawer-field:last-child { border-bottom: none; }
.drawer-field .k { color: var(--text-2); }
.drawer-field .v { font-family: var(--font-mono); font-size: 12.5px; text-align: right; max-width: 60%; overflow-wrap: anywhere; }
.copy-btn {
  flex: none;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
}
.copy-btn svg { width: 12px; height: 12px; }
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }
.copy-btn.is-copied { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, var(--border)); }
.drawer-cli {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  overflow-x: auto;
}

.is-hidden { display: none; }

/* ---- Toast Notifications ------------------------------------------------- */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 360px;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  animation: toast-in 180ms cubic-bezier(0, 0, 0.2, 1);
  transition: opacity 150ms ease, transform 150ms ease;
}
.toast.toast-success { border-color: color-mix(in srgb, var(--green) 40%, var(--border)); }
.toast.toast-error { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.toast-out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Compact KPI Grid --------------------------------------------------- */

.kpi-grid-compact {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: var(--sp-5);
}

/* ---- Sortable Table Headers ---------------------------------------------- */

th.is-sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--ease), background var(--ease);
}
th.is-sortable:hover {
  color: var(--text);
  background: var(--surface-raised);
}
th.is-sortable::after {
  content: " ↕";
  opacity: 0.35;
  font-size: 0.85em;
  display: inline-block;
  margin-left: 4px;
}
th.sort-asc::after {
  content: " ▲";
  opacity: 1;
  color: var(--accent);
}
th.sort-desc::after {
  content: " ▼";
  opacity: 1;
  color: var(--accent);
}

/* ---- Export Button ------------------------------------------------------- */

.export-csv-btn {
  font-size: var(--text-xs);
  padding: 4px 10px;
  gap: 4px;
  border-radius: var(--radius);
}
.export-csv-btn svg {
  width: 13px;
  height: 13px;
}

/* ---- Shortcuts Modal ----------------------------------------------------- */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}
.modal-root.is-hidden {
  display: none !important;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  z-index: 1001;
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: modal-in 160ms cubic-bezier(0, 0, 0.2, 1);
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(-8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
}
.modal-body {
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--text-2);
}
.shortcut-key {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 2px 8px;
  box-shadow: 0 1px 0 var(--border-strong);
}

/* ---- Checkboxes & Batch Action Bar ---------------------------------------- */
.select-col {
  width: 36px !important;
  text-align: center !important;
  padding: var(--sp-2) !important;
}
.row-checkbox, .select-all-checkbox {
  cursor: pointer;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  vertical-align: middle;
}
.batch-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1), opacity 200ms ease;
}
.batch-bar.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.batch-bar-count {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  padding-right: var(--sp-3);
  border-right: 1px solid var(--border);
}
.batch-bar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ---- Inline Copy & Search Polish ----------------------------------------- */
.copyable-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-inline-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-3);
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 120ms ease;
  line-height: 1;
}
.btn-inline-copy:hover {
  color: var(--text);
  background: var(--surface-2);
}
.btn-inline-copy.is-copied {
  color: var(--green);
}
.btn-inline-copy svg {
  width: 12px;
  height: 12px;
}

.search-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}
.search-wrapper input[type="search"] {
  width: 100%;
  padding-right: 48px;
}
.search-wrapper .search-clear-btn {
  position: absolute;
  right: 28px;
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 13px;
  display: none;
}
.search-wrapper .search-clear-btn:hover {
  color: var(--text);
}
.search-wrapper.has-val .search-clear-btn {
  display: block;
}
.search-wrapper .search-kbd-hint {
  position: absolute;
  right: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-3);
  pointer-events: none;
}

/* Active filter chips */
.active-filters-bar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  font-size: var(--text-xs);
}
.active-filters-bar.has-filters {
  display: flex;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  color: var(--text-2);
}
.filter-chip-remove {
  cursor: pointer;
  color: var(--text-3);
  font-size: 12px;
  font-weight: bold;
  border: none;
  background: none;
  padding: 0;
}
.filter-chip-remove:hover {
  color: var(--red);
}
.filter-clear-all {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: var(--text-xs);
  padding: 2px 6px;
}
.filter-clear-all:hover {
  text-decoration: underline;
}
.search-highlight {
  background: rgba(234, 179, 8, 0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ---- Storage Distribution Bar -------------------------------------------- */
.storage-dist-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
}
.storage-dist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--text-2);
}
.storage-dist-bar {
  display: flex;
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: var(--sp-2);
}
.dist-segment {
  height: 100%;
  transition: width 300ms ease;
}
.dist-segment.watched {
  background: var(--green);
}
.dist-segment.unwatched {
  background: var(--border-strong);
}
.storage-dist-legend {
  display: flex;
  gap: var(--sp-4);
  font-size: var(--text-xs);
  color: var(--text-2);
}
.storage-dist-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.action-col { white-space: nowrap; }
.row-actions { display: flex; gap: var(--sp-2); }
.row-actions form { margin: 0; }
