/* @couchdicks/ui fleet adapter — shared chassis for legacy and standalone apps */
body.cd-fleet-surface {
  --cd-site-shell-height: 54px;
  --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: var(--cd-site-shell-height) !important;
  background-color: var(--cd-bg) !important;
  color: var(--cd-text) !important;
}

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

.cd-site-shell__home {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  min-height: 36px;
  color: var(--cd-text) !important;
  text-decoration: none !important;
}

.cd-site-shell__mark {
  position: relative;
  width: 17px;
  height: 17px;
  border: 1px solid color-mix(in srgb, var(--cd-accent) 72%, var(--cd-text));
  background: var(--cd-accent-2);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--cd-accent) 12%, transparent), 0 0 18px color-mix(in srgb, var(--cd-accent-2) 30%, transparent);
  transform: rotate(45deg);
}

.cd-site-shell__mark::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid color-mix(in srgb, var(--cd-bg) 76%, transparent);
}

.cd-site-shell__home b { font-size: 11px; font-weight: 900; letter-spacing: .11em; }

.cd-site-shell__breadcrumb {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
  padding-left: 14px;
  border-left: 1px solid var(--cd-border);
}

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

.cd-fleet-rail__shelf { color: var(--cd-accent) !important; }
.cd-site-shell__slash { color: var(--cd-border-strong); }
.cd-fleet-rail__title {
  min-width: 0;
  max-width: min(30vw, 360px);
  overflow: hidden;
  color: var(--cd-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cd-site-shell__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
}

.cd-site-shell__button,
.cd-site-shell__status,
.cd-site-shell .cd-theme-toggle {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--cd-border);
  border-radius: 2px;
  background: color-mix(in srgb, var(--cd-surface-2) 82%, transparent);
  color: var(--cd-muted) !important;
  font: 700 9px/1 "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  letter-spacing: .06em;
  text-decoration: none !important;
  text-transform: uppercase;
  cursor: pointer;
}

.cd-site-shell__button:hover,
.cd-site-shell__button[aria-expanded="true"],
.cd-site-shell__status:hover {
  border-color: var(--cd-accent);
  color: var(--cd-text) !important;
  background: color-mix(in srgb, var(--cd-accent) 10%, var(--cd-surface-2));
}

.cd-site-shell__button kbd,
.cd-site-drawer kbd {
  border: 1px solid var(--cd-border);
  padding: 3px 5px;
  background: var(--cd-surface-1);
  color: var(--cd-quiet);
  font: inherit;
  box-shadow: inset 0 -1px color-mix(in srgb, #000 22%, transparent);
}

.cd-site-shell__status i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cd-good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cd-good) 12%, transparent), 0 0 10px color-mix(in srgb, var(--cd-good) 52%, transparent);
}

.cd-site-shell .cd-theme-slot { display: inline-flex; }
.cd-site-shell .cd-theme-toggle {
  min-width: 38px;
  height: 34px;
  padding: 0 9px;
  border-color: var(--cd-border-strong);
  background: var(--cd-surface-2);
  color: var(--cd-text);
}

.cd-site-shell .cd-theme-toggle__icon {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border: 1px solid currentColor;
  border-radius: 50%;
  box-shadow: inset -4px 0 currentColor;
  font-size: 0;
}

body.cd-fleet-surface [data-cd-theme-duplicate] { display: none !important; }

html.cd-site-shell-ready body.cd-shelf .shell > :is(.topbar, .top),
html.cd-site-shell-ready body.cd-home .shell > .topbar { display: none !important; }

.cd-site-drawer {
  position: fixed;
  inset: var(--cd-site-shell-height, 54px) 0 0;
  z-index: 2147482999;
  display: grid;
  place-items: start center;
  padding: 14px;
  overflow: auto;
  background: color-mix(in srgb, #000 66%, transparent);
  backdrop-filter: blur(9px);
}

.cd-site-drawer[hidden] { display: none !important; }
.cd-site-drawer__panel {
  width: min(1060px, 100%);
  max-height: calc(100vh - var(--cd-site-shell-height, 54px) - 28px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--cd-border-strong);
  border-top: 2px solid var(--cd-accent);
  border-radius: 3px;
  background:
    linear-gradient(90deg, var(--cd-bg-grid) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(var(--cd-bg-grid) 1px, transparent 1px) 0 0 / 32px 32px,
    var(--cd-bg);
  color: var(--cd-text);
  box-shadow: 0 32px 90px rgba(0,0,0,.42);
  animation: cd-site-drawer-in .16s ease-out both;
  outline: none;
}

@keyframes cd-site-drawer-in {
  from { opacity: 0; transform: translateY(-10px) scale(.99); }
  to { opacity: 1; transform: none; }
}

.cd-site-drawer__head {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--cd-border);
  background: color-mix(in srgb, var(--cd-surface-1) 94%, transparent);
}

.cd-site-drawer__head span,
.cd-site-drawer__group > span,
.cd-site-drawer__utilities > span,
.cd-site-drawer__result-head {
  color: var(--cd-accent);
  font: 700 8px/1.2 "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.cd-site-drawer__head h2 {
  margin: 5px 0 0;
  color: var(--cd-text);
  font: 800 clamp(22px, 3vw, 34px)/.95 Georgia, "Times New Roman", serif;
  letter-spacing: -.03em;
  text-transform: none;
}

.cd-site-drawer__close {
  min-height: 36px;
  border: 1px solid var(--cd-border);
  padding: 0 10px;
  background: var(--cd-surface-2);
  color: var(--cd-muted);
  font: 700 9px "IBM Plex Mono", monospace;
  text-transform: uppercase;
  cursor: pointer;
}

.cd-site-drawer__search {
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr;
  min-height: 66px;
  border-bottom: 1px solid var(--cd-border);
  background: var(--cd-surface-2);
}

.cd-site-drawer__search-mark {
  position: relative;
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--cd-border);
  color: var(--cd-accent);
}

.cd-site-drawer__search-mark::before {
  content: "";
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-radius: 50%;
  transform: translate(-2px, -2px);
}

.cd-site-drawer__search-mark::after {
  content: "";
  position: absolute;
  width: 7px;
  border-top: 2px solid currentColor;
  transform: translate(7px, 7px) rotate(45deg);
}

.cd-site-drawer__search-label {
  align-self: end;
  padding: 8px 12px 0;
  color: var(--cd-quiet);
  font: 700 7px/1 "IBM Plex Mono", monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.cd-site-drawer__search input {
  min-width: 0;
  height: 38px;
  border: 0 !important;
  padding: 0 12px 8px !important;
  background: transparent !important;
  color: var(--cd-text) !important;
  font: 600 16px/1 "IBM Plex Mono", monospace !important;
  outline: none;
}

.cd-site-drawer__content { min-height: 0; padding: 14px; overflow: auto; }
.cd-site-drawer__groups { display: grid; grid-template-columns: 1.5fr 1fr .85fr; gap: 10px; }
.cd-site-drawer__group,
.cd-site-drawer__utilities { border: 1px solid var(--cd-border); background: color-mix(in srgb, var(--cd-surface-1) 90%, transparent); }
.cd-site-drawer__group > span,
.cd-site-drawer__utilities > span,
.cd-site-drawer__result-head { display: block; padding: 11px 12px; border-bottom: 1px solid var(--cd-border); }
.cd-site-drawer__group > div { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cd-site-drawer__group:nth-child(n+2) > div { grid-template-columns: 1fr; }

.cd-site-drawer__link,
.cd-site-drawer__result {
  min-width: 0;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--cd-border);
  color: var(--cd-text) !important;
  text-decoration: none !important;
  transition: background .14s ease, color .14s ease;
}

.cd-site-drawer__link:hover,
.cd-site-drawer__link:focus-visible,
.cd-site-drawer__result:hover,
.cd-site-drawer__result:focus-visible,
.cd-site-drawer :is(a)[aria-current] {
  background: color-mix(in srgb, var(--cd-accent) 10%, var(--cd-surface-2));
  box-shadow: inset 2px 0 var(--cd-accent);
}

.cd-site-drawer__link b,
.cd-site-drawer__result b { display: block; overflow: hidden; font: 800 11px/1.2 "IBM Plex Mono", monospace; text-overflow: ellipsis; white-space: nowrap; }
.cd-site-drawer__link small,
.cd-site-drawer__result small { display: block; margin-top: 4px; overflow: hidden; color: var(--cd-muted); font: 500 8px/1.2 "IBM Plex Mono", monospace; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.cd-site-drawer__arrow { color: var(--cd-accent); }
.cd-site-drawer__utilities { margin-top: 10px; }
.cd-site-drawer__utilities > div { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cd-site-drawer__results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--cd-border); border-top: 0; }
.cd-site-drawer__result:nth-child(odd) { border-right: 1px solid var(--cd-border); }
.cd-site-drawer__empty { grid-column: 1 / -1; margin: 0; padding: 24px; color: var(--cd-muted); font: 500 11px/1.6 "IBM Plex Mono", monospace; }
.cd-site-drawer__panel > footer { display: flex; gap: 18px; padding: 9px 14px; border-top: 1px solid var(--cd-border); color: var(--cd-quiet); font: 700 7px "IBM Plex Mono", monospace; letter-spacing: .08em; text-transform: uppercase; }

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(.cd-site-shell__button):not(.cd-site-drawer__close):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 { --cd-site-shell-height: 48px; padding-top: var(--cd-site-shell-height) !important; }
  .cd-fleet-rail, .cd-site-shell { height: var(--cd-site-shell-height); gap: 8px; padding-inline: 8px; }
  .cd-site-shell__home { gap: 7px; }
  .cd-site-shell__home b { display: none; }
  .cd-site-shell__mark { width: 15px; height: 15px; }
  .cd-site-shell__breadcrumb { gap: 6px; padding-left: 9px; }
  .cd-fleet-rail__title { max-width: 32vw; font-size: 8px; }
  .cd-site-shell__actions { gap: 5px; }
  .cd-site-shell__button { position: relative; width: 34px; min-width: 34px; padding: 0; font-size: 0; }
  .cd-site-shell__button[data-cd-browse]::before {
    content: "";
    width: 14px;
    height: 10px;
    background:
      linear-gradient(currentColor, currentColor) 0 0 / 100% 1px no-repeat,
      linear-gradient(currentColor, currentColor) 0 50% / 100% 1px no-repeat,
      linear-gradient(currentColor, currentColor) 0 100% / 100% 1px no-repeat;
  }
  .cd-site-shell__button[data-cd-search]::before {
    content: "";
    width: 10px;
    height: 10px;
    border: 1px solid currentColor;
    border-radius: 50%;
    transform: translate(-1px, -1px);
  }
  .cd-site-shell__button[data-cd-search]::after {
    content: "";
    position: absolute;
    width: 5px;
    border-top: 1px solid currentColor;
    transform: translate(5px, 5px) rotate(45deg);
  }
  .cd-site-shell__button kbd,
  .cd-site-shell__button span,
  .cd-site-shell__status span { display: none; }
  .cd-site-shell__status { width: 30px; min-width: 30px; padding: 0; }
  .cd-site-shell .cd-theme-toggle { width: 34px; min-width: 34px; padding: 0; }
  .cd-site-drawer { inset: var(--cd-site-shell-height) 0 0; padding: 0; background: var(--cd-bg); }
  .cd-site-drawer__panel { width: 100%; max-height: none; min-height: 100%; border: 0; border-top: 2px solid var(--cd-accent); border-radius: 0; }
  .cd-site-drawer__head { min-height: 68px; padding: 11px 12px; }
  .cd-site-drawer__head h2 { font-size: 25px; }
  .cd-site-drawer__groups { grid-template-columns: 1fr; }
  .cd-site-drawer__group > div,
  .cd-site-drawer__group:nth-child(n+2) > div,
  .cd-site-drawer__utilities > div,
  .cd-site-drawer__results { grid-template-columns: 1fr; }
  .cd-site-drawer__result:nth-child(odd) { border-right: 0; }
}

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

@media (prefers-reduced-motion: reduce) {
  .cd-site-drawer__panel { animation: none; }
}
