:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --text: #14161c;
  --muted: #646b7a;
  --line: #e3e6ec;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eceafd;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --amber: #a16207;
  --amber-soft: #fef3c7;
  --orange: #c2410c;
  --orange-soft: #ffedd5;
  --purple: #7e22ce;
  --purple-soft: #f3e8ff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --panel: #171a21;
    --text: #eef0f4;
    --muted: #9aa1b0;
    --line: #2a2f3a;
    --accent: #8b85ff;
    --accent-ink: #0e1015;
    --accent-soft: #24224a;
    --green: #4ade80;
    --green-soft: #12311f;
    --red: #f87171;
    --red-soft: #3a1717;
    --amber: #fbbf24;
    --amber-soft: #352a0d;
    --orange: #fb923c;
    --orange-soft: #3a220f;
    --purple: #c084fc;
    --purple-soft: #2c1840;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
a { color: var(--accent); }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }

/* ---- Centered screens (sign in, PIN) ---- */
.center {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  text-align: center; gap: 12px;
}
.center h1 { font-size: 22px; margin: 8px 0 0; }
.center p { color: var(--muted); margin: 0; max-width: 340px; }
.logo { width: 64px; height: 64px; border-radius: 16px; }
.msg { min-height: 1.4em; font-size: 14px; color: var(--red); }
.msg.ok { color: var(--green); }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: 8px 14px; font-weight: 550; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ok { color: var(--green); }
.btn.ok.solid { background: var(--green); border-color: var(--green); color: #fff; }
.btn.big { min-height: 48px; padding: 12px 22px; font-size: 16px; border-radius: 12px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 6px; min-height: 0; font-weight: 500; }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }

/* ---- PIN pad ---- */
.dots { display: flex; gap: 14px; margin: 18px 0 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.dot.on { background: var(--text); border-color: var(--text); }
.dots.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; margin-top: 8px; }
.pad button {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--panel);
  font-size: 28px; font-weight: 400; box-shadow: var(--shadow);
}
.pad button:active { background: var(--line); }
.pad button.ghost { background: none; box-shadow: none; font-size: 15px; color: var(--muted); }

/* ---- App chrome ---- */
header.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}
header.top .wrap { padding-bottom: 0; }
.topbar { display: flex; align-items: center; gap: 10px; height: 52px; }
.topbar .title { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.topbar .title img { width: 26px; height: 26px; border-radius: 7px; }
.topbar .clock { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.iconbtn { border: 0; background: none; padding: 8px; border-radius: 8px; color: var(--muted); display: flex; }
.iconbtn:active { background: var(--line); }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; }
nav.tabs button {
  border: 0; background: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 550; white-space: nowrap;
}
nav.tabs button.on { background: var(--accent-soft); color: var(--accent); }

.banner {
  margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; font-size: 13.5px;
  background: var(--amber-soft); color: var(--amber);
}

/* ---- Toolbar ---- */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 12px; }
.search {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 12px;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 11px;
  font-size: 13px; white-space: nowrap; color: var(--muted);
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: 0.7; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ---- User cards ---- */
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.card .head { display: flex; gap: 10px; align-items: flex-start; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 650; font-size: 14px; background: var(--accent-soft); color: var(--accent);
}
.who { min-width: 0; flex: 1; }
.who .name { font-weight: 620; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.who .email { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.b-active { background: var(--green-soft); color: var(--green); }
.b-suspended { background: var(--red-soft); color: var(--red); }
.b-staged { background: var(--amber-soft); color: var(--amber); }
.b-locked { background: var(--orange-soft); color: var(--orange); }
.b-admin { background: var(--accent-soft); color: var(--accent); }
.b-super { background: var(--purple-soft); color: var(--purple); }
.b-you { background: var(--line); color: var(--muted); }
.sched {
  margin-top: 10px; display: flex; align-items: center; gap: 8px; font-size: 13px;
  background: var(--accent-soft); color: var(--accent); padding: 7px 10px; border-radius: 9px;
}
.sched .grow { flex: 1; }
.sched .by { opacity: 0.75; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.note { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---- Sections (settings/admins/activity) ---- */
.section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.section h2 { font-size: 16px; margin: 0 0 6px; }
.section p { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.section .row { display: flex; gap: 8px; flex-wrap: wrap; }
.adminrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.adminrow:first-of-type { border-top: 0; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: 0.2s; }
.switch span::before {
  content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: 0.2s;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:disabled + span { opacity: 0.5; }
.logrow { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.logrow:first-of-type { border-top: 0; }
.logrow .ts { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.logrow .det { grid-column: 2; color: var(--muted); font-size: 12.5px; }

/* ---- Sheet / dialog ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.15s;
}
@media (min-width: 640px) { .overlay { align-items: center; } }
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--panel); width: 100%; max-width: 480px; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto;
}
.sheet.anim, .dialog { animation: up 0.2s ease-out; }
@media (min-width: 640px) { .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0.6; } }
.sheet h3 { margin: 0 0 14px; font-size: 17px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 8px; font-weight: 550; color: var(--muted); font-size: 14px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.presets button { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 4px; font-weight: 550; }
.presets button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.customrow { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.customrow input, .customrow select, .field {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 10px; min-width: 0;
}
.customrow input { width: 90px; }
.field { width: 100%; font-size: 20px; font-variant-numeric: tabular-nums; text-align: center; letter-spacing: 0.5px; }
.hint { font-size: 12px; color: var(--muted); text-align: center; margin: 4px 0 10px; }
.cal { user-select: none; }
.cal .calhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; }
.cal .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal .dow { font-size: 11px; color: var(--muted); padding: 4px 0; }
.cal .d { border: 0; background: none; padding: 8px 0; border-radius: 9px; font-variant-numeric: tabular-nums; }
.cal .d.today { color: var(--accent); font-weight: 700; }
.cal .d.sel { background: var(--accent); color: var(--accent-ink); }
.cal .d:disabled { opacity: 0.25; }
.timerow { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 10px; }
.timerow select { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 12px; font-size: 18px; font-variant-numeric: tabular-nums; }
.summary { margin: 16px 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--bg); font-size: 14px; }
.summary.bad { color: var(--red); }
.sheetbtns { display: flex; gap: 8px; }
.sheetbtns .btn { flex: 1; min-height: 46px; }
.dialog p { margin: 0 0 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); animation: fade 0.2s;
}
.toast.err { background: var(--red); color: #fff; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot 0.7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
