:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1b2330;
  --muted: #667085;
  --line: #dfe3ec;
  --primary: #2447c4;
  --primary-ink: #ffffff;
  --primary-soft: #e8edfc;
  --ok: #0f7b4b;
  --ok-soft: #e3f5ec;
  --warn: #9a6200;
  --warn-soft: #fff1d6;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --calc: #f0f2f7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151c; --card: #1a202b; --ink: #e8ecf3; --muted: #9aa6b8; --line: #2d3647;
    --primary: #6f8cf5; --primary-ink: #0b1020; --primary-soft: #232d4d;
    --ok: #5fd39a; --ok-soft: #16322a; --warn: #f2c14e; --warn-soft: #3a2f14;
    --bad: #ff8a80; --bad-soft: #3d1f1d; --calc: #232b39;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.boot { text-align: center; color: var(--muted); margin-top: 30vh; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* ---------- thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { white-space: nowrap; display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; color: var(--ink); }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; }
.brand .logo svg { width: 18px; height: 18px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .95rem;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.me { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.me .who { text-align: right; line-height: 1.2; }
.me .who b { display: block; }

main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 80px; }

/* ---------- thành phần chung ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card > h2 { margin-bottom: 4px; }
.card .sub { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; min-height: 40px;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .875rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.badge.none { background: var(--calc); color: var(--muted); }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.submitted { background: var(--ok-soft); color: var(--ok); }
.badge.role { background: var(--primary-soft); color: var(--primary); }
.badge.proj { background: var(--calc); color: var(--ink); margin-left: 8px; font-weight: 600; }
.group { margin-bottom: 22px; }
.grouphead { display: flex; justify-content: space-between; align-items: baseline; margin: 0 2px 8px; font-weight: 700; }
.member.static { cursor: default; }
.member.static:hover { border-color: var(--line); }
.badge.off { background: var(--bad-soft); color: var(--bad); }

label.field { display: block; }
label.field > span.lbl { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); min-height: 42px;
}
textarea { resize: vertical; min-height: 44px; line-height: 1.45; overflow: hidden; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[readonly], textarea[readonly], input:disabled, textarea:disabled, select:disabled { background: var(--calc); color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); }
.calc { background: var(--calc); border-radius: 9px; padding: 9px 11px; min-height: 42px; font-weight: 700; display: flex; align-items: center; }
.calc.good { color: var(--ok); }
.calc.bad { color: var(--bad); }
.err { color: var(--bad); background: var(--bad-soft); padding: 10px 12px; border-radius: 9px; margin: 10px 0; font-size: .92rem; }

/* ---------- đăng nhập ---------- */
.auth { max-width: 420px; margin: 8vh auto 0; padding: 0 16px; }
.auth .card { padding: 28px; }
.auth h1 { margin: 10px 0 4px; }
.auth form { display: grid; gap: 14px; margin-top: 18px; }
.auth .logo-big { width: 48px; height: 48px; border-radius: 12px; background: var(--primary); display: grid; place-items: center; }
.auth .logo-big svg { width: 28px; height: 28px; }

/* ---------- điều hướng tuần ---------- */
.weeknav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.weeknav .wlabel { font-weight: 700; font-size: 1.15rem; min-width: 190px; text-align: center; }
.weeknav .wlabel small { display: block; font-weight: 500; color: var(--muted); font-size: .8rem; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; font-weight: 600; }

/* ---------- tổng quan nhóm ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 1.5rem; font-weight: 800; }
.stat .t { color: var(--muted); font-size: .85rem; }
.list { display: grid; gap: 10px; }
.member {
  display: grid; grid-template-columns: minmax(150px, 1.4fr) 110px 1.6fr 90px auto; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.member:hover { border-color: var(--primary); }
.member .nm b { display: block; }
.bar { height: 8px; border-radius: 99px; background: var(--calc); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.member .rev { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- phiếu check-in ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.sectitle { margin: 18px 0 10px; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.okr { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; background: var(--bg); }
.okr .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 700; }
.okr .g { display: grid; gap: 12px; grid-template-columns: repeat(12, 1fr); }
.okr .g > * { grid-column: span 12; }
@media (min-width: 760px) {
  .okr .c6 { grid-column: span 6; }
  .okr .c4 { grid-column: span 4; }
  .okr .c3 { grid-column: span 3; }
  .okr .c2 { grid-column: span 2; }
}
.pctwrap { display: flex; gap: 10px; align-items: center; }
.pctwrap .bar { flex: 1; }
.pctwrap input { width: 84px; }
.scale { display: flex; gap: 6px; flex-wrap: wrap; }
.scale button {
  width: 42px; height: 42px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 700;
}
.scale button.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.scale button:disabled { cursor: default; }
.qgroup { margin-bottom: 20px; }
.qgroup h3 { margin-bottom: 10px; color: var(--primary); }
.q { margin-bottom: 14px; }
.q .qt { font-weight: 600; margin-bottom: 6px; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); z-index: 15;
  padding: 10px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.savebar .in { max-width: 1120px; width: 100%; margin: 0 auto; display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.savestate { font-size: .9rem; color: var(--muted); }
.savestate.err2 { color: var(--bad); font-weight: 600; }
.comment-box { border-left: 4px solid var(--primary); background: var(--primary-soft); border-radius: 10px; padding: 14px; }
.comment-box .who { font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.comment-box .txt { white-space: pre-wrap; }

/* ---------- bảng nhân sự ---------- */
.utable { width: 100%; border-collapse: collapse; }
.utable th, .utable td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.utable th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.utable tr.off td { opacity: .6; }

/* ---------- hộp thoại & thông báo ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 15, 25, .5); z-index: 50; display: grid; place-items: center; padding: 16px; overflow: auto; }
.modal { background: var(--card); border-radius: 14px; padding: 22px; width: 100%; max-width: 480px; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.modal h2 { margin-bottom: 14px; }
.modal .form { display: grid; gap: 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.cred { background: var(--calc); border-radius: 10px; padding: 12px 14px; font-family: ui-monospace, Menlo, monospace; font-size: .95rem; white-space: pre-wrap; word-break: break-all; }
#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); font-size: .93rem; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- điện thoại ---------- */
@media (max-width: 820px) {
  .topbar { position: static; }
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { padding: 10px; }
  .stat .n { font-size: 1.05rem; word-break: break-all; }
  .stat .t { font-size: .72rem; }
  .member { grid-template-columns: 1fr auto; }
  .member .prog { grid-column: 1 / -1; order: 5; }
  .member .nm { order: 1; }
  .member .st { order: 2; justify-self: end; }
  .member .num, .member .go { display: none; }
  .topbar-in { gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .me .who { display: none; }
  .brand { flex: 1; }
  .utable, .utable thead, .utable tbody, .utable tr, .utable td { display: block; }
  .utable thead { display: none; }
  .utable tr { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
  .utable td { border: 0; padding: 4px 0; }
  .weeknav .wlabel { flex-basis: 100%; order: -1; }
}
@media print {
  .topbar, .savebar, .btn { display: none !important; }
  body { background: #fff; }
}
