:root {
  --bg: #0b0d10;
  --surface: #15191e;
  --surface-2: #1c2127;
  --border: #2a313a;
  --text: #eef2f6;
  --muted: #9aa6b2;
  --accent: #3b82f6;
  --accent-soft: #16304f;
  --green: #34d399;
  --green-soft: #0f3b30;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* hidden must always win, even over display:flex elements like .login */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 18px;
}
.id .label { font-size: 18px; font-weight: 600; }
.id .site { font-size: 13px; color: var(--muted); margin-top: 2px; }
.device-select {
  font-size: 17px; font-weight: 600; color: var(--text);
  background: transparent; border: none; padding: 2px 22px 2px 0;
  max-width: 220px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa6b2' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right center;
}
.device-select:focus { outline: none; }
.device-select option { color: #000; }
.device-row { display: flex; align-items: center; gap: 4px; }
.rename-btn {
  background: transparent; border: none; cursor: pointer;
  font-size: 14px; padding: 2px 4px; line-height: 1; opacity: 0.65;
}
.rename-btn:active { transform: scale(0.9); }
#userLine { font-size: 13px; color: var(--muted); margin-top: 2px; }
.provider { font-size: 12px; color: var(--muted); margin-top: 1px; opacity: 0.85; }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 500;
  padding: 6px 11px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="online"] { background: var(--green-soft); color: var(--green); }
.status[data-state="online"] .dot { background: var(--green); }
.status[data-state="offline"] { background: #3a1414; color: var(--red); }
.status[data-state="offline"] .dot { background: var(--red); }

.controls { display: flex; flex-direction: column; gap: 16px; }

.row.primary { display: flex; gap: 12px; }
.big {
  flex: 1; min-height: 78px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: transform .05s ease, background .15s ease;
}
.big:active { transform: scale(0.97); }
.big .ico { font-size: 24px; line-height: 1; }
.big.freeze { flex: 0 0 34%; }
#btnPower[data-on="false"] { background: #3a1414; border-color: #5b2020; color: var(--red); }
#btnPower[data-on="true"] .ico { color: var(--green); }
#btnFreeze[data-frozen="true"] { background: var(--accent-soft); border-color: #244a73; color: #9cc4f5; }

.block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.block-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--muted); margin-bottom: 10px;
}
.block-head .val { color: var(--text); font-weight: 600; font-size: 14px; }

input[type="range"] {
  width: 100%; height: 30px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--surface-2); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--text); margin-top: -10px; border: none;
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--surface-2); }
input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--text); border: none; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid button {
  min-height: 46px; padding: 8px 10px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; font-weight: 500; cursor: pointer;
}
.grid button:active { transform: scale(0.97); }
.grid button.active { background: var(--accent-soft); border-color: var(--accent); color: #cfe2fb; }

.seg { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1; min-height: 44px; padding: 8px 6px;
  background: var(--surface-2); color: var(--muted);
  border: none; border-left: 1px solid var(--border);
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.seg button:first-child { border-left: none; }
.seg button.active { background: var(--accent-soft); color: #cfe2fb; }

.health { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.metric .k { font-size: 12px; color: var(--muted); }
.metric .v { font-size: 16px; font-weight: 600; margin-top: 3px; }
.metric .v.good { color: var(--green); }
.metric .v.warn { color: var(--amber); }
.metric .v.bad { color: var(--red); }
.degf { color: var(--accent); }
.metric .v.warn .degf, .metric .v.bad .degf { color: inherit; }

/* Tappable info "i" + popover */
.info {
  width: 18px; height: 18px; min-width: 18px; padding: 0; margin-left: 6px;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); font-size: 11px; font-style: italic; font-weight: 700;
  line-height: 1; cursor: pointer; vertical-align: middle;
}
.info:active { transform: scale(0.9); }
.info-pop {
  position: absolute; z-index: 1000; max-width: 240px;
  background: #2a313a; color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: 12.5px; line-height: 1.45;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
}

.empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }

/* Team panel */
.x-btn { background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer; }
.team-member { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.team-member:first-child { border-top: none; }
.team-member .tm-role { font-size: 12px; color: var(--muted); }
.team-invite { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.team-invite input, .team-invite select { flex: 1; min-width: 120px; height: 40px; padding: 0 10px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 9px; font-size: 14px; }
.team-invite button, .sched-add button, .tm-sel { height: 40px; padding: 0 14px; background: var(--accent); color: #fff; border: none; border-radius: 9px; font-weight: 600; font-size: 14px; cursor: pointer; }
.tm-x { background: #3a1414; color: var(--red); border: 1px solid #5b2020; height: 32px; border-radius: 8px; padding: 0 10px; cursor: pointer; font-size: 12px; }
.tm-sel { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); height: 32px; }

/* Scheduler */
.sched-list .sched-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.sched-list .sched-row:first-child { border-top: none; }
.sched-meta { font-size: 12px; color: var(--muted); }
.sched-days { display: flex; gap: 6px; margin: 10px 0; }
.sched-days button { flex: 1; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.sched-days button.on { background: var(--accent-soft); border-color: var(--accent); color: #cfe2fb; }
.sched-add { display: flex; gap: 8px; align-items: center; }
.sched-add input[type="time"] { height: 40px; padding: 0 10px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 9px; font-size: 14px; }
.sched-bri input { width: 56px; height: 40px; padding: 0 8px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 9px; font-size: 14px; text-align: center; }
.sched-bri { color: var(--muted); font-size: 13px; }

/* Remote-support banner (customer) */
.support { margin-bottom: 16px; }
.support[data-state="idle"] { display: flex; }
.support .support-msg { font-size: 14px; margin-bottom: 10px; }
.support .support-actions { display: flex; gap: 10px; }
.support .support-actions button { flex: 1; min-height: 44px; border-radius: 10px; border: none; font-size: 14px; font-weight: 600; cursor: pointer; }
.support-req { width: 100%; min-height: 48px; border-radius: var(--radius); border: 1px dashed var(--border); background: var(--surface); color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer; }
.support[data-state="prompt"], .support[data-state="active"], .support[data-state="waiting"] {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
}
.support[data-state="prompt"] { border-color: var(--accent); }
.support[data-state="active"] { border-color: var(--green); }
.s-approve { background: var(--accent); color: #fff; }
.s-deny { background: var(--surface-2); color: var(--text); border: 1px solid var(--border) !important; }

/* Staff-only support tools */
.advanced { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.adv-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; font-weight: 600; color: var(--text); padding: 0 2px;
}
.adv-note { font-size: 12px; color: var(--muted); font-weight: 400; }
.adv-select {
  width: 100%; height: 40px; padding: 0 10px; margin-bottom: 10px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; font-size: 14px;
}
.advanced .block input[type="range"] { margin-top: 6px; }
.advanced .block.unsupported { opacity: 0.5; }
.cap-note { font-size: 12px; color: var(--amber); margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #2a313a; color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 13px;
  border: 1px solid var(--border); max-width: 90%;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.toast.err { background: #3a1414; border-color: #5b2020; color: #ffd5d5; }

button:disabled { opacity: .5; cursor: default; }

/* Login */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 22px; text-align: center;
}
.login-mark {
  width: 56px; height: 56px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: #cfe2fb;
  border-radius: 14px; font-size: 20px; font-weight: 700; letter-spacing: .5px;
}
.login-card h1 { font-size: 19px; margin: 0 0 6px; }
.login-sub { font-size: 13px; color: var(--muted); margin: 0 0 20px; }
#loginForm { display: flex; flex-direction: column; gap: 10px; }
#loginPassword {
  width: 100%; height: 46px; padding: 0 14px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 11px; font-size: 16px;
}
#loginPassword:focus { outline: none; border-color: var(--accent); }
#loginBtn {
  height: 46px; background: var(--accent); color: #fff; border: none;
  border-radius: 11px; font-size: 15px; font-weight: 600; cursor: pointer;
}
#loginBtn:active { transform: scale(0.98); }
.login-err { color: var(--red); font-size: 13px; margin-top: 12px; }
#signupForm { display: flex; flex-direction: column; gap: 10px; }
.login-card input, .login-card select {
  width: 100%; height: 46px; padding: 0 14px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 11px; font-size: 16px;
}
.login-card select { appearance: none; -webkit-appearance: none; }
.login-card input:focus, .login-card select:focus { outline: none; border-color: var(--accent); }
.login-toggle { margin-top: 16px; font-size: 13px; }
.login-toggle a { color: var(--accent); text-decoration: none; }

/* First-screen onboarding */
.onboard { margin-bottom: 16px; }
.onboard-h { font-size: 16px; margin: 0 0 4px; }
.onboard-sub { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.onboard-form { display: flex; gap: 10px; }
.onboard-form input {
  flex: 1; height: 44px; padding: 0 12px; background: var(--surface-2);
  color: var(--text); border: 1px solid var(--border); border-radius: 10px; font-size: 15px;
}
.onboard-form button, .obdone {
  height: 44px; padding: 0 16px; background: var(--accent); color: #fff;
  border: none; border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.obdone { margin-top: 12px; }
.cmd {
  background: #0d1117; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px;
  color: #cbd5e1; white-space: pre-wrap; word-break: break-all; margin-top: 6px;
}

.top-right { display: flex; align-items: center; gap: 10px; }
.logout {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); font-size: 16px; cursor: pointer;
}
.logout:active { transform: scale(0.95); }

/* Wider, two-column layout on browsers so there's far less scrolling. */
@media (min-width: 820px) {
  .app { max-width: 920px; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .controls > .row.primary { grid-column: 1 / -1; }
  .controls > .sched-full { grid-column: 1 / -1; }
  .advanced { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .advanced > .adv-head { grid-column: 1 / -1; }
  .support, .onboard, .teampanel { max-width: 100%; }
}
