/* ============================================================
   EAST SOLUTIONS SCADA — SINGLE LINE DIAGRAM STYLES
   ============================================================ */

.sld-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}

.sld-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-primary);
}

.sld-toolbar-left,
.sld-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sld-canvas {
  width: 100%;
  min-height: 600px;
  position: relative;
  overflow: auto;
  background:
    radial-gradient(circle, rgba(30,58,90,0.3) 1px, transparent 1px);
  background-size: 24px 24px;
  background-color: var(--bg-secondary);
}

/* SVG SLD Elements */
.sld-svg {
  width: 100%;
  min-height: 600px;
  display: block;
}

/* Busbar */
.sld-busbar {
  stroke: var(--el-busbar);
  stroke-width: 4;
  fill: none;
}

.sld-busbar.dead {
  stroke: var(--el-dead);
  stroke-dasharray: 8 4;
}

/* Cables / conductors */
.sld-cable {
  stroke: var(--el-cable);
  stroke-width: 2;
  fill: none;
}

.sld-cable.live {
  stroke: var(--el-live);
}

.sld-cable.dead {
  stroke: var(--el-dead);
  stroke-dasharray: 6 3;
}

/* Breakers */
.sld-breaker {
  cursor: pointer;
  transition: all 0.2s ease;
}

.sld-breaker-body {
  fill: var(--bg-tertiary);
  stroke: var(--el-cable);
  stroke-width: 1.5;
  rx: 3;
}

.sld-breaker.closed .sld-breaker-body {
  fill: rgba(34,197,94,0.2);
  stroke: var(--el-closed);
}

.sld-breaker.open .sld-breaker-body {
  fill: rgba(245,158,11,0.15);
  stroke: var(--el-open);
}

.sld-breaker.fault .sld-breaker-body {
  fill: rgba(239,68,68,0.2);
  stroke: var(--el-dead);
  animation: blink 1s infinite;
}

.sld-breaker:hover .sld-breaker-body {
  stroke: var(--brand-orange);
  filter: drop-shadow(0 0 4px rgba(232,98,10,0.5));
}

.sld-breaker-label {
  font-family: var(--font-mono);
  font-size: 9px;
  fill: var(--text-secondary);
  text-anchor: middle;
}

/* Transformers */
.sld-transformer {
  cursor: pointer;
}

.sld-transformer-circle {
  fill: none;
  stroke-width: 2;
}

.sld-transformer-circle.primary {
  stroke: var(--el-busbar);
}

.sld-transformer-circle.secondary {
  stroke: var(--el-live);
}

.sld-transformer.fault .sld-transformer-circle {
  stroke: var(--el-dead);
  animation: blink 1s infinite;
}

/* Generators */
.sld-generator {
  cursor: pointer;
}

.sld-generator-body {
  fill: rgba(168,85,247,0.1);
  stroke: #A855F7;
  stroke-width: 2;
}

.sld-generator.running .sld-generator-body {
  fill: rgba(34,197,94,0.1);
  stroke: var(--el-live);
}

.sld-generator.fault .sld-generator-body {
  fill: rgba(239,68,68,0.1);
  stroke: var(--el-dead);
  animation: blink 1s infinite;
}

/* PV Array */
.sld-pv {
  cursor: pointer;
}

.sld-pv-body {
  fill: rgba(245,158,11,0.1);
  stroke: #F59E0B;
  stroke-width: 2;
}

.sld-pv.generating .sld-pv-body {
  fill: rgba(245,158,11,0.2);
  stroke: #F59E0B;
  filter: drop-shadow(0 0 6px rgba(245,158,11,0.4));
}

/* Battery */
.sld-battery {
  cursor: pointer;
}

.sld-battery-body {
  fill: rgba(34,197,94,0.1);
  stroke: var(--el-live);
  stroke-width: 2;
}

.sld-battery.charging .sld-battery-body {
  fill: rgba(34,197,94,0.2);
}

.sld-battery.discharging .sld-battery-body {
  fill: rgba(245,158,11,0.15);
  stroke: #F59E0B;
}

/* Meters */
.sld-meter {
  cursor: pointer;
}

.sld-meter-body {
  fill: var(--bg-tertiary);
  stroke: var(--border-secondary);
  stroke-width: 1.5;
}

/* Value labels on SLD */
.sld-value-label {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--text-primary);
  text-anchor: middle;
}

.sld-value-label.critical {
  fill: var(--status-critical);
}

.sld-value-label.warning {
  fill: var(--status-warning);
}

.sld-unit-label {
  font-family: var(--font-mono);
  font-size: 8px;
  fill: var(--text-muted);
  text-anchor: middle;
}

.sld-name-label {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  fill: var(--text-secondary);
  text-anchor: middle;
}

/* Alarm highlight overlay */
.sld-alarm-overlay {
  fill: rgba(239,68,68,0.15);
  stroke: var(--status-critical);
  stroke-width: 2;
  stroke-dasharray: 4 2;
  animation: blink 1.5s infinite;
  pointer-events: none;
}

/* Comms indicator on SLD */
.sld-comms-ok {
  fill: var(--status-healthy);
  filter: drop-shadow(0 0 4px rgba(34,197,94,0.6));
}

.sld-comms-fail {
  fill: var(--status-critical);
  animation: blink 2s infinite;
}

/* Tooltip */
.sld-tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.75rem;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  z-index: 100;
  min-width: 160px;
  animation: fadeIn 0.15s ease;
}

.sld-tooltip-title {
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  font-size: 0.8125rem;
}

.sld-tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0;
  color: var(--text-secondary);
}

.sld-tooltip-value {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

/* Legend */
.sld-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-primary);
}

.sld-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.sld-legend-line {
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

.sld-legend-circle {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid;
}

/* Zoom controls */
.sld-zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 50;
}

.sld-zoom-btn {
  width: 32px; height: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  transition: all var(--transition-fast);
}

.sld-zoom-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--brand-orange);
}

/* ============================================================
   SLD CB CONTROL BUTTONS (Open / Close in the element info modal)
   ============================================================ */
.sld-control-buttons {
  display: flex;
  gap: 12px;
}

.sld-control-btn {
  flex: 1;
  justify-content: center;
}

/* On phones the breaker Open/Close buttons must be large and clearly
   separated to avoid accidental operation. Stack them full-width, tall, with
   a generous gap so the two actions can't be confused or mis-tapped. */
@media (max-width: 600px) {
  .sld-control-buttons {
    flex-direction: column;
    gap: 16px;
  }

  .sld-control-btn {
    width: 100%;
    min-height: 54px;
    font-size: 1rem;
    font-weight: 700;
  }
}

/* ============================================================
   SLD MOBILE RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .sld-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .sld-toolbar-left,
  .sld-toolbar-right {
    flex-wrap: wrap;
    gap: 6px;
  }

  .sld-canvas {
    min-height: 400px;
    -webkit-overflow-scrolling: touch;
  }

  .sld-svg {
    min-height: 400px;
  }

  /* The SLD scroll container is the pan surface on touch. Stop the browser
     from claiming pan/zoom gestures so our handlers drive it, and stop the
     long-press selection / callout while dragging the diagram. */
  #sld-canvas-wrap {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  /* Enlarge circuit-breaker / switch tap targets WITHOUT resizing the visible
     symbol. An invisible pseudo-element extends the hittable area to a ~44px
     minimum around the element's centre — comfortably tappable on a phone even
     when the diagram is zoomed out to fit. Pure hit area, no visual change. */
  .sld-interactive::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 100%;
    height: 100%;
    min-width: 44px;
    min-height: 44px;
    transform: translate(-50%, -50%);
    /* invisible, but captures touches */
    background: transparent;
    z-index: -1;
  }
}

@media (max-width: 600px) {
  .sld-toolbar {
    padding: 6px 8px;
  }

  .sld-toolbar .btn {
    padding: 6px 8px;
    font-size: 0.6875rem;
  }

  .sld-zoom-controls {
    bottom: 8px;
    right: 8px;
  }

  .sld-zoom-btn {
    width: 36px;
    height: 36px;
  }

  .sld-tooltip {
    max-width: calc(100vw - 32px);
    font-size: 0.6875rem;
  }

  .sld-legend {
    gap: 8px;
    padding: 8px 12px;
    font-size: 0.625rem;
  }
}
