/* Keep content in normal flow: card contents must never shrink into each other. */
html { min-width: 320px; }
body { overflow: auto; }
#app { width: 100%; min-width: 0; height: auto; min-height: 100dvh; padding: 0 clamp(12px, 1.5vw, 28px); }
.app-header { min-height: 86px; height: auto; flex: 0 0 auto; padding: 16px 0; gap: 20px; }
.brand, .header-status { min-width: 0; flex-shrink: 0; }
.project-title { min-width: 0; margin-left: 0; }
.project-title h1 { font-size: clamp(18px, 1.5vw, 28px); line-height: 1.5; letter-spacing: 1px; overflow-wrap: anywhere; }
.main-nav { min-height: 52px; flex: 0 0 auto; margin-bottom: 16px; }
.nav-tabs { min-height: 52px; }
.nav-tab { min-height: 48px; white-space: nowrap; }
.dashboard { flex: 0 0 auto; min-height: 0; grid-template-columns: clamp(240px, 18vw, 300px) minmax(0, 1fr) clamp(260px, 19vw, 316px); gap: 16px; align-items: start; }
.left-column, .right-column { min-width: 0; min-height: 0; gap: 12px; overflow: visible; }
.panel { min-width: 0; }
.panel-heading, .right-column .panel-heading { min-height: 46px; height: auto; flex-shrink: 0; padding: 12px 16px; gap: 12px; }
.panel-heading h2 { font-size: 13px; line-height: 1.5; }
.panel-heading > span { font-size: 8px; letter-spacing: .7px; flex-shrink: 0; }
.energy-panel { min-height: 0; flex: 0 0 auto; }
.energy-card { flex: 0 0 auto; min-height: 106px; padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; }
.energy-card-top { font-size: 12px; line-height: 1.5; gap: 8px; }
.energy-card-top .equipment-icon { flex-shrink: 0; }
.energy-card-top .equipment-icon { width: 24px; height: 24px; }
.energy-card-top > span:not(.equipment-icon) { min-width: 0; }
.card-arrow { flex-shrink: 0; }
.power-value { margin: 0; gap: 8px; }
.power-value strong { font-size: 34px; line-height: 1.1; }
.card-bottom { margin: 0; gap: 8px; min-height: 18px; white-space: normal; font-size: 10px; line-height: 1.4; }
.card-bottom > span:first-child { flex-shrink: 0; }
.mini-spark { flex: 0 1 90px; min-width: 44px; height: 18px; margin: 0; }
.renewable-panel { flex: 0 0 auto; min-height: 0; }
.renewable-value { padding: 8px 18px; }
.renewable-value strong { font-size: 32px; }
.supply-legend { flex-wrap: wrap; row-gap: 8px; }
.annual-small { padding: 8px 18px; gap: 8px; }
.center-column { min-height: 0; height: clamp(440px, 60dvh, 620px); }
.scene-shell { min-height: 0; }
.scene-container { touch-action: pan-y; }
.right-column .detail-panel { flex: 0 0 auto; min-height: 0; }
.right-column #device-detail { display: grid; grid-template-columns: 92px minmax(0, 1fr); }
.right-column .selected-device, .right-column .detail-note { grid-column: 1 / -1; }
.right-column .soc-display, .right-column .selected-power { grid-column: 1; align-self: center; }
.right-column .detail-rows { grid-column: 2; align-self: center; padding: 0 12px 0 4px; }
.right-column .selected-device { padding: 16px 16px 8px; }
.right-column .soc-display { padding: 12px 0; gap: 10px; }
.right-column .soc-ring { width: 78px; height: 78px; }
.right-column .soc-ring strong { font-size: 24px; }
.right-column .detail-rows > div { min-height: 28px; font-size: 10px; gap: 8px; flex-wrap: wrap; }
.right-column .detail-note { padding: 12px 16px; font-size: 10px; line-height: 1.7; }
.right-column .selected-power { padding: 16px 8px; }
.right-column .selected-power strong { font-size: 28px; }
.right-column .selected-power strong small { font-size: 9px; margin-left: 3px; }
.right-column .load-panel, .right-column .weather-panel { flex: 0 0 auto; }
.right-column .load-panel { min-height: 0; }
.right-column .load-item { min-height: 46px; padding: 8px 16px 4px; }
.right-column .weather-panel { min-height: 0; }
.right-column .weather-values { padding: 10px 16px 6px; }
.right-column .weather-values strong { font-size: 26px; }
.right-column .weather-panel p { padding: 8px 16px 14px; line-height: 1.5; }
.playback-panel { flex: 0 0 auto; margin-top: 16px; padding-bottom: 12px; }
.playback-top { flex-wrap: wrap; gap: 12px 20px; padding: 14px 16px; }
.playback-title { min-height: 30px; }
.scenario-buttons { flex-wrap: wrap; margin-left: auto; }
.scenario-buttons button, .scenario-buttons button:nth-last-child(-n+2) { display: block; min-height: 34px; font-size: 11px; padding: 8px 10px; }
.play-controls { margin-left: auto; flex-wrap: wrap; gap: 8px; }
.play-controls > button, .play-controls select, .play-controls input { min-height: 36px; height: 36px; font-size: 11px; }
.play-controls > button { width: 36px; }
.play-controls input { width: 136px; }
.chart-container { height: 150px; margin-bottom: 8px; }
.timeline-row { min-height: 40px; height: auto; padding: 8px 20px; }
#year-slider { min-width: 60px; height: 6px; }
#year-slider::-webkit-slider-thumb { width: 16px; height: 24px; }
#year-slider::-moz-range-thumb { width: 16px; height: 24px; }
.app-footer { height: auto; min-height: 40px; flex: 0 0 auto; gap: 12px; flex-wrap: wrap; padding: 12px 0; line-height: 1.6; }
.overlay-view { overflow-y: auto; }
.layout-body { min-height: 520px; }
.site-map { min-height: 400px; }
.annual-metrics, .annual-foot { min-width: 0; }
.annual-metrics strong { font-size: clamp(28px, 2.7vw, 44px); }
.annual-chart-heading { gap: 12px; flex-wrap: wrap; }
#monthly-chart { flex: 0 0 auto; height: 250px; min-height: 250px; }
.annual-foot { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #6ee4e4; outline-offset: 3px; }
.replay-jump { padding: 10px 12px; font-size: 12px; color: #8edce0; text-decoration: none; white-space: nowrap; }
.replay-jump:hover { color: #d3ffff; }
.playback-panel { scroll-margin-top: 16px; }
.scene-toolbar .zoom-control { font-size: 24px; line-height: 1; }
.scene-bottom #scene-interaction { pointer-events: auto; color: #a6c5d2; background: #091d2bdd; border: 1px solid #335566; border-radius: 4px; padding: 7px 10px; font-size: 11px; line-height: 1.4; cursor: pointer; }
.scene-bottom #scene-interaction[aria-pressed="true"] { color: #9df3e7; border-color: #50b8aa; background: #103a3bdd; }
.scene-shell.is-interacting { box-shadow: inset 0 0 0 1px #50b8aa66; }

/* Wide monitors: a two-by-two metric group keeps replay visible below the scene. */
@media (min-width: 1600px) {
  .energy-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .energy-panel > .panel-heading { grid-column: 1 / -1; }
  .energy-card { min-height: 144px; padding: 12px; gap: 8px; }
  .energy-card:nth-child(even) { border-right: 1px solid #24415670; }
  .energy-card:last-child { border-bottom: 1px solid #24415670; }
  .energy-card-top { gap: 6px; font-size: 11px; }
  .card-arrow { display: none; }
  .card-bottom { flex-direction: column; align-items: flex-start; gap: 5px; }
  .mini-spark { flex: 0 0 18px; width: 100%; max-width: 90px; }
}

/* Laptop/tablet: give the scene room and move equipment details below it. */
@media (max-width: 1199px) {
  .app-header { flex-wrap: wrap; }
  .brand { flex: 1 0 auto; }
  .header-status { order: 1; }
  .project-title { order: 2; flex: 0 0 100%; text-align: left; }
  .project-title h1 { font-size: 22px; }
  .project-title > div { justify-content: flex-start; font-size: 9px; }
  .dashboard { grid-template-columns: 240px minmax(0, 1fr); min-height: 0; }
  .center-column { min-height: 0; height: 540px; }
  .scene-shell { min-height: 0; }
  .right-column { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
  .right-column .detail-panel { grid-row: span 2; min-height: 0; }
  .right-column .weather-panel, .right-column .load-panel { min-height: 0; }
  .layout-body { grid-template-columns: 1fr; }
  .layout-notes { display: block; }
  .site-map { min-height: 360px; }
  .scene-mode { display: none; }
  .scene-label { min-width: 96px; }
  .scene-label.label-transfer { min-width: 120px; }
}

/* Phone: no page-wide horizontal scrolling; controls and metrics reflow. */
@media (max-width: 767px) {
  #app { padding: 0 12px; }
  .app-header { gap: 14px; padding: 16px 0; }
  .brand { flex: 0 1 auto; gap: 10px; }
  .brand-symbol { width: 34px; height: 38px; }
  .brand-symbol svg { width: 24px; height: 24px; }
  .brand strong { font-size: 21px; letter-spacing: 2px; }
  .brand small { font-size: 6px; letter-spacing: 1px; }
  .header-status { margin-left: auto; }
  .simulation-badge { font-size: 9px; }
  .header-time { gap: 5px; }
  .header-time strong { font-size: 14px; }
  .header-time > span { font-size: 16px; }
  .header-time small { display: none; }
  .project-title h1 { font-size: 19px; letter-spacing: .5px; }
  .project-title > div { flex-wrap: wrap; gap: 7px; line-height: 1.6; }
  .main-nav { min-width: 0; margin-bottom: 12px; }
  .main-nav { flex-wrap: wrap; }
  .replay-jump { margin-left: auto; font-size: 11px; padding: 8px 0; }
  .nav-tabs { width: 100%; overflow-x: auto; gap: 0; }
  .nav-tab { flex: 1 1 0; min-width: 0; justify-content: center; padding: 0 6px; font-size: 12px; gap: 5px; }
  .nav-tab svg { width: 15px; height: 15px; }
  .dashboard { display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
  .center-column { order: -1; width: 100%; min-height: 500px; height: 500px; flex: 0 0 500px; }
  .scene-shell { min-height: 0; height: 100%; }
  .scene-heading { top: 18px; left: 14px; right: 14px; }
  .scene-heading h2 { font-size: 13px; }
  .scene-toolbar { right: 10px; top: 74px; gap: 10px; }
  .scene-toolbar button { width: 40px; height: 40px; }
  .scene-label { min-width: 0; padding: 6px; gap: 4px; }
  .scene-label b { font-size: 9px; }
  .scene-label small, .scene-label .label-power { display: none; }
  .scene-label.label-transfer { min-width: 0; }
  .scene-label.label-curtailment { min-width: 0; gap: 4px; }
  .curtailment-symbol { width: 22px; height: 22px; }
  .scene-label.label-curtailment .label-power { display: none; }
  .scene-status-strip { padding: 0 10px; font-size: 9px; }
  .scene-status-strip strong { font-size: 10px; }
  .left-column, .right-column { width: 100%; }
  .energy-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .energy-panel > .panel-heading { grid-column: 1 / -1; }
  .energy-card { min-height: 144px; padding: 14px 12px; gap: 12px; }
  .energy-card:nth-child(even) { border-right: 1px solid #24415670; }
  .energy-card:last-child { border-bottom: 1px solid #24415670; }
  .energy-card-top { gap: 6px; font-size: 11px; }
  .energy-card-top .equipment-icon { width: 24px; height: 24px; }
  .card-arrow { display: none; }
  .power-value strong { font-size: 34px; }
  .card-bottom { flex-wrap: wrap; gap: 7px; }
  .mini-spark { flex: 1 1 52px; max-width: 80px; height: 22px; }
  .renewable-panel { min-height: 0; }
  .right-column { display: flex; flex-direction: column; }
  .right-column > .panel { width: 100%; flex: 0 0 auto; }
  .right-column #device-detail { display: block; }
  .right-column .detail-rows { padding: 0 14px; }
  .right-column .soc-ring { width: 112px; height: 112px; }
  .right-column .soc-ring strong { font-size: 32px; }
  .right-column .detail-rows > div { min-height: 36px; font-size: 12px; }
  .right-column .detail-note { font-size: 11px; }
  .right-column .load-item { min-height: 60px; }
  .right-column .load-item > strong { font-size: 24px; }
  .right-column .weather-values { gap: 24px; }
  .right-column .weather-values strong { font-size: 28px; }
  .playback-top { gap: 12px; padding: 12px; }
  .playback-title { flex: 0 0 100%; }
  .playback-title > span { display: block; margin-left: auto; }
  .scenario-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; gap: 8px; }
  .scenario-buttons button, .scenario-buttons button:nth-last-child(-n+2) { font-size: 11px; min-height: 40px; padding: 8px 4px; }
  .play-controls { margin: 0; display: grid; width: 100%; grid-template-columns: repeat(3, 40px) minmax(80px, 1fr); }
  .play-controls > button { width: 40px; height: 40px; }
  #play { width: 40px; }
  .play-controls select { width: 100%; height: 40px; padding: 0 4px; }
  .play-controls input { width: 100%; grid-column: 1 / -1; height: 40px; font-size: 13px; }
  .chart-container { height: 185px; padding: 0 8px; }
  .chart-legend { gap: 8px; flex-wrap: wrap; font-size: 9px; }
  .timeline-row { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .timeline-row > span:first-child { min-width: 0; }
  #year-slider { order: 2; flex: 1 0 100%; margin: 10px 0; }
  #timeline-timestamp { margin-left: auto; }
  .month-labels { margin: 0 12px; padding: 0; font-size: 8px; }
  .month-labels span { white-space: nowrap; }
  .app-footer { font-size: 9px; gap: 5px; padding: 14px 0; }
  .app-footer > span { flex-basis: 100%; }
  .view-title { padding: 16px 14px; gap: 10px; }
  .view-title h2 { font-size: 15px; line-height: 1.5; }
  .view-eyebrow { font-size: 8px; letter-spacing: 1px; }
  .outline-badge { font-size: 9px; flex-shrink: 0; }
  .layout-body { min-height: 0; padding: 12px; gap: 18px; flex: 0 0 auto; }
  .site-map { min-height: 290px; height: 290px; }
  .site-map > img { height: 100%; }
  .layout-notes h3 { font-size: 13px; }
  .layout-notes p, .layout-notes li span { font-size: 11px; line-height: 1.7; }
  #topology-diagram { display: block; flex: 0 0 auto; overflow-x: auto; padding: 12px; }
  #topology-diagram svg { display: block; min-width: 560px; height: 330px; max-height: none; }
  .topology-note { text-align: left; padding: 12px 14px; font-size: 11px; }
  .annual-metrics { grid-template-columns: 1fr; gap: 12px; padding: 16px; }
  .annual-metrics > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border-right: 0; border-bottom: 1px solid #294a5e66; padding-bottom: 8px; }
  .annual-metrics strong { font-size: 28px; white-space: nowrap; }
  .annual-metrics span { font-size: 11px; }
  .annual-chart-heading { margin: 8px 14px; }
  .annual-foot { padding: 16px; gap: 16px; }
  .annual-foot span { font-size: 10px; }
  .annual-foot b { font-size: 18px; }
  #annual-view > .muted-note { padding: 0 16px 18px; }
  .dialog-head, .dialog-body { padding: 18px; }
  .dialog-body dl { grid-template-columns: 1fr; gap: 6px; }
  .dialog-body dd { margin-bottom: 10px; }
  #toast { width: max-content; max-width: calc(100% - 32px); line-height: 1.6; }
}

@media (max-width: 420px) {
  .nav-tab svg { display: none; }
  .project-title h1 { font-size: 18px; }
  .panel-heading > span { font-size: 7px; }
}
