body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f3f4f6;
  color: #111;
  margin: 0;
  padding: 16px;
}

h1 {
  text-align: center;
  color: #2f3f59;
}

#devicesContainer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

#facilityContainer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

:root {
  --accent: #2f3e5a;
  --accentdark: #1c2535;
  --accentlight: #3d5278;
  --accenttint: #f0f4fa;
  --bg: #eef1f6;
  --card: #ffffff;
  --card-inner: #f7f9fc;
  --text: #0f1923;
  --text-secondary: #4a5568;
  --muted: #8a96a8;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(17, 24, 39, 0.06), 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-hover: 0 8px 24px rgba(17, 24, 39, 0.1), 0 2px 6px rgba(17, 24, 39, 0.06);
  --ok: #16a34a;
  --warn: #f59e0b;
  --crit: #ef4444;
  --border: #e2e7ef;
  --border-strong: #c8d0dc;
  --fill: 0%;
}

/* ============================================================
   DEVICE CARD
   ============================================================ */
.panel-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1.0px;
  color: var(--accent);
  text-transform: uppercase;
  text-align: center;
}

.device-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex: 1;
  min-width: 260px;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}

.device-card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

/* Top accent line */
.device-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accentdark), var(--accentlight));
}

/* ---------- Title bar ---------- */
.device-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 13px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.device-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--accent);
}

.device-id-badge {
  font-size: 12px;
  letter-spacing: 0.4px;
  color: var(--muted);
  font-family: "Courier New", monospace;
  background: var(--accenttint);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.device-category-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accenttint, #f0f4fa);
  color: var(--accent, #2f3e5a);
  border: 1px solid var(--border, #e2e7ef);
}
/* ---------- Metrics ---------- */
.metrics-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  transition: background 0.15s;
}

.metric:hover {
  background: var(--accenttint);
}

.metric .left {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: var(--muted);
  text-transform: uppercase;
  flex: 1;
}

.metric .right {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  font-family: "Courier New", monospace;
  text-align: right;
}

/* unit text after value */
.metric .right span {
  color: var(--text);
}

.metric .right span+* {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

/* ---------- Toggle switch ---------- */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}

.toggle-switch input:checked+.toggle-slider {
  background: var(--accent);
  border-color: var(--accentdark);
}

.toggle-switch input:checked+.toggle-slider::before {
  transform: translateX(16px);
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* ---------- Shed panel ---------- */
.shed-panel {
  margin: 0 12px 12px;
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid transparent;
  transition: all 0.3s ease;
}

.shed-active {
  background: rgba(245, 158, 11, 0.06);
  border-color: rgba(245, 158, 11, 0.25);
}

.shed-inactive {
  background: var(--card-inner);
  border-color: var(--border);
}

.shed-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.shed-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background 0.3s;
  flex-shrink: 0;
}

.shed-active .shed-indicator {
  background: var(--warn);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
}

.shed-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
  flex: 1;
}

.shed-active .shed-label {
  color: var(--warn);
}

.shed-toggle-wrap {
  margin-left: auto;
}

.shed-meta {
  display: flex;
  gap: 20px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(245, 158, 11, 0.15);
}

.shed-meta-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.shed-meta-label {
  font-size: 8px;
  letter-spacing: 0.8px;
  color: var(--muted);
  text-transform: uppercase;
}

.shed-meta-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--warn);
  font-family: "Courier New", monospace;
}

/* END OF DEVICES CSS */

/* input[type="range"] {
  width: 140px;
} */

/* MQTT agent form styles */
.panel {
  max-width: 1080px;
  margin: 20px auto;
  background: #ffffff;
  padding: 16px;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.06);
  border: 1px solid var(--bg);
}

.panel h2 {
  margin-top: 0;
  color: #1f2d4a;
  font-display: optional;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.form-row.small {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.form-row.small .inline {
  margin-left: 8px;
}

label {
  font-size: 13px;
  color: #334155;
}

input,
select {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #d1e3f0;
  background: var(--accenttint);
  font-size: 14px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

button {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button.secondary {
  background: #f3f4f6;
  color: #111;
}

.form-msg {
  margin-top: 8px;
  font-size: 13px;
  color: #0f5132;
}

@media (max-width: 640px) {
  .panel {
    padding: 12px;
  }

  .form-row.small {
    flex-direction: column;
  }
}

.device-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}

.device-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.device-switch .slider {
  position: absolute;
  cursor: pointer;
  background-color: #c46767;
  border-radius: 22px;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  transition: 0.25s;
}

.device-switch .slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: 0.25s;
}

.device-switch input:checked+.slider {
  background-color: #4caf50;
}

.device-switch input:checked+.slider::before {
  transform: translateX(20px);
}

.agent-card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.agent-card-header {
  border-bottom: 1px solid #eef0f2;
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.agent-name {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
}

.agent-id {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.agent-card-body {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 24px;
}

/* Mobile fallback */
@media (max-width: 768px) {
  .agent-card-body {
    grid-template-columns: 1fr;
  }
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.info-label {
  font-size: 13px;
  color: #6b7280;
}

.info-value {
  font-size: 13px;
  font-weight: 500;
  color: #111827;
  text-align: right;
  word-break: break-word;
}

/* telemetry row card */
.telemetry-row {
  border: 1px solid #e6e8eb;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 10px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

/* header with remove button */
.telemetry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.telemetry-header .telemetry-title {
  font-size: 14px;
  font-weight: 600;
}

.remove-telemetry {
  background: transparent;
  border: none;
  color: #a00;
  font-size: 16px;
  cursor: pointer;
}

/* Add button */
.add-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.add-btn:hover {
  background: #095bb0;
}

/* pub-write section slight indent */
.pub-write-section {
  margin-left: 6px;
  border-left: 2px dashed #eef2f6;
  padding-left: 10px;
}

.tab-buttons {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  justify-content: center;
}

.tab-buttons button {
  padding: 8px 20px;
  cursor: pointer;
  /* border: 1px solid #ccc; */
  background: #c5c5c5;
  border-radius: var(--radius);
  color: var(--text);
}

.tab-buttons button:hover {
  background-color: #2f3f597c;
}

.tab-buttons button.active {
  background: var(--accent);
  font-weight: bold;
  color: white;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Setpoint controller */
.setpoint-control {
  display: flex;
  flex-direction: row;
  gap: 6px;
  width: 100%;
  align-items: center;
}

.setpoint-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(to right,
      var(--accent, #2f3e5a) var(--fill, 0%), var(--border) var(--fill, 0%));
  outline: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.setpoint-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: var(--shadow);
  cursor: grab;
  transition: transform 0.15s;
}

.setpoint-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.2);
}

.setpoint-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.setpoint-input {
  width: 64px;
  padding: 4px 6px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--card-inner);
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
  text-align: center;
}

.setpoint-input:focus {
  outline: none;
  border-color: var(--accent);
}

.setpoint-unit {
  font-size: 11px;
  color: var(--muted);
}

.device-title-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.device-indicator {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  opacity: 0;
  transition: opacity 0.3s;
  white-space: nowrap;
}

.indicator-ok,
.indicator-fail {
  opacity: 1;
}

.indicator-ok {
  color: var(--ok);
}

.indicator-fail {
  color: var(--crit);
}

.icon {
  font-size: 24px;
  color: #666;
  vertical-align: middle;
  margin-right: 8px;
}

.icon-mini {
  font-size: 16px;
  /* color: #000; */
}

.icon-green {
  color: var(--ok);
}

.icon-red {
  color: var(--crit);

}

.icon-yellow {
  color: var(--warn);

}

