/* @couchdicks/ui fleet adapter — shared chassis for legacy and standalone apps */
body.cd-fleet-surface {
  --bg: var(--cd-bg) !important;
  --background: var(--cd-bg) !important;
  --page: var(--cd-bg) !important;
  --surface: var(--cd-surface-1) !important;
  --surface-1: var(--cd-surface-1) !important;
  --surface-2: var(--cd-surface-2) !important;
  --surface-3: var(--cd-surface-3) !important;
  --surface-raised: var(--cd-surface-2) !important;
  --panel: var(--cd-surface-1) !important;
  --panel-2: var(--cd-surface-2) !important;
  --panel-bg: var(--cd-surface-1) !important;
  --panel-background: var(--cd-surface-1) !important;
  --card: var(--cd-surface-1) !important;
  --card-bg: var(--cd-surface-1) !important;
  --card-background: var(--cd-surface-1) !important;
  --ink: var(--cd-text) !important;
  --text: var(--cd-text) !important;
  --text-primary: var(--cd-text) !important;
  --muted: var(--cd-muted) !important;
  --text-muted: var(--cd-muted) !important;
  --line: var(--cd-border) !important;
  --border: var(--cd-border) !important;
  --border-color: var(--cd-border) !important;
  --ok: var(--cd-good) !important;
  --success: var(--cd-good) !important;
  --warning: var(--cd-warn) !important;
  --danger: var(--cd-danger) !important;
  min-width: 320px;
  margin-top: 0;
  padding-top: 38px !important;
  background-color: var(--cd-bg) !important;
  color: var(--cd-text) !important;
}

.cd-fleet-rail {
  position: fixed;
  inset: 0 0 auto;
  z-index: 2147483000;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--cd-border);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--cd-accent) 10%, transparent), transparent 28%),
    color-mix(in srgb, var(--cd-surface-1) 96%, transparent);
  color: var(--cd-text);
  box-shadow: 0 8px 26px color-mix(in srgb, #000 18%, transparent);
  backdrop-filter: blur(14px);
  font: 700 10px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.cd-fleet-rail::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--cd-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cd-accent) 14%, transparent), 0 0 14px var(--cd-accent);
}

.cd-fleet-rail__home,
.cd-fleet-rail__shelf {
  color: var(--cd-text) !important;
  text-decoration: none !important;
  white-space: nowrap;
}

.cd-fleet-rail__home { font-weight: 900; }
.cd-fleet-rail__divider { width: 1px; height: 16px; background: var(--cd-border); }
.cd-fleet-rail__shelf { color: var(--cd-accent) !important; }
.cd-fleet-rail__title {
  min-width: 0;
  overflow: hidden;
  color: var(--cd-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cd-fleet-rail__status {
  margin-left: auto;
  color: var(--cd-muted);
  white-space: nowrap;
}
.cd-fleet-rail .cd-theme-toggle {
  min-width: 34px;
  min-height: 28px;
  height: 28px;
  padding: 0 8px;
  border-color: var(--cd-border-strong);
  background: var(--cd-surface-2);
  color: var(--cd-text);
}

body.cd-fleet-surface :where(a) { text-underline-offset: 2px; }
body.cd-fleet-surface :where(button, input, select, textarea) { color-scheme: inherit; }

/*
 * Legacy dashboards arrive with one native palette and a mixture of variable-
 * backed and hard-coded surfaces. The fleet contract owns neutral structure in
 * both modes; product accents, charts, status colors, and bespoke art remain
 * app-owned. This prevents shared foreground tokens from landing on a retained
 * surface from the opposite theme.
 */
:root[data-cd-theme] body.cd-fleet-surface :where(
  .card, .panel, .metric, .metrics, .kpi, .stat, .stats, .tile, .module, .widget,
  .summary-card, .metric-card, .stat-card, .data-card, .chart-card, .chart-panel,
  .table-card, .table-panel, .info-card, .detail-card, .result-card,
  .table-wrap, .table-container, .table-shell, .data-table,
  .drawer, .drawer-content, .modal, .modal-content, .dialog, .popover,
  .toolbar, .controls, .control-panel, .filter-bar, .filters,
  .sidebar, .aside, .tabs, .tab-list, .pagination
) {
  border-color: var(--cd-border) !important;
  background-color: var(--cd-surface-1) !important;
  color: var(--cd-text) !important;
}

:root[data-cd-theme] body.cd-fleet-surface :where(
  table, thead, tbody, tfoot, tr, th, td
) {
  border-color: var(--cd-border) !important;
  color: var(--cd-text) !important;
}

:root[data-cd-theme] body.cd-fleet-surface :where(table, tbody, tfoot, tr, td) {
  background-color: var(--cd-surface-1) !important;
}

:root[data-cd-theme] body.cd-fleet-surface :where(thead, th) {
  background-color: var(--cd-surface-2) !important;
  color: var(--cd-muted) !important;
}

:root[data-cd-theme] body.cd-fleet-surface :where(
  input, select, textarea,
  button:not(.cd-theme-toggle):not(.active):not(.is-active):not([aria-selected="true"]):not([aria-pressed="true"])
) {
  border-color: var(--cd-border-strong) !important;
  background-color: var(--cd-surface-2) !important;
  color: var(--cd-text) !important;
}

:root[data-cd-theme] body.cd-fleet-surface :where(
  button.active, button.is-active, button[aria-selected="true"], button[aria-pressed="true"],
  [role="tab"].active, [role="tab"].is-active, [role="tab"][aria-selected="true"]
) {
  border-color: var(--cd-accent) !important;
  background-color: var(--cd-accent) !important;
  color: var(--cd-accent-contrast) !important;
}

:root[data-cd-theme] body.cd-fleet-surface :where(.cd-theme-toggle__icon) {
  color: var(--cd-text) !important;
}

/* Applied only when the compatibility layer measures a failing solid pair. */
body.cd-fleet-surface [data-cd-contrast="dark"] { color: #000 !important; }
body.cd-fleet-surface [data-cd-contrast="light"] { color: #fff !important; }

:root[data-cd-theme="light"] body.cd-fleet-surface {
  background-image:
    linear-gradient(var(--cd-bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--cd-bg-grid) 1px, transparent 1px) !important;
  background-size: 40px 40px !important;
}

@media (max-width: 680px) {
  body.cd-fleet-surface { padding-top: 42px !important; }
  .cd-fleet-rail { height: 42px; gap: 8px; padding-inline: 9px; }
  .cd-fleet-rail__status, .cd-fleet-rail__divider { display: none; }
  .cd-fleet-rail__title { font-size: 9px; }
  .cd-fleet-rail .cd-theme-toggle { width: 34px; min-width: 34px; }
}

@media print {
  body.cd-fleet-surface { padding-top: 0 !important; }
  .cd-fleet-rail { display: none !important; }
}
