/* System detail workstation: KGRID defines identity, DGRID places the
   identity rail beside a full-height detail workspace, and KAP-GRID owns
   vertical movement inside that workspace. */
html:has(body[data-page="system"]) {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body[data-page="system"][data-xgrid="system"]::after {
  background: radial-gradient(circle at 50% 0, rgba(53, 224, 224, .07), transparent 50%);
}

body[data-page="system"] {
  width: 100%;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  display: grid;
  grid-template-rows: var(--aenet-global-header-height, 72px) minmax(0, 1fr) 34px;
  background: var(--bg);
}

body[data-page="system"] > header.site {
  grid-row: 1;
  position: relative;
  min-height: 0;
}

@media (min-width: 1920px) {
  body[data-page="system"] .topbar-system { display: none; }
}

body[data-page="system"] > .wrap {
  grid-row: 2;
  width: 100%;
  max-width: none;
  min-width: 0;
  min-height: 0;
  padding: 0 clamp(12px, 1.5vw, 28px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body[data-page="system"] .context-bar {
  flex: 0 0 auto;
  min-width: 0;
}

body[data-page="system"] .route-context {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

body[data-page="system"] .route-context nav.breadcrumb {
  width: 100%;
  min-width: 0;
  white-space: nowrap;
  text-overflow: ellipsis;
}

body[data-page="system"] .route-context-meta { min-width: 0; }

body[data-page="system"] nav.breadcrumb {
  min-height: 30px;
  padding: 7px 6px;
  overflow: hidden;
}

body[data-page="system"] main.content-field {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: 8px 0;
  display: grid;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
}

body[data-page="system"] main.content-field > .page-head {
  grid-column: 1 / 7;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: clamp(16px, 2vw, 30px);
  border: 1px solid var(--line);
  background: rgba(16, 26, 46, .88);
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: auto;
}

body[data-page="system"] .page-head h1 {
  font-size: var(--f-size-11, 28px);
  line-height: var(--f-line-heading, 1.25);
}

body[data-page="system"] .page-head .lede {
  font-size: var(--f-size-05, 14px);
  line-height: var(--f-line-relaxed, 1.65);
}

body[data-page="system"] .page-head .meta-row {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  font-size: var(--f-size-03, 12px);
  line-height: var(--f-line-normal, 1.5);
}

body[data-page="system"] .system-workspace {
  grid-column: 7 / 25;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid rgba(77, 163, 255, .25);
  background: rgba(8, 14, 26, .84);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  overscroll-behavior: contain;
  color: var(--text);
}

body[data-page="system"] .system-workspace::-webkit-scrollbar { display: none; }

body[data-page="system"] .kap-grid-controls {
  position: sticky;
  z-index: 2;
  top: 0;
  width: max-content;
  max-width: 100%;
  min-height: 32px;
  margin: 0 0 0 auto;
  flex: 0 0 auto;
  background: rgba(7, 12, 24, .96);
}

body[data-page="system"] .system-facts {
  flex: 0 0 auto;
  min-width: 0;
  margin: 0;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  background: rgba(16, 26, 46, .9);
}

body[data-page="system"] .system-facts .cell {
  min-width: 0;
  min-height: 88px;
  padding: 10px;
  overflow: hidden;
}

body[data-page="system"] .system-facts .cell p,
body[data-page="system"] .system-facts .cell ul,
body[data-page="system"] .system-detail-section p,
body[data-page="system"] .system-detail-section ul,
body[data-page="system"] .system-detail-section li {
  color: var(--text);
}

body[data-page="system"] .system-detail-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

body[data-page="system"] .system-detail-section {
  min-width: 0;
  margin: 0;
  padding: 14px;
  overflow-wrap: anywhere;
}

body[data-page="system"] .system-detail-section h2 {
  margin: 0 0 8px;
  padding: 0;
  border: 0;
  font-size: var(--f-size-09, 20px);
  line-height: var(--f-line-heading, 1.25);
}

body[data-page="system"] .system-detail-section p,
body[data-page="system"] .system-detail-section ul {
  margin: 6px 0;
  font-size: var(--f-size-05, 14px);
  line-height: var(--f-line-normal, 1.5);
}

body[data-page="system"] .system-public-interfaces,
body[data-page="system"] .system-related {
  flex: 0 0 auto;
}

body[data-page="system"] .api-interface-row {
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  gap: 6px 10px;
  min-width: 0;
}

body[data-page="system"] .api-path { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

body[data-page="system"] > footer.site {
  grid-row: 3;
  width: 100%;
  min-height: 0;
  height: 34px;
  padding: 0 clamp(12px, 1.5vw, 28px);
  overflow: hidden;
  display: flex;
  align-items: center;
}

body[data-page="system"] > footer.site .wrap {
  width: 100%;
  max-width: none;
  min-width: 0;
  padding: 0;
}

body[data-page="system"] > footer.site .grid {
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  white-space: nowrap;
  font-size: var(--f-size-03, 12px);
}

body[data-page="system"] > footer.site .grid > div { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 1199px) {
  body[data-page="system"] > .wrap { padding-inline: 12px; }
  body[data-page="system"] main.content-field { gap: 8px; }
  body[data-page="system"] main.content-field { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  body[data-page="system"] main.content-field > .page-head { grid-column: 1 / 5; padding: 18px; }
  body[data-page="system"] .system-workspace { grid-column: 5 / 13; }
}

@media (max-width: 900px) {
  html:has(body[data-page="system"]) { height: 100dvh !important; overflow: hidden !important; }

  body[data-page="system"] {
    height: 100dvh !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: grid !important;
    grid-template-rows: auto minmax(0, 1fr) auto !important;
  }

  body[data-page="system"] > header.site,
  body[data-page="system"] > footer.site {
    grid-row: auto;
    position: relative;
    height: auto;
  }

  body[data-page="system"] > .wrap {
    grid-row: 2;
    height: auto !important;
    min-height: 0 !important;
    padding-inline: 10px;
    display: flex !important;
    overflow: hidden !important;
  }

  body[data-page="system"] .route-context {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  body[data-page="system"] .route-context nav.breadcrumb {
    padding-inline: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  body[data-page="system"] main.content-field {
    height: auto !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    padding: 6px 0 !important;
    overflow: hidden !important;
    align-content: stretch !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: minmax(120px, 30vh) minmax(0, 1fr) !important;
    gap: 8px;
  }

  body[data-page="system"] main.content-field > .page-head {
    grid-column: 1 !important;
    grid-row: 1 !important;
    max-height: 32vh;
    min-height: 0;
    padding: 14px;
    overflow: hidden;
  }

  body[data-page="system"] .system-workspace {
    grid-column: 1 !important;
    grid-row: 2 !important;
    display: flex !important;
    height: clamp(120px, 35dvh, calc(100dvh - 120px)) !important;
    min-height: 0 !important;
    max-height: clamp(120px, 35dvh, calc(100dvh - 120px)) !important;
    flex: 0 0 auto !important;
    padding: 8px;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  body[data-page="system"] #system-detail-kap-grid {
    grid-column: 1 !important;
    grid-row: 2 !important;
    height: clamp(120px, 35dvh, calc(100dvh - 120px)) !important;
    min-height: 0 !important;
    max-height: clamp(120px, 35dvh, calc(100dvh - 120px)) !important;
    flex: 0 0 auto !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  body[data-page="system"] .system-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body[data-page="system"] .system-detail-grid { grid-template-columns: minmax(0, 1fr); }
  body[data-page="system"] .api-interface-row { grid-template-columns: auto minmax(0, 1fr); }
  body[data-page="system"] .api-interface-schema,
  body[data-page="system"] .api-interface-status,
  body[data-page="system"] .api-interface-readonly { grid-column: 2; }
  body[data-page="system"] > footer.site {
    position: relative !important;
    grid-row: 3 !important;
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 10px !important;
    display: flex !important;
    overflow: hidden !important;
  }

  body[data-page="system"] > footer.site .footer-links,
  body[data-page="system"] > footer.site .grid { display: none !important; }

  body[data-page="system"] > footer.site .system-bus {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    display: flex !important;
    grid-template-columns: none !important;
    flex-wrap: nowrap !important;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
  }

  body[data-page="system"] > footer.site .system-bus .bus-cell:nth-child(n+4) { display: none; }
}

@media (max-width: 480px) {
  body[data-page="system"] main.content-field { grid-template-rows: minmax(100px, 20vh) minmax(0, 1fr) !important; }
  body[data-page="system"] main.content-field > .page-head { max-height: 20vh; padding: 9px; }
  body[data-page="system"] .page-head .lede { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  body[data-page="system"] .page-head .meta-row { display: none; }
  body[data-page="system"] .system-facts { grid-template-columns: minmax(0, 1fr); }
  body[data-page="system"] .kap-grid-controls { width: 100%; justify-content: space-between; }
  body[data-page="system"] .kap-grid-status { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-page="system"] .system-workspace { scroll-behavior: auto; }
}
