:root {
  color-scheme: light;
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-soft: #edf6f5;
  --ink: #142126;
  --muted: #62727b;
  --line: #d8e2e5;
  --accent: #006d77;
  --accent-strong: #00545c;
  --danger: #be123c;
  --warning: #a15c07;
  --ok: #0f766e;
  --shadow: 0 12px 30px rgba(20, 33, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
a {
  font: inherit;
}

button,
a {
  touch-action: manipulation;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  width: min(100%, 540px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px max(30px, env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: -18px -14px 12px;
  padding: max(18px, env(safe-area-inset-top)) 14px 12px;
  background: rgba(245, 247, 247, 0.94);
  border-bottom: 1px solid rgba(216, 226, 229, 0.82);
  backdrop-filter: blur(14px);
}

.app-header p,
h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

.app-header p {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin-top: 2px;
  font-size: 28px;
  line-height: 1.08;
}

h2 {
  font-size: 17px;
}

.header-actions,
.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  height: 42px;
  font-size: 19px;
  font-weight: 900;
}

.text-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 900;
}

.text-button.danger {
  color: var(--danger);
}

.board-section,
.add-section {
  margin-top: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.control-grid,
.device-list {
  display: grid;
  gap: 10px;
}

.empty {
  min-height: 122px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  padding: 18px;
}

.switch-card,
.device-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.switch-card {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.switch-card.is-on {
  border-color: rgba(0, 109, 119, 0.42);
  background: var(--surface-soft);
}

.switch-main,
.device-head,
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.switch-title,
.device-title,
.row-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.switch-title strong,
.device-title strong,
.row-title strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.switch-title span,
.device-title span,
.row-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.switch-title code,
.row-title code {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.state-text {
  color: var(--muted);
  font-size: 26px;
  font-weight: 950;
  line-height: 1;
}

.switch-card.is-on .state-text {
  color: var(--accent);
}

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

.round-action,
.pin-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  font-weight: 950;
  cursor: pointer;
}

.round-action.danger {
  color: var(--danger);
}

.pin-button.active {
  border-color: rgba(0, 109, 119, 0.35);
  background: var(--surface-soft);
  color: var(--accent);
}

.switch-control {
  position: relative;
  display: inline-flex;
  flex: 0 0 56px;
  width: 56px;
  height: 32px;
}

.switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-control span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5dc;
  transition: background 160ms ease;
}

.switch-control span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(20, 33, 38, 0.18);
  transition: transform 160ms ease;
}

.switch-control input:checked + span {
  background: var(--accent);
}

.switch-control input:checked + span::after {
  transform: translateX(24px);
}

.search-field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.search-field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
}

.device-card {
  overflow: hidden;
}

.device-head {
  padding: 13px;
  border-bottom: 1px solid var(--line);
}

.status {
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status.online {
  color: var(--ok);
}

.status.offline {
  color: var(--warning);
}

.switch-row {
  padding: 12px 13px;
}

.switch-row + .switch-row {
  border-top: 1px solid var(--line);
}

#toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 20;
  max-width: 512px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 750;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 700px) {
  .app-shell {
    padding-inline: 18px;
  }

  .app-header {
    margin-inline: -18px;
    padding-inline: 18px;
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
