/* ============================================================
   System Status Dashboard — OBS-ready full-viewport layout
   All content visible, no scroll required on main canvas
   ============================================================ */

:root {
  --status-healthy:  #10b981;
  --status-warning:  #f59e0b;
  --status-degraded: #f97316;
  --status-critical: #ef4444;
  --status-offline:  #6b7280;
  --bg:              #030712;
  --surface:         #0f172a;
  --surface2:        #161f35;
  --border:          #1e293b;
  --border2:         #263548;
  --text:            #f1f5f9;
  --text-muted:      #64748b;
  --text-dim:        #334155;
  --accent:          var(--primary, #0066FF);
  --font:            'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --header-h:        40px;
  --nav-h:           28px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Root: allow page scroll, center main canvas ── */
html, body { min-height: 100%; overflow-x: hidden; }

body.system-status-dashboard {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header (40px) ── */
.ssd-header {
  height: var(--header-h);
  min-height: var(--header-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.ssd-header h1,
.ssd-header-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text);
  white-space: nowrap;
}

.ssd-header-tracking {
  font-size: 10px;
  color: var(--text-muted);
  min-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#health-strip-svg {
  flex: 1;
  max-width: 600px;
  height: 32px;
  display: block;
}

/* ── Centered detail modal ── */
.ssd-detail-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.ssd-detail-modal-overlay[hidden] {
  display: none !important;
  pointer-events: none;
  visibility: hidden;
}

.ssd-detail-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}

.ssd-detail-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ssd-detail-modal-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.ssd-detail-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
}

.ssd-detail-modal-close:hover {
  color: var(--text);
  background: var(--border);
}

.ssd-detail-modal-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.55;
}

.ssd-detail-modal-body .status-detail-header { margin-top: 0; }
.ssd-detail-modal-body .status-detail-body { font-size: 11px; }

/* Center view button */
.ssd-center-view-btn {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 10px;
  font-size: 10px;
  font-family: var(--font);
  background: var(--border);
  color: var(--text);
  border: 1px solid var(--border2);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.ssd-center-view-btn:hover:not(:disabled) {
  background: var(--border2);
  border-color: var(--accent);
}

.ssd-center-view-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.detail-panel-content {
  min-height: 60px;
  overflow: visible;
  visibility: visible;
}
.detail-panel .status-detail-header,
.detail-panel .status-detail-body {
  display: block;
}

/* ── Nav (28px) ── */
.ssd-nav {
  height: var(--nav-h);
  min-height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
}

.ssd-nav a {
  font-size: 10px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0 8px;
  white-space: nowrap;
  letter-spacing: 0.06em;
  transition: color 0.15s;
}
.ssd-nav a:hover,
.ssd-nav a[aria-current] { color: var(--text); }
.ssd-nav .ln-sep {
  color: var(--text-dim);
  font-size: 10px;
  user-select: none;
}

/* ── Main two-column layout ── */
.ssd-body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) 280px;
  grid-template-rows: auto;
  max-width: 1400px;
  margin: 12px auto 16px;
  gap: 8px;
  padding: 0 12px;
}

/* ── LEFT panel: ports + graph + bottom strip ── */
.ssd-left {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
  overflow: hidden;
  background: var(--surface);
}

/* Ports grid — compact, always visible */
.ports-hero {
  flex-shrink: 0;
  padding: 8px 12px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.ports-hero-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.ports-hero-title {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.ports-hero-sub {
  font-size: 9px;
  color: var(--text-dim);
}

.ports-hero-updated {
  font-size: 9px;
  color: var(--text-dim);
  margin-left: auto;
}

.ports-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.port-card {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 9px;
  transition: border-color 0.3s;
  min-width: 0;
}

.port-card-online { border-color: rgba(16,185,129,0.35); }
.port-card-offline { opacity: 0.75; }

.port-card-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.port-card-online .port-card-dot {
  background: var(--status-healthy);
  box-shadow: 0 0 5px var(--status-healthy);
  animation: dot-pulse 2s ease-in-out infinite;
}
.port-card-offline .port-card-dot { background: var(--status-offline); }

.port-card-name {
  flex: 1;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 9px;
}

.port-card-port {
  color: var(--text-dim);
  font-size: 8px;
  white-space: nowrap;
}

.port-card-status {
  font-size: 8px;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}
.port-card-online .port-card-status { color: var(--status-healthy); }
.port-card-offline .port-card-status { color: var(--status-offline); }

@keyframes dot-pulse {
  0%,100% { opacity:1; transform:scale(1); }
  50%      { opacity:.7; transform:scale(1.15); }
}

/* Graph — fills remaining left-panel space, but can scale on small heights */
.graph-container {
  flex: 1;
  min-height: 260px;
  position: relative;
  background: var(--bg);
}

.graph-container svg {
  width: 100%;
  height: 100%;
  display: block;
}

.graph-container svg .status-node { transition: fill 0.3s, stroke-width 0.2s; }
.graph-container svg .status-node:hover { stroke-width: 3; stroke: #e2e8f0; }

/* Bottom strip: timeline + workflow log side by side */
.ssd-bottom-strip {
  flex-shrink: 0;
  height: 110px;
  min-height: 110px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.timeline-section {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 6px 10px 8px;
  overflow-y: auto;
}

.timeline-section h4,
.timeline-heading {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
  text-align: center;
}

.timeline-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.timeline-btn {
  padding: 2px 8px;
  font-size: 9px;
  font-family: var(--font);
  border-radius: 999px;
  border: 1px solid var(--border2);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
}

.timeline-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.status-event-row {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 6px;
  padding: 2px 0 2px 6px;
  font-size: 9px;
  border-left: 2px solid var(--text-dim);
  margin-bottom: 3px;
}

.status-event-time  { color: var(--text-muted); }
.status-event-comp  { color: var(--text-dim); font-size: 8px; }

.workflow-log-block {
  background: var(--surface2);
  padding: 6px 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.workflow-log-title {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.workflow-log-pre {
  font-size: 8px;
  color: var(--text-muted);
  overflow-y: auto;
  flex: 1;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

/* ── RIGHT sidebar: scrollable, contains all controls ── */
.ssd-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
}

/* ── Responsive: mobile / narrow viewports ── */
@media (max-width: 900px) {
  .ssd-body {
    grid-template-columns: minmax(0, 1fr);
    max-width: 100%;
    margin: 8px auto 12px;
    padding: 0 8px 8px;
    gap: 6px;
  }

  .ssd-left {
    border-radius: 8px;
    border-right: none;
  }

  .graph-container {
    min-height: 220px;
  }

  .ssd-bottom-strip {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .ssd-right {
    border-radius: 8px;
  }
}

/* Sidebar sections share a common padding */
.sidebar-section {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Section headings always visible (sticky heading) */
.sidebar-heading-always .sidebar-label {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  padding-bottom: 4px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Integrations by category ── */
.integrations-section .integrations-categories { font-size: 10px; }

.integration-category-block {
  margin-bottom: 10px;
}

.integration-category-heading {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.integration-category-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.integration-item {
  padding: 3px 6px;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 9px;
}

.integration-item-healthy { border-color: rgba(16,185,129,0.4); color: var(--status-healthy); }
.integration-item-offline { opacity: 0.7; color: var(--text-dim); }

.integrations-loading,
.integrations-empty { font-size: 9px; color: var(--text-dim); padding: 4px 0; }

/* ── Agents & stream components ── */
.agents-stream-section .agents-stream-list { font-size: 10px; }

.agent-stream-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 4px 6px;
  margin-bottom: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 9px;
}

.agent-stream-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-stream-type { color: var(--text-dim); font-size: 8px; text-transform: uppercase; }
.agent-stream-status { font-size: 8px; font-weight: 600; text-transform: uppercase; }
.agent-stream-row.agent-stream-healthy .agent-stream-status { color: var(--status-healthy); }
.agent-stream-row.agent-stream-offline .agent-stream-status { color: var(--status-offline); }

.agents-stream-loading,
.agents-stream-empty { font-size: 9px; color: var(--text-dim); padding: 4px 0; }

/* ── Controls: poll + search ── */
.controls-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.controls-row label {
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
}

.controls-row select,
.controls-row input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  font-size: 9px;
  border-radius: 3px;
  font-family: var(--font);
}

.controls-row input[type="text"] { flex: 1; min-width: 0; }

.fit-btn {
  background: var(--border);
  color: var(--text);
  border: 1px solid var(--border2);
  padding: 3px 8px;
  font-size: 9px;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
}
.fit-btn:hover { background: var(--border2); }

/* ── Filter chips ── */
.filter-block {
  margin-bottom: 5px;
}

.filter-block-label {
  font-size: 8px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 3px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.filter-chip {
  font-size: 8px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  user-select: none;
}
.filter-chip:hover { border-color: var(--border2); color: var(--text); }
.filter-chip.active {
  background: var(--status-healthy);
  color: #fff;
  border-color: transparent;
}
.filter-chip.status-warning.active   { background: var(--status-warning);  color: #000; }
.filter-chip.status-degraded.active  { background: var(--status-degraded); color: #fff; }
.filter-chip.status-critical.active  { background: var(--status-critical); color: #fff; }
.filter-chip.status-offline.active   { background: var(--status-offline);  color: #fff; }

/* ── Detail panel ── */
.detail-panel {
  flex-shrink: 0;
}

.detail-panel .detail-empty {
  font-size: 9px;
  color: var(--text-dim);
  padding: 6px 0;
}

.status-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 6px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.status-detail-header h3 { font-size: 11px; font-weight: 600; }

.status-detail-badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  color: #fff;
  text-transform: uppercase;
}

.status-detail-body {
  font-size: 10px;
  line-height: 1.6;
  color: var(--text-muted);
}

.status-detail-body strong { color: var(--text); margin-right: 4px; }

.status-detail-body pre {
  margin-top: 6px;
  padding: 6px;
  background: var(--bg);
  border-radius: 3px;
  font-size: 9px;
  overflow-x: auto;
}

.status-detail-metrics { margin-top: 8px; }

.status-metric-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 9px;
}

.status-metric-label { width: 50px; color: var(--text-muted); }
.status-metric-bar-svg { flex: 0 0 90px; display: block; }
.status-metric-value { color: var(--text); min-width: 32px; }

.status-detail-body details { margin-top: 8px; font-size: 9px; }
.status-detail-body details summary { cursor: pointer; color: var(--text-muted); }

/* ── AI Status ── */
.ai-panel {
  flex-shrink: 0;
}

.ai-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.ai-icon {
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #0066FF, #00D4FF);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}

.ai-header h3 { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }

.ai-status-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.ai-status-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 6px;
}

.ai-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ai-status-dot.online  { background: var(--status-healthy); box-shadow: 0 0 5px var(--status-healthy); }
.ai-status-dot.offline { background: var(--status-offline); }
.ai-status-dot.error   { background: var(--status-critical); }

/* ── Municipality ── */
.municipality-section { flex-shrink: 0; }

.municipality-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.municipality-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 6px;
  font-size: 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.2s;
}
.municipality-card:hover { border-color: var(--status-healthy); }
.municipality-name  { color: var(--text); }
.municipality-value { color: var(--status-healthy); font-weight: 600; }
.municipality-updated { color: var(--text-dim); font-size: 8px; }
.municipality-empty { font-size: 9px; color: var(--text-dim); }

/* ── Audit ── */
.audit-section { flex-shrink: 0; }

.audit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.audit-actions { display: flex; gap: 4px; }

.audit-actions button {
  font-size: 8px;
  padding: 3px 7px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--font);
  transition: color 0.15s, border-color 0.15s;
}
.audit-actions button:hover { color: var(--text); border-color: var(--border2); }

.audit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.audit-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px;
}

.audit-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.audit-card-title { font-size: 9px; font-weight: 600; color: var(--text); }

.audit-card-badge {
  font-size: 8px;
  padding: 1px 5px;
  border-radius: 2px;
}
.audit-card-badge.pass { background: var(--status-healthy); color: #fff; }
.audit-card-badge.fail { background: var(--status-critical); color: #fff; }
.audit-card-badge.warn { background: var(--status-warning);  color: #000; }

.audit-metrics {
  display: flex;
  justify-content: space-between;
  font-size: 8px;
  color: var(--text-muted);
}

/* ── Tools/MCPs ── */
.tools-mcp-block { flex-shrink: 0; }
.tools-mcp-desc { font-size: 8px; color: var(--text-dim); margin-bottom: 4px; }

.tools-mcp-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.tool-mcp-card {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  font-size: 9px;
  cursor: pointer;
  font-family: var(--font);
  transition: border-color 0.15s, background 0.15s;
}
.tool-mcp-card:hover { border-color: var(--border2); }
.tool-mcp-card.selected {
  border-color: var(--status-healthy);
  background: rgba(16,185,129,0.08);
}
.tool-mcp-name { font-size: 9px; }
.tool-mcp-type { font-size: 7px; color: var(--text-dim); margin-top: 1px; }
.tools-mcp-empty { font-size: 9px; color: var(--text-dim); }

/* ── Scrollbar styling (sidebar) ── */
.ssd-right::-webkit-scrollbar { width: 4px; }
.ssd-right::-webkit-scrollbar-track { background: transparent; }
.ssd-right::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── OBS: hide nav and reduce header when very short ── */
@media (max-height: 600px) {
  .ssd-nav { display: none; }
  .ssd-bottom-strip { height: 80px; min-height: 80px; }
}

@media (max-height: 480px) {
  .ssd-header { height: 32px; min-height: 32px; }
  .ssd-bottom-strip { display: none; }
}

/* ── Responsive: collapse to single column on narrow screens ── */
@media (max-width: 900px) {
  html, body { overflow: auto; height: auto; }
  body.system-status-dashboard { height: auto; overflow: auto; }

  .ssd-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 400px auto;
    overflow: auto;
    height: auto;
  }

  .ssd-left { height: auto; }
  .graph-container { height: 400px; }
  .ssd-right { overflow: visible; }
  .ssd-bottom-strip { height: auto; grid-template-columns: 1fr; }
  .ports-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 600px) {
  .ports-grid { grid-template-columns: repeat(2, 1fr); }
}
