.portal-overview-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.portal-overview-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.portal-overview-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.portal-overview-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.portal-overview-card-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
}

.portal-generation-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 12px;
}

.portal-generation-tab {
  border: 1px solid var(--brand-primary);
  background: #fff;
  color: var(--brand-primary);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.portal-generation-tab.active {
  background: var(--brand-primary);
  color: #fff;
}

.portal-generation-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg2);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.portal-generation-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text2);
}

.portal-generation-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand-primary);
}

.portal-generation-chart .detail-chart-canvas,
.portal-generation-chart .detail-chart-canvas.portal-generation-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 480 / 200;
  min-height: 260px;
}

.portal-generation-chart .detail-chart-stage {
  padding-top: 56px;
  margin-top: -40px;
}

.portal-generation-chart .detail-chart-svg {
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
}

.portal-generation-chart .chart-grid-line,
.portal-generation-chart .chart-axis-line {
  shape-rendering: geometricPrecision;
  vector-effect: non-scaling-stroke;
}

.portal-generation-chart .chart-line-main,
.portal-generation-chart .chart-line-glow {
  shape-rendering: geometricPrecision;
}

.portal-generation-chart .chart-bar {
  shape-rendering: geometricPrecision;
}

.portal-generation-chart .chart-y-label {
  font-size: 9px;
}

.portal-generation-chart .chart-axis-label {
  font-size: 9px;
}

.portal-generation-chart .chart-line-main {
  stroke-width: 2;
}

.portal-generation-chart .chart-line-glow {
  stroke-width: 3.5;
  opacity: 0.22;
}

.portal-generation-chart .chart-line-reveal-clip-rect {
  width: 0;
  animation: chart-line-reveal 1.05s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes chart-line-reveal {
  to {
    width: 416px;
  }
}

.portal-generation-chart .chart-bar {
  transform-box: fill-box;
  transform-origin: bottom center;
  animation: chart-bar-rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--bar-i, 0) * 38ms);
  opacity: 0.92;
  transition: opacity 0.15s ease;
}

@keyframes chart-bar-rise {
  from {
    transform: scaleY(0);
    opacity: 0.35;
  }

  to {
    transform: scaleY(1);
    opacity: 0.92;
  }
}

.portal-generation-chart .detail-chart-canvas:hover .chart-bar {
  opacity: 1;
}

.chart-hover-halo-generation {
  fill: #ff0c0c;
}

.chart-hover-dot-generation {
  stroke: #ff0c0c;
}

.chart-tooltip-generation {
  border-top: 3px solid var(--brand-primary);
}

.portal-generation-date {
  border: 1px solid var(--brand-primary);
  color: var(--brand-primary);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}

/* Generation period picker (day / month / year) */
.gen-period-picker {
  position: relative;
  flex-shrink: 0;
}

.gen-period-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 180px;
  padding: 7px 12px 7px 10px;
  border: 1px solid rgba(255, 12, 12, 0.38);
  border-radius: 999px;
  background: #fff;
  color: var(--brand-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  font-family: inherit;
  line-height: 1.2;
}

.gen-period-trigger:hover {
  border-color: var(--brand-primary);
  background: var(--brand-primary-bg);
  box-shadow: 0 2px 8px rgba(255, 12, 12, 0.08);
}

.gen-period-trigger-icon,
.gen-period-trigger-chevron {
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--brand-primary);
}

.gen-period-trigger-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gen-period-trigger-chevron {
  transition: transform 0.15s ease;
}

.gen-period-trigger-chevron.is-open {
  transform: rotate(180deg);
}

.gen-period-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(16, 16, 16, 0.18);
}

.gen-period-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 121;
  width: min(320px, calc(100vw - 32px));
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 12px 40px rgba(16, 16, 16, 0.14);
}

.gen-period-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.gen-period-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-black);
}

.gen-period-panel-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text2);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.gen-period-panel-close:hover {
  background: var(--brand-primary-bg);
  color: var(--brand-primary);
}

.gen-period-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.gen-period-nav-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-primary);
  text-align: center;
  flex: 1;
}

.gen-period-nav-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--brand-primary-border);
  border-radius: 10px;
  background: #fff;
  color: var(--brand-primary);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.gen-period-nav-btn:hover:not(:disabled) {
  background: var(--brand-primary-bg);
  border-color: var(--brand-primary);
}

.gen-period-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.gen-period-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}

.gen-period-weekdays span {
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gen-period-day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.gen-period-month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.gen-period-year-scroll {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 2px;
}

.gen-period-year-scroll::-webkit-scrollbar {
  width: 6px;
}

.gen-period-year-scroll::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 999px;
}

.gen-period-cell {
  min-height: 34px;
  border: 1px solid var(--brand-primary-border);
  border-radius: 10px;
  background: #fff;
  color: var(--brand-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  font-family: inherit;
  padding: 6px 4px;
}

.gen-period-day-grid .gen-period-cell {
  min-height: 32px;
  border-radius: 8px;
  font-size: 11px;
}

.gen-period-cell:hover:not(:disabled):not(.is-selected) {
  background: var(--brand-primary-bg);
  border-color: var(--brand-primary);
}

.gen-period-cell.is-selected {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}

.gen-period-cell.is-today:not(.is-selected) {
  border-color: var(--brand-primary);
  font-weight: 700;
}

.gen-period-cell.is-outside {
  opacity: 0.35;
}

.gen-period-cell:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.gen-period-month-cell {
  min-height: 40px;
}

.gen-period-year-cell {
  min-height: 38px;
}

@media (max-width: 720px) {
  .gen-period-panel {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    width: min(320px, calc(100vw - 24px));
  }

  .gen-period-trigger {
    max-width: 150px;
  }
}

.portal-realtime-body {
  margin-top: 4px;
}

.portal-realtime-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 20px;
  align-items: stretch;
}

.portal-realtime-diagram-wrap {
  min-height: 440px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #fff 0%, #f6f6f6 100%);
  padding: 8px 2px 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
}

.portal-realtime-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 440px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: #f6f6f6;
  overflow: hidden;
}

.portal-realtime-sidebar-head {
  padding: 12px 14px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand-black);
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.portal-realtime-sidebar-list {
  flex: 1;
  overflow: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.portal-realtime-metric-card {
  padding: 11px 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
}

.portal-realtime-metric-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-black);
  font-family: 'IBM Plex Mono', monospace;
  line-height: 1.2;
}

.portal-realtime-metric-label {
  margin-top: 3px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text3);
  line-height: 1.35;
}

.portal-realtime-loading {
  flex-direction: column;
  gap: 12px;
}

.portal-realtime-loading-ring {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--brand-primary-bg);
  border-top-color: var(--brand-primary);
  animation: portal-realtime-spin 0.8s linear infinite;
}

@keyframes portal-realtime-spin {
  to { transform: rotate(360deg); }
}

.portal-realtime-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.portal-realtime-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text3);
  font-weight: 500;
}

.portal-realtime-legend-dot {
  width: 20px;
  height: 3px;
  border-radius: 999px;
  background: var(--border2);
}

.portal-realtime-legend-dot.animated {
  background: linear-gradient(90deg, rgba(255, 12, 12, 0.2) 0%, var(--brand-primary) 50%, rgba(255, 12, 12, 0.2) 100%);
  background-size: 200% 100%;
  animation: portal-flow-pulse 1.8s ease-in-out infinite;
}

.portal-realtime-legend-dot.static {
  background: repeating-linear-gradient(
    90deg,
    var(--brand-black) 0,
    var(--brand-black) 3px,
    transparent 3px,
    transparent 7px
  );
  opacity: 0.35;
}

@keyframes portal-flow-pulse {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.energy-flow-diagram {
  position: relative;
  width: min(98%, 640px);
  height: auto;
  min-height: 0;
  max-width: 640px;
  margin: 0 auto;
  aspect-ratio: 420 / 380;
  container-type: size;
  background: transparent;
  border: none;
  box-shadow: none;
  overflow: visible;
}

/* Soft glow — fades to transparent so no box edges show against the wrap */
.energy-flow-diagram::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 76% 62% at 50% 38%, rgba(255, 12, 12, 0.07) 0%, rgba(255, 12, 12, 0.02) 42%, transparent 72%),
    radial-gradient(ellipse 82% 68% at 50% 44%, rgba(255, 255, 255, 0.82) 0%, transparent 74%),
    radial-gradient(ellipse 88% 38% at 50% 92%, rgba(16, 16, 16, 0.045) 0%, transparent 62%);
}

.energy-flow-svg,
.energy-flow-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

.energy-flow-canvas {
  pointer-events: none;
  z-index: 2;
}

.energy-flow-path-base {
  fill: none;
  stroke: transparent;
  stroke-width: 0;
  pointer-events: none;
}

.energy-flow-nodes {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.energy-node-tap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: inherit;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  font-family: inherit;
  color: inherit;
  border-radius: 12px;
  transition: transform 0.15s ease;
}

.energy-node-tap:hover {
  transform: scale(1.03);
}

.energy-node-tap:focus-visible {
  outline: 2px solid rgba(255, 12, 12, 0.45);
  outline-offset: 3px;
}

.energy-node {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.3cqh, 9px);
  width: max-content;
}

.energy-node-top {
  left: 50%;
  top: 0;
  transform: translateX(-50%);
}

.energy-node-center {
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
}

.energy-node-load {
  left: 16%;
  top: 73%;
  transform: translate(-50%, 0);
}

.energy-node-grid {
  left: 50%;
  top: 73%;
  transform: translate(-50%, 0);
}

.energy-node-battery {
  left: 86.8%;
  top: 73%;
  transform: translate(-50%, 0);
}

.energy-node-icon-wrap {
  width: 62px;
  height: 62px;
  width: 13.5cqh;
  height: 13.5cqh;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(16, 16, 16, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8%;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  flex-shrink: 0;
}

.energy-node-icon-wrap-lg {
  width: 74px;
  height: 74px;
  width: 16cqh;
  height: 16cqh;
  border-radius: 18px;
  border: 2px solid var(--brand-black);
  background: linear-gradient(180deg, #fff 0%, #fafafa 100%);
  box-shadow: 0 4px 14px rgba(16, 16, 16, 0.09);
  position: relative;
  z-index: 1;
}

.energy-node.is-active .energy-node-icon-wrap {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(255, 12, 12, 0.1), 0 2px 8px rgba(16, 16, 16, 0.06);
}

.energy-node.is-hub .energy-node-icon-wrap {
  border-color: var(--brand-black);
  box-shadow: 0 4px 16px rgba(16, 16, 16, 0.1);
}

.energy-node-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.energy-node-img-lg {
  transform: scale(1.04);
}

.energy-node-tag {
  font-size: clamp(9px, 2.4cqh, 11px);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text3);
  line-height: 1.2;
  margin-top: clamp(1px, 0.25cqh, 3px);
}

.energy-node.is-active .energy-node-tag {
  color: var(--brand-primary);
}

.energy-node.is-hub .energy-node-tag {
  color: var(--brand-black);
  font-weight: 700;
}

.energy-node .energy-flow-metric {
  position: static;
  transform: none;
  text-align: center;
  width: max-content;
  min-width: 0;
  max-width: min(140px, 34cqh);
  padding: 6px 12px;
  padding: 0.9cqh 1.8cqh;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(16, 16, 16, 0.05);
}

.energy-node .energy-flow-metric.is-live {
  border-color: var(--brand-primary-border);
  background: var(--brand-primary-bg);
}

.energy-flow-metric-value {
  font-size: clamp(10px, 2.8cqh, 13px);
  font-weight: 700;
  color: var(--brand-black);
  font-family: 'IBM Plex Mono', monospace;
  line-height: 1.25;
  white-space: nowrap;
}

.energy-flow-metric-label {
  margin-top: 2px;
  font-size: clamp(8px, 2.1cqh, 10px);
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.2;
}

.energy-node-top .energy-flow-metric {
  margin-bottom: clamp(4px, 0.8cqh, 7px);
}

.energy-node-solar-body {
  position: relative;
  width: 13.5cqh;
  height: 13.5cqh;
  flex-shrink: 0;
}

.energy-node-solar .energy-node-tag {
  position: absolute;
  left: calc(100% + clamp(6px, 1.4cqh, 10px));
  top: 50%;
  transform: translateY(-50%);
  display: block;
  margin: 0;
  white-space: nowrap;
}

.energy-node-bottom .energy-flow-metric {
  margin-top: clamp(3px, 0.6cqh, 6px);
}

.portal-production-card {
  overflow: hidden;
}

.portal-production-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.portal-production-badge {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--brand-primary-bg);
  border: 1px solid var(--brand-primary-border);
  color: var(--brand-primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.portal-production-loading {
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
}

.portal-production-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.portal-production-tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 92px;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(145deg, #fff 0%, #fafafa 100%);
  box-shadow: 0 1px 3px rgba(16, 16, 16, 0.04);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  overflow: hidden;
}

.portal-production-tile::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  border-radius: 16px 0 0 16px;
  background: var(--brand-primary);
  opacity: 0.85;
}

.portal-production-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(255, 12, 12, 0.08);
  border-color: var(--brand-primary-border);
}

.portal-production-tile-icon {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 15px;
  background: #fff;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.portal-production-tile-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.portal-production-tile-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.portal-production-tile-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.03em;
  line-height: 1.25;
}

.portal-production-tile-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--brand-black);
  font-family: 'IBM Plex Mono', monospace;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-production-tile-solar::before {
  background: linear-gradient(180deg, #ff4d4d 0%, var(--brand-primary) 100%);
}

.portal-production-tile-solar .portal-production-tile-icon {
  background: var(--brand-primary-bg);
  border-color: var(--brand-primary-border);
}

.portal-production-tile-grid::before {
  background: linear-gradient(180deg, #4a4a4a 0%, var(--brand-black) 100%);
}

.portal-production-tile-grid .portal-production-tile-icon {
  background: #f5f5f5;
}

.portal-production-tile-battery::before {
  background: linear-gradient(180deg, #ff6b6b 0%, #c90909 100%);
}

.portal-production-tile-battery .portal-production-tile-icon {
  background: var(--brand-primary-bg);
  border-color: var(--brand-primary-border);
}

.portal-production-tile-load::before {
  background: linear-gradient(180deg, #333 0%, var(--brand-black) 100%);
}

.portal-production-tile-load .portal-production-tile-icon {
  background: #f8f8f8;
}

.portal-overview-loading {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  font-size: 13px;
}

@media (max-width: 960px) {
  .portal-realtime-layout {
    grid-template-columns: 1fr;
  }

  .portal-realtime-sidebar {
    min-height: auto;
    max-height: 280px;
  }
}

@media (max-width: 720px) {
  .energy-flow-diagram {
    width: min(96%, 100%);
    max-width: 100%;
    min-height: 0;
    aspect-ratio: 420 / 380;
  }

  .energy-node .energy-flow-metric {
    max-width: 110px;
    padding: 5px 10px;
  }

  .energy-flow-metric-value {
    font-size: 11px;
  }

  .portal-production-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .portal-production-tile {
    min-height: 84px;
    padding: 14px;
  }

  .portal-production-tile-value {
    font-size: 15px;
  }
}
