*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #f5f7fb;
  background: radial-gradient(circle at top, #1b2030, #0b0d12 60%);
  min-height: 100vh;
}

body.editor-open {
  overflow: hidden;
}

.dashboard {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: grid;
  gap: 20px;
}

.dash-header {
  display: grid;
  gap: 10px;
}

.dash-header h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.01em;
}

.subtle {
  margin: 0;
  color: #9aa4b2;
}

.dash-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.ghost {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid #2b3140;
  background: transparent;
  color: #d0d6e1;
  cursor: pointer;
  font-weight: 600;
  position: relative;
  overflow: visible;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.ghost:focus-visible {
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.6);
}

.ghost::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: inherit;
  background: rgba(96, 165, 250, 0.35);
  opacity: 0;
  transform: scale(0.7);
  pointer-events: none;
}

.ghost:active::after {
  animation: pulse 0.5s ease-out;
}

@keyframes pulse {
  0% {
    opacity: 0.6;
    transform: scale(0.6);
  }
  100% {
    opacity: 0;
    transform: scale(1.3);
  }
}
.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.icon-button svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.ghost.primary {
  border-color: #3b82f6;
  color: #f5f7fb;
}

.ghost.active {
  border-color: #3b82f6;
  color: #f5f7fb;
}

.ghost.danger {
  border-color: #7f1d1d;
  color: #fecaca;
}

.ble-status {
  font-size: 13px;
  color: #9aa4b2;
  padding-left: 6px;
}

.ble-status.live {
  color: #22c55e;
}

.widgets {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.widget-card {
  background: rgba(16, 20, 28, 0.78);
  border: 1px solid #242938;
  border-radius: 18px;
  padding: 16px;
  display: grid;
  gap: 10px;
  min-height: 150px;
  position: relative;
  overflow: hidden;
}

.widget-card.large {
  grid-column: span 2;
}

.widget-card.editable {
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.widget-card.editable:hover {
  border-color: #3b82f6;
  transform: translateY(-2px);
}

.widget-card.selected {
  border-color: #60a5fa;
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.4);
}

.widget-title {
  font-size: 13px;
  color: #9aa4b2;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.widget-value {
  font-size: 34px;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.widget-unit {
  font-size: 16px;
  color: #9aa4b2;
}

.gauge {
  display: grid;
  place-items: center;
  width: 150px;
  height: 150px;
  margin: 0 auto;
}

.needle-gauge {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 0 auto;
  display: grid;
  place-items: center;
}

.needle-canvas {
  width: 180px;
  height: 180px;
  display: block;
}

.gauge-ring {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: conic-gradient(#3b82f6 0deg, #1f2633 0deg);
  display: grid;
  place-items: center;
  transition: background 0.3s ease;
  position: relative;
}

.gauge-ring::after {
  content: "";
  width: 110px;
  height: 110px;
  background: #0c0f16;
  border-radius: 50%;
  position: absolute;
}

.gauge-value {
  position: relative;
  z-index: 1;
  text-align: center;
  font-size: 28px;
  font-weight: 700;
}

.gauge-value span {
  display: block;
  font-size: 13px;
  color: #9aa4b2;
  font-weight: 500;
}

.light {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
}

.light-indicator {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #334155;
  box-shadow: 0 0 12px rgba(148, 163, 184, 0.3);
  transition: all 0.2s ease;
}

.light-indicator.on {
  background: #22c55e;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.6);
}

.sparkline {
  height: 56px;
  width: 100%;
  display: flex;
  gap: 4px;
  align-items: flex-end;
}

.sparkline span {
  flex: 1;
  background: linear-gradient(180deg, #60a5fa, #1d4ed8);
  border-radius: 8px 8px 2px 2px;
  min-height: 8px;
  transition: height 0.25s ease;
}

.alerts {
  background: rgba(13, 16, 24, 0.85);
  border: 1px solid #242938;
  border-radius: 18px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.alerts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.alerts-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.dtc-list {
  display: grid;
  gap: 10px;
}

.dtc-item {
  border: 1px solid #2b3140;
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 6px;
  background: rgba(12, 15, 22, 0.8);
}

.dtc-meta {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: #cbd5f5;
}

.dtc-meta strong {
  font-size: 16px;
  color: #f5f7fb;
}

.dtc-time {
  font-size: 12px;
  color: #94a3b8;
}

.dtc-empty {
  color: #9aa4b2;
  font-size: 14px;
}

.editor {
  position: fixed;
  right: 0;
  bottom: 0;
  width: min(420px, 100%);
  max-height: 75vh;
  overflow-y: auto;
  background: #0b0f17;
  border: 1px solid #242938;
  border-radius: 20px 20px 0 0;
  padding: 18px;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
  z-index: 40;
}

.editor.hidden {
  display: none;
}

.editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.editor-header h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.ghost.close {
  padding: 6px 12px;
  font-size: 16px;
  line-height: 1;
}

.editor-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.75);
  backdrop-filter: blur(2px);
  z-index: 30;
}

.editor-backdrop.hidden {
  display: none;
}

.editor-fields {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.editor-fields label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #cbd5f5;
}

.editor-fields input,
.editor-fields select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #2b3140;
  background: #0b0f17;
  color: #f5f7fb;
}

.editor-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.editor-actions .ghost.danger {
  width: 100%;
  text-align: center;
  background: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}

@media (min-width: 720px) {
  .dashboard {
    padding: 26px 24px 60px;
  }

  .dash-header {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .dash-header h1 {
    font-size: 24px;
  }

  .widgets {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .widget-card {
    min-height: 170px;
  }

  .needle-gauge {
    width: 200px;
    height: 200px;
  }

  .needle-canvas {
    width: 200px;
    height: 200px;
  }
}

@media (max-width: 720px) {
  .editor {
    width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border-width: 0;
    padding: 20px 16px 28px;
  }

  .editor-fields {
    grid-template-columns: 1fr;
  }
}
