/* ============================================================
   Solar Monitor Design System � plant.php (dashboard)
   RMUTL โครงการวิจัยไมโครกริดบ้านคลองเรือ � Solar(GCI+SCC) + Wind + Grid + Battery
   ============================================================ */
:root {
  --bg-main: #f5f5f0;
  --bg-card: #ffffff;
  --bg-panel: #fafaf7;
  --bg-hover: #f5f5f0;
  --border-default: #e8e6df;
  --border-hover: #ccc;
  --text-primary: #1a1a1a;
  --text-secondary: #888;
  --text-tertiary: #aaa;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --purple: #8b5cf6;
  --orange: #ea580c;
  --cyan: #06b6d4;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font-sans: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "DM Mono", ui-monospace, monospace;

  /* Device Colors */
  --solar: var(--warning);
  --grid: var(--info);
  --batt: var(--purple);
  --load: #1a1a1a;
  --gen: var(--orange);
}

* {
  box-sizing: border-box;
}

::-webkit-scrollbar {
  display: none;
}

html,
body {
  margin: 0;
  padding: 0;
  scrollbar-width: none;
  /* Firefox */
  -ms-overflow-style: none;
  /* IE and Edge */
}

body {
  font-family: var(--font-sans);
  background: var(--bg-main);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.5;
  padding: 0;
  margin: 0;
  min-height: 100vh;
}

.mono {
  font-family: var(--font-mono);
  font-feature-settings:
    "tnum" 1,
    "zero" 1;
}

/* ---------- LAYOUT ---------- */
.dash {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

.flow-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- CARD ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 0;
  margin: 0;
}

.card-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin: 0 0 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

/* ---------- KPI STRIP ---------- */
.kpi-strip {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.kpi-strip.has-wind-kpi {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}

.kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.kpi-icon {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  margin-top: 4px;
  letter-spacing: -0.5px;
}

.kpi-unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 4px;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.kpi-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--border-default);
}

.kpi-bar-fill {
  height: 100%;
  transition: width 0.6s ease;
}

/* Color accents */
.c-solar {
  color: var(--warning);
}

.c-grid {
  color: var(--info);
}

.c-batt {
  color: var(--purple);
}

.c-load {
  color: var(--text-primary);
}

.c-wind {
  color: var(--cyan);
}

.c-primary {
  color: var(--info);
}

.bg-solar {
  background: var(--warning);
}

.bg-grid {
  background: var(--info);
}

.bg-batt {
  background: var(--purple);
}

.bg-load {
  background: #1a1a1a;
}

.bg-wind {
  background: var(--cyan);
}

.bg-primary {
  background: var(--info);
}

/* Wind PM summary embedded in the Plant page. */
.plant-wind-card {
  overflow: hidden;
}

.plant-wind-card .wind-card-head {
  margin-bottom: 4px;
}

.plant-wind-card .wind-total-grid {
  margin-top: 8px;
}

.plant-wind-card .wind-phase-scroll {
  overflow-x: hidden;
}

.plant-wind-card .wind-phase-table {
  min-width: 0;
}

.plant-wind-card .wind-phase-table th,
.plant-wind-card .wind-phase-table td {
  padding-left: 6px;
  padding-right: 6px;
}

.plant-wind-card .wind-phase-table th:first-child,
.plant-wind-card .wind-phase-table td:first-child {
  padding-left: 8px;
}

/* ---------- POWER FLOW DIAGRAM ---------- */
.flow-wrap {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 0;
  margin-top: 0;
  min-height: 120px;
}

.flow-wrap svg {
  width: 82%;
  height: auto;
  display: block;
  margin: 0 auto;
}

@keyframes pfblink {
  0%,
  100% {
    opacity: 0.2;
  }

  50% {
    opacity: 1;
  }
}

.flow-dot {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: pfblink 1.2s infinite;
}

.flow-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.flow-dot:nth-child(3) {
  animation-delay: 0.4s;
}

.mpf-card {
  background: #fff;
  border: 1px solid var(--border-default);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.mpf-ic {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  font-weight: 500;
}

.mpf-body {
  flex: 1;
  min-width: 0;
}

.mpf-l {
  font-size: 9px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.2px;
  line-height: 1.2;
  word-break: break-word;
}

.mpf-v {
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  margin-top: 1px;
}

.mpf-sub {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 1px;
  line-height: 1.2;
  word-break: break-word;
}

.mpf-arr {
  text-align: center;
  margin: 3px 0;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ---------- METRIC ROWS ---------- */
.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-box {
  background: var(--bg-panel);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.metric-box .lbl {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.metric-box .val {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  margin-top: 2px;
}

.metric-box .val .u {
  font-size: 11px;
  color: var(--text-secondary);
  margin-left: 2px;
  font-weight: 500;
}

.plant-pv-highlight {
  background: #fffbeb;
  border: 1px solid #fde68a;
  box-shadow: inset 3px 0 0 #f59e0b;
}

.plant-pv-highlight .lbl {
  color: var(--text-secondary);
}

.plant-pv-highlight .val {
  color: var(--warning);
  font-weight: 700;
}

.plant-pv-highlight .val .u {
  color: var(--text-secondary);
}

/* ---------- LFS Maldives generator card ---------- */
.lfs-generator-card {
  padding: 16px;
}

.lfs-generator-list {
  display: grid;
  gap: 8px;
}

.lfs-generator-row {
  background: var(--bg-panel);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.lfs-generator-row-head,
.lfs-generator-row-values {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.lfs-generator-name {
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
}

.lfs-generator-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 13px;
}

.lfs-generator-status.is-running {
  padding: 5px 10px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--info);
}

.lfs-generator-status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: #aaa;
}

.lfs-generator-status.is-running .lfs-generator-status-dot {
  background: var(--info);
}

.lfs-generator-row-state,
.lfs-generator-power-label {
  color: var(--text-secondary);
  font-size: 13px;
}

.lfs-generator-row-state {
  margin-top: 4px;
}

.lfs-generator-row-values {
  align-items: flex-end;
  margin-top: 12px;
}

.lfs-generator-electrical {
  display: flex;
  gap: 24px;
  color: var(--text-primary);
  font-size: 14px;
}

.lfs-generator-power {
  text-align: right;
}

.lfs-generator-power-value {
  margin-top: 2px;
  color: #284db7;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.lfs-generator-power-value .u {
  color: #284db7;
  font-size: 13px;
  font-weight: 600;
}

/* 3-phase table */
.phase-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
}

.phase-table th {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
  text-align: right;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-default);
}

.phase-table th:first-child {
  text-align: left;
}

.phase-table td {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px;
  text-align: right;
  border-bottom: 1px solid var(--border-default);
}

.phase-table td:first-child {
  font-family: var(--font-sans);
  text-align: left;
  font-weight: 500;
  color: var(--text-primary);
  font-size: 12px;
}

.phase-table tr:last-child td {
  border-bottom: none;
}

.phase-chip {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}

/* ---------- STATUS PILL / BADGE ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.pill-ok {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
}

.pill-warn {
  background: rgba(245, 158, 11, 0.12);
  color: var(--warning);
}

.pill-err {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.pill-neutral {
  background: var(--bg-panel);
  color: var(--text-secondary);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.dot-ok {
  background: var(--success);
}

.dot-warn {
  background: var(--warning);
}

.dot-err {
  background: var(--danger);
}

.dot-off {
  background: var(--text-tertiary);
}

/* Weather tiles */
.weather-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.weather-grid > :last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.w-tile {
  background: var(--bg-panel);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.w-tile .l {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.w-tile .r {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
}

/* Battery cell */
.batt-vis {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.batt-scale {
  display: flex;
  justify-content: space-between;
  padding: 0 8px;
  margin: 8px 0 2px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 500;
}

.batt-shell {
  flex: 1;
  height: 28px;
  border: 2px solid var(--text-primary);
  border-radius: 6px;
  position: relative;
  padding: 3px;
  overflow: hidden;
}

.batt-shell::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 8px;
  width: 4px;
  height: 12px;
  background: var(--text-primary);
  border-radius: 0 2px 2px 0;
}

.batt-fill {
  height: 100%;
  border-radius: 3px;
  transition:
    width 0.6s ease,
    background 0.3s;
}

.batt-pct {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  min-width: 54px;
  text-align: right;
}

.battery-storage-card {
  padding: 16px;
}

.battery-summary-metrics {
  margin-top: 16px;
}

.battery-status-row {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

.battery-node-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-default);
}

.battery-node-metric {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text-secondary);
  font-size: 11px;
}

@media (max-width: 640px) {
  .battery-node-list {
    grid-template-columns: 1fr;
  }
}

/* Solar irradiance meter */
.irrad-meter {
  position: relative;
  height: 10px;
  background: var(--bg-panel);
  border-radius: 5px;
  overflow: hidden;
  margin-top: 4px;
}

.irrad-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--warning) 0%, #f97316 100%);
  border-radius: 5px;
  transition: width 0.6s ease;
}

/* footer timestamp */
.stamp {
  font-size: 11px;
  color: var(--text-tertiary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  margin-top: 4px;
}

.stamp .live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--success);
  font-weight: 500;
}

.stamp .live::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.4;
    transform: scale(0.8);
  }
}

/* loading skeleton */
.loading .kpi-value,
.loading .metric-box .val,
.loading .v,
.loading .r,
.loading .batt-pct {
  color: transparent;
  background: var(--bg-panel);
  border-radius: 4px;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1024px) {
  .dash {
    grid-template-columns: 1fr;
  }

  .kpi-strip {
    grid-template-columns: repeat(4, 1fr);
  }

  #energy-strip.has-wind-kpi {
    grid-template-columns: repeat(4, 1fr);
  }

  .kpi-strip.has-wind-kpi {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 768px) {
  body {
    padding: 12px;
  }

  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpi-value {
    font-size: 24px;
  }
}

@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .dash {
    gap: 10px;
  }

  .col {
    gap: 10px;
  }

  .card {
    padding: 12px;
    border-radius: 10px;
  }

  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .kpi {
    padding: 10px 12px;
  }

  .kpi-value {
    font-size: 20px;
  }

  .kpi-label {
    font-size: 10px;
  }

  .kpi-sub {
    font-size: 10px;
  }

  .phase-table th,
  .phase-table td {
    padding: 6px 4px;
    font-size: 11px;
  }

  .phase-table th:nth-child(5),
  .phase-table td:nth-child(5) {
    display: none;
  }

  .metric-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .metric-box {
    padding: 8px 10px;
  }

  .metric-box .val {
    font-size: 14px;
  }

  .metric-box .lbl {
    font-size: 9px;
  }

  .weather-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .batt-shell {
    height: 24px;
  }

  .batt-pct {
    font-size: 13px;
    min-width: 44px;
  }

  .flow-wrap {
    padding: 0;
  }

  .flow-wrap svg {
    width: 100%;
  }

  .card-title {
    font-size: 10px;
  }

  .stamp {
    flex-wrap: wrap;
    gap: 6px;
    font-size: 10px;
  }
}

@media (max-width: 380px) {
  body {
    padding: 8px;
  }

  .card {
    padding: 10px;
  }

  .kpi-value {
    font-size: 18px;
  }

  .kpi-unit {
    font-size: 11px;
  }

  .phase-table th:nth-child(2),
  .phase-table td:nth-child(2) {
    display: none;
  }

  .metric-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (hover: none) {
  .card:hover {
    transform: none;
  }
}

/* ---------- GENERATOR CARD ---------- */
.gen-row {
  background: var(--bg-panel);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.gen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.gen-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.gen-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.gen-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gen-item .lbl {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.gen-item .val {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.gen-item .mono {
  font-weight: 600;
  color: var(--text-primary);
}

.gen-item .u {
  font-size: 11px;
  color: var(--text-secondary);
  margin-left: 2px;
  font-weight: 500;
}

/* ---------- BDI MODULE ---------- */
.bdi-module {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.bdi-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bdi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}

.bdi-overall-card {
  padding: 16px;
}

.bdi-section-heading,
.bdi-node-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bdi-heading-main {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--purple);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.bdi-heading-dot,
.bdi-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}

.bdi-heading-dot { background: var(--purple); }

.bdi-node-count {
  color: var(--text-secondary);
  font-size: 11px;
}

.bdi-overall-main {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 0 16px;
}

.bdi-soc-ring {
  position: relative;
  width: 100px;
  height: 100px;
  flex: 0 0 100px;
}

.bdi-soc-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.bdi-soc-track,
.bdi-soc-progress {
  fill: none;
  stroke-width: 8;
}

.bdi-soc-track { stroke: #e8e6df; }

.bdi-soc-progress {
  stroke: var(--purple);
  stroke-linecap: round;
  stroke-dasharray: 263.9;
  stroke-dashoffset: calc(263.9 - (263.9 * var(--bdi-soc) / 100));
  transition: stroke-dashoffset 0.6s ease;
}

.bdi-soc-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--purple);
  font-size: 22px;
  font-weight: 700;
}

.bdi-soc-value span { font-size: 12px; margin-left: 2px; }

.bdi-overall-copy { display: flex; flex-direction: column; gap: 5px; }

.bdi-status-title {
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
}

.bdi-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.bdi-status-pill.is-charging { color: #16a34a; background: #ecfdf3; }
.bdi-status-pill.is-charging .bdi-status-dot { background: #22c55e; }
.bdi-status-pill.is-discharging { color: var(--purple); background: #f3efff; }
.bdi-status-pill.is-discharging .bdi-status-dot { background: var(--purple); }
.bdi-status-pill.is-idle { color: var(--text-secondary); background: var(--bg-panel); }
.bdi-status-pill.is-idle .bdi-status-dot { background: #aaa; }

.bdi-summary-line {
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 3px;
}

.bdi-summary-line strong { color: var(--text-primary); margin-left: 4px; }

.bdi-summary-metrics,
.bdi-dc-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.bdi-metric-box,
.bdi-dc-metrics > div {
  background: var(--bg-panel);
  border-radius: var(--radius-md);
  padding: 11px 12px;
}

.bdi-metric-label,
.bdi-dc-metrics span {
  display: block;
  color: var(--text-secondary);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.bdi-metric-box strong,
.bdi-dc-metrics strong {
  color: var(--text-primary);
  font-size: 17px;
}

.bdi-metric-box small,
.bdi-dc-metrics small { color: var(--text-secondary); font-size: 10px; font-family: var(--font-sans); }

.bdi-node-section {
  border: 2px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: rgba(255, 255, 255, 0.55);
}

.bdi-energy-section {
  border: 2px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: rgba(255, 255, 255, 0.55);
  width: 100%;
}

.bdi-heading-dot-green { background: var(--success); }

.bdi-node-heading {
  padding: 2px 2px 12px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--purple);
  color: var(--purple);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
}

.bdi-node-heading > div { display: flex; align-items: center; gap: 7px; }

.bdi-node-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--purple);
  background: #eee9ff;
  font-size: 15px;
}

.bdi-node-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.bdi-detail-card { min-width: 0; }
.bdi-energy-card { grid-column: 1 / -1; }

.bdi-card-title {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 12px;
}

.bdi-title-bar {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--purple);
}

.bdi-title-bar.bdi-blue { background: var(--info); }
.bdi-title-bar.bdi-green { background: var(--success); }

.bdi-table-scroll { overflow-x: auto; }

.bdi-phase-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 11px;
}

.bdi-phase-table th {
  color: var(--text-secondary);
  font-weight: 500;
  padding: 7px 6px;
  border-bottom: 1px solid var(--border-default);
}

.bdi-phase-table td {
  color: var(--text-primary);
  padding: 9px 6px;
  border-bottom: 1px solid #f0efe9;
  white-space: nowrap;
}

.bdi-phase-table th:first-child,
.bdi-phase-table td:first-child { text-align: left; }

.bdi-single-phase-table { text-align: center; }
.bdi-single-phase-table th,
.bdi-single-phase-table td,
.bdi-single-phase-table th:first-child,
.bdi-single-phase-table td:first-child {
  text-align: center;
}
.bdi-empty-row td {
  border-bottom: none;
}
.bdi-single-phase-table tbody tr:first-child td,
.bdi-single-phase-table tbody tr:not(.bdi-empty-row) td {
  border-bottom: 1px solid #f0efe9;
}

.bdi-phase-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 2px;
}

.bdi-phase-dot.phase-1 { background: #ef4444; }
.bdi-phase-dot.phase-2 { background: #f59e0b; }
.bdi-phase-dot.phase-3 { background: #3b82f6; }

.bdi-dc-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.bdi-energy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.bdi-energy-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bdi-energy-heading {
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.bdi-energy-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bdi-energy-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  overflow: visible;
}

.bdi-energy-group > span {
  grid-column: 1 / -1;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
}

.bdi-energy-group > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  overflow: visible;
}

.bdi-energy-group label {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.2;
}

.bdi-energy-group strong {
  display: inline-block;
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.15;
  font-weight: 700;
  white-space: nowrap;
}

.bdi-energy-group small {
  color: var(--text-secondary);
  font-size: 11px;
  font-family: var(--font-sans);
}

.bdi-empty-state { text-align: center; padding: 56px 20px; }
.bdi-empty-icon { color: var(--purple); font-size: 30px; margin-bottom: 8px; }
.bdi-empty-state p { color: var(--text-secondary); margin: 5px 0 0; }

@media (max-width: 800px) {
  .bdi-node-grid,
  .bdi-energy-grid { grid-template-columns: 1fr; }
  .bdi-energy-card { grid-column: auto; }
}

@media (max-width: 560px) {
  .bdi-overall-card { padding: 14px; }
  .bdi-overall-main { gap: 14px; }
  .bdi-soc-ring { width: 92px; height: 92px; flex-basis: 92px; }
  .bdi-soc-value { font-size: 19px; }
  .bdi-summary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bdi-energy-group { grid-template-columns: 1fr; }
  .bdi-energy-group > span { grid-column: auto; }
}

/* LEN PeakSaving uses its original standalone one-page Plant UI. */
.len-peaksaving-onepage-frame {
  display: block;
  width: 100%;
  min-height: 2200px;
  border: 0;
  background: #0f172a;
}

/* BCP_BKK2 uses its original standalone Plant UI, like LEN PeakSaving. */
.bcp-bkk2-legacy-plant-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 165px);
  min-height: 900px;
  border: 0;
  background: #f5f5f0;
}

/* Original BCP_BKK2 pages are opened only after their navigation item is
   selected. Keep their viewport independent from the SPA card spacing. */
.bcp-bkk2-legacy-page-pane {
  margin: -16px -24px -40px;
  min-height: calc(100vh - 165px);
  background: #f5f5f0;
}

.bcp-bkk2-legacy-page-pane iframe {
  display: block;
  width: 100%;
  height: calc(100vh - 165px);
  min-height: 760px;
  border: 0;
  background: #f5f5f0;
}

/* The 3D legacy page is a viewport-sized scene. Do not apply the minimum
   height used by the data/report pages, otherwise the scene gets both axes of
   scrolling on shorter screens. */
.bcp-bkk2-3d-layout-pane {
  height: calc(100vh - 165px);
  min-height: 0;
  max-height: calc(100vh - 165px);
  overflow: hidden;
}

.bcp-bkk2-3d-layout-pane iframe {
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

@media (max-width: 768px) {
  .bcp-bkk2-legacy-page-pane { margin: -12px -12px -30px; }
  .bcp-bkk2-legacy-page-pane iframe {
    height: calc(100vh - 145px);
    min-height: 680px;
  }

  .bcp-bkk2-3d-layout-pane {
    height: calc(100vh - 145px);
    max-height: calc(100vh - 145px);
  }

  .bcp-bkk2-3d-layout-pane iframe {
    height: 100%;
    min-height: 0;
  }
}
