/* ---------- tokens ---------- */
:root {
  --bg: #faf8f2;
  --surface: #ffffff;
  --surface-2: #f5f2e9;
  --border: #e8e2d3;
  --field-border: #8f877a;
  --text: #24221c;
  --muted: #6b6558;
  --gold: #ffc72f;
  --gold-hover: #edb721;
  --on-gold: #2a2519;
  --accent: #8a5a00;
  --accent-soft: #fff4d6;
  --ok: #17663f;
  --ok-soft: #e4f5ec;
  --warn: #9c3d00;
  --warn-soft: #fff0e3;
  --danger: #a12f22;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px #2b22080d, 0 8px 24px #2b22080f;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.7 var(--font); color: var(--text); background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
h1 { font-size: 24px; line-height: 1.4; margin: 2px 0 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 700; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i.lg { width: 36px; height: 36px; stroke-width: 1.4; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border: 1px solid transparent; border-radius: 12px; font-weight: 700; transition: background .15s, transform .1s; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: var(--on-gold); }
.btn.primary:hover:not(:disabled) { background: var(--gold-hover); }
.btn.secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn.secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn.block { width: 100%; }
.btn.xl { min-height: 60px; font-size: 18px; border-radius: 14px; }
.link { background: none; border: 0; padding: 6px 0; color: var(--accent); font-weight: 700; min-height: 32px; }
.link:hover { text-decoration: underline; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: grid; gap: 6px; font-size: 14px; font-weight: 700; }
.field input, .field select, .search input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--field-border); border-radius: 12px; background: var(--surface); font-weight: 400; }
.field input::placeholder, .search input::placeholder { color: var(--muted); }
.field input[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-soft); }
.field .help { font-weight: 400; font-size: 13px; color: var(--muted); }
.field .help.error { color: var(--danger); }
.field.compact { font-size: 13px; }
.field.compact input { min-height: 44px; width: 130px; text-align: center; }
.with-action { position: relative; display: block; }
.with-action input { padding-left: 48px; }
.with-action .icon-btn { position: absolute; left: 1px; top: 1px; height: 44px; }

/* ---------- toast ---------- */
#toast { position: fixed; z-index: 50; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); max-width: 460px; margin: 0 auto; padding: 14px 18px; border-radius: 14px; font-weight: 700; box-shadow: var(--shadow); background: var(--ok-soft); color: var(--ok); border: 1px solid currentColor; animation: rise .2s ease-out; }
#toast.error { background: var(--danger-soft); color: var(--danger); }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 36px 28px; box-shadow: var(--shadow); text-align: center; }
.login-card .logo { display: block; margin: 0 auto 8px; }
.login-card form { display: grid; gap: 16px; margin-top: 24px; text-align: right; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px; padding: 24px 16px; background: var(--surface); border-left: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand strong, .brand small { display: block; line-height: 1.3; }
.brand small { color: var(--muted); font-size: 12px; }
#nav { display: grid; gap: 4px; }
#nav button { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 10px 12px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-weight: 700; text-align: right; }
#nav button:hover { background: var(--surface-2); color: var(--text); }
#nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--border); }
.me-text { flex: 1; min-width: 0; }
.me-text strong, .me-text small { display: block; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { color: var(--muted); font-size: 12px; }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }

main { padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1180px; width: 100%; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; margin-top: 16px; }
.card-title { padding: 18px 22px 0; }

.pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 99px; font-size: 13px; font-weight: 700; background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--warn-soft); color: var(--warn); }
.pill .i { width: 18px; height: 18px; }

/* ---------- home ---------- */
.home { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.punch-card { display: grid; gap: 18px; }
.clock-row { display: flex; justify-content: space-between; align-items: flex-start; }
.clock { font-size: 44px; font-weight: 800; line-height: 1.1; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
.state { color: var(--muted); font-weight: 700; margin-top: 6px; }
.state-dot { width: 14px; height: 14px; margin-top: 12px; border-radius: 50%; background: var(--border); }
.state-dot.on { background: #22a565; box-shadow: 0 0 0 0 #22a56566; animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px #22a56500; } 100% { box-shadow: 0 0 0 0 #22a56500; } }

.viewfinder { position: relative; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; }
.viewfinder video, .viewfinder img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.viewfinder:not(.live) video { visibility: hidden; }
.face-guide { position: absolute; width: 42%; aspect-ratio: 3 / 4; border: 3px dashed #ffffffcc; border-radius: 50%; box-shadow: 0 0 0 999px #0000004d; opacity: 0; transition: opacity .2s; pointer-events: none; }
.viewfinder.live .face-guide { opacity: 1; }
.countdown { position: absolute; font-size: 96px; font-weight: 800; color: #fff; text-shadow: 0 4px 24px #0008; }
.vf-empty { display: grid; justify-items: center; gap: 10px; max-width: 280px; padding: 16px; text-align: center; color: var(--muted); font-size: 14px; }
.viewfinder.live .vf-empty, .viewfinder.done .vf-empty { display: none; }
.vf-done { position: absolute; bottom: 12px; right: 12px; left: 12px; padding: 10px 14px; border-radius: 12px; background: #0f3a24e6; color: #fff; font-weight: 700; text-align: center; }
.hint { margin: -6px 0 0; text-align: center; color: var(--muted); font-size: 13px; }
.hint.warn { color: var(--warn); font-weight: 700; }

.side { display: grid; gap: 20px; }
.stats, .kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpis { grid-template-columns: repeat(3, 1fr); margin-top: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat span { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.stat strong { display: block; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.warn-stat strong { color: var(--warn); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 10px 26px 10px 0; }
.timeline li::before { content: ""; position: absolute; right: 5px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.timeline li.out::before { background: var(--muted); }
.timeline li:not(:last-child)::after { content: ""; position: absolute; right: 9px; top: 30px; bottom: -8px; width: 2px; background: var(--border); }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- reports ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 40px; padding: 6px 16px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; color: var(--muted); }
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.range { display: flex; align-items: flex-end; gap: 8px; }
.table-wrap { position: relative; overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; text-align: right; }
th, td { padding: 12px 22px; border-bottom: 1px solid var(--border); }
th { font-size: 13px; color: var(--muted); background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td .link { padding: 0; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 700; background: var(--ok-soft); color: var(--ok); }
.tag.out { background: var(--surface-2); color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.empty { padding: 28px 22px; margin: 0; text-align: center; color: var(--muted); }

/* ---------- people ---------- */
.search { position: relative; display: block; max-width: 420px; }
.search .i { position: absolute; right: 12px; top: 13px; color: var(--muted); }
.search input { padding-right: 42px; }
.people { list-style: none; margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.person { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.person > div { flex: 1; min-width: 0; }
.person strong { display: block; }
.person small { display: block; color: var(--muted); font-size: 13px; }
.person .tags { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

/* ---------- dialogs ---------- */
dialog { width: min(480px, calc(100% - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--text); box-shadow: 0 24px 64px #0004; }
dialog::backdrop { background: #1b170c80; backdrop-filter: blur(2px); }
#photo-dialog { width: min(640px, calc(100% - 32px)); }
.dialog-body { display: grid; gap: 16px; padding: 20px 22px 22px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin: -6px -10px 0 0; }
.dialog-head h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-start; flex-direction: row-reverse; gap: 8px; margin-top: 4px; }
.roles { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; padding: 0; border: 0; }
.roles legend { font-size: 14px; font-weight: 700; margin-bottom: 6px; padding: 0; }
.roles label { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 14px; border: 1px solid var(--border); border-radius: 12px; }
.roles label:has(:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.roles input { accent-color: var(--accent); }
.photo-frame { display: grid; place-items: center; min-height: 240px; border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.photo-frame img { max-width: 100%; max-height: 70vh; display: block; }
.photo-frame img:not([src]) { display: none; }
.photo-frame span { padding: 24px; text-align: center; }
#photo-dialog a { color: var(--accent); }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .shell { display: block; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .shell.solo { padding-bottom: 0; }
  .sidebar { position: sticky; z-index: 20; height: auto; flex-direction: row; align-items: center; justify-content: space-between; padding: 10px 16px; border-left: 0; border-bottom: 1px solid var(--border); }
  .me { margin: 0; padding: 0; border: 0; }
  .me-text { display: none; }
  .avatar { width: 34px; height: 34px; font-size: 14px; }
  #nav { position: fixed; z-index: 20; bottom: 0; left: 0; right: 0; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  #nav button { min-width: 0; flex-direction: column; gap: 2px; min-height: 56px; padding: 6px; font-size: 12px; justify-content: center; }
  #nav button[aria-current="page"] { background: transparent; }
  main { padding-top: 20px; }
  .home { grid-template-columns: 1fr; }
  .clock { font-size: 38px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis .stat:first-child { grid-column: 1 / -1; }
  .range { width: 100%; }
  .range .field { flex: 1; }
  .field.compact input { width: 100%; }
  th, td { padding: 12px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
