/* CSIP Management API Dashboard - Global Styles */
:root {
  --bg: #121417;
  --panel: #1e242b;
  --accent: #2d8cff;
  --danger: #c0392b;
  --ok: #27ae60;
  --txt: #e0e6ed;
  --muted: #8899aa;
}

/* DERSec-standard iconography.
 *
 * Icons are line SVGs from the Tabler icon set (MIT), vendored into
 * index.html as a <symbol> sprite and referenced with <use>. This class is
 * the brand token for how they render -- one shared source so every surface
 * uses the same size + stroke rather than re-picking the numbers by hand.
 * `stroke: currentColor` lets each icon inherit its container's color, so it
 * picks up active / hover / status-badge states with no per-icon styling. */
.tabler-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* The sprite itself is a definition block, never painted. Symbols inside a
 * display:none parent remain referenceable by <use>. */
.icon-sprite {
  display: none;
}

/* Surfaces that pair an icon with adjacent text need to be flex rows so the
 * SVG sits on the text baseline instead of on its own line. */
.header-banner-icon,
.heading-icon {
  vertical-align: -0.2em;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--txt);
  margin: 0;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 101;
  border-bottom: 1px solid #2d343c;
}

.header-row {
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Header banner — slots into the header as a second row when config changes
   are pending or the restart failed. Driven by config-apply.js along with
   the Restart button's state. */
.header-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1.5rem;
  font-size: 0.8rem;
  border-top: 1px solid #2d343c;
}

.header-banner.hidden {
  display: none;
}

.header-banner-pending {
  background: #3a2a0f;
  color: #ffd49a;
}

.header-banner-failed {
  background: #3a1111;
  color: #ffb4b4;
}

/* When the header grows extra rows, the fixed left panel starts lower so it
   doesn't overlap the banner(s). The offset scales with the number of visible
   banners: updateHeaderBannerLayout() (config-apply.js) sets
   --header-banner-offset to count * 32px (one banner row ~= 32px given its
   padding + font-size). Fallback 32px covers a single row if the var is unset. */
body.with-header-banner .left-panel {
  top: calc(70px + var(--header-banner-offset, 32px));
  height: calc(100vh - 70px - var(--header-banner-offset, 32px) - 60px);
}

/* Restart button: idle is default header-button styling; pending (amber) and
   restart-failed (red) variants are driven by config-apply.js. The alert
   variants prepend an icon, so lay the label out as a row. */
.restart-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.restart-btn-pending {
  background: #d97706;
  color: #1a1203;
  font-weight: 600;
}

.restart-btn-pending:hover:not(:disabled) {
  background: #f08a1a;
}

.restart-btn-failed {
  background: #dc2626;
  color: #fff;
  font-weight: 600;
}

.restart-btn-failed:hover:not(:disabled) {
  background: #ef4444;
}

/* Configuration editor: tab strip + panels inside the Configuration section. */
.config-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
  border-bottom: 1px solid #2d343c;
  margin: 0 -0.15rem 1rem;
}

.config-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.config-tab:hover:not(.active) {
  color: var(--txt);
}

.config-tab.active {
  color: var(--txt);
  border-bottom-color: var(--accent);
}

.config-panel {
  padding-top: 0.25rem;
}

.config-panel.hidden {
  display: none;
}

.config-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.config-raw-textarea {
  width: 100%;
  min-height: 420px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  background: #111820;
  color: var(--txt);
  border: 1px solid #2d343c;
  border-radius: 6px;
  padding: 0.75rem;
  resize: vertical;
  box-sizing: border-box;
}

.config-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.config-status {
  font-size: 0.75rem;
  color: var(--muted);
}

.config-status.ok {
  color: var(--ok);
}

.config-status.err {
  color: #ff9999;
}

.config-error {
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  background: #3a1111;
  color: #ffb4b4;
  border: 1px solid #6b1f1f;
  border-radius: 6px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.config-error.hidden {
  display: none;
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
  max-width: 780px;
}

.config-field {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  column-gap: 1rem;
  row-gap: 0.2rem;
  align-items: center;
}

.config-field > label {
  font-size: 0.8rem;
  color: var(--txt);
}

.config-field > .config-input {
  width: 100%;
  box-sizing: border-box;
}

.config-field > input[type="checkbox"].config-input {
  width: auto;
  justify-self: start;
}

.config-field > .config-field-help {
  grid-column: 2 / -1;
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.4;
}

/* CRUD list shared across Devices / Groups / Forwarders sub-editors. */
.config-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 0.75rem;
}

.config-list-header h3,
.config-editor-wrap h4 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
}

.config-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.config-list-empty {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.config-list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  background: #111820;
  border: 1px solid #2d343c;
  border-radius: 6px;
  font-size: 0.8rem;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.config-list-row:hover {
  background: #161e27;
  border-color: #3a4350;
}

.config-list-row.editing {
  background: #14263a;
  border-color: var(--accent);
  border-left-width: 3px;
  padding-left: calc(0.75rem - 2px);
}

.config-list-row.placeholder {
  background: #1a2230;
  border-style: dashed;
  border-color: var(--accent);
  font-style: italic;
}

.config-list-row .row-summary {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.config-list-row .row-summary-title {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: var(--txt);
}

.config-list-row .row-summary-detail {
  font-size: 0.7rem;
  color: var(--muted);
}

.config-list-row .row-actions {
  display: flex;
  gap: 0.35rem;
}

.config-list-row .row-actions button {
  font-size: 0.72rem;
  padding: 0.25rem 0.6rem;
}

.config-editor-wrap {
  border-top: 1px solid #2d343c;
  padding-top: 0.9rem;
}

.config-editor-wrap.hidden {
  display: none;
}

/* Documentation viewer: TOC on the left, rendered markdown on the right. */
.docs-layout {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.docs-toc {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  position: sticky;
  top: 5.5rem;
}

.docs-toc-item {
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  color: var(--muted);
  text-align: left;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.8rem;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.docs-toc-item:hover:not(.active) {
  color: var(--txt);
  background: rgba(45, 140, 255, 0.06);
}

.docs-toc-item.active {
  color: var(--txt);
  border-left-color: var(--accent);
  background: rgba(45, 140, 255, 0.08);
}

.docs-content {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--txt);
  max-width: 820px;
}

.docs-content h1,
.docs-content h2,
.docs-content h3,
.docs-content h4 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  letter-spacing: 0.01em;
}

.docs-content h1 { font-size: 1.3rem; }
.docs-content h2 { font-size: 1.05rem; }
.docs-content h3 { font-size: 0.95rem; }
.docs-content h4 { font-size: 0.85rem; }

.docs-content p,
.docs-content ul,
.docs-content ol {
  margin: 0.5rem 0;
}

/* The docs pages label each sidebar section with the same icon the nav
   renders, so the operator can map a bullet to what they see on screen.
   Nudge it onto the text baseline and give the label some air. */
.docs-content .tabler-icon {
  vertical-align: -0.2em;
  margin-right: 0.2rem;
}

.docs-content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.8rem;
  background: #111820;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  border: 1px solid #2d343c;
}

.docs-content pre {
  background: #111820;
  border: 1px solid #2d343c;
  border-radius: 6px;
  padding: 0.75rem;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.45;
}

.docs-content pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* "How do I add a plugin?" help code blocks: match the dark code-block
   convention (.docs-content pre) rather than the browser-default light <pre>
   (was a white box on the dark page). */
.plugins-help pre {
  background: #111820;
  color: #fff;
  padding: 0.5rem;
  border-radius: 4px;
  border: 1px solid #2d343c;
  overflow-x: auto;
}

.plugins-help pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

.docs-content table {
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.8rem;
  width: 100%;
}

.docs-content th,
.docs-content td {
  border: 1px solid #2d343c;
  padding: 0.4rem 0.6rem;
  text-align: left;
  vertical-align: top;
  /* Override the global td rule's mid-word breaking; let the layout size
     narrow first columns to fit short labels (Subscription, Aggregator)
     on a single line and only wrap the wider description columns. */
  word-break: normal;
  overflow-wrap: anywhere;
}

.docs-content table tr > *:first-child {
  white-space: nowrap;
  width: 1%;
}

.docs-content th {
  background: #1a2129;
  font-weight: 600;
}

.docs-content a {
  color: var(--accent);
}

/* In-page Swagger UI for the API Documentation section. */
.api-docs-frame {
  width: 100%;
  height: calc(100vh - 70px - 70px - 60px);
  min-height: 480px;
  border: 1px solid #2d343c;
  border-radius: 6px;
  background: #fff;
}

/* Member checklist — used by Groups editor for the LFDI member multi-select. */
.config-checklist {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 240px;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  background: #111820;
  border: 1px solid #2d343c;
  border-radius: 6px;
}

.config-checklist-empty {
  font-size: 0.75rem;
  color: var(--muted);
  font-style: italic;
}

.config-checklist label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.78rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: var(--txt);
  cursor: pointer;
}

.config-checklist label .lfdi {
  color: var(--muted);
  font-size: 0.7rem;
}

.left-panel {
  position: fixed;
  left: 0;
  top: 70px;
  width: 220px;
  height: calc(100vh - 70px - 60px);
  background: var(--panel);
  border-right: 1px solid #2d343c;
  padding: 1rem 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: hidden;
  z-index: 100;
}

.left-panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

/* Certification badge sits between the nav groups and the Tools tray. */
.nav-cert-logo {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 0.4rem 1rem;
}

.nav-cert-logo img {
  width: 100%;
  max-width: 170px;
  height: auto;
  object-fit: contain;
}

.nav-header {
  font-weight: bold;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  padding: 0.5rem 1rem;
  letter-spacing: 0.5px;
}

/* Subsequent group headings need extra breathing room so the SETTINGS /
   MONITORING / DOCUMENTATION groups read as distinct sections. */
.nav-header + .nav-item ~ .nav-header,
.nav-item + .nav-header {
  margin-top: 0.75rem;
}

/* Cross-link banner shown at the top of Monitoring sections, pointing the
   operator at the matching Configuration tab. Quiet visually -- it's a
   pointer, not the main content. */
.config-crosslink {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0.4rem 0 0;
}

.config-crosslink a {
  color: var(--accent);
  text-decoration: none;
}

.config-crosslink a:hover {
  text-decoration: underline;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--txt);
  padding: 0.4rem 1rem;
  cursor: pointer;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 400;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  letter-spacing: 0.01em;
  text-decoration: none;
  box-sizing: border-box;
}

a.nav-item {
  color: var(--txt);
}

.nav-item:hover {
  background: rgba(45, 140, 255, 0.1);
  color: var(--accent);
}

.nav-item.active {
  background: rgba(45, 140, 255, 0.1);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

.nav-addons {
  flex-shrink: 0;
  border-top: 1px solid #2d343c;
  padding: 0.25rem 0 0.5rem 0;
}

.nav-addons-toggle {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: color 0.2s ease;
}

.nav-addons-toggle:hover {
  color: var(--accent);
}

.nav-addons-arrow {
  display: inline-block;
  font-size: 0.6rem;
  transition: transform 0.2s ease;
  margin-right: 0.25rem;
}

.nav-addons:not(.collapsed) .nav-addons-arrow {
  transform: rotate(180deg);
}

.nav-addons-menu {
  display: block;
}

.nav-addons.collapsed .nav-addons-menu {
  display: none;
}

/* Tools tray — pinned to bottom of sidebar, outside scroll flow */
main {
  display: grid;
  gap: 1rem;
  padding: 1rem 1.2rem;
  padding-bottom: 220px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  margin-left: 220px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
}

h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.header-titles {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.header-lfdi {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
}

.header-lfdi-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.68rem;
}

.header-lfdi-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  cursor: pointer;
  word-break: break-all;
  /* IEEE 2030.5 6.3.4 wants the displayed LFDI in groups of four, but a full
     monospace space between all ten reads as ten separate words rather than one
     identifier. Narrow the gap without touching the digits. */
  word-spacing: -0.35em;
}

.header-lfdi-value.muted {
  color: var(--muted);
  cursor: default;
  /* The fallback is a sentence, not a grouped identifier: undo the tightening
     the populated state needs. This class is the state discriminator -- the
     script removes it once an LFDI is rendered. */
  word-spacing: normal;
}

.header-lfdi-value:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.content-section {
  display: none;
}

.content-section.visible {
  display: contents;
}

/* Device grouping content section spans full width */
.content-section[data-section="device-grouping"].visible {
  display: contents;
}

section {
  background: var(--panel);
  border-radius: 8px;
  padding: 1rem 1.15rem 1.15rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(45, 52, 60, 0.5);
  position: relative;
}

section h2 {
  margin: 0.15rem 0 0.6rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

small {
  color: var(--muted);
}

button,
select,
input[type="text"],
input[type="number"] {
  background: #2a313b;
  color: var(--txt);
  border: 1px solid #3a444f;
  border-radius: 5px;
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
}

button {
  cursor: pointer;
  font-weight: 500;
  letter-spacing: 0.02em;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button.inline {
  margin-left: 0.5rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* GitHub-style indented key/value tree (renderTable in ui.js). Each nested
   level indents one fixed step against a left guide line instead of cascading
   into a right-shifted column (issue #397). */
.tree {
  font-size: 0.78rem;
  line-height: 1.55;
}

.tree-leaf {
  display: grid;
  grid-template-columns: minmax(7rem, 15rem) 1fr;
  gap: 0.75rem;
  padding: 0.1rem 0;
}

.tree-leaf .tree-key {
  color: var(--muted);
  word-break: break-word;
}

.tree-val {
  word-break: break-all;
}

.tree-count {
  color: var(--muted);
}

.tree-node > .tree-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  padding: 0.1rem 0;
  list-style: none;
}

.tree-node > .tree-summary::-webkit-details-marker {
  display: none;
}

/* Triangle disclosure marker that rotates on open (no width change). */
.tree-node > .tree-summary::before {
  content: '';
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 4px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.12s ease;
}

.tree-node[open] > .tree-summary::before {
  transform: rotate(90deg);
}

.tree-children {
  padding-left: 0.85rem;
  margin-left: 0.4rem;
  border-left: 1px solid rgba(136, 153, 170, 0.25);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

th,
td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(45, 52, 60, 0.6);
  text-align: left;
  word-break: break-word;
  white-space: pre-wrap;
}

th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.01em;
}

tr:last-child td {
  border-bottom: none;
}

code {
  background: #2a313b;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.7rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}

.grid-span-2 {
  grid-column: span 2;
}

footer {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  background: #12171d;
  padding: 0.5rem 1.25rem;
  font-size: 0.65rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  max-height: 200px;
  overflow-y: auto;
  z-index: 99;
  border-top: 1px solid #2d343c;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  background: #2a313b;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 500;
  margin-left: 0.35rem;
  letter-spacing: 0.02em;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.about-dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.25rem;
  margin: 0;
  font-size: 0.8rem;
}

.about-dl dt {
  color: var(--muted);
  font-weight: 600;
}

.about-dl dd {
  margin: 0;
}

.about-dl dd.about-nowrap {
  white-space: nowrap;
}

/* Widen the License card so the 36-char License ID fits on one line without
   a scrollbar, while capping it so it doesn't stretch across a wide monitor. */
#aboutPanel {
  grid-column: 1 / -1;
  max-width: 560px;
}

.mono {
  font-family: "SFMono-Regular", ui-monospace, Consolas, monospace;
}

.error {
  color: var(--danger);
  font-size: 0.7rem;
  margin-top: 0.25rem;
}

.success {
  color: var(--ok);
  font-size: 0.7rem;
  margin-top: 0.25rem;
}

.section-header {
  grid-column: 1 / -1;
  background: #1a2028;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  margin-top: 1rem;
  border-left: 3px solid var(--accent);
}

.section-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

.section-header p {
  margin: 0.2rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.device-section {
  margin: 5px 0;
  background: #1a2028;
  border-radius: 5px;
}

.device-section .section-header {
  margin: 0;
  padding: 6px 12px;
  background: #232a33;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}

.device-section .section-header:hover {
  background: #2a313b;
}

.device-section table {
  margin: 0;
  font-size: 0.7rem;
}

.device-section td,
.device-section th {
  padding: 0.3rem 0.5rem;
}

.muted {
  color: var(--muted);
}

#logEventsContainer table {
  font-size: 0.6rem;
}

#logEventsContainer th {
  position: sticky;
  top: 0;
  background: #2a313b;
}

/* Collapsible Section Styles */
.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: 0.5rem 0;
  user-select: none;
}

.collapsible-header h2 {
  margin: 0;
  font-size: 0.95rem;
}

.collapse-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
}

.collapse-toggle.collapsed {
  transform: rotate(-90deg);
}

.collapsible-content {
  max-height: 1000px;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}

.collapsible-content.collapsed {
  max-height: 0;
  opacity: 0;
}

/* Statistics Panel Styles */
#statisticsPanel {
  grid-column: 1 / -1;
  background-color: #1a1f26;
  border-top: 3px solid var(--accent);
  border-radius: 10px;
  padding: 0.75rem;
}

#statisticsPanel h2 {
  margin: 0;
  color: #64b5f6;
}

.stat-card {
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.85rem;
}

.stat-card-blue {
  background: rgba(100, 181, 246, 0.15);
  border-left: 4px solid #64b5f6;
}

.stat-card-green {
  background: rgba(76, 175, 80, 0.15);
  border-left: 4px solid #4caf50;
}

.stat-card-purple {
  background: rgba(156, 39, 176, 0.15);
  border-left: 4px solid #9c27b0;
}

.stat-card-orange {
  background: rgba(255, 152, 0, 0.1);
  border-left: 4px solid #ff9800;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 0.2rem;
  font-weight: 600;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: inherit;
}

.stat-card-blue .stat-value {
  color: #64b5f6;
}

.stat-card-green .stat-value {
  color: #4caf50;
}

.stat-card-purple .stat-value {
  color: #9c27b0;
}

.stat-card-orange .stat-value {
  color: #ff9800;
}

.stat-subtext {
  font-size: 0.55rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.stat-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.stat-column {
  flex: 1;
}

.stat-column-label {
  font-size: 0.65rem;
  margin-bottom: 0.1rem;
}

.stat-column-value {
  font-size: 1rem;
  font-weight: 600;
  color: inherit;
}

/* Diagnostics Panel Styles */
#diagnosticsPanel {
  grid-column: 1 / -1;
  background-color: #1a1f26;
}

.diag-card {
  border-radius: 6px;
  padding: 0.75rem;
}

.diag-card-errors {
  background: #3d2020;
  border-left: 4px solid #c0392b;
}

.diag-card-warnings {
  background: #3d3420;
  border-left: 4px solid #f39c12;
}

.diag-card-faults {
  background: #1f3a52;
  border-left: 4px solid #2980b9;
}

.diag-card-info {
  background: #2a3139;
  border-left: 4px solid #7f8c8d;
}

.diag-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.diag-title {
  font-weight: 600;
  font-size: 0.85rem;
}

.diag-title-errors {
  color: #c0392b;
}

.diag-title-warnings {
  color: #f39c12;
}

.diag-title-faults {
  color: #2980b9;
}

.diag-title-info {
  color: #7f8c8d;
}

.diag-list {
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.7rem;
}

/* ===== UTILITY CLASSES ===== */

/* Spacing utilities */
.mb-lg { margin-bottom: 0.75rem; }
.mb-sm { margin-bottom: 0.5rem; }
.p-sm { padding: 0.2rem 0.4rem; }
.p-xs { padding: 0.3rem 0.6rem; }

/* Font size utilities */
.fs-sm { font-size: 0.6rem; }
.fs-xs { font-size: 0.7rem; }

/* Layout utilities */
.grid-content {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.grid-content > * {
  flex: 1 1 calc(25% - 0.75rem);
  min-width: 200px;
}

.grid-diag {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.flex-between-mb {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

/* Text utilities */
.text-center { text-align: center; }
.text-muted-light { color: var(--muted); }
.h2-reset { margin: 0; }
.w-full { width: 100%; }
.grid-full { grid-column: 1 / -1; }

/* Color utilities */
.color-upstream { color: #64b5f6; }
.color-downstream { color: #4caf50; }
.color-valid { color: #66bb6a; }
.color-invalid { color: #ef5350; }

/* Button size utilities */
.btn-sm { padding: 0.2rem 0.4rem; font-size: 0.6rem; }

/* Statistics content */
.stat-content { font-size: 0.7rem; color: var(--txt); }

/* Diagnostic message */
.diag-msg { 
  text-align: center; 
  color: var(--muted); 
  padding: 1rem; 
  font-size: 0.8rem; 
}

/* Diagnostic clear button */
.diag-clear-btn {
  padding: 0.2rem 0.4rem;
  font-size: 0.6rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--txt);
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.diag-clear-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

.diag-clear-btn:active {
  background: rgba(0, 0, 0, 0.4);
}

/* ===== Device and Groups Panel Layout ===== */
/* Wrapper container for side-by-side layout */
.device-grouping-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  width: 100%;
  min-height: 0;
  grid-column: 1 / -1;
}

/* Force panels to 50% width side-by-side */
#devicesPanel,
#groupsPanel,
#defaultControlsPanel,
#scheduledControlsPanel {
  flex: 1 1 calc(50% - 0.5rem);
  width: 50%;
  min-width: 0;
  max-height: 70vh;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Ensure device details container doesn't wrap text */
#deviceDetailsContainer,
#groupDetailsContainer {
  flex: 1;
  overflow: auto;
  min-width: 0;
}

/* Prevent text wrapping in tables */
#devicesPanel table,
#groupsPanel table {
  white-space: nowrap;
}

/* Responsive: stack panels vertically on screens < 800px */
@media (max-width: 799px) {
  .device-grouping-wrapper {
    flex-direction: column;
    gap: 1rem;
  }

  #devicesPanel,
  #groupsPanel,
  #defaultControlsPanel,
  #scheduledControlsPanel {
    width: 100%;
    flex: 1;
  }
}


/* ===== Live Traffic ===== */
.traffic-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.traffic-table th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #2d343c;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.traffic-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid #232a32;
  vertical-align: top;
}

.traffic-table .nowrap { white-space: nowrap; }
.traffic-url { word-break: break-all; }

.traffic-dir {
  font-weight: 600;
  font-size: 0.72rem;
  white-space: nowrap;
}

.traffic-out { color: #2d8cff; }
.traffic-in { color: #27ae60; }
.traffic-notify { color: #f9a825; }

.traffic-status-ok { color: #27ae60; font-weight: 600; }
.traffic-status-err { color: #e0574a; font-weight: 600; }

.method-pill {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  color: #fff;
}

.method-get { background: #1f6b3a; }
.method-post { background: #2a4a8c; }
.method-put { background: #8a5a1a; }
.method-delete { background: #8c2a2a; }
.method-other { background: #4a525c; }

.traffic-show { cursor: pointer; }
.traffic-size { font-size: 0.7rem; }

.traffic-payload-row.hidden { display: none; }
.traffic-payload-row td { background: #0d1218; padding: 0; }

.traffic-body {
  background: #111820;
  color: #fff;
  border: 1px solid #2d343c;
  border-radius: 4px;
  padding: 0.5rem;
  margin: 0.4rem;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 480px;
  overflow: auto;
}

/* Measurement freshness. Values are served from the point store, so the panel
   has to distinguish a current reading from a held-over one. */
.freshness-stale {
  color: var(--danger);
}

.freshness-lost {
  color: var(--danger);
  font-weight: 600;
}
