/* ============================================================
   PlantGuard IoT — Premium Dark Dashboard Theme
   Cyberpunk × Botanical Aesthetic
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --bg-primary: #060b18;
  --bg-secondary: #0a1128;
  --bg-card: rgba(10, 17, 40, 0.82);
  --bg-card-hover: rgba(15, 25, 55, 0.9);
  --border-card: rgba(74, 222, 128, 0.12);
  --border-card-hover: rgba(74, 222, 128, 0.3);

  --accent-green: #4ade80;
  --accent-cyan: #22d3ee;
  --accent-amber: #fbbf24;
  --accent-red: #f87171;
  --accent-emerald: #34d399;
  --accent-blue: #60a5fa;

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --glow-green: 0 0 24px rgba(74, 222, 128, 0.25);
  --glow-cyan: 0 0 24px rgba(34, 211, 238, 0.25);
  --glow-amber: 0 0 24px rgba(251, 191, 36, 0.25);
  --glow-red: 0 0 24px rgba(248, 113, 113, 0.25);

  --font-display: 'Orbitron', monospace, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --ring-circumference: 314.16; /* 2 * PI * 50 */
  --health-circumference: 515.22; /* 2 * PI * 82 */
  --transition-fast: 0.2s ease;
  --transition-med: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* --- Animated Background Mesh --- */
.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(74, 222, 128, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(34, 211, 238, 0.05) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 50% 50%, rgba(96, 165, 250, 0.03) 0%, transparent 60%);
  animation: meshDrift 20s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes meshDrift {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-20px, 15px) scale(1.02); }
  100% { transform: translate(10px, -10px) scale(0.98); }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(74, 222, 128, 0.2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(74, 222, 128, 0.4); }

/* --- Layout Shell --- */
#app-header, main, #app-footer {
  position: relative;
  z-index: 1;
}

/* ===================== HEADER ===================== */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid rgba(74, 222, 128, 0.08);
  backdrop-filter: blur(16px);
  background: rgba(6, 11, 24, 0.7);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

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

.logo-icon-wrap {
  position: relative;
  font-size: 1.6rem;
  line-height: 1;
}

.logo-pulse {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--accent-green);
  opacity: 0;
  animation: logoPulse 2.5s ease-out infinite;
}

@keyframes logoPulse {
  0% { transform: scale(0.8); opacity: 0.6; }
  100% { transform: scale(1.6); opacity: 0; }
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-primary);
}

.logo-accent { color: var(--accent-green); }
.logo-sub {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--accent-cyan);
  vertical-align: super;
  letter-spacing: 3px;
  margin-left: 4px;
}

/* Simulation Badge */
.sim-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid rgba(251, 191, 36, 0.3);
  background: rgba(251, 191, 36, 0.08);
  font-family: var(--font-display);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--accent-amber);
}

.sim-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-amber);
  animation: blink 1.5s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Connection Status */
.connection-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.status-dot.connected {
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
  animation: statusPulse 2s ease-in-out infinite;
}

.status-dot.disconnected {
  background: var(--accent-red);
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.5);
}

@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(74, 222, 128, 0.5); }
  50% { box-shadow: 0 0 16px rgba(74, 222, 128, 0.8); }
}

/* ===================== MAIN DASHBOARD ===================== */
#dashboard {
  max-width: 1340px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===================== SIM CONTROLS ===================== */
.sim-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  backdrop-filter: blur(12px);
  flex-wrap: wrap;
}

.sim-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border: 1px solid var(--accent-green);
  border-radius: var(--radius-sm);
  background: rgba(74, 222, 128, 0.08);
  color: var(--accent-green);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sim-btn:hover {
  background: rgba(74, 222, 128, 0.18);
  box-shadow: var(--glow-green);
}

.sim-btn.running {
  border-color: var(--accent-amber);
  color: var(--accent-amber);
  background: rgba(251, 191, 36, 0.08);
}

.sim-btn.running:hover {
  background: rgba(251, 191, 36, 0.18);
  box-shadow: var(--glow-amber);
}

.speed-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.speed-label {
  font-family: var(--font-display);
  font-size: 0.6rem;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-right: 4px;
}

.speed-btn {
  padding: 5px 12px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.speed-btn:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.speed-btn.active {
  border-color: var(--accent-cyan);
  background: rgba(34, 211, 238, 0.1);
  color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.15);
}

.virtual-time {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.vt-label {
  font-size: 0.55rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-display);
}

.vt-value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent-cyan);
}

/* ===================== METRIC CARDS ===================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.metric-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 16px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  transition: all var(--transition-med);
  cursor: default;
}

.metric-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-card-hover);
  transform: translateY(-4px);
  box-shadow: var(--glow-green);
}

.metric-ring-wrap {
  position: relative;
  width: 110px;
  height: 110px;
}

.metric-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: rgba(148, 163, 184, 0.08);
  stroke-width: 6;
}

.ring-fill {
  fill: none;
  stroke: var(--accent-green);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: var(--ring-circumference);
  stroke-dashoffset: var(--ring-circumference);
  transition: stroke-dashoffset 0.8s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.4s ease;
  filter: drop-shadow(0 0 6px rgba(74, 222, 128, 0.3));
}

.metric-val-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.metric-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  transition: color var(--transition-fast);
}

.metric-unit {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-secondary);
  align-self: flex-end;
  margin-bottom: 4px;
}

.metric-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.metric-icon { font-size: 1rem; }

.metric-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.metric-status {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.06);
}

.metric-status.optimal { color: var(--accent-green); background: rgba(74, 222, 128, 0.08); }
.metric-status.warning { color: var(--accent-amber); background: rgba(251, 191, 36, 0.08); }
.metric-status.critical { color: var(--accent-red); background: rgba(248, 113, 113, 0.08); }

/* ===================== PANEL SHARED ===================== */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  padding: 22px;
  transition: border-color var(--transition-fast);
}

.panel:hover { border-color: var(--border-card-hover); }

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

.title-icon { font-size: 1rem; }

/* ===================== MIDDLE ROW ===================== */
.middle-row {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
}

/* --- Plant Health --- */
.health-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.health-ring-wrap {
  position: relative;
  width: 180px;
  height: 180px;
  margin-bottom: 18px;
}

.health-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.health-ring-bg {
  fill: none;
  stroke: rgba(148, 163, 184, 0.06);
  stroke-width: 8;
}

.health-ring-fill {
  fill: none;
  stroke: url(#grad-good);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: var(--health-circumference);
  stroke-dashoffset: var(--health-circumference);
  transition: stroke-dashoffset 1s cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 0 10px rgba(74, 222, 128, 0.3));
}

.health-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.health-score {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--text-primary);
  line-height: 1;
}

.health-rating {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 3px;
  margin-top: 4px;
  color: var(--accent-green);
  transition: color var(--transition-fast);
}

.health-details {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.06);
}

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

.detail-value {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* --- Chart --- */
.chart-panel {
  min-height: 340px;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ===================== BOTTOM ROW ===================== */
.bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* --- Alert Log --- */
.alert-badge {
  margin-left: auto;
  padding: 2px 10px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  background: rgba(248, 113, 113, 0.12);
  color: var(--accent-red);
  min-width: 28px;
  text-align: center;
}

.alert-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.alert-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
  font-style: italic;
}

.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(148, 163, 184, 0.03);
  border-left: 3px solid var(--text-muted);
  animation: alertSlide 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.alert-item.warning { border-left-color: var(--accent-amber); }
.alert-item.critical { border-left-color: var(--accent-red); }
.alert-item.info { border-left-color: var(--accent-cyan); }

@keyframes alertSlide {
  0% { opacity: 0; transform: translateX(20px); }
  100% { opacity: 1; transform: translateX(0); }
}

.alert-severity {
  font-size: 0.9rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-msg {
  font-size: 0.78rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.alert-time {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* --- Telemetry Stream --- */
.stream-panel .panel-title {
  position: relative;
}

.stream-clear-btn {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.stream-clear-btn:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.stream-terminal {
  max-height: 260px;
  overflow-y: auto;
  padding: 14px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(74, 222, 128, 0.06);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.7;
}

.stream-line {
  color: var(--accent-green);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: streamFade 0.3s ease;
}

.stream-line.sys { color: var(--accent-cyan); }

.stream-line .json-key { color: var(--accent-cyan); }
.stream-line .json-num { color: var(--accent-amber); }
.stream-line .json-str { color: var(--accent-green); }

@keyframes streamFade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* ===================== FOOTER ===================== */
#app-footer {
  text-align: center;
  padding: 28px 24px;
  border-top: 1px solid rgba(74, 222, 128, 0.06);
  margin-top: 20px;
}

.footer-badges {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tech-badge {
  padding: 4px 14px;
  border-radius: 20px;
  border: 1px solid rgba(34, 211, 238, 0.2);
  background: rgba(34, 211, 238, 0.05);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--accent-cyan);
  letter-spacing: 1px;
}

.footer-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 1px;
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 1100px) {
  .middle-row {
    grid-template-columns: 1fr;
  }
  .health-panel {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 24px;
  }
  .health-details { max-width: 280px; }
}

@media (max-width: 900px) {
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .bottom-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  #app-header { padding: 12px 16px; }
  .logo-text { font-size: 0.9rem; }
  .sim-badge { font-size: 0.5rem; padding: 4px 10px; }
  #dashboard { padding: 14px 12px 30px; }
  .metrics-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .metric-card { padding: 16px 10px 14px; }
  .metric-ring-wrap { width: 90px; height: 90px; }
  .metric-value { font-size: 1.1rem; }
  .sim-controls { gap: 10px; padding: 10px 14px; }
  .sim-controls .virtual-time { margin-left: 0; }
  .panel { padding: 16px; }
}

@media (max-width: 400px) {
  .metrics-grid { grid-template-columns: 1fr; }
}
