/* ====================================================================
   ELECTRO-LOG 4G | IoT Smart Grid Fleet Dashboard
   Theme: Industrial Dark Glassmorphism
   ==================================================================== */

:root {
  --bg-primary: #070b14;
  --bg-secondary: #0c1220;
  --bg-card: rgba(16, 24, 40, 0.75);
  --bg-card-hover: rgba(23, 34, 56, 0.9);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(0, 240, 255, 0.4);
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --cyan: #00f0ff;
  --cyan-glow: rgba(0, 240, 255, 0.25);
  --amber: #ffb703;
  --amber-glow: rgba(255, 183, 3, 0.25);
  --purple: #c084fc;
  --purple-glow: rgba(192, 132, 252, 0.25);
  --green: #10b981;
  --green-glow: rgba(16, 185, 129, 0.25);
  --red: #f43f5e;
  --red-glow: rgba(244, 63, 94, 0.25);
  
  --phase-l1: #00f0ff;
  --phase-l2: #ffb703;
  --phase-l3: #c084fc;
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body.dark-theme {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 15% 20%, rgba(0, 240, 255, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(192, 132, 252, 0.05) 0%, transparent 40%),
    linear-gradient(180deg, var(--bg-primary) 0%, #05080e 100%);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--font-mono);
}

/* Top App Header */
.app-header {
  height: 72px;
  background: rgba(12, 18, 32, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.2), rgba(255, 183, 3, 0.2));
  border: 1px solid var(--cyan);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cyan);
  font-size: 1.4rem;
  box-shadow: 0 0 15px var(--cyan-glow);
}

.brand-info h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-info h1 span {
  color: var(--cyan);
  background: rgba(0, 240, 255, 0.15);
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(0, 240, 255, 0.3);
}

.brand-info .tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stat-pill strong {
  color: var(--text-main);
  font-family: var(--font-mono);
}

.clock-pill {
  font-family: var(--font-mono);
  color: var(--cyan);
  border-color: rgba(0, 240, 255, 0.2);
}

.online-pulse {
  width: 9px;
  height: 9px;
  background-color: var(--green);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 10px var(--green);
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.icon-cyan { color: var(--cyan); }
.icon-amber { color: var(--amber); }
.icon-green { color: var(--green); }
.icon-red { color: var(--red); }

/* Badges */
.badge {
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: rgba(255, 183, 3, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(255, 183, 3, 0.3);
}

.badge-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

/* App Container & Views */
.app-container {
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 1720px;
  margin: 0 auto;
  width: 100%;
}

.view-section {
  display: none;
  animation: fadeIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* KPI Top Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  transition: var(--transition);
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.16);
  background: var(--bg-card-hover);
}

.kpi-icon-wrap {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.bg-cyan-glow {
  background: rgba(0, 240, 255, 0.1);
  color: var(--cyan);
  border: 1px solid rgba(0, 240, 255, 0.25);
  box-shadow: 0 0 15px var(--cyan-glow);
}

.bg-amber-glow {
  background: rgba(255, 183, 3, 0.1);
  color: var(--amber);
  border: 1px solid rgba(255, 183, 3, 0.25);
  box-shadow: 0 0 15px var(--amber-glow);
}

.bg-purple-glow {
  background: rgba(192, 132, 252, 0.1);
  color: var(--purple);
  border: 1px solid rgba(192, 132, 252, 0.25);
  box-shadow: 0 0 15px var(--purple-glow);
}

.bg-green-glow {
  background: rgba(16, 185, 129, 0.1);
  color: var(--green);
  border: 1px solid rgba(16, 185, 129, 0.25);
  box-shadow: 0 0 15px var(--green-glow);
}

.kpi-title {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.kpi-val {
  font-size: 1.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-main);
  line-height: 1.2;
}

.kpi-val .unit {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-muted);
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Fleet Content Layout: Map + Device Grid */
.fleet-content-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel {
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.panel-header {
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.panel-title i {
  color: var(--cyan);
  font-size: 1.1rem;
}

.panel-title h3 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.panel-tag {
  background: rgba(0, 240, 255, 0.1);
  color: var(--cyan);
  border: 1px solid rgba(0, 240, 255, 0.25);
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-weight: 500;
}

.legend-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.map-container {
  height: 380px;
  width: 100%;
  background: #090e18;
}

/* Device Cards Grid */
.device-grid {
  padding: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1.25rem;
}

.device-card {
  background: rgba(14, 21, 37, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.device-card:hover {
  transform: translateY(-4px);
  border-color: var(--cyan);
  box-shadow: 0 10px 30px -10px rgba(0, 240, 255, 0.2);
  background: rgba(18, 28, 48, 0.95);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.card-device-id {
  font-size: 1.1rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-location {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Mini Phase Meters inside Device Card */
.card-phases-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.mini-phase {
  text-align: center;
}

.mini-phase-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

.mini-phase.l1 .mini-phase-label { color: var(--phase-l1); }
.mini-phase.l2 .mini-phase-label { color: var(--phase-l2); }
.mini-phase.l3 .mini-phase-label { color: var(--phase-l3); }

.mini-phase-val {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.mini-phase-val small {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-muted);
}

.card-metrics-strip {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.75rem;
}

.card-metrics-strip strong {
  color: var(--text-main);
  font-family: var(--font-mono);
}

.card-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.25rem;
  padding-top: 0.5rem;
}

.card-cta .btn-view {
  width: 100%;
  background: rgba(0, 240, 255, 0.1);
  color: var(--cyan);
  border: 1px solid rgba(0, 240, 255, 0.3);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.device-card:hover .btn-view {
  background: var(--cyan);
  color: #05080e;
  box-shadow: 0 0 15px var(--cyan-glow);
}

/* ==================== VIEW 2: DEVICE DEEP-DIVE ==================== */
.detail-header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.detail-header-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.device-title-box h2 {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-main);
  line-height: 1.2;
}

.device-alias {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: block;
}

.detail-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.device-meta-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, #00f0ff, #0099ff);
  color: #030712;
  box-shadow: 0 4px 15px rgba(0, 240, 255, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 240, 255, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--cyan);
  border-color: rgba(0, 240, 255, 0.3);
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.btn-outline:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

/* Status Strip */
.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  background: rgba(14, 21, 37, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.25rem;
  font-size: 0.8rem;
}

.strip-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.strip-label {
  color: var(--text-dim);
}

.strip-item strong {
  color: var(--cyan);
}

/* Meter Grid ( Gauges & KPI Cards ) */
.meter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.meter-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  position: relative;
  overflow: hidden;
}

.meter-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.meter-card.phase-l1::before { background: var(--phase-l1); box-shadow: 0 0 10px var(--cyan); }
.meter-card.phase-l2::before { background: var(--phase-l2); box-shadow: 0 0 10px var(--amber); }
.meter-card.phase-l3::before { background: var(--phase-l3); box-shadow: 0 0 10px var(--purple); }
.meter-card.power-card::before { background: linear-gradient(90deg, var(--amber), var(--cyan)); }
.meter-card.thermal-card::before { background: linear-gradient(90deg, #f43f5e, #fb923c); }
.meter-card.vibration-card::before { background: linear-gradient(90deg, #10b981, #06b6d4); }

.meter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.meter-value {
  font-size: 2.2rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-main);
  line-height: 1;
}

.meter-value small {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-muted);
}

.meter-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.meter-sub span {
  color: var(--text-main);
  font-family: var(--font-mono);
}

.meter-bar-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
}

.meter-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.fill-l1 { background: var(--phase-l1); box-shadow: 0 0 8px var(--cyan); }
.fill-l2 { background: var(--phase-l2); box-shadow: 0 0 8px var(--amber); }
.fill-l3 { background: var(--phase-l3); box-shadow: 0 0 8px var(--purple); }
.fill-power { background: linear-gradient(90deg, var(--amber), #fb8500); }
.fill-vib { background: linear-gradient(90deg, var(--green), #38bdf8); }

.thermal-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.thermal-col {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.thermal-col .label {
  color: var(--text-muted);
}

.thermal-col strong {
  font-family: var(--font-mono);
  color: #fb7185;
}

/* Charts Grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(520px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.chart-panel {
  display: flex;
  flex-direction: column;
}

.chart-badges {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.badge-dot {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
}

.badge-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.badge-l1::before { background: var(--phase-l1); box-shadow: 0 0 6px var(--cyan); }
.badge-l2::before { background: var(--phase-l2); box-shadow: 0 0 6px var(--amber); }
.badge-l3::before { background: var(--phase-l3); box-shadow: 0 0 6px var(--purple); }

.badge-power-p::before { background: var(--amber); }
.badge-power-s::before { background: var(--cyan); }

.badge-temp1::before { background: #f43f5e; }
.badge-temp2::before { background: #fb923c; }
.badge-temp-mpu::before { background: #c084fc; }

.badge-ax::before { background: #38bdf8; }
.badge-ay::before { background: #e879f9; }
.badge-az::before { background: #4ade80; }

.chart-body {
  padding: 1rem 1.25rem;
  height: 280px;
  position: relative;
  width: 100%;
}

/* Bottom Split: Mini Map & Console */
.detail-bottom-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.mini-map-container {
  height: 250px;
  width: 100%;
  background: #090e18;
}

.terminal-body {
  height: 250px;
  background: #04070e;
  padding: 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  overflow-y: auto;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column-reverse; /* auto scrolls to latest */
}

.term-line {
  line-height: 1.6;
  word-break: break-all;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  padding: 2px 0;
}

.term-line.info { color: #38bdf8; }
.term-line.telemetry { color: #a7f3d0; }
.term-line.warn { color: #fde047; }
.term-line.error { color: #f87171; }

/* Footer */
.app-footer {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  padding: 1.25rem 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.footer-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .detail-bottom-split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .app-header {
    height: auto;
    padding: 1rem;
    flex-direction: column;
    gap: 0.75rem;
  }
  .header-stats {
    flex-wrap: wrap;
    justify-content: center;
  }
  .app-container {
    padding: 1rem;
  }
  .detail-header-bar {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Modern Industrial Dark Theme for Map Tiles */
.leaflet-tile {
  filter: brightness(0.65) invert(1) contrast(2.6) hue-rotate(200deg) saturate(0.25) brightness(0.85) !important;
}
.leaflet-container {
  background: #070b14 !important;
}
