/* DAYHAB Timeclock — MAINT design system (tokens.css) with a real desktop layout.
 * Phone (<1024px): sticky header + bottom tab bar, like MAINT.
 * Desktop (>=1024px): fixed left sidebar, wide fluid content, multi-column grids. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--ap-font-family); font-size: var(--ap-font-size-base);
  background: var(--ap-color-bg); color: var(--ap-color-text);
  line-height: 1.5; -webkit-font-smoothing: antialiased;
  min-height: 100vh; min-height: 100dvh;
}
a { color: var(--ap-color-brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { letter-spacing: -0.02em; margin: 0; line-height: 1.25; }
h1 { font-size: var(--ap-font-size-2xl); font-weight: 700; }
h2 { font-size: var(--ap-font-size-lg); font-weight: 650; }
h3 { font-size: var(--ap-font-size-base); font-weight: 650; }
input, select, textarea, button { font-family: inherit; font-size: max(16px, 1em); }
:focus-visible { outline: 2px solid var(--ap-color-brand); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
.ic { flex: none; vertical-align: middle; }
.muted { color: var(--ap-color-text-muted); }
.subtle { color: var(--ap-color-text-subtle); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip-link { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* ---------------------------------------------------------------- shell */
.shell { min-height: 100vh; }
.sidebar { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--ap-color-card); border-bottom: 1px solid var(--ap-color-border);
  padding: var(--ap-space-3) var(--ap-space-4); padding-top: calc(var(--ap-space-3) + env(safe-area-inset-top));
  display: flex; align-items: center; gap: var(--ap-space-3);
}
.brand { display: flex; align-items: center; gap: var(--ap-space-2); font-weight: 700; font-size: 15px; color: var(--ap-color-text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; background: var(--ap-color-brand); color: #fff; border-radius: var(--ap-radius-sm); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--ap-color-text-muted); letter-spacing: .02em; }
.topbar .page-title { display: none; }
.spacer { flex: 1; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--ap-color-brand), #f97316); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; }
.avatar:hover { text-decoration: none; filter: brightness(1.05); }
.icon-btn { width: 40px; height: 40px; border-radius: var(--ap-radius-md); display: inline-flex; align-items: center; justify-content: center; background: transparent; border: 0; color: var(--ap-color-text-muted); cursor: pointer; position: relative; }
.icon-btn:hover { background: var(--ap-color-neutral-bg); color: var(--ap-color-text); }
.badge-dot { position: absolute; top: 6px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--ap-color-brand); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--ap-color-card); }

.main { padding: var(--ap-space-4); padding-bottom: calc(96px + env(safe-area-inset-bottom)); max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--ap-space-3); margin-bottom: var(--ap-space-5); }
.page-head .grow { flex: 1; min-width: 200px; }
.page-head p { margin: 4px 0 0; color: var(--ap-color-text-muted); }

/* bottom tabs (phone/tablet) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--ap-color-card); border-top: 1px solid var(--ap-color-border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; box-shadow: var(--ap-shadow-lg);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 54px; border-radius: var(--ap-radius-md); color: var(--ap-color-text-muted); font-size: 11px; font-weight: 500; position: relative; background: none; border: 0; cursor: pointer; }
.tab:hover { background: var(--ap-color-neutral-bg); text-decoration: none; }
.tab.active { color: var(--ap-color-brand); }
.tab.active::before { content: ''; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; background: var(--ap-color-brand); border-radius: 0 0 2px 2px; }
.tab .badge-dot { top: 2px; right: calc(50% - 22px); }

/* "More" sheet on phones */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; display: none; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; background: var(--ap-color-card); border-radius: 18px 18px 0 0; padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); box-shadow: var(--ap-shadow-xl); transform: translateY(105%); transition: transform .18s ease; }
.sheet.open { transform: none; }
.sheet-backdrop.open { display: block; }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--ap-color-border-strong); margin: 0 auto 10px; }
.sheet a { display: flex; align-items: center; gap: 12px; padding: 14px 12px; border-radius: var(--ap-radius-md); color: var(--ap-color-text); font-weight: 500; }
.sheet a:hover { background: var(--ap-color-neutral-bg); text-decoration: none; }

@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); }
  .sidebar {
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
    background: var(--ap-color-card); border-right: 1px solid var(--ap-color-border); padding: 18px 14px;
  }
  .sidebar .brand { padding: 4px 8px 18px; }
  .nav-group { margin-top: 14px; }
  .nav-group h4 { margin: 0 0 4px; padding: 0 10px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ap-color-text-subtle); }
  .nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--ap-color-text-muted); font-weight: 500; position: relative; }
  .nav-link:hover { background: var(--ap-color-neutral-bg); color: var(--ap-color-text); text-decoration: none; }
  .nav-link.active { background: #fdf2f2; color: var(--ap-color-brand); }
  .nav-link .count { margin-left: auto; background: var(--ap-color-brand); color: #fff; font-size: 11px; font-weight: 700; border-radius: 9px; padding: 1px 7px; }
  .sidebar .who { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-top: 1px solid var(--ap-color-border); }
  .sidebar .who .meta { min-width: 0; }
  .sidebar .who .meta b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar .who .meta span { font-size: 12px; color: var(--ap-color-text-muted); }
  .topbar .brand, .tabbar, .topbar .avatar { display: none; }
  .topbar { padding: 14px 28px; }
  .topbar .page-title { display: block; font-weight: 600; color: var(--ap-color-text-muted); }
  .main { padding: 24px 28px 48px; }
}

/* ---------------------------------------------------------------- components */
.card { background: var(--ap-color-card); border: 1px solid var(--ap-color-border); border-radius: var(--ap-radius-lg); box-shadow: var(--ap-shadow-sm); }
.card-pad { padding: var(--ap-space-5); }
.card-head { display: flex; align-items: center; gap: var(--ap-space-3); padding: var(--ap-space-4) var(--ap-space-5); border-bottom: 1px solid var(--ap-color-border); }
.card-head h2 { flex: 1; }
.card-body { padding: var(--ap-space-4) var(--ap-space-5); }
.stack > * + * { margin-top: var(--ap-space-4); }
.grid { display: grid; gap: var(--ap-space-4); }
.grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .grid-kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .grid-kpi { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.grid-2 { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); } }

.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; font-weight: 600; color: var(--ap-color-text-muted); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: 12px; color: var(--ap-color-text-muted); margin-top: 2px; }
.kpi.alert .value { color: var(--ap-color-brand); }
a.kpi { color: inherit; display: block; }
a.kpi:hover { text-decoration: none; border-color: var(--ap-color-border-strong); box-shadow: var(--ap-shadow-md); }

.delta { font-size: 12px; font-weight: 600; padding: 1px 6px; border-radius: 6px; white-space: nowrap; }
.delta.up { color: var(--ap-color-success); background: var(--ap-color-success-bg); }
.delta.down { color: var(--ap-color-danger); background: var(--ap-color-danger-bg); }
.delta.flat { color: var(--ap-color-text-muted); background: var(--ap-color-neutral-bg); }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-in { background: var(--ap-color-success-bg); color: #166534; }
.pill-out { background: var(--ap-color-neutral-bg); color: var(--ap-color-text-muted); }
.pill-warn { background: var(--ap-color-warning-bg); color: #9a3412; }
.pill-danger { background: var(--ap-color-danger-bg); color: #991b1b; }
.pill-info { background: var(--ap-color-info-bg); color: #075985; }
.pill-lock { background: #ede9fe; color: #5b21b6; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: var(--ap-radius-md); border: 1px solid transparent; background: var(--ap-color-brand); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--ap-color-brand-hover); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn-ghost { background: var(--ap-color-card); color: var(--ap-color-text); border-color: var(--ap-color-border-strong); }
.btn-ghost:hover { background: var(--ap-color-neutral-bg); }
.btn-quiet { background: transparent; color: var(--ap-color-text-muted); }
.btn-quiet:hover { background: var(--ap-color-neutral-bg); color: var(--ap-color-text); }
.btn-danger { background: var(--ap-color-card); color: var(--ap-color-danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--ap-color-danger-bg); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--ap-color-text-muted); }
.input, select.input, textarea.input { width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--ap-color-border-strong); border-radius: 10px; background: #fff; color: var(--ap-color-text); }
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid rgba(190,7,7,.25); border-color: var(--ap-color-brand); }
.form-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } .form-grid .span-2 { grid-column: span 2; } }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ap-color-brand); }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.days label { display: inline-flex; align-items: center; justify-content: center; min-width: 50px; height: 40px; border: 1px solid var(--ap-color-border-strong); border-radius: 10px; cursor: pointer; font-weight: 600; user-select: none; }
.days input { position: absolute; opacity: 0; pointer-events: none; }
.days input:checked + span { color: #fff; }
.days label:has(input:checked) { background: var(--ap-color-brand); border-color: var(--ap-color-brand); color: #fff; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--ap-color-border); }
.toolbar .input { width: auto; min-height: 38px; }
.seg { display: inline-flex; background: var(--ap-color-neutral-bg); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg a, .seg button { padding: 6px 12px; border-radius: 8px; color: var(--ap-color-text-muted); font-weight: 600; font-size: 13px; background: none; border: 0; cursor: pointer; }
.seg a:hover, .seg button:hover { color: var(--ap-color-text); text-decoration: none; }
.seg .on { background: #fff; color: var(--ap-color-text); box-shadow: var(--ap-shadow-sm); }

/* tables: full width on desktop, card-like rows on phones */
.table-wrap { width: 100%; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ap-color-text-muted); padding: 10px 14px; border-bottom: 1px solid var(--ap-color-border); background: #fafafa; position: sticky; top: 0; white-space: nowrap; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ap-color-text); }
table.data th[aria-sort="ascending"]::after { content: ' ▲'; font-size: 10px; }
table.data th[aria-sort="descending"]::after { content: ' ▼'; font-size: 10px; }
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--ap-color-border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--ap-color-card-hover); }
table.data tr.total td { font-weight: 700; background: #fafafa; }
table.data a.rowlink { color: var(--ap-color-text); font-weight: 600; }
@media (max-width: 719px) {
  table.data.stack-sm thead { display: none; }
  table.data.stack-sm tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--ap-color-border); }
  table.data.stack-sm td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 3px 0; text-align: right; }
  table.data.stack-sm td::before { content: attr(data-label); font-weight: 600; color: var(--ap-color-text-muted); text-align: left; }
  table.data.stack-sm td.primary { font-size: 15px; font-weight: 700; }
  table.data.stack-sm td.primary::before { content: none; }
}
.empty { padding: 40px 20px; text-align: center; color: var(--ap-color-text-muted); }
.empty .ic { color: var(--ap-color-success); margin-bottom: 6px; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--ap-color-border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 13px; color: var(--ap-color-text-muted); }
a.list-item { color: inherit; }
a.list-item:hover { background: var(--ap-color-card-hover); text-decoration: none; }

.flash { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: var(--ap-color-success-bg); color: #14532d; }
.flash.error { background: var(--ap-color-danger-bg); color: #7f1d1d; }
.banner { padding: 12px 16px; border-radius: 12px; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { background: var(--ap-color-warning-bg); color: #7c2d12; }
.banner.info { background: var(--ap-color-info-bg); color: #0c4a6e; }
.banner.lock { background: #ede9fe; color: #4c1d95; }

/* punch timeline on the audit day page */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 76px 92px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--ap-color-border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.timeline .photo { width: 76px; height: 57px; border-radius: 8px; object-fit: cover; background: var(--ap-color-neutral-bg); display: flex; align-items: center; justify-content: center; color: var(--ap-color-text-subtle); font-size: 11px; text-align: center; }
.timeline .photo img { width: 76px; height: 57px; border-radius: 8px; object-fit: cover; cursor: zoom-in; }
@media (max-width: 719px) { .timeline li { grid-template-columns: 64px minmax(0, 1fr); } .timeline .photo, .timeline .photo img { width: 64px; height: 48px; } .timeline .acts { grid-column: 1 / -1; } }
details.inline > summary { cursor: pointer; list-style: none; }
details.inline > summary::-webkit-details-marker { display: none; }
details.inline[open] > summary { margin-bottom: 8px; }

.heat { display: grid; grid-template-rows: repeat(7, 12px); grid-auto-flow: column; grid-auto-columns: 12px; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat span { width: 12px; height: 12px; border-radius: 3px; background: #ececee; }
.heat span.l1 { background: #fecaca; } .heat span.l2 { background: #f87171; } .heat span.l3 { background: #dc2626; } .heat span.l4 { background: #991b1b; }
.heat span.bad { background: #f59e0b; }
.legend { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--ap-color-text-muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

.chart-box { position: relative; height: 280px; }
@media (min-width: 1024px) { .chart-box { height: 320px; } }

dialog.modal { border: 0; border-radius: 18px; padding: 0; max-width: min(92vw, 820px); box-shadow: var(--ap-shadow-xl); }
dialog.modal::backdrop { background: rgba(0,0,0,.5); }
dialog.modal img { display: block; max-width: 100%; border-radius: 18px 18px 0 0; }
dialog.modal .foot { padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* bare layout (login, errors) */
.bare { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.bare .card { width: 100%; max-width: 440px; padding: 32px; }
.bare .brand { justify-content: center; margin-bottom: 20px; font-size: 17px; }
.bare h1 { font-size: 22px; text-align: center; margin-bottom: 8px; }
.bare p.lead { text-align: center; color: var(--ap-color-text-muted); margin: 0 0 20px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 28px; font-weight: 700; letter-spacing: .25em; background: var(--ap-color-neutral-bg); padding: 10px 16px; border-radius: 12px; display: inline-block; }
.assistant { background: #f5f3ff; border: 1px solid #ddd6fe; color: #3b0764; border-radius: 12px; padding: 12px 14px; white-space: pre-wrap; }
