:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e4e9f2;
  --brand: #1d4ed8;
  --brand-soft: #e8efff;
  --green: #16a34a;
  --amber: #f59e0b;
  --red: #dc2626;
  --purple: #7c3aed;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -16px rgba(15, 23, 42, .25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

.boot { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 12px; color: var(--muted); }
.boot-logo { width: 56px; height: 56px; border-radius: 16px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; }

/* ---------- Khung ---------- */
#app { min-height: 100vh; }
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.sidebar { display: none; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(244, 246, 251, .92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  padding: 10px 14px; display: flex; align-items: center; gap: 10px;
}
.topbar h1 { flex: 1; font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
.topbar .who { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.2; }
#view { padding: 14px 14px 96px; max-width: 1100px; width: 100%; margin: 0 auto; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--muted); padding: 4px 0; font-weight: 500; }
.tabbar a.active { color: var(--brand); }
.tabbar .tab-add { display: grid; place-items: center; }
.tabbar .tab-add span { width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 22px; line-height: 1; box-shadow: 0 6px 14px -6px rgba(29, 78, 216, .8); }

/* ---------- Thành phần ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section { margin-top: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.section-head h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.mono { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 12px; font-size: 13.5px; font-weight: 600; cursor: pointer; min-height: 38px;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.soft { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.btn.danger { background: #fef2f2; border-color: #fecaca; color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.sm { padding: 5px 9px; min-height: 30px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: none; background: transparent; font-size: 17px; line-height: 1; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #eef2f9; color: #475569;
  white-space: nowrap;
}
.chip.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.green { background: #e9f9ef; color: #15803d; }
.chip.red { background: #feecec; color: #b91c1c; }
.chip.amber { background: #fef3e2; color: #b45309; }
.chip.blue { background: #e8efff; color: #1d4ed8; }
.chip.purple { background: #f2ecff; color: #6d28d9; }
.chip.slate { background: #eef2f7; color: #475569; }
.chip.line { background: #fff; border: 1px solid var(--line); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; text-align: left;
}
.stat .n { font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.alert .n { color: var(--red); }
.stat.warn .n { color: var(--amber); }
.stat.good .n { color: var(--green); }

.task-row { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.task-row:last-child { border-bottom: none; }
.task-row .grow { flex: 1; min-width: 0; }
.task-row .title { font-weight: 600; font-size: 14px; display: block; margin-bottom: 3px; word-break: break-word; }
.task-row .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.task-row.overdue .title { color: #b91c1c; }
.progress { height: 6px; border-radius: 3px; background: #eef2f7; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 3px; }
.progress.done > i { background: var(--green); }
.progress.late > i { background: var(--red); }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .big { font-size: 26px; margin-bottom: 6px; }
.loading { padding: 24px; text-align: center; color: var(--muted); }
.skeleton { height: 62px; border-radius: 12px; background: linear-gradient(90deg, #eef2f8, #f7f9fc, #eef2f8); background-size: 200% 100%; animation: sk 1.2s infinite; margin-bottom: 8px; }
@keyframes sk { 0% { background-position: 0 0; } 100% { background-position: -200% 0; } }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > label { font-size: 12.5px; font-weight: 600; color: #334155; }
.field .hint { font-size: 11.5px; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="time"], input[type="tel"], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; font-size: 14px; min-height: 40px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d8ff; border-color: #93b4ff; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; padding: 6px 0; }
.check input { width: 18px; height: 18px; min-height: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.people-pick { display: flex; flex-wrap: wrap; gap: 6px; max-height: 168px; overflow: auto; padding: 2px; }
.people-pick label { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; font-size: 12.5px; background: #fff; cursor: pointer; }
.people-pick input { display: none; }
.people-pick label:has(input:checked) { background: var(--brand-soft); border-color: #b9cdff; color: var(--brand); font-weight: 600; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 100; padding: 0; }
.modal { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { flex: 1; }
.modal-body { padding: 14px 16px; overflow: auto; flex: 1; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

#toast-root { position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #0f172a; color: #fff; padding: 9px 14px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); animation: pop .18s ease-out; max-width: 90vw; }
.toast.err { background: #b91c1c; }
.toast.ok { background: #14532d; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, #dbe6ff, transparent), var(--bg); }
.login-card { width: 100%; max-width: 400px; padding: 22px; }
.login-card .logo { width: 46px; height: 46px; border-radius: 13px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; margin-bottom: 12px; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.kanban .col { min-width: 232px; width: 232px; flex-shrink: 0; }
.kanban .col > h4 { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.kanban .kcard { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.kanban .kcard .t { font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }

/* ---------- Chi tiết việc ---------- */
.detail-head { padding: 14px; }
.detail-title { font-size: 19px; font-weight: 700; margin-bottom: 8px; letter-spacing: -.3px; }
.kv { display: grid; grid-template-columns: 118px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); padding: 0 4px; }
.tabs button { border: none; background: none; padding: 10px 12px; font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-color: var(--brand); }
.comment { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.comment .who { font-weight: 600; font-size: 13px; }
.comment .body { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; display: flex; gap: 8px; }
.timeline .when { color: var(--muted); font-size: 11.5px; white-space: nowrap; min-width: 92px; }

/* ---------- OKR ---------- */
.obj { padding: 14px; }
.obj + .obj { margin-top: 12px; }
.obj.child { margin-left: 14px; border-left: 3px solid var(--brand-soft); }
.light { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.light.green { background: var(--green); }
.light.yellow { background: var(--amber); }
.light.red { background: var(--red); }
.light.gray { background: #cbd5e1; }
.kr { padding: 10px 0; border-top: 1px dashed var(--line); }
.kr:first-child { border-top: none; }
.bar { height: 8px; border-radius: 4px; background: #eef2f7; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 10px; padding: 8px 10px; font-size: 12.5px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.scroll-x { overflow-x: auto; }
.hr-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.chart { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding: 8px 4px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; }
.chart .bar-a { background: #93b4ff; border-radius: 4px 4px 0 0; }
.chart .bar-b { background: #16a34a; border-radius: 4px 4px 0 0; }
.chart .lbl { font-size: 10px; color: var(--muted); text-align: center; }

@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 18px; max-height: 88vh; }
  .hr-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
  .shell { grid-template-columns: 244px 1fr; }
  .sidebar { display: flex; flex-direction: column; gap: 2px; padding: 16px 12px; background: #fff; border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; }
  .sidebar .brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 16px; font-weight: 800; letter-spacing: -.3px; }
  .sidebar .brand span { width: 32px; height: 32px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; }
  .sidebar a { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 10px; color: #334155; font-size: 13.5px; font-weight: 600; }
  .sidebar a.active { background: var(--brand-soft); color: var(--brand); }
  .sidebar .side-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 10px; }
  .tabbar { display: none; }
  .topbar { padding: 14px 24px; }
  .topbar .menu-btn { display: none; }
  #view { padding: 20px 24px 48px; }
  .login-wrap { background: radial-gradient(900px 500px at 30% -10%, #dbe6ff, transparent), var(--bg); }
  .login-card { padding: 28px; }
}
