/* Zalo Điểm Danh admin. Mobile-first; tokens in tokens.css. No inline styles (CSP): dynamic values go through CSSOM
   custom properties (--value, --ticks). */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--c-paper);
  color: var(--c-ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--c-primary); text-underline-offset: 0.18em; }
a:hover { color: var(--c-primary-hover); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
:focus-visible { outline: 3px solid var(--c-primary); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
::selection { background: var(--c-primary-tint); color: var(--c-ink); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--c-ink-muted); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.wrap-anywhere { overflow-wrap: anywhere; }

.skip-link {
  position: absolute; left: var(--s-2); top: -100px; z-index: 100;
  background: var(--c-primary); color: var(--c-on-primary); padding: var(--s-2) var(--s-4);
  border-radius: var(--r-control); font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: var(--s-2); }

/* ---------- App frame ---------- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-bar);
  background: color-mix(in srgb, var(--c-paper) 92%, transparent);
  border-bottom: 1px solid var(--c-rule);
  padding-top: env(safe-area-inset-top);
}
@supports not (background: color-mix(in srgb, red 50%, transparent)) {
  .topbar { background: var(--c-paper); }
}
.topbar-inner {
  max-width: var(--content-max); margin: 0 auto; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
}
.brand {
  display: inline-flex; align-items: center; gap: var(--s-2); min-height: var(--tap);
  color: var(--c-ink); text-decoration: none; margin-right: auto;
}
.brand:hover { color: var(--c-ink); }
.brand-mark { width: 26px; height: 26px; color: var(--c-primary); stroke-width: 2.2; }
.brand-name { font-family: var(--font-title); font-weight: 600; font-size: var(--fs-lg); }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-bar);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--c-surface); box-shadow: var(--shadow-bar);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.nav-link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--bottomnav-h); padding: var(--s-1) var(--s-2);
  color: var(--c-ink-muted); text-decoration: none; font-size: var(--fs-xs); font-weight: 500;
  position: relative; transition: color var(--t-fast) ease;
}
.nav-link .icon { width: 22px; height: 22px; }
.nav-link:hover { color: var(--c-ink); }
.nav-link[aria-current="page"] { color: var(--c-primary); font-weight: 600; }
.nav-link[aria-current="page"]::before {
  content: ''; position: absolute; top: 0; left: 30%; right: 30%; height: 3px;
  background: var(--c-primary); border-radius: 0 0 3px 3px;
}
.logout-label { display: none; }
body.is-guest .nav, body.is-guest .logout-btn, body.is-booting .nav, body.is-booting .logout-btn { display: none; }

.main {
  display: block; outline: none;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + var(--s-6));
}
body.is-guest .main { padding-bottom: var(--s-6); }
.page {
  max-width: var(--content-max); margin: 0 auto;
  padding: var(--s-5) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
}
.page-narrow { max-width: 44rem; }
.boot { min-height: 40vh; }

@media (min-width: 960px) {
  .nav {
    position: static; display: flex; gap: var(--s-1); box-shadow: none; background: none; padding: 0;
  }
  .nav-link {
    flex-direction: row; gap: var(--s-2); min-height: var(--tap); padding: 0 var(--s-3);
    font-size: var(--fs-sm); border-radius: var(--r-control);
  }
  .nav-link .icon { width: 18px; height: 18px; }
  .nav-link[aria-current="page"] { background: var(--c-primary-tint); }
  .nav-link[aria-current="page"]::before { display: none; }
  .logout-label { display: inline; }
  .page { padding-top: var(--s-6); }
}

/* ---------- Type ---------- */
.title {
  font-family: var(--font-title); font-weight: 600; font-size: var(--fs-xl);
  letter-spacing: -0.005em; text-wrap: balance; overflow-wrap: anywhere;
}
/* Titles get focus only programmatically (route change, for screen readers); they are not controls, so no ring. */
.title:focus, .title:focus-visible { outline: none; }
@media (min-width: 600px) { .title { font-size: var(--fs-2xl); } }
.section-title { font-size: var(--fs-lg); font-weight: 600; }
.lead { color: var(--c-ink-muted); max-width: 60ch; }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3) var(--s-4); margin-bottom: var(--s-5); }
.page-head > .grow { flex: 1 1 16rem; min-width: 0; }
.page-head .sub { margin-top: var(--s-1); color: var(--c-ink-muted); font-size: var(--fs-sm); display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-3); }
.back-link {
  display: inline-flex; align-items: center; gap: var(--s-1); min-height: var(--tap);
  color: var(--c-ink-muted); text-decoration: none; font-size: var(--fs-sm); margin: calc(-1 * var(--s-3)) 0 var(--s-1) -6px;
}
.back-link:hover { color: var(--c-ink); }

.section { margin-top: var(--s-6); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0.55rem 1rem; border-radius: var(--r-control);
  border: 1px solid transparent; font-weight: 600; font-size: var(--fs-sm); line-height: 1.25;
  text-decoration: none; white-space: nowrap; touch-action: manipulation;
  transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease;
}
.btn .icon { width: 18px; height: 18px; }
.btn-primary { background: var(--c-primary); color: var(--c-on-primary); }
.btn-primary:hover { background: var(--c-primary-hover); color: var(--c-on-primary); }
.btn-secondary { background: var(--c-surface); color: var(--c-ink); border-color: var(--c-rule-strong); }
.btn-secondary:hover { background: var(--c-surface-2); color: var(--c-ink); }
.btn-ghost { background: transparent; color: var(--c-ink); }
.btn-ghost:hover { background: var(--c-surface-2); color: var(--c-ink); }
.btn-danger { background: var(--c-surface); color: var(--c-danger); border-color: currentColor; }
.btn-danger:hover { background: var(--c-danger-bg); color: var(--c-danger); }
.btn-danger-solid { background: var(--c-danger); color: var(--c-surface); }
.btn-danger-solid:hover { filter: brightness(0.95); color: var(--c-surface); }
.btn:active:not(:disabled) { filter: brightness(0.94); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn[aria-busy="true"] { opacity: 0.75; cursor: progress; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.btn-row .push { margin-left: auto; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); border-radius: var(--r-control);
  border: 0; background: transparent; color: var(--c-ink-muted);
}
.icon-btn:hover { background: var(--c-surface-2); color: var(--c-ink); }
.link-btn { border: 0; background: none; padding: 0 var(--s-1); min-height: var(--tap); color: var(--c-primary); font-weight: 600; text-decoration: underline; text-underline-offset: 0.18em; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Panels, lists ---------- */
.panel { background: var(--c-surface); border: 1px solid var(--c-rule); border-radius: var(--r-panel); }
.panel-pad { padding: var(--s-4); }
@media (min-width: 600px) { .panel-pad { padding: var(--s-5); } }
.rows { list-style: none; }
.rows > li { border-top: 1px solid var(--c-rule); }
.rows > li:first-child { border-top: 0; }
.row-item { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); padding: var(--s-3) var(--s-4); }
.row-item .grow { flex: 1 1 12rem; min-width: 0; }
a.row-item { color: var(--c-ink); text-decoration: none; min-height: var(--tap); transition: background-color var(--t-fast) ease; }
a.row-item:hover { background: var(--c-surface-2); color: var(--c-ink); }
a.row-item > .icon { color: var(--c-ink-muted); }
.rows > li:first-child > a.row-item { border-radius: var(--r-panel) var(--r-panel) 0 0; }
.rows > li:last-child > a.row-item { border-radius: 0 0 var(--r-panel) var(--r-panel); }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-meta { color: var(--c-ink-muted); font-size: var(--fs-sm); display: flex; flex-wrap: wrap; gap: 0 var(--s-3); }

/* ---------- Badges & banners ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem; white-space: nowrap;
  padding: 0.15rem 0.55rem 0.15rem 0.4rem; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.4;
  background: var(--c-surface-2); color: var(--c-ink-muted);
}
.badge .icon { width: 14px; height: 14px; stroke-width: 2.4; }
.badge.is-done { background: var(--c-done-bg); color: var(--c-done); }
.badge.is-pending { background: var(--c-pending-bg); color: var(--c-pending); }
.badge.is-error { background: var(--c-danger-bg); color: var(--c-danger); }
.badge.is-info { background: var(--c-primary-tint); color: var(--c-primary); }

.banner {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-panel); border: 1px solid;
  margin-bottom: var(--s-3);
}
.banner .icon { margin-top: 2px; }
.banner .grow { flex: 1; min-width: 0; }
.banner strong { display: block; }
.banner.is-danger { background: var(--c-danger-bg); border-color: color-mix(in srgb, var(--c-danger) 35%, transparent); color: var(--c-ink); }
.banner.is-danger > .icon { color: var(--c-danger); }
.banner.is-warn { background: var(--c-pending-bg); border-color: color-mix(in srgb, var(--c-pending) 35%, transparent); color: var(--c-ink); }
.banner.is-warn > .icon { color: var(--c-pending); }
.banner.is-info { background: var(--c-primary-tint); border-color: color-mix(in srgb, var(--c-primary) 30%, transparent); color: var(--c-ink); }
.banner.is-info > .icon { color: var(--c-primary); }
.banner a { font-weight: 600; }

/* ---------- Overview ---------- */
.card-grid { display: grid; gap: var(--s-3); grid-template-columns: 1fr; }
@media (min-width: 600px) { .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); } }
@media (min-width: 1100px) { .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.slip {
  display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-4); background: var(--c-surface); border: 1px solid var(--c-rule); border-radius: var(--r-panel);
  color: var(--c-ink); text-decoration: none; transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease;
}
.slip:hover { border-color: var(--c-rule-strong); color: var(--c-ink); }
.slip-head { display: flex; gap: var(--s-3); align-items: flex-start; justify-content: space-between; }
.slip-name { font-family: var(--font-title); font-weight: 600; font-size: var(--fs-lg); line-height: 1.3; overflow-wrap: anywhere; }
.slip-group { color: var(--c-ink-muted); font-size: var(--fs-sm); display: flex; align-items: center; gap: var(--s-1); margin-top: 2px; }
.slip-group .icon { width: 15px; height: 15px; }
.daycount { text-align: right; flex: none; }
.daycount-n { font-family: var(--font-title); font-weight: 600; font-size: var(--fs-xl); line-height: 1.1; font-variant-numeric: tabular-nums lining-nums; }
.daycount-n small { font-size: var(--fs-sm); color: var(--c-ink-muted); font-weight: 600; }
.daycount-label { font-size: var(--fs-xs); color: var(--c-ink-muted); }

/* Day ruler: one tick per day of the challenge (vở ô li). */
.ruler { display: flex; gap: 2px; align-items: flex-end; height: 14px; }
.ruler .tick { flex: 1 1 0; min-width: 2px; height: 8px; border-radius: 1px; background: var(--c-rule); }
.ruler .tick.is-past { background: var(--c-rule-strong); }
.ruler .tick.is-today { background: var(--c-primary); height: 14px; }

.meter { height: 8px; background: var(--c-surface-2); border-radius: 999px; overflow: hidden; }
.meter-fill { display: block; height: 100%; width: var(--value, 0%); background: var(--c-done); border-radius: inherit; }
.today-line { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--fs-sm); margin-bottom: var(--s-1); }
.today-line strong { font-variant-numeric: tabular-nums; }
.slip-flags { display: flex; flex-wrap: wrap; gap: var(--s-2); min-height: 1.5rem; }

.account-state { display: inline-flex; align-items: center; gap: var(--s-1); font-size: var(--fs-sm); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c-rule-strong); flex: none; }
.dot.is-done { background: var(--c-done); }
.dot.is-pending { background: var(--c-pending); }
.dot.is-error { background: var(--c-danger); }

/* ---------- Empty, error, skeleton ---------- */
.empty {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-5); border: 1px dashed var(--c-rule-strong); border-radius: var(--r-panel); background: var(--c-surface);
}
.empty .icon { width: 28px; height: 28px; color: var(--c-primary); }
.empty p { max-width: 52ch; }
.error-state { border-style: solid; border-color: color-mix(in srgb, var(--c-danger) 40%, transparent); }
.error-state .icon { color: var(--c-danger); }

.skeleton { background: var(--c-surface-2); border-radius: var(--r-control); position: relative; overflow: hidden; }
.skeleton::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--c-surface) 55%, transparent), transparent);
  transform: translateX(-100%); animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.sk-line { height: 14px; margin: 6px 0; }
.sk-title { height: 28px; width: 55%; margin-bottom: var(--s-4); }
.sk-card { height: 168px; border-radius: var(--r-panel); }
.sk-block { height: 280px; border-radius: var(--r-panel); }
.w-40 { width: 40%; } .w-60 { width: 60%; } .w-80 { width: 80%; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: var(--s-4); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-row { display: grid; gap: var(--s-4); grid-template-columns: 1fr; }
@media (min-width: 600px) { .field-row { grid-template-columns: 1fr 1fr; } }
.label { font-weight: 600; font-size: var(--fs-sm); }
.label .opt { font-weight: 400; color: var(--c-ink-muted); }
.help { font-size: var(--fs-sm); color: var(--c-ink-muted); }
.field-error { display: flex; gap: var(--s-1); align-items: flex-start; font-size: var(--fs-sm); color: var(--c-danger); font-weight: 500; }
.field-error .icon { width: 16px; height: 16px; margin-top: 2px; }
.input, .textarea, .select {
  width: 100%; min-height: var(--tap); padding: 0.6rem 0.75rem;
  background: var(--c-surface); color: var(--c-ink);
  border: 1px solid var(--c-rule-strong); border-radius: var(--r-control);
  font-size: var(--fs-md); line-height: 1.4;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
.textarea { min-height: 6.5rem; resize: vertical; }
.textarea.mono-ish { font-variant-numeric: tabular-nums; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 30%, transparent); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--c-danger); }
.input::placeholder, .textarea::placeholder { color: var(--c-ink-muted); opacity: 0.8; }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 3.25rem; }
.input-wrap .icon-btn { position: absolute; right: 0; top: 0; }
.search-wrap { position: relative; }
.search-wrap > .icon { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--c-ink-muted); pointer-events: none; }
.search-wrap .input { padding-left: 2.5rem; }

.choice-list { display: flex; flex-direction: column; gap: var(--s-2); }
.choice {
  display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4); min-height: var(--tap);
  background: var(--c-surface); border: 1px solid var(--c-rule); border-radius: var(--r-panel); cursor: pointer;
  transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease;
}
.choice:hover { border-color: var(--c-rule-strong); }
.choice:has(input:checked) { border-color: var(--c-primary); background: var(--c-primary-tint); }
.choice:has(input:disabled) { cursor: not-allowed; opacity: 0.65; }
.choice:has(input:focus-visible) { outline: 3px solid var(--c-primary); outline-offset: 2px; }
.choice input { margin: 3px 0 0; width: 20px; height: 20px; accent-color: var(--c-primary); flex: none; }
.choice .grow { flex: 1; min-width: 0; }
.choice-title { font-weight: 600; overflow-wrap: anywhere; }
.choice-sub { font-size: var(--fs-sm); color: var(--c-ink-muted); overflow-wrap: anywhere; }
.scroll-list { max-height: min(55dvh, 26rem); overflow: auto; padding: 2px; margin: -2px; overscroll-behavior: contain; }

.switch { display: flex; align-items: center; gap: var(--s-3); min-height: var(--tap); cursor: pointer; font-weight: 600; }
.switch input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none; cursor: pointer;
  width: 46px; height: 28px; border-radius: 999px; background: var(--c-rule-strong); position: relative;
  transition: background-color var(--t-fast) ease;
}
.switch input::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--c-surface); transition: transform var(--t-fast) var(--ease-out);
}
.switch input:checked { background: var(--c-primary); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:focus-visible { outline: 3px solid var(--c-primary); outline-offset: 2px; }

.form-alert { margin: 0; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: var(--s-1); overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--c-rule); margin: 0 calc(-1 * var(--gutter)) var(--s-4); padding: 0 var(--gutter);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: var(--s-2); min-height: var(--tap); padding: 0 var(--s-3);
  white-space: nowrap; color: var(--c-ink-muted); text-decoration: none; font-weight: 600; font-size: var(--fs-sm);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--c-ink); }
.tab[aria-current="page"] { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.tab .count {
  min-width: 1.4rem; padding: 0 0.35rem; border-radius: 999px; text-align: center; font-size: var(--fs-xs);
  background: var(--c-surface-2); color: var(--c-ink-muted); font-variant-numeric: tabular-nums;
}
.tab .count.is-error { background: var(--c-danger); color: var(--c-surface); }

/* ---------- Detail header ---------- */
.facts { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); font-size: var(--fs-sm); color: var(--c-ink-muted); margin-top: var(--s-2); }
.facts > * { display: inline-flex; align-items: center; gap: var(--s-1); }
.facts .icon { width: 16px; height: 16px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: var(--s-4) 0 var(--s-5); }
.detail-actions .danger-slot { margin-left: auto; }
@media (max-width: 599px) {
  .detail-actions .btn { flex: 1 1 calc(50% - var(--s-2)); }
  .detail-actions .danger-slot { margin-left: 0; flex-basis: 100%; }
}

/* ---------- Ledger (attendance grid) ---------- */
.legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin-bottom: var(--s-3); font-size: var(--fs-sm); color: var(--c-ink-muted); }
.legend li { display: inline-flex; align-items: center; gap: var(--s-2); list-style: none; }
.legend .swatch { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 5px; border: 1px solid var(--c-rule); }

.ledger-wrap {
  overflow: auto; max-height: min(72dvh, 46rem); overscroll-behavior-x: contain;
  background: var(--c-surface); border: 1px solid var(--c-rule); border-radius: var(--r-panel);
  -webkit-overflow-scrolling: touch;
}
.ledger-wrap:focus-visible { outline-offset: 2px; }
.ledger { border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.ledger th, .ledger td { border-right: 1px solid var(--c-rule); border-bottom: 1px solid var(--c-rule); }
.ledger thead th {
  position: sticky; top: 0; z-index: 2; background: var(--c-surface-2);
  font-weight: 600; padding: 6px 2px; text-align: center; min-width: 46px; vertical-align: bottom;
}
.ledger .day-n { display: block; font-family: var(--font-title); font-size: var(--fs-md); line-height: 1.2; font-variant-numeric: tabular-nums lining-nums; }
.ledger .day-date { display: block; font-size: 0.75rem; font-weight: 500; color: var(--c-ink-muted); font-variant-numeric: tabular-nums; }
.ledger thead th.is-today { background: var(--c-primary); color: var(--c-on-primary); }
.ledger thead th.is-today .day-date { color: var(--c-on-primary); }
.ledger .corner, .ledger .who {
  position: sticky; left: 0; z-index: 1; text-align: left; background: var(--c-surface);
  width: 10rem; min-width: 10rem; max-width: 10rem; padding: 6px 10px;
  box-shadow: 1px 0 0 var(--c-rule-strong);
}
.ledger .corner { z-index: 3; background: var(--c-surface-2); vertical-align: bottom; font-size: var(--fs-xs); color: var(--c-ink-muted); }
@media (min-width: 600px) { .ledger .corner, .ledger .who { width: 14rem; min-width: 14rem; max-width: 14rem; } }
.ledger .who-name { display: block; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.ledger .who-meta { display: flex; gap: var(--s-2); justify-content: space-between; font-size: 0.75rem; color: var(--c-ink-muted); font-weight: 500; }
.ledger tr.is-inactive .who-name { color: var(--c-ink-muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.ledger td.cell { height: 44px; min-width: 46px; text-align: center; padding: 0; }
.ledger td.cell .icon { margin: 0 auto; width: 20px; height: 20px; stroke-width: 2.6; }
.ledger td.is-today { background: var(--c-primary-tint); }
.cell-done { color: var(--c-done); }
.ledger td.cell-done:not(.is-today) { background: color-mix(in srgb, var(--c-done-bg) 60%, var(--c-surface)); }
.cell-pending { color: var(--c-pending); }
.ledger td.cell-pending { background: var(--c-pending-bg); }
.cell-error { color: var(--c-danger); }
.ledger td.cell-error { background: var(--c-danger-bg); }
.cell-missed { color: var(--c-rule-strong); }
.cell-open { color: var(--c-primary); }
.cell-open .icon { stroke-width: 2 !important; }
.ledger tfoot th, .ledger tfoot td {
  position: sticky; bottom: 0; background: var(--c-surface-2); font-weight: 600; text-align: center;
  font-variant-numeric: tabular-nums; padding: 6px 2px; font-size: var(--fs-xs); z-index: 2;
}
.ledger tfoot .who { z-index: 3; background: var(--c-surface-2); font-size: var(--fs-xs); }
.ledger tfoot td.is-today { background: var(--c-primary-tint); color: var(--c-primary); }
.legend .swatch.cell-done { background: var(--c-done-bg); }
.legend .swatch.cell-pending { background: var(--c-pending-bg); }
.legend .swatch.cell-error { background: var(--c-danger-bg); }
.legend .swatch .icon { width: 16px; height: 16px; stroke-width: 2.6; }
.legend .swatch.cell-open { background: var(--c-primary-tint); }

/* ---------- Cases & log ---------- */
.entries { display: flex; flex-direction: column; gap: var(--s-3); list-style: none; }
.entry { padding: var(--s-4); background: var(--c-surface); border: 1px solid var(--c-rule); border-radius: var(--r-panel); }
.entry.is-open { border-left: 4px solid var(--c-danger); }
.entry-head { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-3); align-items: center; justify-content: space-between; }
.entry-who { font-weight: 600; overflow-wrap: anywhere; }
.entry-time { font-size: var(--fs-sm); color: var(--c-ink-muted); font-variant-numeric: tabular-nums; }
.quote {
  margin: var(--s-3) 0 0; padding: var(--s-2) var(--s-3); border-left: 3px solid var(--c-rule-strong);
  background: var(--c-surface-2); border-radius: 0 var(--r-control) var(--r-control) 0;
  font-size: var(--fs-sm); overflow-wrap: anywhere; white-space: pre-line;
}
.entry-note { margin-top: var(--s-2); font-size: var(--fs-sm); color: var(--c-ink-muted); }
.entry .btn-row { margin-top: var(--s-3); }
.subtle-details { margin-top: var(--s-5); }
.subtle-details > summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; font-weight: 600; color: var(--c-ink-muted); }

.log-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.log-table th { text-align: left; font-weight: 600; color: var(--c-ink-muted); font-size: var(--fs-xs); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--c-rule); }
.log-table td { padding: var(--s-3); border-bottom: 1px solid var(--c-rule); vertical-align: top; }
.log-table tr:last-child td { border-bottom: 0; }
@media (max-width: 719px) {
  .log-table thead { display: none; }
  .log-table, .log-table tbody, .log-table tr, .log-table td { display: block; width: 100%; }
  .log-table tr { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-rule); }
  .log-table tr:last-child { border-bottom: 0; }
  .log-table td { padding: 2px 0; border: 0; }
  .log-table td[data-label]::before { content: attr(data-label) ': '; color: var(--c-ink-muted); font-weight: 500; }
}

/* ---------- Wizard ---------- */
.stepper { margin-bottom: var(--s-5); }
.stepper-bar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: var(--s-2); }
.stepper-bar span { height: 4px; border-radius: 2px; background: var(--c-rule); }
.stepper-bar span.is-done { background: var(--c-rule-strong); }
.stepper-bar span.is-current { background: var(--c-primary); }
.stepper-count { font-size: var(--fs-sm); color: var(--c-ink-muted); font-variant-numeric: tabular-nums; }
.stepper-list { display: none; }
@media (min-width: 960px) {
  .stepper-bar { display: none; }
  .stepper-list { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--s-2); list-style: none; margin-top: var(--s-3); counter-reset: step; }
  .stepper-list li {
    display: flex; gap: var(--s-2); align-items: center; padding-top: var(--s-2); border-top: 3px solid var(--c-rule);
    font-size: var(--fs-sm); color: var(--c-ink-muted); font-weight: 500;
  }
  .stepper-list li .n {
    display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; flex: none;
    border: 1px solid var(--c-rule-strong); font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums;
  }
  .stepper-list li.is-done { border-top-color: var(--c-rule-strong); color: var(--c-ink); }
  .stepper-list li.is-done .n { background: var(--c-rule-strong); border-color: var(--c-rule-strong); color: var(--c-surface); }
  .stepper-list li.is-current { border-top-color: var(--c-primary); color: var(--c-primary); font-weight: 600; }
  .stepper-list li.is-current .n { background: var(--c-primary); border-color: var(--c-primary); color: var(--c-on-primary); }
}
.step-body { display: flex; flex-direction: column; gap: var(--s-5); }
.step-title { font-family: var(--font-title); font-weight: 600; font-size: var(--fs-xl); }
.step-title:focus { outline: none; }

.wizard-bar {
  position: sticky; bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); z-index: var(--z-bar);
  margin: var(--s-6) calc(-1 * var(--gutter)) 0; padding: var(--s-3) var(--gutter);
  background: var(--c-surface); box-shadow: var(--shadow-bar);
  display: flex; gap: var(--s-2); justify-content: space-between; align-items: center;
}
.wizard-bar .btn { min-width: 7.5rem; }
@media (min-width: 960px) {
  .wizard-bar { position: static; box-shadow: none; background: none; margin: var(--s-6) 0 0; padding: var(--s-4) 0 0; border-top: 1px solid var(--c-rule); }
}

.edit-grid-wrap { overflow-x: auto; border: 1px solid var(--c-rule); border-radius: var(--r-panel); background: var(--c-surface); }
.edit-grid { border-collapse: collapse; width: 100%; min-width: 40rem; font-size: var(--fs-sm); }
.edit-grid th { text-align: left; padding: var(--s-2); font-size: var(--fs-xs); color: var(--c-ink-muted); background: var(--c-surface-2); font-weight: 600; }
.edit-grid td { padding: 4px; border-top: 1px solid var(--c-rule); }
.edit-grid td.idx { width: 2.5rem; text-align: center; color: var(--c-ink-muted); font-variant-numeric: tabular-nums; }
.edit-grid .input { min-height: 40px; padding: 0.4rem 0.5rem; font-size: var(--fs-sm); border-color: var(--c-rule); }
.edit-grid .input:hover { border-color: var(--c-rule-strong); }
.edit-grid tr.has-error .input[aria-invalid="true"] { border-color: var(--c-danger); }
.edit-grid td.act { width: var(--tap); }

.match-list { list-style: none; }
.match-list > li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--c-rule); }
.match-list > li:first-child { border-top: 0; }
.match-list .grow { flex: 1 1 12rem; min-width: 0; }
.match-zalo { display: inline-flex; align-items: center; gap: var(--s-1); font-size: var(--fs-sm); }
.match-zalo.is-done { color: var(--c-done); font-weight: 600; }
.match-zalo.is-missing { color: var(--c-danger); font-weight: 600; }

.summary { display: grid; grid-template-columns: 1fr; gap: 0; margin: 0; }
.summary > div {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--s-3); row-gap: 2px; align-items: center;
  padding: var(--s-3) var(--s-2) var(--s-3) var(--s-4); border-top: 1px solid var(--c-rule);
}
.summary > div:first-child { border-top: 0; }
.summary dt { grid-column: 1; font-size: var(--fs-sm); color: var(--c-ink-muted); }
.summary dd { grid-column: 1; margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.summary .link-btn { grid-column: 2; grid-row: 1 / span 2; padding: 0 var(--s-3); }
@media (min-width: 600px) {
  .summary > div { grid-template-columns: 11rem minmax(0, 1fr) auto; column-gap: var(--s-4); }
  .summary dt, .summary dd { grid-row: 1; }
  .summary dd { grid-column: 2; }
  .summary .link-btn { grid-column: 3; grid-row: 1; }
}

.preview-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.preview-table th, .preview-table td { text-align: left; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--c-rule); }
.preview-table th { font-size: var(--fs-xs); color: var(--c-ink-muted); background: var(--c-surface-2); position: sticky; top: 0; }
.preview-wrap { max-height: 22rem; overflow: auto; border: 1px solid var(--c-rule); border-radius: var(--r-panel); background: var(--c-surface); }

/* ---------- Dialogs & pickers ---------- */
.dialog {
  width: min(32rem, calc(100vw - 2 * var(--s-4))); max-height: min(86dvh, 44rem);
  padding: 0; border: 1px solid var(--c-rule); border-radius: var(--r-dialog);
  background: var(--c-surface); color: var(--c-ink); box-shadow: var(--shadow-pop);
}
.dialog[open] { display: flex; flex-direction: column; animation: dialog-in var(--t-enter) var(--ease-out); }
.dialog::backdrop { background: var(--c-scrim); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog-head { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-2) var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-rule); }
.dialog-head h2 { flex: 1; font-size: var(--fs-lg); font-weight: 600; }
.dialog-body { padding: var(--s-4); overflow: auto; display: flex; flex-direction: column; gap: var(--s-3); }
.dialog-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--c-rule); }
@media (max-width: 599px) {
  .dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: var(--r-dialog) var(--r-dialog) 0 0; max-height: 90dvh; padding-bottom: env(safe-area-inset-bottom); }
  @keyframes dialog-in { from { transform: translateY(24px); opacity: 0; } }
  .dialog-foot .btn { flex: 1; }
}
.picker-group-label { font-size: var(--fs-xs); font-weight: 600; color: var(--c-ink-muted); margin: var(--s-2) 0 var(--s-1); }
.picker-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.picker-option {
  width: 100%; min-height: var(--tap); display: flex; align-items: center; gap: var(--s-3); text-align: left;
  padding: var(--s-2) var(--s-3); border: 1px solid transparent; border-radius: var(--r-control); background: transparent;
}
.picker-option:hover { background: var(--c-surface-2); }
.picker-option[aria-pressed="true"] { background: var(--c-primary-tint); border-color: var(--c-primary); }
.picker-option .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.picker-option .hint { display: block; font-size: var(--fs-xs); color: var(--c-ink-muted); }
.picker-option .icon { color: var(--c-primary); }
.picker-more { font-size: var(--fs-sm); color: var(--c-ink-muted); padding: var(--s-2) var(--s-3); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: var(--z-toast); left: var(--s-3); right: var(--s-3);
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + var(--s-3));
  display: flex; flex-direction: column; gap: var(--s-2); align-items: stretch; pointer-events: none;
}
@media (min-width: 600px) { .toasts { left: auto; right: var(--s-5); width: 24rem; bottom: var(--s-5); } }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-3) var(--s-2) var(--s-3) var(--s-4); border-radius: var(--r-panel);
  background: var(--c-ink); color: var(--c-paper); box-shadow: var(--shadow-pop);
  animation: toast-in var(--t-enter) var(--ease-out);
}
.toast .icon { margin-top: 2px; }
.toast .grow { flex: 1; min-width: 0; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.toast.is-error { background: var(--c-danger-bg); color: var(--c-ink); border: 1px solid var(--c-danger); }
.toast.is-error > .icon { color: var(--c-danger); }
.toast .toast-actions { display: flex; gap: var(--s-1); align-items: center; margin-top: -6px; margin-bottom: -6px; }
.toast .btn-ghost { color: inherit; min-height: 40px; padding: 0.4rem 0.6rem; }
.toast .icon-btn { color: inherit; width: 40px; height: 40px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Login ---------- */
.login {
  min-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
  display: grid; place-items: center; padding: var(--s-5) var(--gutter);
}
.login-card { width: min(100%, 25rem); padding: var(--s-5); }
.login-card .title { margin-bottom: var(--s-2); }
.login-rules {
  height: 6px; margin: var(--s-4) 0 var(--s-5);
  background: repeating-linear-gradient(90deg, var(--c-rule) 0 18px, transparent 18px 22px);
  border-radius: 3px;
}

/* ---------- Settings ---------- */
.steps-list { padding-left: 1.4rem; display: flex; flex-direction: column; gap: var(--s-2); }
.steps-list li { padding-left: var(--s-1); }
code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 0.9em; background: var(--c-surface-2); padding: 0.1em 0.35em; border-radius: 4px; overflow-wrap: anywhere; }
.result-line { display: flex; gap: var(--s-2); align-items: flex-start; font-size: var(--fs-sm); font-weight: 500; }
.result-line.is-done { color: var(--c-done); }
.result-line.is-error { color: var(--c-danger); }
.result-line .icon { width: 18px; height: 18px; margin-top: 1px; }

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  .skeleton::after { display: none; }
  .spinner { animation: none; border-right-color: currentColor; opacity: 0.6; }
}
@media (forced-colors: active) {
  .badge, .banner, .btn, .choice, .slip, .entry { border: 1px solid CanvasText; }
  .ruler .tick.is-today, .meter-fill { background: Highlight; }
}
.section-tight { margin-top: var(--s-2); }
.plain-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.plain-fieldset > legend { padding: 0; margin-bottom: 6px; }
@media (max-width: 599px) { .tab { padding: 0 0.6rem; } }

/* Scroll containers are positioned so that visually hidden (absolute) text inside them is clipped with them and
   cannot widen the page. */
.ledger-wrap, .edit-grid-wrap, .preview-wrap, .scroll-list, .tabs, .dialog-body, .log-table td { position: relative; }
.choice-title, .choice-sub { display: block; }
.match-actions { display: flex; gap: var(--s-2); align-items: center; }

.dialog-foot:empty { display: none; }
.readonly-value { padding: 0.6rem 0.75rem; min-height: var(--tap); background: var(--c-surface-2); border: 1px solid var(--c-rule); border-radius: var(--r-control); font-variant-numeric: tabular-nums; }

/* Name guess ("đoán"): calm teal, always with icon + text. */
.badge.is-guess { background: var(--c-guess-bg); color: var(--c-guess); }
.ledger td.cell { position: relative; }
.cell-mark { display: block; font-size: 0.75rem; line-height: 1; font-weight: 600; color: var(--c-guess); margin-top: 1px; }
.ledger td.cell .icon + .cell-mark { margin-top: 1px; }
.legend .swatch.cell-guess { background: var(--c-guess-bg); color: var(--c-guess); font-size: 0.75rem; font-weight: 600; width: auto; padding: 0 4px; }
.guess-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin-top: var(--s-3); font-size: var(--fs-sm); }
.guess-from { font-size: var(--fs-xs); color: var(--c-ink-muted); margin-top: 4px; overflow-wrap: anywhere; }
.rows-head { display: flex; gap: var(--s-3); padding: var(--s-2) var(--s-4); font-size: var(--fs-xs); font-weight: 600; color: var(--c-ink-muted); background: var(--c-surface-2); border-radius: var(--r-panel) var(--r-panel) 0 0; }
.hint-box { margin-top: var(--s-3); }
.rows-head { border: 1px solid var(--c-rule); border-bottom: 0; }
.rows-head + .rows { border-top-left-radius: 0; border-top-right-radius: 0; }

/* Tick removed by the organiser in the sheet: hatched and muted, never looks like "done" or "empty". */
.cell-unticked { color: var(--c-ink-muted); }
.ledger td.cell-unticked, .legend .swatch.cell-unticked {
  background: repeating-linear-gradient(135deg, var(--c-surface) 0 5px, var(--c-surface-2) 5px 8px);
}
.badge.is-unticked { background: var(--c-surface-2); color: var(--c-ink-muted); border: 1px dashed var(--c-rule-strong); }
.badge.is-unticked .icon { color: var(--c-ink-muted); }
