/* =========================================================================
   STYLE.CSS - BITAC MPS Lab Power SCADA System
   FAL Knitting IoT V2 Color Grade & Industrial Pattern
   Features: Precision Modern Analog Arc Gauges & Grid-to-MPS-Lab Electron Flow
   ========================================================================= */

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

:root {
  /* Color Palette - Matching FAL Knitting IoT V2 */
  --bg-primary:     #020617; /* Deepest industrial slate black */
  --bg-card:        #0f172a; /* Slate navy */
  --border:         rgba(255, 255, 255, 0.08);
  --border-focus:   rgba(59, 130, 246, 0.5);

  /* Accents */
  --blue:           #3b82f6;
  --sky:            #7dd3fc;
  --cyan:           #06b6d4;
  --green:          #22c55e;
  --yellow:         #f59e0b;
  --red:            #ef4444;
  --purple:         #a855f7;

  /* 3-Phase Standard Colors */
  --phase-l1:       #22c55e; /* L1 Green */
  --phase-l2:       #f43f5e; /* L2 Rose/Magenta */
  --phase-l3:       #0ea5e9; /* L3 Vibrant Sky/Blue */

  /* Text */
  --text-primary:   #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;

  /* UI Tokens */
  --font-main:      'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:      'Outfit', 'Inter', sans-serif;
  --radius:         16px;
  --radius-sm:      10px;
  --shadow:         0 8px 30px rgba(0, 0, 0, 0.4);
  --transition:     0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 15px;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.4;
  padding: 8px 16px 16px;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.scada-container {
  max-width: 1440px;
  margin: 0 auto;
}

/* ============================================================
   BRAND HEADER - BITAC & MPS LAB (COMPACT CONTROL ROOM)
   ============================================================ */
.scada-header {
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.6) 0%, rgba(15, 23, 42, 0.2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  position: relative;
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.scada-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2.5px;
  background: linear-gradient(90deg, #059669, #0284c7, #7c3aed);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  height: 38px;
  width: auto;
  border-radius: 6px;
  background: #ffffff;
  padding: 2px;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.35);
  transition: transform var(--transition);
}
.header-logo:hover {
  transform: scale(1.03);
}

.header-title-box h1 {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
  margin: 0;
  letter-spacing: -0.3px;
  line-height: 1.15;
}

.header-title-box .org-badge {
  color: var(--sky);
  font-weight: 700;
}

.header-title-box p {
  font-size: 0.68rem;
  color: var(--text-secondary);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge-lab {
  background: rgba(14, 165, 233, 0.15);
  border: 1px solid rgba(14, 165, 233, 0.35);
  color: var(--sky);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 800;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

.badge-plc {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: var(--green);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.time-box {
  text-align: right;
  font-family: var(--font-mono);
}
.time-val {
  font-size: 1.02rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.1;
}
.time-sub {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.85);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.sync-text-header {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.live-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: pulse-green 1.6s infinite;
}
.live-dot.offline {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
  animation: none;
}
@keyframes pulse-green {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70%  { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ============================================================
   ROW 2-5: COMPACT TELEMETRY CARDS (SINGLE MONITOR NO SCROLL)
   ============================================================ */
.metrics-section {
  margin-bottom: 9px;
}

.section-header-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.section-title-sm {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.2px;
}

.section-tag {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.7);
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.cards-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.cards-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (max-width: 900px) {
  .cards-grid-3 { grid-template-columns: 1fr; }
  .cards-grid-2 { grid-template-columns: 1fr; }
}

.telemetry-card {
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.95) 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 64px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.telemetry-card:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.telemetry-card.card-l1 { border-left: 3px solid var(--phase-l1); }
.telemetry-card.card-l2 { border-left: 3px solid var(--phase-l2); }
.telemetry-card.card-l3 { border-left: 3px solid var(--phase-l3); }
.telemetry-card.card-freq { border-left: 3px solid var(--yellow); }
.telemetry-card.card-today { border-left: 3px solid var(--green); }
.telemetry-card.card-kwh { border-left: 3px solid var(--cyan); }

.card-header-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1px;
}

.card-title-compact {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0.2px;
}

.phase-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-l1 { background: var(--phase-l1); box-shadow: 0 0 5px var(--phase-l1); }
.dot-l2 { background: var(--phase-l2); box-shadow: 0 0 5px var(--phase-l2); }
.dot-l3 { background: var(--phase-l3); box-shadow: 0 0 5px var(--phase-l3); }

.badge-compact {
  font-size: 0.55rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-normal {
  color: var(--green);
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.3);
}
.badge-idle {
  color: var(--text-muted);
  background: rgba(100, 116, 139, 0.15);
  border: 1px solid rgba(100, 116, 139, 0.25);
}
.badge-warn {
  color: var(--yellow);
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
}
.badge-danger {
  color: var(--red);
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.badge-cyan {
  color: var(--cyan);
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.35);
}

.card-body-compact {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin: 2px 0 2px;
}

.card-val-compact {
  font-family: var(--font-mono);
  font-size: 1.38rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  color: #f8fafc;
}
.card-l1 .card-val-compact { color: var(--phase-l1); }
.card-l2 .card-val-compact { color: var(--phase-l2); }
.card-l3 .card-val-compact { color: var(--phase-l3); }
.card-freq .card-val-compact { color: var(--yellow); }
.card-today .card-val-compact { color: #4ade80; }
.card-kwh .card-val-compact { color: var(--cyan); }

.card-unit-compact {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-left: 2px;
}

.card-progress-bar {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
  margin: 3px 0 2px;
}
.bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}
.bar-l1 { background: var(--phase-l1); }
.bar-l2 { background: var(--phase-l2); }
.bar-l3 { background: var(--phase-l3); }

.card-footer-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Wire state tags */
.wire-state-tag {
  font-size: 0.55rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  margin-left: 3px;
}
.wire-state-tag.idle {
  background: rgba(100, 116, 139, 0.2);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.3);
}
.wire-state-tag.active {
  background: rgba(34, 197, 94, 0.18);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

/* ============================================================
   ROW 1 (TOP): GRID-TO-MPS-LAB SCADA BUS BAR & ELECTRON FLOW
   ============================================================ */
.scada-flow-card {
  background: linear-gradient(180deg, #070d19 0%, #030712 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.flow-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.flow-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--sky);
  display: flex;
  align-items: center;
  gap: 6px;
}
.flow-status-tag {
  font-size: 0.64rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* 2-Terminal Pipeline Container: Grid (Left) -> Cables (Center) -> MPS Lab (Right) */
.pipeline-container {
  display: flex;
  align-items: center;
  gap: 10px;
}
@media (max-width: 860px) {
  .pipeline-container {
    flex-direction: column;
  }
}

.pipeline-station {
  width: 175px;
  flex-shrink: 0;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  transition: border-color var(--transition);
}
.pipeline-station:hover {
  border-color: var(--blue);
}

.station-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.grid-station .station-icon {
  background: rgba(59, 130, 246, 0.15);
  color: var(--blue);
  border: 1px solid rgba(59, 130, 246, 0.3);
}
.lab-station .station-icon {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.station-info h3 {
  font-size: 0.78rem;
  font-weight: 800;
  color: #fff;
  margin: 0;
  line-height: 1.15;
}
.station-info p {
  font-size: 0.62rem;
  color: var(--text-muted);
  margin: 1px 0;
}
.station-stat {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--sky);
}

/* 3-Phase Transmission Cables */
.pipeline-cables {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

.cable-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cable-phase-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 800;
  width: 18px;
  text-align: center;
}
.cable-l1 .cable-phase-label { color: var(--phase-l1); }
.cable-l2 .cable-phase-label { color: var(--phase-l2); }
.cable-l3 .cable-phase-label { color: var(--phase-l3); }

.cable-wire {
  position: relative;
  flex: 1;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cable-wire::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-50%);
  border-radius: 1px;
}

/* Animated Wire Conduits */
.cable-stream {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 3px;
  transform: translateY(-50%);
  background-size: 24px 3px;
  border-radius: 2px;
}

.cable-l1 .cable-stream {
  background-image: repeating-linear-gradient(90deg, #22c55e 0, #22c55e 10px, transparent 10px, transparent 20px);
  animation: stream-flow-l1 1.2s linear infinite;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}
.cable-l2 .cable-stream {
  background-image: repeating-linear-gradient(90deg, #f43f5e 0, #f43f5e 10px, transparent 10px, transparent 20px);
  animation: stream-flow-l2 1.2s linear infinite;
  box-shadow: 0 0 8px rgba(244, 63, 94, 0.4);
}
.cable-l3 .cable-stream {
  background-image: repeating-linear-gradient(90deg, #0ea5e9 0, #0ea5e9 10px, transparent 10px, transparent 20px);
  animation: stream-flow-l3 1.2s linear infinite;
  box-shadow: 0 0 8px rgba(14, 165, 233, 0.4);
}

@keyframes stream-flow-l1 {
  from { background-position: 0 0; }
  to   { background-position: 24px 0; }
}
@keyframes stream-flow-l2 {
  from { background-position: 0 0; }
  to   { background-position: 24px 0; }
}
@keyframes stream-flow-l3 {
  from { background-position: 0 0; }
  to   { background-position: 24px 0; }
}

/* On-Wire Live Telemetry Badges (Voltage & Current Displayed Directly On The Line) */
.cable-badge {
  position: relative;
  z-index: 2;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border);
  padding: 1.5px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

.cable-l1 .cable-badge { border-color: rgba(34, 197, 94, 0.4); color: #4ade80; }
.cable-l2 .cable-badge { border-color: rgba(244, 63, 94, 0.4); color: #fb7185; }
.cable-l3 .cable-badge { border-color: rgba(14, 165, 233, 0.4); color: #38bdf8; }

.cable-badge strong {
  font-size: 0.74rem;
  color: #fff;
}

/* ============================================================
   ANALYTICS & TIME RANGE TOOLBAR (1H, 5H, TODAY, CUSTOM)
   ============================================================ */
.analytics-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  margin-bottom: 6px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.btn-group-range {
  display: flex;
  background: rgba(2, 6, 23, 0.8);
  border-radius: 6px;
  padding: 2px;
  border: 1px solid var(--border);
  gap: 2px;
}

.btn-range {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
}
.btn-range:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}
.btn-range.active {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.btn-range-view {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--yellow);
  font-family: var(--font-main);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
}
.btn-range-view:hover {
  background: rgba(245, 158, 11, 0.22);
}
.btn-range-view.active {
  background: var(--yellow);
  color: #020617;
  font-weight: 800;
}

.custom-date-filter {
  display: flex;
  align-items: center;
  gap: 5px;
}

.scada-date-input {
  background: rgba(2, 6, 23, 0.9);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 2.5px 6px;
  outline: none;
}
.scada-date-input:focus {
  border-color: var(--blue);
}

.btn-date-filter {
  background: rgba(14, 165, 233, 0.15);
  border: 1px solid rgba(14, 165, 233, 0.35);
  color: var(--sky);
  font-family: var(--font-main);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-date-filter:hover {
  background: rgba(14, 165, 233, 0.3);
}

/* Hourly Chart Panel */
.hourly-chart-panel {
  margin-top: 6px;
  margin-bottom: 8px;
}

.chart-wrapper-hourly {
  position: relative;
  height: 180px;
  width: 100%;
}

.hourly-stats-badge {
  font-size: 0.66rem;
  color: var(--text-secondary);
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.hourly-stats-badge strong {
  color: var(--yellow);
}

.chart-mode-pill {
  font-size: 0.58rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  background: rgba(59, 130, 246, 0.18);
  color: var(--sky);
  border: 1px solid rgba(59, 130, 246, 0.35);
  margin-left: 4px;
}

/* ============================================================
   ROW 5: REAL-TIME STREAMING CHARTS (CLEAN DUAL VIEW)
   ============================================================ */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
  margin-bottom: 10px;
}
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.chart-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chart-title i {
  color: var(--blue);
}

.chart-wrapper {
  position: relative;
  height: 145px;
  width: 100%;
}

/* ============================================================
   FOOTER
   ============================================================ */
.scada-footer {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.65rem;
  color: var(--text-muted);
}
.scada-footer a {
  color: var(--sky);
  text-decoration: none;
}
