/* ============================================
   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: 1fr 320px;
  gap: 16px;
  align-items: start;
}

@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-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-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;
}

/* 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-security-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
}

.sec-badge {
  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;
  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;
}

/* OTA Guide & Instructions Grid */
.ota-guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.ota-info-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;
  transition: border-color 0.2s ease;
}

.ota-info-card:hover {
  border-color: var(--border-medium);
}

.info-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-weak);
  padding-bottom: 8px;
}

.info-icon {
  font-size: 16px;
}

.info-card-content {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.info-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.info-list li {
  color: var(--text-secondary);
}

.info-list code {
  background: var(--bg-primary);
  border: 1px solid var(--border-weak);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  font-size: 11px;
}
