:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #121212;
  color: #f3f3f0;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  background: #121212;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid #3b3b36;
  border-radius: 8px;
  padding: 0 14px;
  color: #f3f3f0;
  background: #262622;
}

button:active {
  transform: translateY(1px);
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #3b3b36;
  border-radius: 8px;
  padding: 0 12px;
  color: #f3f3f0;
  background: #181815;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: #aaa79d;
  font-size: 0.86rem;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: 1.45rem;
}

h2 {
  font-size: 1rem;
}

h3 {
  font-size: 1.05rem;
}

h4 {
  font-size: 0.95rem;
}

main {
  width: min(980px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 32px;
  display: grid;
  gap: 12px;
}

body.auth-only {
  display: grid;
  place-items: center;
  padding: 16px;
}

body.auth-only main {
  width: min(420px, 100%);
  padding: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px max(12px, calc((100vw - 980px) / 2));
  border-bottom: 1px solid #2f2f2b;
  background: #171717;
}

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

.topbar p,
.section-heading span,
.device p {
  color: #aaa79d;
  font-size: 0.86rem;
}

.panel,
.device {
  border: 1px solid #30302c;
  border-radius: 8px;
  background: #1b1b18;
}

.panel {
  padding: 14px;
}

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

.auth-grid,
.schedule-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
}

.auth-panel .auth-grid {
  grid-template-columns: 1fr;
}

.device-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.device {
  padding: 14px;
  display: grid;
  gap: 14px;
}

.empty-state {
  min-height: 160px;
  display: grid;
  place-items: center;
  border: 1px dashed #3b3b36;
  border-radius: 8px;
  color: #aaa79d;
  text-align: center;
  padding: 24px;
}

.pill {
  min-width: 82px;
  border-radius: 999px;
  padding: 5px 10px;
  text-align: center;
  color: #bbb8ad;
  background: #2a2a26;
}

.pill.online {
  color: #baf0cc;
  background: #183c24;
}

.pill.offline {
  color: #ffb8ad;
  background: #4c211c;
}

.toggle-line {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  justify-content: start;
  gap: 8px;
  color: #f3f3f0;
  font-size: 0.95rem;
}

.toggle-line input {
  width: 18px;
  min-height: 18px;
}

.local-access-toggle {
  min-height: 42px;
  display: inline-flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 10px;
  border: 1px solid #1f6f36;
  border-radius: 999px;
  padding: 0 14px 0 8px;
  color: #e8f7eb;
  background: #174c28;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.local-access-toggle input {
  position: absolute;
  width: 1px;
  min-height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.local-access-toggle:has(input:checked) {
  border-color: #9d2a2a;
  color: #ffe4df;
  background: #651c1c;
}

.toggle-track {
  width: 44px;
  height: 24px;
  border-radius: 999px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.28);
}

.toggle-track span {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #f3f3f0;
  transition: transform 160ms ease;
}

.local-access-toggle input:checked + .toggle-track span {
  transform: translateX(20px);
}

.button-row {
  justify-content: start;
  flex-wrap: wrap;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) auto;
  align-items: center;
}

.control-row button[data-role="on"],
.control-row button[data-role="off"] {
  width: 100%;
}

.button-row button[data-role="on"] {
  background: #14532d;
  border-color: #1c7c42;
}

.button-row button[data-role="off"] {
  background: #651c1c;
  border-color: #9d2a2a;
}

.device-message {
  margin-top: 4px;
}

.schedule-block {
  border-top: 1px solid #30302c;
  padding-top: 14px;
}

.device-details {
  border-top: 1px solid #30302c;
  padding-top: 10px;
}

.device-details summary {
  cursor: pointer;
  color: #d6d2c5;
}

.details-grid {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.label-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.meta-row {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
}

.meta-row span:first-child {
  color: #aaa79d;
}

.meta-row code,
.meta-row a {
  color: #f3f3f0;
  overflow-wrap: anywhere;
}

.maintenance-grid {
  border-top: 1px solid #30302c;
  border-bottom: 1px solid #30302c;
  padding: 10px 0;
  display: grid;
  gap: 10px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.schedule-form {
  grid-template-columns: 72px 130px 110px 130px 150px 100px auto;
}

.schedule-form [data-role="scheduleDateLabel"] {
  min-height: 66px;
}

.schedule-form [data-role="scheduleDateLabel"].is-hidden {
  visibility: hidden;
  pointer-events: none;
}

.schedule-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.schedule-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid #30302c;
  border-radius: 8px;
  padding: 8px 10px;
  background: #181815;
}

.schedule-row.disabled {
  border-color: #282824;
  background: #121210;
  opacity: 0.72;
}

.schedule-row small {
  color: #aaa79d;
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .auth-grid,
  .schedule-form {
    grid-template-columns: 1fr;
  }

  .control-row {
    grid-template-columns: 1fr 1fr;
  }

  .device-head {
    align-items: start;
    flex-direction: column;
  }

  .local-access-toggle {
    width: 100%;
    justify-content: center;
    grid-column: 1 / -1;
  }

  .control-row button[data-role="on"],
  .control-row button[data-role="off"] {
    min-width: 0;
  }

  .schedule-form [data-role="scheduleDateLabel"].is-hidden {
    display: none;
    visibility: visible;
  }

  .button-row button {
    flex: 1 1 45%;
  }

  .label-row,
  .meta-row {
    grid-template-columns: 1fr;
  }

  .schedule-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .schedule-row > div:first-child {
    grid-column: 1 / -1;
  }
}
