/* =========================================================================
   ERP Infrastructure Dashboard — single stylesheet
   One status palette, one spacing scale, one typography scale for every
   panel. Dark mode is the default; light mode is opt-in via data-theme.
   ========================================================================= */

:root {
  /* status palette — the only semantic colours in the system */
  --status-healthy: #2fbf71;   /* GREEN   healthy            */
  --status-warning: #e0a83a;   /* YELLOW  warning / degraded */
  --status-critical: #e5534b;  /* RED     critical / failed  */
  --status-unknown: #7d8794;   /* GRAY    unknown / not connected */
  --status-info: #4a9eff;      /* BLUE    informational      */

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 11px;
  --text-sm: 12.5px;
  --text-md: 14px;
  --text-lg: 17px;
  --text-xl: 22px;
  --text-2xl: 30px;

  --bg: #0d1117;
  --bg-elevated: #151b23;
  --bg-panel: #12181f;
  --bg-inset: #0a0e13;
  --border: #232c38;
  --border-strong: #2f3a48;
  --text: #e6edf3;
  --text-muted: #98a3b3;
  --text-dim: #6b7684;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --grid-line: rgba(255, 255, 255, 0.035);
}

[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-elevated: #ffffff;
  --bg-panel: #ffffff;
  --bg-inset: #eef1f5;
  --border: #dde3ea;
  --border-strong: #c6cfd9;
  --text: #101720;
  --text-muted: #5b6673;
  --text-dim: #8794a3;
  --shadow: 0 8px 24px rgba(16, 23, 32, 0.08);
  --grid-line: rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

/* ---------------------------------------------------------------- notice */
.notice {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  background: repeating-linear-gradient(135deg, rgba(224, 168, 58, 0.16) 0 12px, rgba(224, 168, 58, 0.07) 12px 24px);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}
.notice__headline { font-weight: 700; color: var(--status-warning); }
.notice__detail { color: var(--text-muted); text-transform: none; letter-spacing: 0; }

/* ---------------------------------------------------------------- topbar */
.topbar-mount { position: sticky; top: 0; z-index: 40; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { display: flex; align-items: center; gap: var(--space-3); }
.topbar__mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: linear-gradient(140deg, var(--status-info), #2f6fd0);
  color: #fff; font-weight: 700; font-size: var(--text-sm); letter-spacing: 0.04em;
}
.topbar__names { display: flex; flex-direction: column; }
.topbar__title { font-size: var(--text-lg); }
.topbar__subtitle { font-size: var(--text-xs); color: var(--text-muted); }
.topbar__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); }
.topbar__field { display: flex; flex-direction: column; gap: 2px; }
.topbar__field-label { font-size: var(--text-xs); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.topbar__field-value { font-size: var(--text-sm); }

.badge {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
}
.badge--mock { color: var(--status-warning); border-color: color-mix(in srgb, var(--status-warning) 45%, transparent); background: color-mix(in srgb, var(--status-warning) 12%, transparent); }

.env-select, .input {
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: var(--text-sm);
  font-family: inherit;
  min-width: 150px;
}
.input:focus, .env-select:focus { outline: 2px solid color-mix(in srgb, var(--status-info) 60%, transparent); outline-offset: 1px; }

.btn {
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: var(--text-sm);
  font-family: inherit;
  cursor: pointer;
}
.btn:hover { border-color: var(--border-strong); background: var(--bg-elevated); }
.btn--primary { background: color-mix(in srgb, var(--status-info) 22%, transparent); border-color: color-mix(in srgb, var(--status-info) 55%, transparent); color: var(--text); }
.btn--ghost { background: transparent; }
.btn--small { padding: 4px 9px; font-size: var(--text-xs); }
.btn--icon { width: 32px; height: 30px; padding: 0; display: grid; place-items: center; font-size: var(--text-md); }

.menu-wrap { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 240px; display: none; flex-direction: column;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); box-shadow: var(--shadow); padding: var(--space-2); z-index: 50;
}
.menu-panel.is-open { display: flex; }
.menu-panel__item { font-size: var(--text-sm); color: var(--text-muted); padding: 6px 8px; }

/* ---------------------------------------------------------------- layout */
.layout { max-width: 1520px; margin: 0 auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-5); }

.section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.section__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.section__title { font-size: var(--text-lg); }
.section__subtitle { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.section__actions { display: flex; gap: var(--space-2); align-items: center; }
.section__body { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-5); }
.section.is-collapsed .section__body { display: none; }

/* ------------------------------------------------------------ status chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--bg-inset) 70%, transparent);
  white-space: nowrap;
}
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--status-unknown); }
.chip--healthy { color: var(--status-healthy); border-color: color-mix(in srgb, var(--status-healthy) 40%, transparent); }
.chip--healthy .chip__dot { background: var(--status-healthy); }
.chip--warning { color: var(--status-warning); border-color: color-mix(in srgb, var(--status-warning) 40%, transparent); }
.chip--warning .chip__dot { background: var(--status-warning); }
.chip--critical { color: var(--status-critical); border-color: color-mix(in srgb, var(--status-critical) 45%, transparent); }
.chip--critical .chip__dot { background: var(--status-critical); }
.chip--unknown { color: var(--status-unknown); }
.chip--info { color: var(--status-info); border-color: color-mix(in srgb, var(--status-info) 40%, transparent); }
.chip--info .chip__dot { background: var(--status-info); }

/* ------------------------------------------------------------ status cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: var(--space-3); }
.stat-card {
  display: flex; flex-direction: column; gap: var(--space-2);
  text-align: left; cursor: pointer;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--status-unknown);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  color: var(--text); font-family: inherit;
}
.stat-card--healthy { border-left-color: var(--status-healthy); }
.stat-card--warning { border-left-color: var(--status-warning); }
.stat-card--critical { border-left-color: var(--status-critical); }
.stat-card:hover { border-color: var(--border-strong); }
.stat-card__head { display: flex; align-items: center; gap: var(--space-2); }
.stat-card__icon { color: var(--text-muted); display: grid; place-items: center; }
.stat-card__icon .icon { width: 18px; height: 18px; }
.stat-card__label { font-size: var(--text-sm); font-weight: 600; flex: 1; }
.stat-card__value { font-size: var(--text-xl); font-weight: 650; }
.stat-card__detail { font-size: var(--text-xs); color: var(--text-muted); }
.stat-card__foot { display: flex; align-items: center; justify-content: space-between; font-size: var(--text-xs); color: var(--text-dim); }
.trend--up { color: var(--status-healthy); }
.trend--down { color: var(--status-critical); }
.trend--flat { color: var(--text-dim); }

/* ---------------------------------------------------------- environments */
.env-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); }
.env-card {
  text-align: left; cursor: pointer; font-family: inherit; color: var(--text);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.env-card.is-active { border-color: color-mix(in srgb, var(--status-info) 60%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--status-info) 35%, transparent); }
.env-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.env-card__name { font-size: var(--text-sm); font-weight: 700; letter-spacing: 0.06em; }
.env-card__detail { font-size: var(--text-xs); color: var(--text-muted); }
.env-card__url { font-size: var(--text-xs); color: var(--text-dim); font-family: var(--font-mono); }

/* -------------------------------------------------------------- topology */
.topology { display: flex; flex-direction: column; gap: var(--space-3); }
.topology__toolbar { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; justify-content: space-between; }
.topology__zoomers { display: flex; align-items: center; gap: var(--space-2); }
.zoom-readout { font-size: var(--text-xs); color: var(--text-muted); font-family: var(--font-mono); min-width: 42px; text-align: center; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.segmented__item {
  border: 0; background: transparent; color: var(--text-muted);
  font-family: inherit; font-size: var(--text-xs); padding: 6px 10px; cursor: pointer;
}
.segmented__item + .segmented__item { border-left: 1px solid var(--border); }
.segmented__item.is-active { background: color-mix(in srgb, var(--status-info) 20%, transparent); color: var(--text); font-weight: 600; }

.topology__viewport {
  position: relative; overflow: hidden; height: 640px;
  background: var(--bg-inset);
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: grab;
  touch-action: none;
}
.topology__viewport.is-panning { cursor: grabbing; }
.topology__canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.topology__edges { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }

.topology__edge { fill: none; stroke: var(--status-unknown); stroke-width: 1.6; opacity: 0.85; }
.topology__edge--healthy { stroke: var(--status-healthy); }
.topology__edge--warning { stroke: var(--status-warning); stroke-dasharray: 6 4; }
.topology__edge--critical { stroke: var(--status-critical); }
.topology__edge.is-dimmed, .topology__edge-label.is-dimmed { opacity: 0.12; }
.topology__arrow { fill: var(--status-unknown); }
.topology__edge-label { fill: var(--text-dim); font-size: 10px; font-family: var(--font-mono); }

.node-card {
  position: absolute; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between; gap: var(--space-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-top: 3px solid var(--status-unknown);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  color: var(--text); font-family: inherit;
  box-shadow: var(--shadow);
}
.node-card--healthy { border-top-color: var(--status-healthy); }
.node-card--warning { border-top-color: var(--status-warning); }
.node-card--critical { border-top-color: var(--status-critical); }
.node-card--info { border-top-color: var(--status-info); }
.node-card:hover { border-color: var(--border-strong); }
.node-card.is-selected { outline: 2px solid var(--status-info); outline-offset: 2px; }
.node-card.is-dimmed { opacity: 0.25; }
.node-card__head { display: flex; align-items: center; gap: var(--space-2); }
.node-card__icon .icon { width: 18px; height: 18px; color: var(--text-muted); }
.node-card__name { font-size: var(--text-sm); font-weight: 650; }
.node-card__type { font-size: var(--text-xs); color: var(--text-muted); }
.node-card__foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.node-card__latency { font-size: var(--text-xs); color: var(--text-dim); font-family: var(--font-mono); }

.topology__tip {
  position: absolute; z-index: 20; max-width: 300px;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: var(--space-2) var(--space-3); font-size: var(--text-xs); color: var(--text-muted);
  pointer-events: none;
}
.topology__legend { display: flex; flex-wrap: wrap; gap: var(--space-4); font-size: var(--text-xs); color: var(--text-muted); }
.legend__item::before { content: "●"; margin-right: 6px; }
.legend__item--healthy::before { color: var(--status-healthy); }
.legend__item--warning::before { color: var(--status-warning); }
.legend__item--critical::before { color: var(--status-critical); }
.legend__item--unknown::before { color: var(--status-unknown); }
.legend__item--info::before { color: var(--status-info); }

/* ---------------------------------------------------------- node detail */
.detail-mount { display: none; }
.detail-mount.is-open { display: block; position: fixed; inset: 0 0 0 auto; width: min(440px, 92vw); z-index: 60; }
.detail {
  height: 100%; overflow-y: auto;
  background: var(--bg-elevated); border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow); padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-5);
}
.detail__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.detail__eyebrow { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.detail__title { font-size: var(--text-xl); }
.detail__subtitle { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-1); }
.detail__section { display: flex; flex-direction: column; gap: var(--space-2); border-top: 1px solid var(--border); padding-top: var(--space-3); }
.detail__section-title { font-size: var(--text-sm); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.detail__field { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); font-size: var(--text-sm); }
.detail__field-label { color: var(--text-dim); }
.detail__field-value { text-align: right; font-family: var(--font-mono); font-size: var(--text-xs); }
.detail__group { display: flex; flex-direction: column; gap: var(--space-2); }
.detail__group-title { font-size: var(--text-xs); color: var(--text-dim); }
.detail__conn { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.detail__conn-name { flex: 1; }
.detail__conn-type { color: var(--text-dim); font-family: var(--font-mono); }
.detail__note { font-size: var(--text-xs); color: var(--text-dim); }

/* ---------------------------------------------------------------- matrix */
.matrix { display: flex; flex-direction: column; gap: var(--space-3); }
.matrix__filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.matrix__host { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-xs); }
.data-table th, .data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th { color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; font-size: 10.5px; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--bg-inset) 60%, transparent); }
.matrix__node { font-weight: 600; }
.matrix__env, .matrix__count { color: var(--text-muted); }
.matrix__count { font-size: var(--text-xs); }

.dep { font-size: 10.5px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-muted); }
.dep--required { color: var(--status-info); border-color: color-mix(in srgb, var(--status-info) 40%, transparent); }

/* ---------------------------------------------------------------- alerts */
.alerts { display: flex; flex-direction: column; gap: var(--space-3); }
.alerts__filters { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.alerts__host { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-3); }
.alert {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-left: 3px solid var(--status-unknown);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.alert--critical { border-left-color: var(--status-critical); }
.alert--high { border-left-color: #ef7a4b; }
.alert--medium { border-left-color: var(--status-warning); }
.alert--low { border-left-color: var(--status-info); }
.alert--info { border-left-color: var(--status-unknown); }
.alert__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.alert__severity { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; }
.alert__severity--critical { color: var(--status-critical); }
.alert__severity--high { color: #ef7a4b; }
.alert__severity--medium { color: var(--status-warning); }
.alert__severity--low { color: var(--status-info); }
.alert__severity--info { color: var(--status-unknown); }
.alert__time { font-size: var(--text-xs); color: var(--text-dim); }
.alert__title { font-size: var(--text-sm); }
.alert__detail { font-size: var(--text-xs); color: var(--text-muted); }
.alert__foot { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: var(--text-xs); color: var(--text-dim); }
.alert__state { text-transform: uppercase; letter-spacing: 0.06em; }
.alert__state--open { color: var(--status-warning); }
.alert__state--acknowledged { color: var(--status-info); }
.alert__state--resolved { color: var(--status-healthy); }

/* ---------------------------------------------------------------- panels */
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: var(--space-4); }
.panel { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.panel--wide { grid-column: 1 / -1; }
.panel__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.panel__title { font-size: var(--text-md); }
.panel__subtitle { font-size: var(--text-xs); color: var(--text-muted); }
.panel__body { display: flex; flex-direction: column; gap: var(--space-3); }
.panel__rows { display: flex; flex-direction: column; }
.def-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: var(--text-sm); }
.def-row:last-child { border-bottom: 0; }
.def-row__label { color: var(--text-muted); }
.def-row__value { font-family: var(--font-mono); font-size: var(--text-xs); text-align: right; }
.panel__metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--space-2); border-top: 1px solid var(--border); padding-top: var(--space-3); }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric__label { font-size: var(--text-xs); color: var(--text-dim); }
.metric__value { font-size: var(--text-md); font-weight: 600; }

.stage-flow { display: flex; flex-direction: column; gap: var(--space-1); }
.stage { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-inset); }
.stage--warning { border-color: color-mix(in srgb, var(--status-warning) 45%, transparent); }
.stage__index { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-dim); }
.stage__name { font-size: var(--text-sm); font-weight: 600; }
.stage__meta { font-size: var(--text-xs); color: var(--text-dim); font-family: var(--font-mono); }
.stage__arrow { grid-column: 1 / -1; text-align: center; color: var(--text-dim); font-size: var(--text-xs); }

/* -------------------------------------------------------------- timeline */
.timeline { padding-left: var(--space-2); }
.tl { position: relative; display: flex; flex-direction: column; gap: var(--space-4); }
.tl::before { content: ""; position: absolute; left: 66px; top: 6px; bottom: 6px; width: 1px; background: var(--border-strong); }
.tl__item { display: grid; grid-template-columns: 60px 1fr; gap: var(--space-4); align-items: start; position: relative; }
.tl__item::after { content: ""; position: absolute; left: 62px; top: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--status-unknown); border: 2px solid var(--bg-panel); }
.tl__item--healthy::after { background: var(--status-healthy); }
.tl__item--warning::after { background: var(--status-warning); }
.tl__time { font-size: var(--text-xs); color: var(--text-muted); font-family: var(--font-mono); text-align: right; padding-top: 2px; }
.tl__card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); display: flex; flex-direction: column; gap: var(--space-1); }
.tl__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.tl__title { font-size: var(--text-sm); font-weight: 600; }
.tl__meta { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: var(--text-xs); color: var(--text-dim); font-family: var(--font-mono); }

/* ------------------------------------------------------- dependency graph */
.graph { display: flex; flex-direction: column; gap: var(--space-3); }
.graph__toolbar { display: flex; align-items: center; gap: var(--space-2); }
.graph__viewport { position: relative; overflow: hidden; height: 420px; background: var(--bg-inset); border: 1px solid var(--border); border-radius: var(--radius-md); cursor: grab; touch-action: none; }
.graph__viewport.is-panning { cursor: grabbing; }
.graph__canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; display: flex; gap: var(--space-4); padding: var(--space-4); }
.dep-tree { min-width: 230px; background: var(--bg-elevated); border: 1px solid var(--border); border-top: 3px solid var(--status-unknown); border-radius: var(--radius-md); padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.dep-tree--healthy { border-top-color: var(--status-healthy); }
.dep-tree--warning { border-top-color: var(--status-warning); }
.dep-tree__root { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.dep-tree__name { font-size: var(--text-sm); font-weight: 650; }
.dep-tree__children { display: flex; flex-direction: column; gap: 4px; }
.dep-tree__child { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.dep-tree__branch { color: var(--text-dim); font-family: var(--font-mono); }

/* ------------------------------------------------------------- layers etc */
.layers { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-3); }
.layer { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.layer__head { display: flex; align-items: center; gap: var(--space-2); }
.layer__index { font-size: 10.5px; letter-spacing: 0.08em; color: var(--text-dim); font-family: var(--font-mono); }
.layer__name { font-size: var(--text-md); font-weight: 650; flex: 1; }
.layer__items { display: flex; flex-wrap: wrap; gap: 6px; }
.layer__item { font-size: var(--text-xs); padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); }

.modules { display: flex; flex-direction: column; gap: var(--space-3); }
.modules__root { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-3); background: var(--bg-elevated); border: 1px solid var(--border); border-left: 3px solid var(--status-info); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); }
.modules__root-name { font-size: var(--text-md); font-weight: 700; letter-spacing: 0.04em; }
.modules__root-note { font-size: var(--text-xs); color: var(--text-muted); }
.modules__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-2); }
.module { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3); display: flex; flex-direction: column; gap: 2px; }
.module__name { font-size: var(--text-sm); font-weight: 600; }
.module__tag { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

/* --------------------------------------------------------------- summary */
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-5); }
.summary__overall { display: flex; align-items: center; gap: var(--space-3); }
.summary__overall-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.summary__cells { display: flex; flex-wrap: wrap; gap: var(--space-5); }
.summary__cell { display: flex; flex-direction: column; gap: 2px; }
.summary__cell-label { font-size: var(--text-xs); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.summary__cell-value { font-size: var(--text-xl); font-weight: 650; }
.summary__cell-value--healthy { color: var(--status-healthy); }
.summary__cell-value--warning { color: var(--status-warning); }
.summary__cell-value--critical { color: var(--status-critical); }
.summary__cell-value--unknown { color: var(--status-unknown); }

.empty { font-size: var(--text-sm); color: var(--text-dim); }

.page-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-3); max-width: 1520px; margin: 0 auto; padding: 0 var(--space-5) var(--space-6); font-size: var(--text-xs); color: var(--text-dim); }

/* =======================================================================
   RESPONSIVE — desktop first
   Tablet: fewer columns. Mobile (<= 900px): topology becomes a vertical
   flow and every grid collapses to a single column.
   ======================================================================= */
@media (max-width: 1200px) {
  .env-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .layout { padding: var(--space-3); gap: var(--space-4); }
  .topbar { padding: var(--space-3); }
  .topbar__meta { width: 100%; justify-content: space-between; }

  .stat-grid,
  .env-grid,
  .panel-grid,
  .alerts__host,
  .layers,
  .modules__grid { grid-template-columns: 1fr; }

  /* mobile vertical flow: node cards stack in layout order, edges hidden */
  .topology__viewport { height: auto; max-height: none; cursor: default; overflow: visible; background-image: none; }
  .topology__canvas { position: static; transform: none !important; display: flex; flex-direction: column; gap: var(--space-2); width: auto !important; height: auto !important; padding: 0; }
  .topology__edges { display: none; }
  .node-card { position: static !important; width: auto !important; height: auto !important; }
  .topology__toolbar { flex-direction: column; align-items: stretch; }
  .topology__zoomers { display: none; }

  .graph__viewport { height: auto; max-height: 60vh; }
  .graph__canvas { position: static; transform: none !important; flex-direction: column; }

  .tl::before { left: 52px; }
  .tl__item { grid-template-columns: 46px 1fr; gap: var(--space-3); }
  .tl__item::after { left: 48px; }

  .detail-mount.is-open { width: 100vw; }
}

/* =======================================================================
   ERP ID — reference points for ordering an edit
   Every point of the dashboard carries a short id (SEC-02, NODE-11,
   ROW-PNL-05-02, …). Click a badge to highlight the element it belongs to.
   ======================================================================= */
.erp-id {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: color-mix(in srgb, var(--bg-inset) 80%, transparent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  cursor: pointer;
  white-space: nowrap;
}
.erp-id:hover { color: var(--text); border-color: var(--status-info); }
.erp-id.is-plain { cursor: default; }
.erp-id.is-empty { opacity: 0.4; }

body.ids-hidden .erp-id { display: none; }

.is-highlighted {
  outline: 2px solid var(--status-info);
  outline-offset: 2px;
  animation: erp-pulse 1.3s ease-in-out 2;
}
@keyframes erp-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 158, 255, 0); }
  50% { box-shadow: 0 0 0 7px rgba(74, 158, 255, 0.22); }
}

.section__id { margin-top: var(--space-1); }
.stat-card__id { margin-top: calc(-1 * var(--space-1)); }
.layer__id, .dep-tree__id { margin-top: var(--space-1); }

.def-row__label { display: inline-flex; align-items: center; gap: 6px; }
.panel__title, .alert__title, .tl__title, .stage__name, .node-card__name {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.detail__conn { flex-wrap: wrap; }

.id-jump { display: flex; gap: 6px; align-items: center; }
.input--id { width: 118px; min-width: 118px; font-family: var(--font-mono); text-transform: uppercase; }
.topbar__field-hint { font-size: 10.5px; color: var(--text-dim); }
.topbar__field-hint.is-error { color: var(--status-critical); }

@media (max-width: 900px) {
  .topbar__field--id { width: 100%; }
  .input--id { width: 100%; min-width: 0; }
}
