:root {
  --navy: #2e3366;
  --yellow: #fecc17;
  --blue: #2e3366;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --green: #15803d;
  --green-bg: #dcfce7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --amber: #a16207;
  --amber-bg: #fef3c7;
  --radius: 14px;
  font-family: Poppins, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
button, input, select { font: inherit; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .02em; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: var(--navy); color: #fff;
  border-bottom: 4px solid var(--yellow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 34px; height: 34px; fill: #fff; }
.logo { height: 44px; width: auto; max-width: 160px; object-fit: contain; background: #fff; border-radius: 10px; padding: 4px 8px; }
.who { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; line-height: 1.3; margin-right: 6px; }
.who-label { opacity: .7; }
.who-email { font-size: 14px; font-weight: 600; }
.who-admin { background: var(--yellow); color: var(--navy); border-radius: 6px; padding: 0 6px; font-weight: 700; font-size: 11px; margin-top: 2px; }
.who-out { color: #fff; opacity: .8; background: none; border: 0; padding: 0; font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; }
@media (max-width: 700px) { .who-label, .app-name { display: none; } .who-email { font-size: 12px; } }
.app-name { font-size: 13px; opacity: .8; }
.site-name { font-size: 20px; font-weight: 600; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 10px; padding: 8px 14px; min-height: 44px; }
.ghost[aria-pressed="true"] { background: var(--yellow); color: var(--navy); border-color: var(--yellow); }
.site-picker { min-height: 44px; border-radius: 10px; border: 0; padding: 0 10px; }

main { padding: 16px 20px 40px; max-width: 1200px; margin: 0 auto; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 10px; }
.clock { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 0 0 1px var(--line); display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; }
.card h3 { margin: 0; font-size: 22px; }
.r-slot { font-size: 13px; }
.icon-btn { background: var(--bg); border: 0; border-radius: 10px; width: 44px; height: 44px; font-size: 18px; }

.status-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pill { padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.pill.on { background: var(--green-bg); color: var(--green); }
.pill.off { background: var(--red-bg); color: var(--red); }
.pill.bed { background: var(--amber-bg); color: var(--amber); }
.big-toggle { min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0; font-weight: 600; color: #fff; }
.big-toggle.turn-off { background: var(--red); }
.big-toggle.turn-on { background: var(--green); }

.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.value { font-size: 16px; margin-top: 2px; }
.btns { display: flex; gap: 8px; }
.problem { background: var(--amber-bg); color: var(--amber); border-radius: 10px; padding: 8px 10px; font-size: 14px; }

button.primary, button.secondary, button.danger-outline { min-height: 44px; padding: 0 16px; border-radius: 10px; font-weight: 600; }
button.small { min-height: 40px; padding: 0 12px; }
button.primary { background: var(--yellow); color: var(--navy); border: 0; }
button.secondary { background: #fff; color: var(--text); border: 1px solid var(--line); }
button.danger-outline { background: #fff; color: var(--red); border: 1px solid #fca5a5; }
button:disabled { opacity: .5; }

.activity { background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--line); overflow: hidden; }
.act { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.act:last-child { border-bottom: 0; }
.act .when { color: var(--muted); font-size: 14px; }
.act .what { font-weight: 600; }
.act .why { color: var(--muted); font-size: 14px; }
h2 { font-size: 18px; margin: 4px 0 12px; }

.banner { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #111827; color: #fff; padding: 12px 18px; border-radius: 12px; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.banner.err { background: var(--red); }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(480px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0; font-size: 20px; }
dialog p { margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 14px; color: var(--muted); }
.field input, .field select { min-height: 48px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: #fff; font-size: 17px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; font-size: 17px; }
.check input { width: 24px; height: 24px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.error { color: var(--red); font-size: 14px; }

@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --card: #111a2b; --text: #e5e7eb; --line: #1f2a3d; --muted: #9ca3af; }
  button.secondary, button.danger-outline, .field input, .field select { background: #0b1220; color: var(--text); }
  .icon-btn { background: #0b1220; }
}

.support { max-width: 640px; margin: 24px auto; background: var(--card); border-radius: var(--radius); padding: 28px; box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 0 0 1px var(--line); border-top: 6px solid var(--yellow); }
.support-kicker { margin: 0; color: var(--muted); }
.support-company { margin: 4px 0 20px; font-size: 26px; color: var(--navy); }
.support-links { display: grid; gap: 12px; }
.support-link { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 12px; background: var(--bg); color: var(--navy); text-decoration: none; min-height: 64px; }
.support-link .label { display: block; }
.support-icon { font-size: 24px; }
.support-value { display: block; font-size: 20px; font-weight: 600; }
.support-note { margin: 18px 0 0; font-size: 14px; }

/* Sign-in screen */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--navy); }
.login-card { width: 100%; max-width: 420px; background: #fff; border-radius: 18px; padding: 28px; border-top: 6px solid var(--yellow); text-align: center; }
.login-card h1 { margin: 8px 0 18px; color: var(--navy); font-size: 24px; }
.login-card form, .login-card #loginDevice { text-align: left; }
.login-logo { height: 84px; }
.login-home { font-size: 24px; font-weight: 700; color: var(--navy); margin: 0 0 16px; }
#loginDevice .muted:first-child { margin-bottom: 2px; }
.primary.wide { width: 100%; min-height: 52px; font-size: 17px; margin-top: 4px; }
.login-links { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; align-items: center; }
.link { background: none; border: 0; color: var(--navy); text-decoration: underline; font: inherit; padding: 6px; cursor: pointer; }
.small { font-size: 13px; }
.code-input { font-size: 28px; letter-spacing: 8px; text-align: center; }
.check { display: flex; gap: 10px; align-items: center; margin: 4px 0 12px; }
.check input { width: 22px; height: 22px; }
.login-support { margin-top: 20px; }
.login-support a { color: var(--navy); }
