:root {
  --bg-primary: #0b0f19;
  --bg-card: rgba(18, 24, 39, 0.75);
  --bg-card-hover: rgba(28, 36, 56, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(56, 189, 248, 0.3);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-cyan: #06b6d4;
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  --led-glow-on: #00f2fe;
  --led-glow-halo: rgba(0, 242, 254, 0.45);
  
  --status-green: #10b981;
  --status-green-glow: rgba(16, 185, 129, 0.4);
  --status-red: #ef4444;
  --status-red-glow: rgba(239, 68, 68, 0.4);
  --status-orange: #f59e0b;

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.12) 0px, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  padding: 2rem 1.5rem;
  line-height: 1.5;
}

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

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 1rem;
}

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

.logo-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 8px 20px -4px rgba(6, 182, 212, 0.4);
}

.header-title h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, #ffffff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-title p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.badge-broker {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border-color: rgba(59, 130, 246, 0.25);
}

.badge-broker.connected {
  background: rgba(16, 185, 129, 0.12);
  color: var(--status-green);
  border-color: rgba(16, 185, 129, 0.25);
}

.badge-device.online {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.2);
}

.badge-device.offline {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.4);
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
  box-shadow: 0 0 8px currentColor;
}

/* Grid Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

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

/* Glass Cards */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
  transition: var(--transition);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
}

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

.card-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* ============================================================
   ESP32 Device Status Box (Online / Offline Telemetry)
   ============================================================ */
.device-status-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.75rem 1.25rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.04);
  margin-bottom: 1rem;
  transition: var(--transition);
}

.device-status-box.online {
  background: radial-gradient(circle at 50% 30%, rgba(16, 185, 129, 0.12) 0%, rgba(0, 0, 0, 0.25) 70%);
  border-color: rgba(16, 185, 129, 0.3);
}

.device-status-box.offline {
  background: radial-gradient(circle at 50% 30%, rgba(239, 68, 68, 0.08) 0%, rgba(0, 0, 0, 0.25) 70%);
  border-color: rgba(239, 68, 68, 0.25);
}

.device-visual-container {
  position: relative;
  width: 110px;
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.device-aura {
  position: absolute;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: transparent;
  transition: var(--transition);
}

.device-status-box.online .device-aura {
  background: var(--status-green-glow);
  box-shadow: 0 0 50px 20px rgba(16, 185, 129, 0.4);
  animation: aura-pulse 2s infinite ease-in-out;
}

.device-status-box.offline .device-aura {
  background: var(--status-red-glow);
  box-shadow: 0 0 35px 10px rgba(239, 68, 68, 0.2);
}

@keyframes aura-pulse {
  0%, 100% { transform: scale(0.95); opacity: 0.6; }
  50% { transform: scale(1.18); opacity: 1; }
}

.device-chip {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  background: #1e293b;
  border: 3px solid #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: var(--transition);
}

.device-status-box.online .device-chip {
  background: radial-gradient(circle at 30% 30%, #34d399 0%, #059669 100%);
  border-color: #a7f3d0;
  box-shadow: 0 0 25px rgba(16, 185, 129, 0.7);
}

.device-status-box.offline .device-chip {
  background: #1e293b;
  border-color: #ef4444;
}

.device-icon {
  font-size: 1.8rem;
  transition: var(--transition);
}

.device-main-text {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
  transition: var(--transition);
}

.device-status-box.online .device-main-text {
  color: #34d399;
  text-shadow: 0 0 15px rgba(52, 211, 153, 0.5);
}

.device-status-box.offline .device-main-text {
  color: #f87171;
}

.device-sub-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1.25rem;
}

.device-info-table {
  width: 100%;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

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

.info-val {
  font-weight: 600;
  color: var(--text-primary);
}

.info-val.val-online {
  color: #34d399;
}

.info-val.val-offline {
  color: #f87171;
}

/* ============================================================
   LED Interactive Box
   ============================================================ */
.led-interactive-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.75rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.04);
  margin-bottom: 1.5rem;
}

.led-visual-container {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.led-halo {
  position: absolute;
  width: 95px;
  height: 95px;
  border-radius: 50%;
  background: transparent;
  transition: var(--transition);
}

.led-halo.on {
  background: var(--led-glow-halo);
  box-shadow: 0 0 60px 25px rgba(0, 242, 254, 0.6);
  animation: pulse-led 2s infinite ease-in-out;
}

@keyframes pulse-led {
  0%, 100% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.15); opacity: 1; }
}

.led-diode {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  background: #1e293b;
  border: 3px solid #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: var(--transition);
}

.led-diode.on {
  background: radial-gradient(circle at 30% 30%, #ffffff 0%, var(--led-glow-on) 60%, #0072ff 100%);
  border-color: #e0f2fe;
  box-shadow: 0 0 25px #00f2fe, inset 0 0 15px #ffffff;
}

.led-icon {
  font-size: 1.8rem;
  color: #64748b;
  transition: var(--transition);
}

.led-diode.on .led-icon {
  color: #0f172a;
}

.led-state-text {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.led-state-text.on {
  color: #38bdf8;
  text-shadow: 0 0 15px rgba(56, 189, 248, 0.6);
}

.led-state-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Control Buttons */
.controls-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.btn-ctrl {
  padding: 0.95rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  transition: var(--transition);
}

.btn-on {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: white;
  box-shadow: 0 6px 20px -4px rgba(14, 165, 233, 0.5);
}

.btn-on:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px -4px rgba(14, 165, 233, 0.7);
}

.btn-on:active { transform: translateY(1px); }

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

.btn-off:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
  transform: translateY(-2px);
}

.btn-off:active { transform: translateY(1px); }

/* Form Group */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-control {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  font-size: 0.88rem;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.config-btn-row {
  margin-top: 1.25rem;
}

.btn-secondary {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Terminal Log */
.terminal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.terminal-body {
  background: #060911;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  overflow-y: auto;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.82rem;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.log-entry {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  line-height: 1.4;
}

.log-time {
  color: var(--text-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.log-tag {
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.tag-sent { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.tag-recv { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.tag-info { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }
.tag-err  { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.tag-live { background: rgba(16, 185, 129, 0.3); color: #4ade80; }

.log-msg { word-break: break-all; }

/* ============================================================
   RGB LED Interactive Card & Color Controls
   ============================================================ */
.rgb-interactive-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.04);
  margin-bottom: 1.25rem;
  transition: var(--transition);
}

.rgb-visual-container {
  position: relative;
  width: 110px;
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.rgb-halo {
  position: absolute;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: transparent;
  transition: var(--transition);
}

.rgb-orb {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  background: #1e293b;
  border: 3px solid #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: var(--transition);
}

.rgb-icon {
  font-size: 1.7rem;
  transition: var(--transition);
}

.rgb-color-hex {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 0.2rem;
  color: var(--text-primary);
  transition: var(--transition);
}

.rgb-color-code {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rgb-controls-panel {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.color-picker-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.picker-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.color-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 44px;
  height: 38px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

#picker-preview-text {
  font-size: 0.85rem;
  font-family: 'Consolas', monospace;
  font-weight: 600;
  color: var(--text-primary);
}

/* Presets */
.presets-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.presets-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.presets-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.5rem;
}

.btn-preset {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
}

.btn-preset:hover {
  transform: scale(1.2);
  border-color: #ffffff;
  box-shadow: 0 0 12px currentColor;
}

.btn-preset:active {
  transform: scale(0.95);
}

/* Brightness Slider */
.brightness-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
  transition: var(--transition);
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.6);
  border: 2px solid #ffffff;
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.rgb-btn-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.rgb-calibration-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  margin-top: 0.25rem;
}

.toggle-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.toggle-option:hover {
  color: var(--text-primary);
}

.toggle-option input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

/* Footer */
footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-top: 1rem;
}
