/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 200px;
  --props-w:   260px;
  --topbar-h:  52px;
  --charts-h:  200px;
  --color-primary: #1a3a5c;
  --color-heat:    #e84545;
  --color-cold:    #2b6cb0;
  --color-border:  #e0e0e0;
  --color-bg:      #ffffff;
  --color-surface: #fafafa;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: #222;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-size: 13px;
}

#app {
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  user-select: none; /* Prevents text selection while dragging/connecting */
}

/* ── TOP BAR — sticky so controls stay visible while scrolling ── */
#topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: #fff;
  border-bottom: 1.5px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 6px;
  flex-shrink: 0;
  z-index: 30;
  flex-wrap: nowrap;
  overflow-x: auto;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
#topbar::-webkit-scrollbar { display: none; }

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
  flex-shrink: 0;
}
.logo img { height: 26px; width: auto; flex-shrink: 0; border-radius: 4px; }
.v-tag {
  font-size: 9px;
  background: #f1f3f5;
  color: #adb5bd;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 700;
  margin-left: -2px;
  align-self: flex-start;
  margin-top: 2px;
}
.logo span { display: none; }

.h-sep { width: 1px; height: 26px; background: var(--color-border); flex-shrink: 0; margin: 0 2px; }
.spacer { flex: 1; min-width: 4px; }

/* ── BUTTONS ── */
.btn {
  padding: 5px 11px;
  border-radius: 6px;
  border: 1.5px solid #d0d0d0;
  background: #fff;
  font-size: 12px;
  font-weight: 500;
  color: #333;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.4;
}
.btn:hover { background: #f4f4f4; border-color: #bbb; }
.btn:active { opacity: 0.8; }
.btn.primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn.primary:hover { background: #142f49; }
.btn.danger { background: #c62828; color: #fff; border-color: #c62828; }
.btn.danger:hover { background: #b71c1c; border-color: #b71c1c; }
.btn.small { padding: 3px 8px; font-size: 11px; }
.btn.icon-btn { padding: 5px 8px; font-size: 14px; }

#sim-time {
  font-size: 12px;
  color: #555;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-badge, .model-badge {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  background: #edf2f7;
  color: #4a5568;
}

.model-badge {
  background: #e6fffa;
  color: #2c7a7b;
  border: 1px solid #b2f5ea;
  margin-left: 8px;
}

.status-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: #f0f0f0;
  color: #777;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-badge.running { background: #e8f5e9; color: #2e7d32; }
.status-badge.done    { background: #e3f2fd; color: #1565c0; }

/* ── MAIN LAYOUT ── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* ── PALETTE ── */
#palette {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  border-right: 1.5px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-height: 0;
  z-index: 20;
}
.palette-scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0 10px;
}
#palette.hidden {
  transform: translateX(-100%);
  width: 0;
  min-width: 0;
  border-right: none;
}

.panel-title {
  font-size: 10.5px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 12px 12px 4px;
}
.palette-section {
  font-size: 9.5px;
  font-weight: 700;
  color: #bbb;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 7px 12px 2px;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  cursor: grab;
  border-radius: 6px;
  margin: 1px 6px;
  transition: background 0.1s;
  user-select: none;
}
.palette-item:hover { background: #ebebeb; }
.palette-item:active { cursor: grabbing; }
.palette-icon { width: 32px; height: 32px; flex-shrink: 0; }
.p-name { font-size: 12px; font-weight: 600; color: #333; }
.p-sub  { font-size: 10.5px; color: #999; }

/* ── SIDEBAR PANELS (Collapsible) ── */
.sidebar-panel {
  border-top: 1px solid var(--color-border);
  background: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  background: #fff;
  transition: background 0.1s;
  border-bottom: 1px solid transparent;
}
.panel-header:hover { background: #f8f9fa; }
.panel-header .panel-title { 
  padding: 0; 
  font-size: 10.5px; 
  margin: 0; 
  color: var(--color-primary);
  opacity: 0.8;
}
.panel-arrow { 
  font-size: 8px; 
  color: #ccc; 
  transition: transform 0.2s; 
}

.sidebar-panel.collapsed .panel-header { border-bottom: none; }

.panel-content {
  padding: 4px 12px 14px;
  overflow: hidden;
  max-height: 500px;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s;
}

.sidebar-panel.collapsed .panel-content {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
}
.sidebar-panel.collapsed .panel-arrow { transform: rotate(-90deg); }

.sidebar-panel label {
  display: block;
  font-size: 11px;
  color: #555;
  margin-bottom: 6px;
  font-weight: 500;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
}
.input-row input, .input-row select {
  flex: 1;
  padding: 4px 6px;
  border: 1.5px solid #ddd;
  border-radius: 5px;
  font-size: 12px;
  background: #fff;
  min-width: 0;
}
.input-row input:focus, .input-row select:focus { outline: none; border-color: var(--color-primary); }
.unit { font-size: 10.5px; color: #999; flex-shrink: 0; }

/* Specific dashboard adjustments */
#energy-dash-content { min-height: 0; }
.dash-row { display: flex; justify-content: space-between; align-items: center; padding: 1.5px 0; min-width: 0; }
.dash-label { font-size: 11px; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 6px; }
.dash-val        { font-size: 11.5px; font-weight: 700; color: var(--color-primary); white-space: nowrap; flex-shrink: 0; }
.dash-val.hot    { color: #c62828; }
.dash-val.cool   { color: #1565c0; }
.dash-val.green  { color: #2e7d32; }
.dash-val.warn   { color: #e65100; }
.dash-sep { height: 1px; background: #eee; margin: 4px 0; }

/* ── CANVAS ── */
#canvas-wrap {
  flex: 1;
  min-width: 0;
  min-height: 300px;    /* never compress below usable size */
  position: relative;
  overflow: hidden;
  background: #fff;
  background-image:
    linear-gradient(rgba(200,210,220,0.4) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200,210,220,0.4) 1px, transparent 1px);
  background-size: 30px 30px;
}
#canvas { width: 100%; height: 100%; display: block; }
#canvas.connecting { cursor: crosshair; }
 
.canvas-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 25;
}
.ctrl-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  border: 1.5px solid var(--color-border);
  color: #333;
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: all 0.1s;
  user-select: none;
  line-height: 1;
}
.ctrl-btn:hover {
  background: #fff;
  border-color: #bbb;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.ctrl-btn:active {
  transform: translateY(0);
  background: #f0f0f0;
}
 
#canvas-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #bbb;
  pointer-events: none;
  white-space: nowrap;
  text-align: center;
  padding: 0 20px;
}

/* ── PROPERTIES PANEL ── */
#props {
  width: var(--props-w);
  min-width: var(--props-w);
  border-left: 1.5px solid var(--color-border);
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  min-height: 0;
  transition: transform 0.25s ease, width 0.25s ease;
  z-index: 20;
}
#props.hidden {
  transform: translateX(100%);
  width: 0;
  min-width: 0;
  border-left: none;
}

#props-header {
  padding: 11px 12px 9px;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-primary);
  border-bottom: 1px solid #ebebeb;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#props-body {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}
.props-empty {
  padding: 18px 12px;
  color: #aaa;
  font-size: 12px;
  line-height: 1.6;
}
.prop-section {
  padding: 7px 12px 1px;
  font-size: 10px;
  font-weight: 700;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.prop-section-sub {
  padding: 5px 12px 1px;
  font-size: 9.5px;
  font-weight: 700;
  color: #bbb;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-top: 1px solid #f0f0f0;
  margin-top: 3px;
}
.prop-row {
  display: flex;
  align-items: center;
  padding: 3px 12px;
  gap: 5px;
}
.prop-row label { flex: 0 0 105px; font-size: 11.5px; color: #555; }
.prop-row input, .prop-row select {
  flex: 1;
  padding: 3px 6px;
  border: 1.5px solid #ddd;
  border-radius: 5px;
  font-size: 12px;
  background: #fff;
  min-width: 0;
}
.prop-row input:focus, .prop-row select:focus { outline: none; border-color: var(--color-primary); }
.prop-row .pu { font-size: 10.5px; color: #999; width: 30px; flex-shrink: 0; }

.result-block {
  margin: 5px 12px;
  padding: 7px 9px;
  background: #f5f8fc;
  border-radius: 6px;
  border: 1px solid #dde8f4;
}
.result-block .rb-title {
  font-size: 10px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.rb-row {
  display: flex;
  justify-content: space-between;
  padding: 1.5px 0;
}
.rb-label { font-size: 11px; color: #666; }
.rb-val   { font-size: 11.5px; font-weight: 600; color: var(--color-primary); }
.rb-val.hot  { color: #c62828; }
.rb-val.cold { color: #1565c0; }

.delete-btn {
  margin: 8px 12px 4px;
  width: calc(100% - 24px);
  padding: 7px;
  background: #fff5f5;
  border: 1.5px solid #ffcdd2;
  color: #c62828;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.delete-btn:hover { background: #ffebee; }

/* ── CHARTS PANEL ── */
#charts-panel {
  height: var(--charts-h);
  min-height: var(--charts-h);
  flex-shrink: 0;
  border-top: 1.5px solid var(--color-border);
  background: #fff;
  display: flex;
  flex-direction: column;
  /* no transition when resizing — disable it dynamically via JS */
  transition: height 0.2s ease;
}
#charts-panel.collapsed { height: 34px; min-height: 34px; overflow: hidden; }
#charts-panel.collapsed #charts-body { display: none; }
#charts-panel.collapsed #charts-resizer { display: none; }
@media (max-width: 767px) { #charts-resizer { display: none; } }

/* ── CHARTS RESIZER ── */
#charts-resizer {
  height: 8px;
  flex-shrink: 0;
  cursor: ns-resize;
  background: transparent;
  position: relative;
  z-index: 30;
  /* pull it up so it overlaps the border-top of #charts-panel */
  margin-top: -1px;
  user-select: none;
  touch-action: none;
}
#charts-resizer::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 3px;
  border-radius: 3px;
  background: #d0d7de;
  transition: background 0.15s, width 0.15s;
}
#charts-resizer:hover::before,
#charts-resizer.dragging::before {
  background: var(--color-primary);
  width: 56px;
}
#charts-resizer.dragging {
  background: rgba(43, 108, 176, 0.05);
}

#charts-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.chart-title { font-size: 12px; font-weight: 600; color: #333; }
#charts-header label { font-size: 11.5px; color: #666; display: flex; align-items: center; gap: 4px; }
#charts-header select {
  padding: 2px 5px;
  border: 1.5px solid #ddd;
  border-radius: 5px;
  font-size: 11.5px;
  background: #fff;
}
#charts-body {
  flex: 1;
  padding: 4px 8px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}
#chart-canvas { flex: 1; min-width: 0; min-height: 0; display: block; }

/* Legend sits BELOW the canvas as a compact wrapping row */
#chart-legend-html {
  flex-shrink: 0;
  max-height: 72px;          /* ~3 rows of items; scrolls if more */
  overflow-y: auto;
  padding: 4px 2px 2px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  align-content: flex-start;
}
#chart-legend-html:empty { display: none; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: #444;
  max-width: 200px;
  overflow: hidden;
  white-space: nowrap;
}
.legend-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.legend-color {
  width: 20px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── PANEL TOGGLE BUTTONS (mobile only, float over canvas) ── */
.panel-toggle {
  position: absolute;
  z-index: 25;
  top: 8px;
  background: rgba(255,255,255,0.95);
  border: 1.5px solid var(--color-border);
  border-radius: 7px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.14);
  display: none;
  white-space: nowrap;
  line-height: 1.3;
}
#toggle-palette { left: 8px; }
#toggle-props   { right: 8px; }

/* ── TOOLTIP ── */
#tooltip {
  position: fixed;
  display: none;
  background: rgba(26, 58, 92, 0.96); /* Industrial dark blue */
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  pointer-events: none;
  z-index: 2000;
  white-space: pre-line;
  box-shadow: 0 4px 15px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  line-height: 1.5;
  backdrop-filter: blur(4px);
  max-width: 280px;
}

/* ── SCROLLBARS ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
═══════════════════════════════════════════════════════════ */

/* ── Large desktop (≥ 1280px) ── */
@media (min-width: 1280px) {
  :root { --sidebar-w: 210px; --props-w: 275px; }
  .logo span { display: inline; }
}

/* ── Medium desktop (1024–1279px) ── */
@media (max-width: 1279px) and (min-width: 1024px) {
  :root { --sidebar-w: 185px; --props-w: 248px; }
}

/* ── Tablet landscape (768–1023px): narrower panels ── */
@media (max-width: 1023px) and (min-width: 768px) {
  :root { --sidebar-w: 155px; --props-w: 210px; --charts-h: 170px; }
  .p-sub  { display: none; }
  .logo span { display: none; }
  .palette-icon { width: 26px; height: 26px; }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE: vertical stacking layout (< 768px)
═══════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  #topbar {
    height: auto;
    min-height: 46px;
    padding: 6px 8px;
    flex-wrap: wrap;
    gap: 5px;
  }
  .logo span { display: none; }
  #sim-time  { font-size: 11px; }

  /* Main: vertical column, auto height, scrollable */
  #main {
    flex-direction: column;
    height: auto;
    overflow: visible;
    min-height: 0;
  }

  /* Canvas gets a fixed height — tall enough to work with */
  #canvas-wrap {
    width: 100%;
    height: 56vw;        /* portrait: sensible square-ish canvas  */
    min-height: 280px;
    max-height: 480px;
    flex-shrink: 0;
    order: 1;
  }

  #canvas-hint { font-size: 11px; }

  /* Palette: inline full-width block below the canvas, collapsible */
  #palette {
    position: static;
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: 0;
    overflow: hidden;
    border-right: none;
    border-top: 1.5px solid var(--color-border);
    transform: none !important;   /* override any leftover transition */
    transition: max-height 0.3s ease;
    order: 2;
  }
  #palette.open {
    max-height: 420px;
    overflow-y: auto;
  }

  /* Palette items: two-column grid on wider phones */
  .palette-item {
    padding: 7px 12px;
    margin: 1px 4px;
  }

  /* Props: full-width section below palette */
  #props {
    position: static;
    width: 100%;
    min-width: 0;
    height: auto;
    border-left: none;
    border-top: 1.5px solid var(--color-border);
    transform: none !important;
    order: 3;
    /* collapsed by default; JS toggles .open */
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }
  #props.open {
    max-height: 600px;
    overflow-y: auto;
  }
  /* Props header always visible when open */
  #props-header { position: sticky; top: 0; background: #fff; z-index: 2; }

  /* Floating toggle buttons shown on mobile */
  .panel-toggle { display: block; }

  /* Charts: full-width at bottom */
  #charts-panel {
    height: auto;
    min-height: 170px;
    border-top: 1.5px solid var(--color-border);
    order: 4;
  }
  #charts-panel.collapsed { min-height: 34px; height: 34px; }
  #charts-body { height: 140px; }
}

/* ── Small phones (< 480px) ── */
@media (max-width: 479px) {
  #canvas-wrap {
    height: 72vw;
    max-height: 360px;
  }
  .btn { padding: 4px 8px; font-size: 11px; }
  #btn-step { display: none; }
  #sim-time { display: none; }
  .prop-row label { flex: 0 0 90px; }
}

/* ═══════════════════════════════════════════════════════════
   INPUT VALIDATION
═══════════════════════════════════════════════════════════ */
.prop-row input.input-error,
.prop-row select.input-error {
  border-color: #e53935 !important;
  background: #fff5f5;
  box-shadow: 0 0 0 2px rgba(229,57,53,0.15);
  animation: shake 0.25s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-3px); }
  75%      { transform: translateX(3px); }
}
.validation-msg {
  display: block;
  font-size: 10.5px;
  color: #e53935;
  padding: 1px 12px 3px;
  line-height: 1.3;
}

/* ═══════════════════════════════════════════════════════════
   NETWORK WARNING BANNER
═══════════════════════════════════════════════════════════ */
#network-warning {
  position: sticky;
  top: var(--topbar-h);
  z-index: 28;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: linear-gradient(90deg, #fff8e1, #fff3cd);
  border-bottom: 1.5px solid #ffe082;
  font-size: 12px;
  color: #6d4c00;
  font-weight: 500;
  animation: slideDown 0.2s ease;
}
#network-warning.visible { display: flex; }
#network-warning .warn-icon { font-size: 15px; flex-shrink: 0; }
#network-warning .warn-text { flex: 1; }
#network-warning .warn-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: #9e6b00;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}
#network-warning .warn-close:hover { color: #6d4c00; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════
   SUPABASE CLOUD MODAL
═══════════════════════════════════════════════════════════ */
#db-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15,25,45,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  animation: fadeIn 0.18s ease;
}
#db-modal-overlay.open { display: flex; }
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

#db-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.28);
  width: min(520px, calc(100vw - 32px));
  max-height: min(640px, calc(100svh - 48px));
  display: flex;
  flex-direction: column;
  animation: modalUp 0.2s ease;
  overflow: hidden;
}
@keyframes modalUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#db-modal-header {
  display: flex;
  align-items: center;
  padding: 14px 18px 12px;
  border-bottom: 1.5px solid #efefef;
  gap: 8px;
  flex-shrink: 0;
}
#db-modal-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-primary);
  flex: 1;
}
#db-modal-header .modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #999;
  padding: 0 4px;
  line-height: 1;
}
#db-modal-header .modal-close:hover { color: #333; }

#db-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px;
}

.db-model-row {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border-radius: 8px;
  gap: 10px;
  border: 1.5px solid #e8eef4;
  margin-bottom: 7px;
  transition: background 0.1s;
}
.db-model-row:hover { background: #f4f8fc; }
.db-model-info { flex: 1; min-width: 0; }
.db-model-name { font-size: 13px; font-weight: 600; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.db-model-meta { font-size: 11px; color: #999; margin-top: 2px; }
.db-model-actions { display: flex; gap: 6px; flex-shrink: 0; }
.db-model-actions button { padding: 4px 10px; border-radius: 6px; border: 1.5px solid; cursor: pointer; font-size: 11.5px; font-weight: 500; }
.db-btn-load   { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.db-btn-load:hover { background: #142f49; }
.db-btn-del    { background: #fff5f5; color: #c62828; border-color: #ffcdd2; }
.db-btn-del:hover  { background: #ffebee; }

#db-modal-empty {
  text-align: center;
  padding: 32px 0;
  color: #bbb;
  font-size: 13px;
}
#db-modal-spinner {
  text-align: center;
  padding: 28px 0;
  color: #888;
  font-size: 12px;
}

#db-modal-footer {
  padding: 10px 18px 14px;
  border-top: 1.5px solid #efefef;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
#db-modal-footer input[type="text"] {
  flex: 1;
  padding: 6px 10px;
  border: 1.5px solid #ddd;
  border-radius: 7px;
  font-size: 13px;
  background: #fff;
}
#db-modal-footer input[type="text"]:focus { outline: none; border-color: var(--color-primary); }

/* ── Toast notification ── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  z-index: 2000;
  background: #1a3a5c;
  color: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 6px 24px rgba(0,0,0,0.22);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: nowrap;
}
#toast.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
#toast.toast-error { background: #c62828; }

/* ── btn.cloud variant ── */
.btn.cloud {
  background: linear-gradient(135deg, #1a3a5c, #2b6cb0);
  color: #fff;
  border-color: #2b6cb0;
}
.btn.cloud:hover { background: linear-gradient(135deg, #142f49, #1a5a9a); }
.btn.cloud:disabled { opacity: 0.45; cursor: not-allowed; }


/* ── PRINT / REPORT STYLES ── */
#print-report {
  display: none; /* Hidden on screen by default */
  background: white;
  padding: 10mm;
  margin: 0;
  color: #333;
  width: 277mm; /* Standard A4 landscape width minus some margin */
  font-family: 'Inter', sans-serif;
}

#print-report .print-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid #1a3a5c;
  padding-bottom: 15px;
  margin-bottom: 30px;
}

#print-report .print-header img {
  height: 50px;
}

#print-report .print-header h1 {
  font-size: 28px;
  margin: 0;
  color: #1a3a5c;
  letter-spacing: -0.5px;
}

#print-report .print-date {
  font-size: 12px;
  color: #666;
}

#print-report .print-section {
  margin-bottom: 30px;
  page-break-inside: avoid;
}

#print-report .print-section h3 {
  border-left: 5px solid #1a3a5c;
  padding-left: 12px;
  margin-bottom: 15px;
  background: #f1f4f8;
  padding: 10px 15px;
  font-size: 16px;
  color: #1a3a5c;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#print-report #print-canvas-target {
  width: 100%;
  border: 1px solid #d1d9e6;
  background: #fff;
  padding: 10px;
  border-radius: 4px;
  display: flex;
  justify-content: center;
}

#print-report .print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  box-shadow: 0 0 0 1px #d1d9e6;
  border-radius: 4px;
  overflow: hidden;
}

#print-report .print-table th, 
#print-report .print-table td {
  border: 1px solid #d1d9e6;
  padding: 8px 10px;
  text-align: left;
}

#print-report .print-table th {
  background: #1a3a5c;
  color: white;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
}

#print-report .print-table tr:nth-child(even) {
  background: #f9fbfe;
}

#print-report .print-footer {
  margin-top: 20px;
  border-top: 1px solid #d1d9e6;
  padding-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: #4a5568;
}

#print-report .footer-logo {
  height: 25px;
}

/* Two-column info row (config + network summary side by side) */
#print-report .print-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
#print-report .print-two-col h3 { margin-top: 0; }

/* Small info table used inside config / network summary */
#print-report .print-info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
#print-report .print-info-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #e8eef4;
}
#print-report .print-info-table td:first-child {
  color: #666;
  width: 55%;
  font-weight: 500;
}
#print-report .print-info-table td:last-child {
  font-weight: 700;
  color: #1a3a5c;
}

/* KPI cards for energy balance */
#print-report .print-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
#print-report .print-kpi-card {
  border: 1.5px solid #d1d9e6;
  border-radius: 6px;
  padding: 12px 14px;
  background: #f8fafd;
}
#print-report .print-kpi-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #888;
  font-weight: 600;
  margin-bottom: 4px;
}
#print-report .print-kpi-value {
  font-size: 20px;
  font-weight: 700;
  color: #1a3a5c;
  line-height: 1.1;
}
#print-report .print-kpi-unit {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}
#print-report .print-kpi-card.hot  { border-color: #ffcdd2; background: #fff5f5; }
#print-report .print-kpi-card.hot  .print-kpi-value { color: #c62828; }
#print-report .print-kpi-card.cool { border-color: #bbdefb; background: #f0f7ff; }
#print-report .print-kpi-card.cool .print-kpi-value { color: #1565c0; }
#print-report .print-kpi-card.green{ border-color: #c8e6c9; background: #f1f8f1; }
#print-report .print-kpi-card.green .print-kpi-value { color: #2e7d32; }

@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }
  body * { visibility: hidden; }
  #print-report, #print-report * { visibility: visible; }
  #print-report { display: block !important; position: absolute; left: 0; top: 0; width: 100%; }
}

input, textarea, select {
  user-select: auto;
}

/* ═══════════════════════════════════════════════════════════
   VELOCITY STATUS BADGES (pipe props panel)
═══════════════════════════════════════════════════════════ */
.vel-badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
  line-height: 1.4;
}
.vel-badge.vel-ok   { background: #e8f5e9; color: #2e7d32; }
.vel-badge.vel-high { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }
.vel-badge.vel-low  { background: #fff8e1; color: #f57f17; border: 1px solid #ffe082; }

/* ═══════════════════════════════════════════════════════════
   PRESSURE MAP BUTTON ACTIVE STATE
═══════════════════════════════════════════════════════════ */
.ctrl-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.ctrl-btn.active:hover {
  background: #142f49;
}

/* ═══════════════════════════════════════════════════════════
   THERMOSTAT NODE HIGHLIGHT
═══════════════════════════════════════════════════════════ */
.rb-val.green { color: #2e7d32; }

/* Thermostat ON state glow on canvas (applied via SVG, no extra CSS needed) */

/* ═══════════════════════════════════════════════════════════
   RUBBER-BAND SELECTION RECT
═══════════════════════════════════════════════════════════ */
#rubber-band {
  position: absolute;
  pointer-events: none;
  border: 1.5px dashed var(--color-primary);
  background: rgba(26, 58, 92, 0.07);
  border-radius: 2px;
  z-index: 10;
  display: none;
}

/* Multi-select list for thermostat targets */
.multi-select-list {
  background: #fdfdfd;
  border: 1px solid #ddd;
  border-radius: 4px;
  max-height: 140px;
  overflow-y: auto;
  margin-top: 4px;
  padding: 4px;
}

.multi-select-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  font-size: 11px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}

.multi-select-item:last-child {
  border-bottom: none;
}

.multi-select-item:hover {
  background: #f0f7ff;
}

.multi-select-item input {
  margin: 0;
  cursor: pointer;
}

.multi-select-empty {
  font-size: 11px;
  color: #888;
  padding: 10px;
  text-align: center;
  font-style: italic;
}

/* Signal lines animation */
@keyframes signal-dash {
  to { stroke-dashoffset: -20; }
}
.control-signal-line {
  stroke-dasharray: 5, 5;
  animation: signal-dash 1s linear infinite;
}


.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15,25,45,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  animation: fadeIn 0.18s ease;
}
.modal-overlay.open { display: flex; }

.modal-content {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.28);
  padding: 20px;
  animation: modalUp 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes modalUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── BUTTON LOADING STATE ── */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: calc(50% - 8px);
  left: calc(50% - 8px);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
