/* Modern Industrial SCADA Dark Theme */
:root {
  --bg-dark: #090d16;
  --card-bg: #111827;
  --card-border: #1f2937;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --cyan: #06b6d4;
  --cyan-glow: rgba(6, 182, 212, 0.4);
  --amber: #f59e0b;
  --green: #10b981;
  --red: #ef4444;
  --blue: #3b82f6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: 14px;
  min-height: 100vh;
}

#scada-app {
  max-width: 1400px;
  margin: 0 auto;
}

/* Header */
.scada-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  margin-bottom: 14px;
}

.scada-title h1 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
}

.scada-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.scada-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Roboto Mono", monospace;
  font-size: 12px;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}

.status-indicator.online {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.badge {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.back-home-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid #334155;
  color: #e2e8f0;
  font-family: "Roboto Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.back-home-btn:hover {
  border-color: #38bdf8;
  color: #38bdf8;
  background: rgba(14, 165, 233, 0.12);
}

.cudy-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 6px;
  font-family: "Roboto Mono", monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.4px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.cudy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.cudy-badge.cudy-online {
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.6);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.25);
}

.cudy-badge.cudy-online .cudy-dot {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.cudy-badge.cudy-off {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.6);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.2);
}

.cudy-badge.cudy-off .cudy-dot {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

/* Main Grid */
.scada-main-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
}

.scada-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 16px;
  position: relative;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: #38bdf8;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

/* Viewport & SVG */
.scada-viewport {
  position: relative;
  background: #030712;
  border: 1px solid #1e293b;
  border-radius: 8px;
  overflow: hidden;
  height: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scada-svg {
  width: 100%;
  height: 100%;
  max-height: 480px;
}

/* Equipment SVG styling */
.equipment-outline {
  fill: #1e293b;
  stroke: #475569;
  stroke-width: 1.5;
}

.detail-line {
  stroke: #334155;
  stroke-width: 1;
}

.text-label {
  fill: #94a3b8;
  font-family: 'Roboto Mono', monospace;
  font-size: 10px;
  font-weight: 700;
}

.screw-helix {
  stroke: #64748b;
  stroke-width: 2;
  stroke-linecap: round;
  transition: transform 0.1s linear;
}

.screw-active .screw-helix {
  stroke: #38bdf8;
  animation: screwSpin 0.6s linear infinite;
}

.screw-ash-active .screw-helix {
  stroke: #f59e0b;
  animation: screwSpin 0.6s linear infinite;
}

@keyframes screwSpin {
  0% { transform: translateX(0); }
  100% { transform: translateX(12px); }
}

.flow-stream {
  stroke: transparent;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 4 4;
}

.flow-active-cement {
  stroke: #38bdf8;
  animation: flowDown 0.4s linear infinite;
}

.flow-active-ash {
  stroke: #f59e0b;
  animation: flowDown 0.4s linear infinite;
}

@keyframes flowDown {
  0% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -16; }
}

/* Gate */
.gate-blade {
  stroke: #ef4444;
  transition: transform 0.3s ease;
}

.gate-open .gate-blade {
  transform: translateX(25px);
  stroke: #10b981;
}

/* Viewport Overlays */
.overlay-badge {
  position: absolute;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.3);
  backdrop-filter: blur(4px);
  z-index: 10;
}

.badge-label {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
}

.badge-val {
  font-family: "Roboto Mono", monospace;
  font-size: 16px;
  font-weight: 800;
  color: var(--cyan);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: "Roboto Mono", monospace;
  font-size: 11px;
  font-weight: 700;
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
}

.pill-dot.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.selector-relays-overlay {
  position: absolute;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.relay-tag {
  padding: 4px 8px;
  border-radius: 6px;
  font-family: "Roboto Mono", monospace;
  font-size: 10px;
  font-weight: 700;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid #475569;
  color: #94a3b8;
}

.relay-tag.active {
  background: rgba(245, 158, 11, 0.2);
  border-color: var(--amber);
  color: #fde68a;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

.hopper-overlay-container {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 10;
  pointer-events: none;
  background: rgba(10, 15, 29, 0.75);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.25);
  backdrop-filter: blur(4px);
}

.net-weight-text {
  font-family: "Roboto Mono", monospace;
  font-size: 26px;
  font-weight: 900;
  color: #00f0ff;
  text-shadow: 0 0 12px var(--cyan-glow);
}

.gross-weight-text {
  font-family: "Roboto Mono", monospace;
  font-size: 11px;
  color: #cbd5e1;
}

.viewport-bottom-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 6px;
  font-family: "Roboto Mono", monospace;
  font-size: 11px;
  color: #bae6fd;
}

/* Scales Sidebar */
.scales-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.scale-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
}

.scale-item.highlight {
  border-color: rgba(6, 182, 212, 0.5);
  background: rgba(6, 182, 212, 0.05);
}

.scale-name {
  font-size: 12px;
  color: var(--text-muted);
}

.scale-val {
  font-family: "Roboto Mono", monospace;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
}

.scale-item.highlight .scale-val {
  color: var(--cyan);
}

/* Ash Plan Box */
.ash-plan-box {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: "Roboto Mono", monospace;
  font-size: 11px;
}

.plan-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.plan-row span {
  color: var(--text-muted);
}

.plan-row b {
  color: #e2e8f0;
}

/* History Photo Table */
.history-card {
  grid-column: 1 / -1;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.history-count {
  font-family: "Roboto Mono", monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.table-container {
  overflow-x: auto;
}

.photo-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Roboto Mono", monospace;
  font-size: 12px;
  text-align: left;
}

.photo-table th {
  padding: 8px 12px;
  background: #0f172a;
  color: #94a3b8;
  border-bottom: 1px solid #334155;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10px;
}

.photo-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #1e293b;
  color: #e2e8f0;
}

.photo-table tr:hover td {
  background: rgba(30, 41, 59, 0.4);
}

.tag-success {
  color: var(--green);
  font-weight: bold;
}

.tag-warn {
  color: var(--amber);
  font-weight: bold;
}

/* Desktop HUD wrappers & stage */
.hud-silos,
.hud-signals {
  display: contents;
}

.pos-silo-cem {
  top: 16px;
  left: 16px;
}

.pos-silo-ash {
  top: 16px;
  right: 16px;
}

.pos-perm {
  top: 76px;
  left: 16px;
}

.pos-di2 {
  top: 76px;
  right: 16px;
}

.pos-relays {
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
}

.svg-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hopper-overlay-container {
  top: 51%;
}

/* Mobile & Tablet Responsive Layout */
@media (max-width: 900px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    padding: 8px;
  }

  #scada-app {
    width: 100%;
    max-width: 100%;
  }

  .scada-header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 12px;
  }

  .scada-title {
    flex-wrap: wrap;
    gap: 8px !important;
    min-width: 0;
  }

  .scada-title h1 {
    font-size: 14px;
    line-height: 1.25;
  }

  .scada-status {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
  }

  .scada-main-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .scada-card {
    padding: 10px;
    min-width: 0;
    max-width: 100%;
  }

  .scada-viewport {
    height: auto;
    min-height: 0;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 8px;
    gap: 8px;
    overflow: hidden;
    width: 100%;
  }

  .hud-silos {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    width: 100%;
  }

  .hud-signals {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    width: 100%;
  }

  .overlay-badge,
  .selector-relays-overlay,
  .viewport-bottom-bar {
    position: static;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    transform: none;
    min-width: 0;
  }

  .overlay-badge {
    padding: 7px 10px;
  }

  .badge-val {
    font-size: 15px;
  }

  .status-pill {
    font-size: 10px;
    line-height: 1.25;
  }

  .selector-relays-overlay {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    width: 100%;
  }

  .relay-tag {
    text-align: center;
    font-size: 10px;
    padding: 5px 6px;
  }

  .svg-stage {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    min-height: 220px;
  }

  .scada-svg {
    width: 100%;
    height: 100%;
    max-height: none;
    display: block;
  }

  .viewport-bottom-bar {
    width: 100%;
    font-size: 11px;
  }
}

@media (max-width: 520px) {
  .scada-title {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 6px !important;
  }

  .hud-signals {
    grid-template-columns: minmax(0, 1fr);
  }

  .hopper-overlay-container {
    padding: 4px 10px;
    top: 52%;
  }

  .net-weight-text {
    font-size: 18px;
  }

  .gross-weight-text {
    font-size: 9px;
  }

  .table-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .photo-table {
    font-size: 11px;
    min-width: 580px;
  }

  .photo-table th,
  .photo-table td {
    padding: 6px 8px;
  }
}
