:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --line: #e8e8e4;
  --ink: #111113;
  --ink-2: #4a4a50;
  --muted: #8a8a90;
  --accent: #3e63dd;
  --accent-soft: #e9eefc;
  --good: #1f9d55;
  --good-soft: #e3f5ea;
  --bad: #d93a3a;
  --bad-soft: #fbe8e8;
  --warn: #b7791f;
  --warn-soft: #fbf1df;
  --shadow: 0 1px 2px rgba(17, 17, 19, .04), 0 8px 24px -12px rgba(17, 17, 19, .12);
  --shadow-lg: 0 24px 60px -20px rgba(17, 17, 19, .35);
  --r: 18px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    --surface: #17171a;
    --surface-2: #1f1f23;
    --line: #2a2a2f;
    --ink: #f2f2f3;
    --ink-2: #c0c0c6;
    --muted: #8b8b93;
    --accent: #7c9cff;
    --accent-soft: #1d2440;
    --good: #3ccf7a;
    --good-soft: #15291d;
    --bad: #ff6b6b;
    --bad-soft: #351919;
    --warn: #f0b34a;
    --warn-soft: #33270f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}
button, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 24px; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .3s;
}
.top.scrolled { border-bottom-color: var(--line); }
.top-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.02em; font-size: 17px; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--ink); display: grid; place-items: center; }
.brand-mark i { width: 8px; height: 8px; border-radius: 50%; background: #34c759; box-shadow: 0 0 0 3px rgba(52, 199, 89, .25); }

.device {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; color: var(--ink-2);
  transition: all .4s var(--ease);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; position: relative; }
.device[data-state="online"] .dot { background: var(--good); }
.device[data-state="online"] .dot::after,
.live .dot::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: inherit; animation: ping 2s var(--ease) infinite;
}
.device[data-state="offline"] .dot { background: var(--bad); }
@keyframes ping { 0% { transform: scale(1); opacity: .6; } 100% { transform: scale(2.8); opacity: 0; } }

/* ---------- Hero ---------- */
.hero { display: flex; align-items: flex-end; justify-content: space-between; padding: 36px 0 28px; gap: 16px; }
.eyebrow { color: var(--muted); font-size: 14px; text-transform: capitalize; margin-bottom: 4px; }
h1 { font-size: clamp(28px, 4vw, 40px); letter-spacing: -.035em; font-weight: 650; line-height: 1.1; }
.clock { font-size: clamp(28px, 4vw, 40px); font-weight: 300; letter-spacing: -.03em; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ---------- Pending ---------- */
.pending {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 16px; margin-bottom: 16px;
  background: var(--warn-soft); border-radius: 14px;
  animation: rise .5s var(--ease) both;
}
.pending-icon { width: 34px; height: 34px; border-radius: 10px; background: var(--surface); display: grid; place-items: center; flex: none; }
.pending-icon svg { width: 18px; height: 18px; color: var(--warn); }
.pending-text { flex: 1; min-width: 200px; }
.pending-text b { font-weight: 600; }
.pending-text code { font: 500 13px ui-monospace, "SF Mono", Menlo, monospace; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border-radius: var(--r); padding: 18px 20px;
  box-shadow: var(--shadow);
  animation: rise .6s var(--ease) both;
}
.kpi:nth-child(2) { animation-delay: .04s; }
.kpi:nth-child(3) { animation-delay: .08s; }
.kpi:nth-child(4) { animation-delay: .12s; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 34px; font-weight: 600; letter-spacing: -.035em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Layout ---------- */
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.col-main { display: grid; gap: 16px; min-width: 0; }
.card {
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 8px 8px 12px; min-width: 0;
  animation: rise .7s var(--ease) both; animation-delay: .1s;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px 10px; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Segmented */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 5px 11px; border-radius: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer; transition: all .25s var(--ease);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- People ---------- */
.people { list-style: none; margin: 0; padding: 0; }
.person {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 12px; border-radius: 12px; cursor: pointer;
  transition: background .2s;
  animation: rise .45s var(--ease) both;
}
.person:hover { background: var(--surface-2); }
.person.flash { animation: flash 1.6s var(--ease); }
@keyframes flash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }

.avatar {
  --size: 40px;
  width: var(--size); height: var(--size); border-radius: 50%;
  display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--ink-2);
  font-weight: 600; font-size: calc(var(--size) * .36); letter-spacing: -.02em;
  position: relative;
}
.avatar.in::after {
  content: ""; position: absolute; right: 0; bottom: 0;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--good); border: 2px solid var(--surface);
}
.avatar.lg { --size: 64px; }
.avatar.lg.in::after { width: 15px; height: 15px; border-width: 3px; }

.p-name { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 2px; flex-wrap: wrap; }
.p-right { text-align: right; }
.p-hours { font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.p-balance { font-size: 12px; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.chip.in { background: var(--good-soft); color: var(--good); }
.chip.denied { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip .dot { width: 6px; height: 6px; background: currentColor; }

.empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- Feed ---------- */
.feed-card { position: sticky; top: 80px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--good); font-weight: 500; }
.live .dot { background: var(--good); width: 6px; height: 6px; }
.feed { list-style: none; margin: 0; padding: 0 4px; max-height: calc(100vh - 170px); overflow: auto; scrollbar-width: thin; }
.ev {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 9px 8px; border-radius: 10px; cursor: pointer; transition: background .2s;
}
.ev:hover { background: var(--surface-2); }
.ev.enter { animation: slideIn .6s var(--ease) both; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }
.ev-icon { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; }
.ev-icon svg { width: 15px; height: 15px; }
.ev-icon.in { background: var(--good-soft); color: var(--good); }
.ev-icon.out { background: var(--surface-2); color: var(--ink-2); }
.ev-icon.denied { background: var(--bad-soft); color: var(--bad); }
.ev-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-sub { font-size: 12px; color: var(--muted); }
.ev-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Chart ---------- */
.chart { position: relative; padding: 4px 12px 0; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .target-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis.today { fill: var(--ink); font-weight: 600; }
.chart .bar { fill: var(--accent); transition: opacity .2s; transform-origin: bottom; transform-box: fill-box; animation: grow .8s var(--ease) both; }
.chart .bar.zero { fill: var(--line); }
.chart .hit { fill: transparent; cursor: default; }
.chart svg:hover .bar { opacity: .45; }
.chart svg .bar.hover { opacity: 1; }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--ink); color: var(--bg); border-radius: 10px;
  padding: 7px 10px; font-size: 12px; line-height: 1.35; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity .15s;
  box-shadow: var(--shadow);
}
.tip.on { opacity: 1; }
.tip b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Drawer ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 40; background: rgba(10, 10, 12, .28);
  opacity: 0; pointer-events: none; transition: opacity .35s var(--ease);
}
.scrim.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; z-index: 50; top: 10px; right: 10px; bottom: 10px;
  width: min(520px, calc(100vw - 20px));
  background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg);
  transform: translateX(calc(100% + 24px)); transition: transform .5s var(--ease);
  overflow: hidden; display: flex;
}
.drawer.on { transform: none; }
.drawer-inner { overflow: auto; padding: 22px 24px 32px; width: 100%; scrollbar-width: thin; }
.d-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-2);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2); transition: transform .2s var(--ease), background .2s;
}
.icon-btn:hover { transform: scale(1.06); }
.icon-btn svg { width: 16px; height: 16px; }
.d-id { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.d-name { font-size: 24px; font-weight: 650; letter-spacing: -.03em; line-height: 1.15; }
.d-meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.d-meta code { font: 500 12px ui-monospace, "SF Mono", Menlo, monospace; }
.d-status { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.balance {
  border-radius: 16px; padding: 18px 20px; margin-bottom: 12px;
  background: var(--surface-2);
}
.balance-label { font-size: 13px; color: var(--muted); }
.balance-value { font-size: 40px; font-weight: 650; letter-spacing: -.04em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.balance-sub { font-size: 13px; color: var(--ink-2); }

.progress { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 14px 0 8px; }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 1s linear; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 22px; border: 1px solid var(--line); }
.stat { background: var(--surface); padding: 12px 14px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }

.section-title { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 24px 0 10px; display: flex; justify-content: space-between; align-items: baseline; }
.section-title span { font-weight: 400; color: var(--muted); }
.drawer .chart { padding: 0; }

.sessions { list-style: none; margin: 0; padding: 0; }
.sess { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; gap: 10px; }
.sess:last-child { border-bottom: 0; }
.sess-day { font-weight: 500; }
.sess-range { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.sess-dur { font-weight: 600; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; }

.form { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
.field input[type="text"], .field input[type="number"] {
  width: 100%; padding: 11px 13px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface);
  transition: border-color .2s, box-shadow .2s; outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); cursor: pointer; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .25s var(--ease); }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .3s var(--ease); }
.switch input:checked + i { background: var(--good); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { box-shadow: 0 0 0 4px var(--accent-soft); }

.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.btn {
  border: 0; border-radius: 11px; padding: 10px 16px; font-weight: 550; font-size: 14px; cursor: pointer;
  background: var(--surface-2); color: var(--ink); transition: transform .15s var(--ease), opacity .2s, background .2s;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.danger { background: transparent; color: var(--bad); padding-left: 4px; padding-right: 4px; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 15px; height: 15px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px 10px 10px; border-radius: 999px;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg);
  animation: toastIn .55s var(--ease) both; pointer-events: auto;
}
.toast.out { animation: toastOut .4s var(--ease) both; }
.toast .avatar { --size: 34px; background: rgba(255,255,255,.12); color: inherit; }
@media (prefers-color-scheme: dark) { .toast .avatar { background: rgba(0,0,0,.08); } }
.toast-title { font-weight: 600; font-size: 14px; }
.toast-sub { font-size: 12px; opacity: .7; }
.toast .badge { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-left: 4px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.96); } }

.foot { text-align: center; padding: 32px 0 40px; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .grid { grid-template-columns: 1fr; }
  .feed-card { position: static; }
  .feed { max-height: 420px; }
}
@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 14px 16px; }
  .kpi-value { font-size: 28px; }
  .hero { padding: 24px 0 20px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .drawer { top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 92vh; border-radius: 22px 22px 0 0; transform: translateY(100%); }
  .drawer.on { transform: none; }
  .row2 { grid-template-columns: 1fr; }
  .card-head { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Login ---------- */
.top-right { display: flex; align-items: center; gap: 8px; }
body.locked { overflow: hidden; }
body.locked .top, body.locked main { filter: blur(6px); pointer-events: none; user-select: none; }
.login {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  opacity: 0; transition: opacity .35s var(--ease);
}
.login.on { opacity: 1; }
.login-card {
  width: min(360px, 100%); display: grid; justify-items: center; gap: 12px; text-align: center;
  background: var(--surface); border-radius: 22px; padding: 32px 24px 24px; box-shadow: var(--shadow-lg);
  transform: translateY(10px) scale(.98); transition: transform .45s var(--ease);
}
.login.on .login-card { transform: none; }
.login-card.shake { animation: shake .4s var(--ease); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.brand-mark.lg { width: 44px; height: 44px; border-radius: 13px; }
.brand-mark.lg i { width: 12px; height: 12px; }
.login-title { font-size: 22px; font-weight: 650; letter-spacing: -.03em; }
.field input[type="password"] {
  width: 100%; padding: 12px 14px; border-radius: 11px; text-align: center;
  border: 1px solid var(--line); background: var(--surface); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.login-err { min-height: 18px; font-size: 13px; color: var(--bad); }

[hidden] { display: none !important; }
