:root {
  --bg: #07110f;
  --bg-elev: #0f1b18;
  --bg-elev-2: #15241f;
  --line: #274038;
  --text: #e7f3ee;
  --muted: #8aa397;
  --accent: #3dcc8a;
  --accent-dim: rgba(61, 204, 138, 0.14);
  --warn: #f0b429;
  --danger: #e85d4c;
  --info: #4cc4d4;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(61, 204, 138, 0.12), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(76, 196, 212, 0.08), transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", sans-serif;
}

h1,
h2,
h3 {
  font-family: Outfit, sans-serif;
  font-weight: 600;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 0 3px 0 #081210;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
  border-color: #3c5d52;
}

button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 0 0 #081210;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

button.primary {
  background: var(--accent);
  color: #062015;
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 3px 0 #1f7a52;
}

button.primary:active:not(:disabled) {
  box-shadow: 0 0 0 #1f7a52;
}

button.danger {
  color: #ffd4ce;
  border-color: #7a322a;
  background: #2a1412;
  box-shadow: 0 3px 0 #5a221c;
}

button.danger:active:not(:disabled) {
  box-shadow: 0 0 0 #5a221c;
}

button.stop-telemetry {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 3px 0 #9a3228;
}

button.stop-telemetry:active:not(:disabled) {
  box-shadow: 0 0 0 #9a3228;
}

.control-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.control-block > button {
  min-width: 160px;
}

.connection-response {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.connection-response span {
  color: var(--text);
}

.connection-response.error span {
  color: #ffb4ab;
}

.spinner-inline {
  width: 16px;
  height: 16px;
  border-width: 2px;
  flex: 0 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  padding: 22px 28px 16px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--muted);
}

.topbar-meta,
.dash-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 12px;
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5c6f68;
}

.status-pill.on {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: rgba(61, 204, 138, 0.35);
}

.status-pill.on::before {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(61, 204, 138, 0.15);
}

.status-pill.warn {
  color: var(--warn);
}

.status-pill.warn::before {
  background: var(--warn);
}

.status-pill.off::before {
  background: var(--danger);
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: calc(100vh - 92px);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: rgba(15, 27, 24, 0.72);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dash-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

@media (min-width: 1100px) {
  .dash-head {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

.device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  flex: 1;
  min-height: 220px;
}

.device-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  cursor: pointer;
}

.device-row.selected {
  border-color: rgba(61, 204, 138, 0.55);
  box-shadow: inset 0 0 0 1px rgba(61, 204, 138, 0.2);
}

.device-check {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--bg) center / 12px 12px no-repeat;
  cursor: pointer;
  flex-shrink: 0;
}

.device-check:hover {
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.device-check:checked {
  background-color: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='%23062015' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' d='M3.2 8.3 L6.6 11.6 L12.8 4.4'/></svg>");
}

.device-row small {
  display: block;
  color: var(--muted);
}

.device-row .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

.device-row .dot.live {
  background: var(--accent);
}

.device-menu {
  position: relative;
}

.device-menu-button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
}

.device-menu-icon,
.device-menu-icon::before,
.device-menu-icon::after {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

.device-menu-icon {
  position: relative;
}

.device-menu-icon::before,
.device-menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.device-menu-icon::before {
  top: -7px;
}

.device-menu-icon::after {
  top: 7px;
}

.device-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 12;
  min-width: 210px;
  display: grid;
  gap: 6px;
  padding: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.device-menu-panel button {
  width: 100%;
  text-align: left;
}

#bulk-status:empty {
  display: none;
}

.workspace {
  padding: 22px 26px 40px;
}

.empty-state {
  max-width: 520px;
  padding: 48px 8px;
  color: var(--muted);
}

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

.error {
  color: #ffb4ab;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
}

.publish-fields {
  margin-top: 12px;
}

.publish-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input,
select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
}

.group {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.plant-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-top: 14px;
}

.plant-card h4 {
  margin: 0 0 12px;
  font-family: Outfit, sans-serif;
  font-weight: 600;
  font-size: 15px;
}

.lamps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.lamp-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.lamp-card strong {
  display: block;
  color: var(--text);
  font-size: 14px;
}

.lamp-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.lamp-card .key {
  color: var(--info);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.plant-temp-value {
  min-width: 64px;
  font-family: Outfit, sans-serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
}

.lamp {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #3a4743;
  opacity: 0.45;
  box-shadow: inset 0 0 0 2px #1b2824;
  flex-shrink: 0;
}

.lamp.on {
  background: var(--danger);
  opacity: 1;
  box-shadow: 0 0 0 4px rgba(232, 93, 76, 0.22), 0 0 16px rgba(232, 93, 76, 0.45);
}

.plant-fields {
  margin-top: 12px;
}

#telemetry-groups {
  display: grid;
  gap: 18px;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}

.telemetry-table {
  width: 100%;
  border-collapse: collapse;
}

.telemetry-table th,
.telemetry-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.telemetry-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.telemetry-table tbody tr:last-child td {
  border-bottom: 0;
}

.telemetry-table .key {
  color: var(--info);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.telemetry-table .field-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  white-space: nowrap;
}

.telemetry-table .on-cell {
  width: 64px;
  text-align: center;
}

.telemetry-table .on-cell .device-check {
  display: inline-block;
  vertical-align: middle;
}

.telemetry-table .new-value {
  display: flex;
  align-items: center;
  gap: 8px;
}

.telemetry-table .new-value input[type="number"],
.telemetry-table .new-value select {
  width: 140px;
  min-width: 140px;
  max-width: 140px;
  padding: 7px 10px;
}

.telemetry-table .new-value button {
  padding: 7px 12px;
  flex-shrink: 0;
}

.field-row.inactive {
  opacity: 0.55;
}

.key-on-check {
  width: 18px;
  height: 18px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 9, 0.72);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}

#confirm-modal {
  z-index: 30;
}

.login-card {
  width: min(440px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
  position: relative;
}

.busy {
  position: absolute;
  inset: 0;
  background: rgba(8, 18, 16, 0.88);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  border-radius: 18px;
  z-index: 2;
}

.busy p {
  margin: 0;
  color: var(--text);
  font-size: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.login-card > #add-create-fields {
  display: grid;
  gap: 12px;
}

.add-existing-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.add-existing-toggle .device-check {
  width: 18px;
  height: 18px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.rpc-log {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--bg-elev);
}

.rpc-log pre {
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 12px;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
