:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f172a;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --idle: #cbd5e1;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    16px/1.45 system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
.hidden {
  display: none !important;
}

/* ---------- Khung ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--brand);
  color: #fff;
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .who {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: #fff;
  font-size: 13px;
  line-height: 1.25;
  opacity: 0.85;
  text-align: right;
  cursor: pointer;
}
.topbar select {
  max-width: 140px;
  min-height: 36px;
  border-radius: 10px;
  border: 0;
  padding: 0 8px;
  background: #1e293b;
  color: #fff;
}
main {
  padding: 12px 12px calc(var(--nav-h) + var(--safe-b) + 96px);
  max-width: 640px;
  margin: 0 auto;
}
.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: #fff;
  border-top: 1px solid var(--line);
}
.bottomnav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  min-height: 48px;
}
.bottomnav button svg {
  width: 24px;
  height: 24px;
}
.bottomnav button.active {
  color: var(--ink);
}

/* ---------- Thành phần ---------- */
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: #e2e8f0;
  border-radius: 12px;
}
.seg button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: none;
  font-weight: 600;
  color: var(--muted);
}
.seg button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.06);
}
.card h3 {
  margin: 0 0 2px;
  font-size: 16px;
}
.card .sub {
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.row > .grow {
  flex: 1;
  min-width: 0;
}
.tappable {
  width: 100%;
  text-align: left;
  border: 0;
  cursor: pointer;
}
.tappable:active {
  background: #f8fafc;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #f1f5f9;
  color: #334155;
}
.chip.thr {
  background: #ede9fe;
  color: #5b21b6;
}
.chip.ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.chip.bad {
  background: var(--bad-soft);
  color: var(--bad);
}
.chip.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}
.empty strong {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
.btn.block {
  width: 100%;
}
.btn.ghost {
  background: #e2e8f0;
  color: var(--ink);
}
.btn.danger {
  background: var(--bad-soft);
  color: var(--bad);
}
.btn.ok {
  background: var(--ok);
}
.btn:disabled {
  background: var(--idle);
  color: #fff;
  cursor: not-allowed;
}
.btn.busy {
  opacity: 0.6;
  pointer-events: none;
}
.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  z-index: 4;
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.actionbar .btn {
  flex: 1;
}

/* ---------- Form ---------- */
.field {
  display: block;
  margin-bottom: 14px;
}
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}
.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  font-size: 16px; /* >=16px: iOS không tự phóng to */
}
.field input:focus,
.field select:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}
.field small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  margin-bottom: 14px;
  font-weight: 600;
}
.switch input {
  width: 24px;
  height: 24px;
}

/* ---------- Đăng nhập ---------- */
.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}
.login .logo {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
}
.login h1 {
  margin: 0 0 4px;
  font-size: 26px;
}
.login p {
  margin: 0 0 24px;
  color: var(--muted);
}
.error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bad-soft);
  color: var(--bad);
  font-size: 14px;
}

/* ---------- Bottom sheet ---------- */
dialog#sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: #fff;
}
dialog#sheet::backdrop {
  background: rgb(15 23 42 / 0.45);
}
.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  flex: 1;
  margin: 0;
  font-size: 18px;
}
.sheet-head button {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: #f1f5f9;
  font-size: 20px;
}
.sheet-body {
  padding: 16px 16px calc(16px + var(--safe-b));
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 84px);
  z-index: 20;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
#toast.bad {
  background: var(--bad);
}

/* ---------- Kho bài ---------- */
.quota {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.quota > div {
  padding: 10px 8px;
  border-radius: 12px;
  background: #fff;
  text-align: center;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.06);
}
.quota b {
  display: block;
  font-size: 20px;
}
.quota span {
  font-size: 11px;
  color: var(--muted);
}
.hint {
  margin: 0 4px 10px;
  color: var(--muted);
  font-size: 14px;
}
.card.slim {
  padding: 12px 14px;
}
.clamp2,
.clamp3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.clamp2 {
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.clamp3 {
  -webkit-line-clamp: 3;
  line-clamp: 3;
}
.card .caption {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8fafc;
  font-size: 14px;
  white-space: pre-line;
}
.card .web {
  margin-top: 8px;
}
.card .web a,
a.link {
  color: #2563eb;
  font-weight: 600;
  word-break: break-all;
}
a.link {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 500;
}
.card .error {
  margin: 10px 0 0;
}
.steps {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.btn.ok {
  background: var(--ok);
}
.btn.done,
.btn.done:disabled {
  background: var(--ok-soft);
  color: var(--ok);
}
.spin {
  width: 16px;
  height: 16px;
  border: 2px solid rgb(255 255 255 / 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.textbtn {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
}
.offscreen {
  position: fixed;
  top: -1000px;
  opacity: 0;
}

/* ---------- Thống kê ---------- */
.daybar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.daybar input {
  flex: 1;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  font-size: 16px;
}
.btn.sq {
  width: 48px;
  padding: 0;
  font-size: 22px;
}
.card.hero .big {
  font-size: 40px;
  font-weight: 800;
  line-height: 1.1;
}
.bar {
  height: 10px;
  margin: 10px 0 6px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--idle);
}
.good {
  color: var(--ok);
}
.mid {
  color: var(--warn);
}
.low {
  color: var(--bad);
}
.bar i.good {
  background: var(--ok);
}
.bar i.mid {
  background: #f59e0b;
}
.bar i.low {
  background: var(--bad);
}
.kpi {
  font-size: 22px;
  font-weight: 800;
}
.hist {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  align-items: end;
  gap: 2px;
  height: 110px;
  margin-top: 10px;
}
.hist > div {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
}
.hist i {
  display: block;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  background: var(--ink);
}
.hist i.zero {
  background: #e2e8f0;
}
.hist span {
  height: 16px;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
}
h3.section {
  margin: 18px 4px 8px;
  font-size: 15px;
}
.time {
  min-width: 52px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- Lương ---------- */
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.grid2 > div {
  padding: 12px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.06);
}
.grid2 b {
  display: block;
  font-size: 17px;
}
.grid2 span {
  font-size: 12px;
  color: var(--muted);
}
.mid-big {
  font-size: 18px;
}
.right {
  text-align: right;
}
.row.end {
  justify-content: flex-end;
  margin-top: 8px;
}
.btn.small {
  min-height: 44px;
  padding: 0 14px;
  font-size: 14px;
}
.btn.gap {
  margin-bottom: 12px;
}
.weekbox {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 48px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #cbd5e1;
}
.weekbox span {
  font-size: 12px;
  color: var(--muted);
}

.checklist {
  display: grid;
  gap: 2px;
  max-height: 260px;
  overflow: auto;
  padding: 4px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
}
.checklist label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}
.checklist input {
  width: 22px;
  height: 22px;
}
.field input[type="file"] {
  padding: 10px;
}

@media (min-width: 720px) {
  main {
    padding-top: 20px;
  }
}
