:root {
  --bg: #1b1410;
  --card: #2a201a;
  --text: #f6ece4;
  --muted: #b9a89a;
  --off: #4a3d34;
  --on: #ff7a1a;
  --on-glow: rgba(255, 122, 26, .45);
  --error: #ff8a80;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
main { width: 100%; max-width: 360px; text-align: center; }
main:has(> #control:not([hidden])) { padding-top: 56px; }
h1 { font-weight: 600; letter-spacing: .02em; margin: 0 0 32px; }

form { display: grid; gap: 16px; text-align: left; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 15px; }
input {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--off); border-radius: 12px; padding: 14px;
}
input:focus { outline: 2px solid var(--on); border-color: transparent; }
button { font: inherit; cursor: pointer; }
.primary {
  margin-top: 8px; padding: 14px; border: 0; border-radius: 12px;
  background: var(--on); color: #1b1410; font-weight: 600;
}
.error { color: var(--error); min-height: 1.4em; margin: 0; }

.toggle {
  width: 220px; height: 220px; border-radius: 50%;
  border: 0; background: var(--off); color: var(--text);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  font-size: 22px; font-weight: 600;
  transition: background .25s, box-shadow .25s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.toggle:active { transform: scale(.97); }
.toggle[aria-pressed="true"] { background: var(--on); color: #1b1410; box-shadow: 0 0 60px var(--on-glow); }
.toggle:disabled { opacity: .6; }
.icon { width: 64px; height: 64px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2v10M6.3 5.7a8 8 0 1 0 11.4 0' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2v10M6.3 5.7a8 8 0 1 0 11.4 0' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat; }
.status { color: var(--muted); min-height: 1.4em; margin: 24px 0 4px; }
.toggle.offline { background: var(--card); color: var(--muted); }
.temp { margin: 0 0 24px; font-size: 56px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.temp .unit { font-size: 24px; color: var(--muted); margin-left: 4px; vertical-align: top; }
.since { color: var(--muted); font-size: 14px; min-height: 1.3em; margin: 0; }
.nodes { list-style: none; padding: 0; margin: 28px 0 0; display: flex; justify-content: center; gap: 20px; color: var(--muted); font-size: 14px; }
.nodes li { display: inline-flex; align-items: center; gap: 6px; }
.node-state { color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #e0524a; }
.dot.online { background: #4cc26a; }

/* --- Toppfält och meny --- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--bg);
}
.topbar[hidden] { display: none; }
.brand { font-weight: 600; letter-spacing: .02em; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--card); }
.i-menu { width: 24px; height: 24px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 7h16M4 12h16M4 17h16' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 7h16M4 12h16M4 17h16' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat; }
.menu {
  position: absolute; top: calc(100% - 4px); right: 16px; min-width: 220px;
  background: var(--card); border: 1px solid var(--off); border-radius: 14px;
  padding: 8px; box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
  display: grid; gap: 2px; text-align: left;
}
.menu[hidden] { display: none; }
.menu-user { margin: 4px 10px 8px; color: var(--muted); font-size: 14px; }
.menu-user strong { color: var(--text); }
.menu button {
  border: 0; background: transparent; color: var(--text);
  text-align: left; padding: 12px 10px; border-radius: 10px;
}
.menu button:hover, .menu button:focus-visible { background: var(--off); outline: none; }

/* --- Admin --- */
main:has(> .admin:not([hidden])) { max-width: 480px; }
body:has(.admin:not([hidden])) { align-items: flex-start; padding-top: calc(env(safe-area-inset-top) + 72px); }
.admin { text-align: left; }
.admin h2 { margin: 0 0 16px; }
.admin h3 { margin: 32px 0 12px; font-size: 17px; }
.user-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.user-list li {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 12px; padding: 10px 12px;
}
.user-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.user-name small { color: var(--muted); font-weight: 400; }
.switch, .check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 15px; }
.check { grid-auto-flow: column; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--on); padding: 0; }
.danger {
  border: 1px solid var(--off); background: transparent; color: var(--error);
  border-radius: 10px; padding: 8px 12px; font-size: 15px;
}
.danger:disabled { opacity: .35; cursor: not-allowed; }
.admin .error { margin-top: 8px; }
