/* ============================================
   Grafana/Prometheus Inspired Dark Theme
   Clean, minimal, professional monitoring UI
   ============================================ */

/* CSS Variables for consistent theming */
:root {
  --bg-canvas: #111217;
  --bg-primary: #181b1f;
  --bg-secondary: #212529;
  --bg-card: #1e2228;
  --bg-hover: #2a2f36;
  --bg-input: #0b0c0e;
  
  --border-weak: #2c3136;
  --border-medium: #3d444d;
  
  --text-primary: #d8dee9;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --text-link: #58a6ff;
  
  --accent-blue: #3b82f6;
  --accent-green: #73bf69;
  --accent-orange: #ff9830;
  --accent-red: #f2495c;
  --accent-purple: #b877d9;
  --accent-cyan: #5ec4e3;
  --accent-yellow: #fade2a;
  
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg-canvas);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Container */
.container {
  max-width: 1800px;
  margin: 0 auto;
  padding: 16px 24px;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-weak);
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

header .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Navigation Tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  width: fit-content;
}

.tab {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.tab.active {
  background: var(--accent-blue);
  color: #fff;
  transform: scale(1.02);
}

/* Tab Content */
.tab-content {
  animation: tabFadeIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Main Content Grid */
.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.content > * {
  min-width: 0;
}

@media (max-width: 1100px) {
  .content {
    grid-template-columns: 1fr;
  }
}

/* Cards / Panels */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-lg);
  padding: 16px;
  animation: cardFadeIn 0.3s ease;
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-weak);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Nodes Grid Container (holds Board Cards) */
.nodes-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ESP32 Board Card Container */
.board-card {
  background: var(--bg-card);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-lg);
  padding: 18px;
  animation: cardFadeIn 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-weak);
  flex-wrap: wrap;
  gap: 12px;
}

.board-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.board-icon {
  font-size: 18px;
}

.board-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  letter-spacing: -0.3px;
}

.board-count-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 2px 8px;
  border-radius: 12px;
}

.board-totals {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-primary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-weak);
}

.board-total-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.board-total-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-cyan);
}

/* Board Channels Grid (PZEM Cards inside Board) */
.board-channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.node-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.node-card:hover {
  border-color: var(--accent-blue);
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.node-card.no-data {
  border-style: dashed;
  cursor: default;
}

.node-card.no-data:hover {
  border-color: var(--border-weak);
  background: var(--bg-secondary);
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  gap: 8px;
}

.node-title-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.node-channel-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.node-ch-badge {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  width: fit-content;
}

.node-threshold-badge {
  font-size: 11px;
  color: var(--accent-orange);
  font-family: var(--font-mono);
  background: rgba(255, 152, 48, 0.12);
  border: 1px solid rgba(255, 152, 48, 0.35);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  width: fit-content;
  font-weight: 500;
}

.node-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
  transition: all 0.3s ease;
}

.node-status.online {
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.node-status.offline {
  background: #ef4444 !important;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.85) !important;
}

.node-board-badge {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  width: fit-content;
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.node-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.node-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  margin-top: 4px;
}

.node-status.online {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.node-status.offline {
  background: var(--text-muted);
}

/* Sidebar Active Nodes Metric Rows */
.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: border-color 0.15s ease;
}

.metric-row:hover {
  border-color: var(--border-medium);
}

.metric-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.metric-channel {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.metric-board {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-cyan);
  flex-shrink: 0;
  white-space: nowrap;
}

.node-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 100%;
  overflow: hidden;
}

.chip-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Current Value Display */
.current-display {
  margin-bottom: 12px;
}

.current-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  letter-spacing: -1px;
  line-height: 1.1;
}

/* Mini Chart Container */
.mini-chart-container {
  height: 70px;
  margin: 12px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* Mini Stats Grid */
.mini-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.mini-stat {
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-align: left;
}

.mini-stat .muted {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.mini-stat-value {
  font-size: 16px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

/* Right Sidebar */
.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (max-width: 1100px) {
  .controls {
    grid-column: 1;
  }
}

/* Time Range Buttons */
.time-range-btn {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-weak);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.time-range-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.time-range-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

/* Buttons */
.btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-weak);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
}

.btn.primary {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.btn.primary:hover {
  background: #2563eb;
  border-color: #2563eb;
}

.btn.secondary {
  background: transparent;
  color: var(--text-secondary);
}

.btn.secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Form Elements */
input[type="date"],
input[type="time"],
select {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-weak);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  transition: border-color 0.15s ease;
}

input[type="date"]:focus,
input[type="time"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

select {
  cursor: pointer;
}

input[type="checkbox"] {
  accent-color: var(--accent-blue);
}

/* Historical Controls */
.historical-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  margin-top: 12px;
}

.historical-controls label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Historical Download Progress Card */
.historical-progress-card {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.historical-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
}

.historical-progress-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--text-primary);
}

.historical-progress-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mono-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

.history-cancel-btn {
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  background: rgba(242, 73, 92, 0.2);
  border: 1px solid rgba(242, 73, 92, 0.5);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.3;
}

.history-cancel-btn:hover {
  background: var(--accent-red);
  border-color: var(--accent-red);
  box-shadow: 0 0 8px rgba(242, 73, 92, 0.45);
}

.historical-progress-track {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.historical-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-blue) 0%, var(--accent-cyan) 100%);
  border-radius: 3px;
  transition: width 0.15s ease-out, background 0.3s ease;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.historical-progress-bar.success {
  background: linear-gradient(90deg, var(--accent-green) 0%, #48bb78 100%);
  box-shadow: 0 0 8px rgba(115, 191, 105, 0.4);
}

.historical-progress-bar.error {
  background: var(--accent-red);
  box-shadow: 0 0 8px rgba(242, 73, 92, 0.4);
}

.historical-progress-bar.indeterminate {
  width: 40% !important;
  animation: progressShimmer 1.4s infinite ease-in-out;
}

@keyframes progressShimmer {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(120%); }
  100% { transform: translateX(250%); }
}

.historical-progress-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.history-spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(59, 130, 246, 0.25);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: historySpin 0.75s linear infinite;
}

@keyframes historySpin {
  to { transform: rotate(360deg); }
}

.historical-chart-box {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
}

/* Log Panel */
.log {
  height: 400px;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.log::-webkit-scrollbar {
  width: 8px;
}

.log::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.log::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 4px;
}

/* Summary Metrics */
.metrics {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.metric:hover {
  border-color: var(--border-medium);
}

.m-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.m-value {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
}

/* Legend */
.legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.node-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.node-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.node-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.node-dot.white {
  background: #fff;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.25s ease, backdrop-filter 0.25s ease;
}

.modal.active {
  display: flex;
  opacity: 1;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  position: relative;
  transform: scale(0.95) translateY(20px);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.modal.active .modal-content {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.modal-close {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 18px;
  transition: all 0.15s ease;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Modal Time Range Buttons */
.modal-time-range-btn {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-weak);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-time-range-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-time-range-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

/* Tables */
.table-wrap {
  max-height: 300px;
  overflow: auto;
  margin-top: 16px;
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-weak);
}

th {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 11px;
  position: sticky;
  top: 0;
}

td {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

tr:hover td {
  background: var(--bg-hover);
}

/* Helper Classes */
.muted {
  color: var(--text-muted);
  font-size: 12px;
}

.center {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Color Classes for Metrics */
.color-voltage { color: var(--accent-yellow); }
.color-current { color: var(--accent-cyan); }
.color-power { color: var(--accent-orange); }
.color-energy { color: var(--accent-green); }
.color-frequency { color: var(--accent-purple); }
.color-pf { color: var(--accent-blue); }

/* Status Indicators */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}

.status-badge.online {
  background: rgba(115, 191, 105, 0.15);
  color: var(--accent-green);
}

.status-badge.offline {
  background: rgba(242, 73, 92, 0.15);
  color: var(--accent-red);
}

/* Animation for live indicator */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.live-indicator {
  animation: pulse 2s ease-in-out infinite;
}

/* Panel title styling consistent with Grafana */
.panel-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.panel-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================
   Modal-specific styles
   ============================================ */

/* Modal header */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-weak);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Time range selector bar */
.time-range-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 18px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-lg);
}

.time-range-bar .label {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 13px;
}

/* Metric chart box */
.metric-chart-box {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
}

.modal-chart-container {
  height: 250px;
}

.metric-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.metric-chart-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.metric-chart-value {
  font-weight: 700;
  font-size: 16px;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
}

.metric-chart-value.voltage { color: var(--accent-red); }
.metric-chart-value.current { color: var(--accent-cyan); }
.metric-chart-value.power { color: var(--accent-yellow); }
.metric-chart-value.energy { color: var(--accent-green); }
.metric-chart-value.frequency { color: var(--accent-purple); }
.metric-chart-value.pf { color: var(--accent-orange); }

/* Node card enhancements */
.node-card .current-display {
  margin: 12px 0;
}

/* Flex utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.p-3 { padding: 12px; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }

/* Notifications */
.notification {
  position: fixed;
  top: 80px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-weak);
  border-left: 4px solid var(--accent-blue);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  max-width: 400px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  animation: slideInRight 0.3s ease;
  color: var(--text-primary);
}

.notification.error {
  border-left-color: var(--accent-red);
}

.notification.success {
  border-left-color: var(--accent-green);
}

.notification.warning {
  border-left-color: var(--accent-yellow);
}

.notification.fade-out {
  animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideInRight {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

/* Threshold controls */
.threshold-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  margin-top: 8px;
  font-size: 12px;
}

.threshold-control input[type="number"] {
  width: 80px;
  padding: 4px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.threshold-control input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Multi-metric limit inputs inside the node modal */
.threshold-limits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.threshold-limit-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.threshold-limit-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.threshold-limit-field input[type="number"] {
  width: 100%;
  padding: 4px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Snapshot detail ECharts container */
.snapshot-chart {
  margin-top: 14px;
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
}

/* Time range button states */
.time-range-btn:disabled,
.modal-time-range-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--bg-secondary);
  color: var(--text-muted);
}

.time-range-btn:disabled:hover,
.modal-time-range-btn:disabled:hover {
  background: var(--bg-secondary);
  color: var(--text-muted);
  transform: none;
}

/* ============================================
   Secure OTA Manager Styles
   ============================================ */
.ota-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.ota-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ota-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.dropzone {
  border: 2px dashed var(--border-medium);
  border-radius: var(--radius-md);
  padding: 28px 16px;
  text-align: center;
  background: var(--bg-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.08);
}

.dropzone-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.upload-icon {
  font-size: 32px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent-blue);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.ota-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ota-form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.btn.full-width {
  width: 100%;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
}

.upload-preview {
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ota-progress-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 16px;
  animation: cardFadeIn 0.3s ease;
}

.ota-status-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--border-medium);
  color: var(--text-primary);
}

.ota-status-badge.flashing, .ota-status-badge.downloading {
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent-blue);
}

.ota-status-badge.success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-green);
}

.ota-status-badge.failed, .ota-status-badge.rolled_back {
  background: rgba(239, 68, 68, 0.2);
  color: var(--accent-red);
}

.ota-steps {
  display: flex;
  gap: 6px;
  margin: 12px 0;
  overflow-x: auto;
}

.ota-step {
  flex: 1;
  min-width: 90px;
  text-align: center;
  padding: 8px 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.ota-step.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.ota-step.completed {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.progress-bar-container {
  height: 20px;
  background: var(--bg-primary);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-weak);
  margin-bottom: 12px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #06b6d4);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}

.sec-badge strong {
  color: var(--accent-cyan);
}

.badge-icon {
  font-size: 14px;
}

.ota-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.ota-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ota-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.dropzone {
  border: 2px dashed var(--border-medium);
  border-radius: var(--radius-md);
  padding: 28px 16px;
  text-align: center;
  background: var(--bg-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.08);
}

.dropzone-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.upload-icon {
  font-size: 32px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent-blue);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.ota-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ota-form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.btn.full-width {
  width: 100%;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
}

.upload-preview {
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ota-progress-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 16px;
  animation: cardFadeIn 0.3s ease;
}

.ota-status-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--border-medium);
  color: var(--text-primary);
}

.ota-status-badge.flashing, .ota-status-badge.downloading {
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent-blue);
}

.ota-status-badge.success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-green);
}

.ota-status-badge.failed, .ota-status-badge.rolled_back {
  background: rgba(239, 68, 68, 0.2);
  color: var(--accent-red);
}

.ota-steps {
  display: flex;
  gap: 6px;
  margin: 12px 0;
  overflow-x: auto;
}

.ota-step {
  flex: 1;
  min-width: 90px;
  text-align: center;
  padding: 8px 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.ota-step.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.ota-step.completed {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.progress-bar-container {
  height: 20px;
  background: var(--bg-primary);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-weak);
  margin-bottom: 12px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #06b6d4);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.3s ease;
}

.ota-log-box {
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  height: 140px;
  overflow-y: auto;
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
}



/* Modal Overlay & Card Popup */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 99999;
  justify-content: center;
  align-items: center;
}

.modal.active {
  display: flex !important;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
  animation: modalFadeIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ============================================
   Overcurrent Alarm Banner & Visual Feedback
   ============================================ */
.global-alarm-banner {
  background: linear-gradient(90deg, rgba(242, 73, 92, 0.25) 0%, rgba(242, 73, 92, 0.12) 100%);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  animation: alarmPulse 1.5s infinite alternate ease-in-out;
  box-shadow: 0 0 20px rgba(242, 73, 92, 0.35);
  z-index: 1000;
}

@keyframes alarmPulse {
  0% {
    box-shadow: 0 0 12px rgba(242, 73, 92, 0.3);
    border-color: rgba(242, 73, 92, 0.7);
  }
  100% {
    box-shadow: 0 0 24px rgba(242, 73, 92, 0.65);
    border-color: var(--accent-red);
  }
}

.alarm-banner-content {
  display: flex;
  align-items: center;
  gap: 14px;
}

.alarm-banner-icon {
  font-size: 26px;
  animation: iconShake 0.6s infinite ease-in-out;
}

@keyframes iconShake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}

.alarm-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.alarm-banner-text strong {
  color: var(--accent-red);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.alarm-banner-text span {
  color: var(--text-primary);
  font-size: 13px;
}

.btn-danger {
  background-color: var(--accent-red);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-danger:hover {
  background-color: #d93d4f;
  box-shadow: 0 0 10px rgba(242, 73, 92, 0.5);
}

.node-card.alarm-active {
  animation: cardAlarmPulse 1.2s infinite alternate ease-in-out !important;
  border-color: var(--accent-red) !important;
  box-shadow: 0 0 18px rgba(242, 73, 92, 0.55) !important;
}

@keyframes cardAlarmPulse {
  0% {
    box-shadow: 0 0 10px rgba(242, 73, 92, 0.4);
    border-color: rgba(242, 73, 92, 0.8);
  }
  100% {
    box-shadow: 0 0 22px rgba(242, 73, 92, 0.85);
    border-color: var(--accent-red);
  }
}


/* ============================================
   Vector icons (Tabler outline, public/assets/icons)
   Masked SVG so icons inherit currentColor.
   ============================================ */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  vertical-align: -0.125em;
}

.icon-sm { width: 0.9em; height: 0.9em; }
.icon-lg { width: 1.35em; height: 1.35em; }

.btn .icon { margin-right: 6px; }
.tab .icon { margin-right: 6px; }
.panel-title .icon { margin-right: 6px; }

.icon-alert-triangle { -webkit-mask-image: url("assets/icons/alert-triangle.svg"); mask-image: url("assets/icons/alert-triangle.svg"); }
.icon-bolt { -webkit-mask-image: url("assets/icons/bolt.svg"); mask-image: url("assets/icons/bolt.svg"); }
.icon-bell { -webkit-mask-image: url("assets/icons/bell.svg"); mask-image: url("assets/icons/bell.svg"); }
.icon-bell-off { -webkit-mask-image: url("assets/icons/bell-off.svg"); mask-image: url("assets/icons/bell-off.svg"); }
.icon-key { -webkit-mask-image: url("assets/icons/key.svg"); mask-image: url("assets/icons/key.svg"); }
.icon-lock-open { -webkit-mask-image: url("assets/icons/lock-open.svg"); mask-image: url("assets/icons/lock-open.svg"); }
.icon-camera { -webkit-mask-image: url("assets/icons/camera.svg"); mask-image: url("assets/icons/camera.svg"); }
.icon-shield-check { -webkit-mask-image: url("assets/icons/shield-check.svg"); mask-image: url("assets/icons/shield-check.svg"); }
.icon-upload { -webkit-mask-image: url("assets/icons/upload.svg"); mask-image: url("assets/icons/upload.svg"); }
.icon-refresh { -webkit-mask-image: url("assets/icons/refresh.svg"); mask-image: url("assets/icons/refresh.svg"); }
.icon-eye { -webkit-mask-image: url("assets/icons/eye.svg"); mask-image: url("assets/icons/eye.svg"); }
.icon-download { -webkit-mask-image: url("assets/icons/download.svg"); mask-image: url("assets/icons/download.svg"); }
.icon-terminal { -webkit-mask-image: url("assets/icons/terminal-2.svg"); mask-image: url("assets/icons/terminal-2.svg"); }
.icon-antenna { -webkit-mask-image: url("assets/icons/antenna.svg"); mask-image: url("assets/icons/antenna.svg"); }
.icon-server { -webkit-mask-image: url("assets/icons/server.svg"); mask-image: url("assets/icons/server.svg"); }
.icon-chart-bar { -webkit-mask-image: url("assets/icons/chart-bar.svg"); mask-image: url("assets/icons/chart-bar.svg"); }
.icon-file-text { -webkit-mask-image: url("assets/icons/file-text.svg"); mask-image: url("assets/icons/file-text.svg"); }
.icon-clock { -webkit-mask-image: url("assets/icons/clock.svg"); mask-image: url("assets/icons/clock.svg"); }
.icon-gauge { -webkit-mask-image: url("assets/icons/gauge.svg"); mask-image: url("assets/icons/gauge.svg"); }
.icon-circle-check { -webkit-mask-image: url("assets/icons/circle-check.svg"); mask-image: url("assets/icons/circle-check.svg"); }
.icon-circle-x { -webkit-mask-image: url("assets/icons/circle-x.svg"); mask-image: url("assets/icons/circle-x.svg"); }
.icon-loader { -webkit-mask-image: url("assets/icons/loader.svg"); mask-image: url("assets/icons/loader.svg"); }
.icon-cpu { -webkit-mask-image: url("assets/icons/cpu.svg"); mask-image: url("assets/icons/cpu.svg"); }
.icon-settings { -webkit-mask-image: url("assets/icons/settings.svg"); mask-image: url("assets/icons/settings.svg"); }

.board-icon,
.upload-icon,
.alarm-banner-icon {
  display: inline-block;
  line-height: 1;
}

.board-icon { color: var(--accent-cyan); }
.upload-icon { color: var(--accent-blue); }
.alarm-banner-icon { color: var(--accent-red); }

.node-threshold-badge .icon { margin-right: 4px; vertical-align: -0.1em; }

/* ============================================
   Settings tab (Telegram alerts)
   ============================================ */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-field label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.settings-field input[type="text"],
.settings-field input[type="password"],
.settings-field input[type="number"] {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-weak);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
}

.settings-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.settings-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 18px;
}

.settings-status {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.settings-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ============================================
   Responsive / mobile layout
   ============================================ */
@media (max-width: 900px) {
  html,
  body {
    overflow-x: hidden;
  }

  .container {
    padding: 12px 14px;
    max-width: 100%;
  }

  header {
    flex-wrap: wrap;
    gap: 10px;
  }

  header h1 {
    font-size: 17px;
  }

  header .subtitle {
    font-size: 12px;
  }

  .card,
  .board-card,
  .node-card {
    padding: 14px;
  }

  .card-header {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
  }

  .card-header > div {
    min-width: 0;
  }

  .tabs {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 40px;
    padding: 9px 13px;
  }

  .global-alarm-banner {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 12px 14px;
  }

  .alarm-banner-actions {
    width: 100%;
    margin-left: 0;
  }

  .alarm-banner-actions .btn {
    width: 100%;
  }

  .board-totals {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 10px;
  }

  .threshold-limits-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .ota-grid {
    grid-template-columns: 1fr;
  }

  .ota-step {
    min-width: 84px;
  }

  #historicalChart {
    height: 340px !important;
  }

  .snapshot-chart {
    height: 320px !important;
  }

  #snapshotChart {
    height: 320px !important;
  }

  .log {
    height: 320px;
  }

  .modal-content {
    width: 96% !important;
    max-width: 96% !important;
    padding: 16px !important;
    max-height: 92vh;
  }

  .card table {
    font-size: 0.82rem;
  }

  .time-range-bar {
    gap: 6px;
    padding: 10px;
  }

  .time-range-btn,
  .modal-time-range-btn {
    min-height: 34px;
  }

  .btn {
    min-height: 38px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .container {
    padding: 10px;
  }

  .card,
  .board-card,
  .node-card {
    padding: 12px;
  }

  .board-channels-grid {
    grid-template-columns: 1fr;
  }

  .mini-stats {
    grid-template-columns: 1fr 1fr;
  }

  .threshold-limits-grid {
    grid-template-columns: 1fr;
  }

  .threshold-limit-label {
    white-space: normal;
  }

  .historical-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .historical-controls > *,
  .historical-controls .btn {
    width: 100%;
  }

  .settings-actions .btn,
  .settings-actions .settings-status {
    width: 100%;
  }

  .tabs {
    padding: 3px;
  }

  .tab {
    font-size: 12px;
    padding: 8px 11px;
  }

  .modal-content {
    padding: 12px !important;
  }

  .snapshot-chart,
  #snapshotChart {
    height: 300px !important;
  }

  #historicalChart {
    height: 280px !important;
  }

  .log {
    height: 260px;
  }

  .card-header {
    flex-direction: column;
    align-items: stretch;
  }

  .card-header .btn {
    width: 100%;
  }

  .panel-title {
    font-size: 15px;
  }

  .alarm-banner-text strong {
    font-size: 12px;
  }

  .alarm-banner-text span {
    font-size: 11px;
  }
}

/* ============================================
   Responsive overflow hardening
   ============================================ */
@media (max-width: 1100px) {
  .content {
    grid-template-columns: minmax(0, 1fr);
  }

  .content > * {
    min-width: 0;
  }
}

@media (max-width: 900px) {
  .controls,
  .card,
  .board-card,
  .node-card,
  .board-header,
  .board-title-group,
  .card-header,
  .metrics,
  .metric,
  .legend,
  .node-chip,
  .mini-stats,
  .mini-stat,
  .threshold-control,
  .threshold-limits-grid,
  .settings-grid,
  .ota-card,
  .ota-grid,
  .historical-controls {
    min-width: 0;
  }

  .board-title-group {
    flex-wrap: wrap;
  }

  .board-title,
  .node-channel-name,
  .chip-text,
  .metric-channel,
  .panel-title,
  .panel-subtitle,
  .board-total-val,
  .threshold-limit-label {
    overflow-wrap: anywhere;
  }

  .board-title,
  .node-channel-name,
  .chip-text {
    white-space: normal;
  }

  .legend,
  .node-chip,
  .metrics,
  .metric {
    max-width: 100%;
  }

  .node-chip {
    overflow: hidden;
  }

  .chip-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .board-count-badge {
    flex: 0 0 auto;
  }
}

@media (max-width: 600px) {
  .tabs {
    flex-wrap: wrap;
    overflow-x: visible;
    width: 100%;
  }

  .tab {
    flex: 0 0 auto;
  }
}

/* ============================================
   Non-intrusive alarm UI
   ============================================ */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: hidden;
  pointer-events: none;
}

.notification {
  position: relative;
  top: auto;
  right: auto;
  width: 100%;
  max-width: 100%;
  padding: 12px 38px 12px 14px;
  z-index: auto;
  margin: 0;
  pointer-events: auto;
  animation: toastIn 0.22s ease;
}

.notification.fade-out {
  animation: toastOut 0.25s ease forwards;
}

.notification-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.notification-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.notification strong {
  display: block;
  font-size: 12px;
  line-height: 1.3;
  margin-bottom: 2px;
}

.notification-message {
  display: block;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

/* Silenced alarm banner: neutral, still in normal flow */
.global-alarm-banner.muted {
  background: var(--bg-secondary);
  border-color: var(--border-weak);
  box-shadow: none;
}

.global-alarm-banner.muted .alarm-banner-icon,
.global-alarm-banner.muted .alarm-banner-text strong {
  color: var(--text-secondary);
}

.global-alarm-banner.muted .alarm-banner-actions .btn {
  background: var(--bg-hover);
  border-color: var(--border-weak);
  color: var(--text-primary);
}

@keyframes toastIn {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toastOut {
  to { transform: translateY(8px); opacity: 0; }
}

/* Compact, static alarm banner (normal document flow, never overlays) */
.global-alarm-banner {
  animation: none;
  padding: 8px 12px;
  margin-bottom: 12px;
  gap: 10px;
  z-index: auto;
}

.alarm-banner-icon {
  animation: none;
  font-size: 18px;
}

.alarm-banner-text {
  min-width: 0;
  flex: 1;
}

.alarm-banner-text strong {
  font-size: 12px;
  letter-spacing: 0;
}

.alarm-banner-text span {
  display: block;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 600px) {
  .toast-container {
    left: auto;
    right: 12px;
    bottom: 12px;
    width: min(300px, calc(100vw - 24px));
  }

  .notification {
    padding: 10px 34px 10px 12px;
    font-size: 12px;
  }

  .notification-message {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .alarm-banner-text span {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* Compact single-row alarm banner on phones */
.alarm-btn-label-short {
  display: none;
}

@media (max-width: 600px) {
  .global-alarm-banner {
    flex-wrap: nowrap;
    align-items: center;
    padding: 6px 10px;
    gap: 8px;
  }

  .alarm-banner-content {
    min-width: 0;
    flex: 1;
  }

  .alarm-banner-actions {
    width: auto;
    flex: 0 0 auto;
    margin-left: 0;
  }

  .alarm-banner-actions .btn {
    width: auto;
    min-height: 32px;
    padding: 4px 10px;
    white-space: nowrap;
  }

  .alarm-btn-label-full {
    display: none;
  }

  .alarm-btn-label-short {
    display: inline;
  }

  .alarm-banner-text strong {
    font-size: 11px;
  }

  .alarm-banner-text span {
    font-size: 11px;
    -webkit-line-clamp: 1;
  }
}

/* ============================================
   Sortable snapshot tables
   ============================================ */
th.sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable-th:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

th.sortable-th:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: -2px;
}

th.sortable-th[aria-sort] {
  color: var(--text-primary);
}

.sort-indicator {
  display: inline-block;
  min-width: 0.6em;
  margin-left: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-blue);
}

/* ============================================
   Snapshot filters and pagination
   ============================================ */
.snapshot-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-top: 14px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
}

.snapshot-filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
  flex: 1 1 140px;
}

.snapshot-filter-field span {
  font-size: 11px;
  color: var(--text-secondary);
}

.snapshot-filter-field input,
.snapshot-filter-field select {
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
}

.snapshot-filters .btn {
  min-height: 34px;
  align-self: flex-end;
}

.snapshot-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.snapshot-page-info {
  font-size: 12px;
  color: var(--text-secondary);
}

.snapshot-pagination-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 600px) {
  .snapshot-filter-field {
    flex: 1 1 100%;
  }

  .snapshot-filters .btn {
    width: 100%;
  }

  .snapshot-pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .snapshot-pagination-actions .btn {
    flex: 1;
  }
}

/* ============================================
   Transient spike counter (never alarms)
   ============================================ */
.node-transient-badge {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(245, 196, 81, 0.10);
  border: 1px solid rgba(245, 196, 81, 0.40);
  color: var(--accent-yellow);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.node-transient-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-yellow);
}

/* ============================================
   Power overview (RST / PF / power-time guard)
   ============================================ */
.overview-active .controls {
  display: none;
}

.overview-active .content {
  grid-template-columns: minmax(0, 1fr);
}

.overview-setup-hint {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245, 196, 81, 0.45);
  background: rgba(245, 196, 81, 0.10);
  color: var(--accent-yellow);
  font-size: 12px;
}

.overview-phase-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.phase-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
  padding: 14px;
  min-width: 0;
}

.phase-card.empty {
  border-style: dashed;
  opacity: 0.85;
}

.phase-card.offline {
  opacity: 0.6;
}

.phase-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  min-width: 0;
}

.phase-letter {
  display: inline-flex;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(242, 73, 92, 0.15);
  color: var(--accent-red);
  font-weight: 700;
  font-size: 12px;
  flex: 0 0 auto;
}

.phase-name {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.phase-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: auto;
  background: var(--accent-green);
  flex: 0 0 auto;
}

.phase-dot.offline {
  background: var(--text-muted);
}

.phase-power {
  font-size: 28px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1.1;
}

.phase-power span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-left: 4px;
}

.phase-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 4px 0 10px;
}

.phase-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.phase-metrics div {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.phase-metrics span {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.phase-metrics strong {
  font-size: 11px;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.phase-dev {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.phase-dev span,
.balance-row span[class^="dev-"] {
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--bg-secondary);
}

.dev-ok { color: var(--accent-green); }
.dev-warn { color: var(--accent-yellow); }
.dev-bad { color: var(--accent-red); }

.phase-placeholder {
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 0;
}

.overview-panels {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.overview-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
  padding: 14px;
  min-width: 0;
}

.overview-panel h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-primary);
}

.overview-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.overview-kpis div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.overview-kpis span {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.overview-kpis strong {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.balance-rows {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

.balance-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-family: var(--font-mono);
  flex-wrap: wrap;
}

.balance-row > span:first-child {
  width: 16px;
  color: var(--text-muted);
}

.balance-row.muted {
  color: var(--text-muted);
}

.pf-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-weak);
}

.pf-row span {
  color: var(--text-muted);
}

.pf-row strong {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-weight: 600;
  text-align: right;
}

.overview-status {
  font-size: 11px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.overview-status.ok { color: var(--accent-green); background: rgba(16, 185, 129, 0.10); }
.overview-status.warn { color: var(--accent-yellow); background: rgba(245, 196, 81, 0.10); }
.overview-status.bad { color: var(--accent-red); background: rgba(242, 73, 92, 0.12); }

.overview-note {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
}

.guard-progress {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.guard-progress-fill {
  height: 100%;
  background: var(--accent-yellow);
  transition: width 0.4s linear;
}

.guard-progress-fill.bad {
  background: var(--accent-red);
}

.overview-config-section {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-weak);
}

.overview-config-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-primary);
}

.overview-config-form {
  margin-top: 16px;
}

.overview-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.overview-config-grid select,
.overview-config-grid input[type="time"] {
  width: 100%;
  padding: 6px 8px;
  min-height: 34px;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
}

.overview-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-primary);
  margin-bottom: 10px;
  cursor: pointer;
}

.overview-config-section:last-of-type {
  padding-bottom: 0;
  border-bottom: none;
}

@media (max-width: 900px) {
  .overview-phase-grid,
  .overview-panels {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .overview-config-grid {
    grid-template-columns: 1fr;
  }

  .overview-config-section h3 {
    font-size: 14px;
  }
}

.dev-idle { color: var(--text-muted); opacity: 0.65; }


/* Snapshots: sustained vs transient table switch */
.snapshot-view-switch {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.snapshot-view-switch button {
  padding: 7px 14px;
  border: 1px solid var(--border-weak);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.snapshot-view-switch button:hover {
  color: var(--text-primary);
}

.snapshot-view-switch button.active {
  color: var(--text-primary);
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.15);
}

@media (max-width: 520px) {
  .snapshot-view-switch button {
    flex: 1 1 0;
  }
}


/* ============================================
   Plain-language overview
   ============================================ */
.overview-guide {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-weak);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.overview-guide strong {
  color: var(--text-primary);
}

.overview-summary {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-weak);
  font-size: 12px;
  line-height: 1.5;
}

.overview-summary strong {
  display: block;
  margin-bottom: 2px;
}

.overview-summary ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.overview-summary li {
  margin: 2px 0;
}

.overview-summary.ok {
  color: var(--accent-green);
  background: rgba(16, 185, 129, 0.10);
  border-color: rgba(16, 185, 129, 0.35);
}

.overview-summary.warn {
  color: var(--accent-yellow);
  background: rgba(245, 196, 81, 0.10);
  border-color: rgba(245, 196, 81, 0.35);
}

.overview-summary.bad {
  color: var(--accent-red);
  background: rgba(242, 73, 92, 0.10);
  border-color: rgba(242, 73, 92, 0.35);
}

.overview-summary.neutral {
  color: var(--text-secondary);
  background: var(--bg-primary);
}

.overview-verdict {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.overview-verdict.ok { color: var(--accent-green); background: rgba(16, 185, 129, 0.12); }
.overview-verdict.warn { color: var(--accent-yellow); background: rgba(245, 196, 81, 0.12); }
.overview-verdict.bad { color: var(--accent-red); background: rgba(242, 73, 92, 0.12); }
.overview-verdict.neutral { color: var(--text-muted); background: var(--bg-secondary); }

.overview-plain {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
  margin: 0 0 10px;
}

.overview-explain {
  margin: 0 0 10px;
}

.overview-explain summary {
  cursor: pointer;
  font-size: 11px;
  color: var(--accent-blue);
}

.overview-explain p {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
}

.phase-status {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.phase-status.ok { color: var(--accent-green); background: rgba(16, 185, 129, 0.12); }
.phase-status.warn { color: var(--accent-yellow); background: rgba(245, 196, 81, 0.12); }
.phase-status.bad { color: var(--accent-red); background: rgba(242, 73, 92, 0.12); }

.phase-simple {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin: 8px 0 4px;
}

.overview-advanced {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-weak);
}

#overview.advanced .overview-advanced {
  display: block;
}

/* ============================================
   System tab - btop-like server health panels
   Scoped to .system-* so existing components are untouched.
   ============================================ */

.system-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.system-updated {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.system-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.system-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  font-size: 11px;
  white-space: nowrap;
}

.system-chip-label {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.04em;
}

.system-chip-value {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.system-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.system-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  min-width: 0;
}

.system-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.system-card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.system-big {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.system-big.green { color: var(--accent-green); }
.system-big.amber { color: var(--accent-yellow); }
.system-big.red { color: var(--accent-red); }
.system-big.neutral { color: var(--text-muted); }

.system-hint {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
}

.system-mem-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--text-secondary);
}

.system-mem-main {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.system-bar {
  height: 6px;
  width: 100%;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border-weak);
  overflow: hidden;
}

.system-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent-green);
  transition: width 0.35s ease, background-color 0.35s ease;
}

.system-bar-fill.green { background: var(--accent-green); }
.system-bar-fill.amber { background: var(--accent-yellow); }
.system-bar-fill.red { background: var(--accent-red); }
.system-bar-fill.neutral { background: var(--border-medium); }

.system-chart {
  width: 100%;
  height: 90px;
  min-height: 90px;
}

.system-kv {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 8px;
  row-gap: 2px;
  font-size: 11px;
}

.system-kv-label {
  color: var(--text-muted);
}

.system-kv-value {
  font-family: var(--font-mono);
  color: var(--text-primary);
  text-align: right;
}

.system-kv-value.green { color: var(--accent-green); }
.system-kv-value.blue { color: var(--accent-blue); }
.system-kv-value.amber { color: var(--accent-yellow); }
.system-kv-value.red { color: var(--accent-red); }

.system-wrap {
  word-break: break-all;
  text-align: left;
}

.system-cores {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 120px;
  overflow-y: auto;
}

.system-core {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 6px;
  font-size: 10px;
}

.system-core-label {
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-align: right;
}

.system-core-track {
  height: 4px;
  border-radius: 999px;
  background: var(--bg-input);
  overflow: hidden;
}

.system-core-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent-green);
  transition: width 0.35s ease, background-color 0.35s ease;
}

.system-core-fill.green { background: var(--accent-green); }
.system-core-fill.amber { background: var(--accent-yellow); }
.system-core-fill.red { background: var(--accent-red); }

.system-core-value {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  text-align: right;
}

.system-net {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.system-net .system-kv-value {
  font-size: 13px;
}

.system-net-total {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.system-card-table {
  margin-top: 12px;
}

.system-processes {
  max-height: 260px;
  overflow-y: auto;
  overflow-x: auto;
}

.system-process-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  text-align: left;
}

.system-process-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 6px 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-weak);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.system-process-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-weak);
  color: var(--text-secondary);
  white-space: nowrap;
}

.system-process-table tbody tr:hover td {
  background: var(--bg-hover);
}

.system-process-table .num,
.system-process-table .num-mono {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.system-process-table .num-mono.red { color: var(--accent-red); }
.system-process-table .num-mono.amber { color: var(--accent-yellow); }

.system-proc-name {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.system-empty {
  padding: 14px 8px !important;
  text-align: center;
  color: var(--text-muted) !important;
  white-space: normal !important;
}

.system-error {
  display: none;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(242, 73, 92, 0.4);
  border-radius: var(--radius-sm);
  background: rgba(242, 73, 92, 0.1);
  color: var(--accent-red);
  font-size: 11px;
}

@media (min-width: 1500px) {
  .system-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .system-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .system-big {
    font-size: 22px;
  }

  .system-proc-name {
    max-width: 150px;
  }
}

/* Per-sensor day/night power limit rows */
.power-limit-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0;
}

.power-limit-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.4fr) repeat(3, minmax(90px, 1fr));
  gap: 8px;
  align-items: end;
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
}

.power-limit-name {
  font-size: 12px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.power-limit-name small {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.power-limit-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.power-limit-field span {
  font-size: 10px;
  color: var(--text-muted);
}

.power-limit-field input {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
}

.power-limit-empty {
  font-size: 11px;
}

@media (max-width: 700px) {
  .power-limit-row {
    grid-template-columns: 1fr 1fr;
  }

  .power-limit-name {
    grid-column: 1 / -1;
  }
}

.power-limit-enabled {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
}

.power-limit-enabled input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.power-limit-row {
  grid-template-columns: auto minmax(140px, 1.4fr) repeat(3, minmax(90px, 1fr));
}

.settings-limit-fields {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (max-width: 700px) {
  .power-limit-row {
    grid-template-columns: 1fr 1fr;
  }

  .power-limit-enabled {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
  }
}

/* Database maintenance */
.db-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.db-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.db-summary-item {
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-width: 130px;
}

.db-summary-label {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.db-summary-value {
  display: block;
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.db-table-actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.db-table-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.db-table-row {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) minmax(0, 2fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  cursor: pointer;
}

.db-table-row:hover {
  background: var(--bg-hover);
}

.db-table-row input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.db-table-name {
  font-weight: 600;
  color: var(--text-primary);
}

.db-table-meta {
  font-size: 12px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.db-purge-form,
.db-danger-zone {
  border-top: 1px solid var(--border-weak);
  padding-top: 16px;
  margin-top: 18px;
}

.db-purge-form h3,
.db-danger-zone h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text-primary);
}

.db-danger-zone {
  border: 1px solid rgba(242, 73, 92, 0.35);
  border-radius: var(--radius-md);
  background: rgba(242, 73, 92, 0.06);
  padding: 14px;
}

@media (max-width: 700px) {
  .db-table-row {
    grid-template-columns: auto 1fr;
  }

  .db-table-meta {
    grid-column: 2;
  }
}

/* Guest and admin entry points */
.page-guest .admin-tab,
.page-guest .admin-only {
  display: none !important;
}

.page-admin .guest-tab,
.page-admin .guest-only {
  display: none !important;
}

.page-admin.admin-locked .container {
  display: none !important;
}

.page-admin.admin-locked #loginModal {
  display: flex !important;
  opacity: 1;
  background: var(--bg-canvas);
  backdrop-filter: none;
  z-index: 2000;
}

.page-admin.admin-locked #loginModal .modal-content {
  transform: none;
  opacity: 1;
  width: min(420px, 92vw);
  box-shadow: var(--shadow-lg);
}

.page-admin.admin-locked #closeLoginModalBtn {
  display: none;
}

.settings-channel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.overview-updated {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.overview-updated.error {
  color: var(--accent-orange);
}

/* Language switch */
.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.language-switch {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.lang-btn {
  border: 0;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 9px;
  cursor: pointer;
}

.lang-btn + .lang-btn {
  border-left: 1px solid var(--border-weak);
}

.lang-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.lang-btn.active {
  background: var(--accent-blue);
  color: #fff;
}

.login-language-switch {
  margin: 0 0 16px;
  width: fit-content;
}

@media (max-width: 700px) {
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
}
