:root {
  --bg: #f3f5f9; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb; --input-line: #d1d5db; --th-bg: #fafafa; --soft-bg: #fafbff; --hover: #f3f4f6;
  --primary: #1e40af; --primary-2: #1e3a8a; --primary-3: #2563eb; --primary-soft: #eef2ff; --link: var(--primary); --focus: #bfdbfe;
  --side-text: #dbeafe; --side-sub: #93c5fd;
  --red: #dc2626; --red-soft: #fee2e2; --red-line: #fecaca; --red-ink: #7f1d1d; --yellow: #b45309; --yellow-soft: #fef3c7; --yellow-ink: #78350f;
  --green: #15803d; --green-soft: #dcfce7; --orange: #c2410c; --orange-soft: #ffedd5;
  --blue: #1d4ed8; --blue-soft: #dbeafe; --blue-ink: #1e3a8a; --gray-soft: #f3f4f6; --gray-ink: #4b5563; --purple: #6d28d9; --purple-soft: #ede9fe;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 6px rgba(0,0,0,.04);
  color-scheme: light;
}
/* Tông màu (chỉ đổi màu chủ đạo; màu trạng thái giữ cố định) */
:root[data-color="green"] { --primary: #15803d; --primary-2: #14532d; --primary-3: #16a34a; --primary-soft: #ecfdf5; --focus: #bbf7d0; --side-text: #dcfce7; --side-sub: #86efac; }
:root[data-color="teal"] { --primary: #0f766e; --primary-2: #134e4a; --primary-3: #0d9488; --primary-soft: #f0fdfa; --focus: #99f6e4; --side-text: #ccfbf1; --side-sub: #5eead4; }
:root[data-color="maroon"] { --primary: #9f1239; --primary-2: #4c0519; --primary-3: #be123c; --primary-soft: #fff1f2; --focus: #fecdd3; --side-text: #ffe4e6; --side-sub: #fda4af; }
:root[data-color="purple"] { --primary: #6d28d9; --primary-2: #3b0764; --primary-3: #7c3aed; --primary-soft: #f5f3ff; --focus: #ddd6fe; --side-text: #ede9fe; --side-sub: #c4b5fd; }
:root[data-color="slate"] { --primary: #334155; --primary-2: #0f172a; --primary-3: #475569; --primary-soft: #f1f5f9; --focus: #cbd5e1; --side-text: #e2e8f0; --side-sub: #94a3b8; }
/* Chế độ tối */
:root[data-mode="dark"] {
  --bg: #0b1120; --card: #151e2e; --text: #e5e7eb; --muted: #9ca3af; --line: #2a3446; --input-line: #3a465c; --th-bg: #1a2436; --soft-bg: #18233a; --hover: #1f2a3e;
  --primary-soft: #1c2740; --link: var(--side-sub); --focus: #334155;
  --red: #f87171; --red-soft: #3a1717; --red-line: #7f1d1d; --red-ink: #fecaca; --yellow: #fbbf24; --yellow-soft: #3a2a0c; --yellow-ink: #fde68a;
  --green: #4ade80; --green-soft: #12301d; --orange: #fb923c; --orange-soft: #3b2010;
  --blue: #60a5fa; --blue-soft: #172a4a; --blue-ink: #bfdbfe; --gray-soft: #1f2937; --gray-ink: #cbd5e1; --purple: #a78bfa; --purple-soft: #261c45;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
:root[data-mode="dark"] .btn.primary, :root[data-mode="dark"] .btn.success { color: #fff; }
:root[data-mode="dark"] .btn.success { background: #15803d; border-color: #15803d; }
:root[data-mode="dark"] .btn.primary { background: var(--primary-3); border-color: var(--primary-3); }
/* Cỡ chữ */
html { font-size: 16px; }
:root[data-size="sm"] { font-size: 14.5px; }
:root[data-size="lg"] { font-size: 18px; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; font-size: 0.875rem; color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.25rem; margin: 0 0 4px; }
h2 { font-size: 1rem; margin: 0 0 12px; }
h3 { font-size: 0.875rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.75rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }

/* Bố cục */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--primary-2); color: var(--side-text); flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 18px 16px 14px; font-weight: 600; color: #fff; font-size: 0.9375rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar .brand small { display: block; font-weight: 400; color: var(--side-sub); font-size: 0.75rem; margin-top: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 10px 16px; font-size: 0.875rem; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.sidebar .sep { height: 1px; background: rgba(255,255,255,.1); margin: 8px 0; }
.ico { width: 18px; text-align: center; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 20px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 10; }
.topbar .title { font-weight: 600; flex: 1; }
.topbar .user { color: var(--muted); font-size: 0.8125rem; }
.main { padding: 20px; max-width: 1400px; width: 100%; }
.bottomnav { display: none; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Thành phần */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--red); border-color: var(--red-line); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.sm { padding: 4px 8px; font-size: 0.75rem; }
.btn:disabled { opacity: .5; cursor: default; }
.linkbtn { background: none; border: 0; color: var(--link); cursor: pointer; padding: 0; font: inherit; }

label { display: block; font-size: 0.8125rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--input-line); border-radius: 8px; font: inherit; background: var(--card); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.field .req { color: var(--red); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: flex; gap: 6px; align-items: center; color: var(--text); margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters > * { min-width: 140px; }
.filters input[type=search] { min-width: 220px; }

/* Chip trạng thái */
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.st-not_started { background: var(--gray-soft); color: var(--gray-ink); }
.st-in_progress { background: var(--blue-soft); color: var(--blue); }
.st-due_soon { background: var(--yellow-soft); color: var(--yellow); }
.st-overdue { background: var(--red-soft); color: var(--red); }
.st-done_ontime { background: var(--green-soft); color: var(--green); }
.st-done_late { background: var(--orange-soft); color: var(--orange); }
.st-regular { background: var(--purple-soft); color: var(--purple); }
.st-paused, .st-cancelled { background: var(--th-bg); color: var(--muted); border: 1px dashed var(--input-line); }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 0.6875rem; font-weight: 700; color: #fff; }
.prio-1 { color: var(--red); font-weight: 700; }

/* Thẻ số liệu */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); cursor: pointer; }
.kpi:hover { border-color: #93c5fd; }
.kpi .lbl { font-size: 0.75rem; color: var(--muted); }
.kpi .val { font-size: 1.625rem; font-weight: 700; margin-top: 2px; }
.kpi .sub { font-size: 0.75rem; color: var(--muted); }
.kpi.red { background: var(--red-soft); border-color: var(--red-line); } .kpi.red .val { color: var(--red); }
.kpi.yellow .val { color: var(--yellow); } .kpi.green .val { color: var(--green); } .kpi.blue .val { color: var(--blue); }

/* Bảng */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 0.75rem; color: var(--muted); font-weight: 600; background: var(--th-bg); white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--hover); }
td .title { font-weight: 600; color: var(--text); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Thanh tiến độ */
.bar { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--blue); }
.bar.big { height: 12px; }
.bar.ok > span { background: var(--green); } .bar.late > span { background: var(--red); }

/* Danh sách nhiệm vụ dạng thẻ */
.tcard { border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--card); }
.tcard + .tcard { margin-top: 8px; }
.tcard.overdue { border-left-color: var(--red); } .tcard.due_soon { border-left-color: #f59e0b; } .tcard.in_progress { border-left-color: var(--blue); }
.tcard .t { font-weight: 600; }
.tcard .meta { font-size: 0.75rem; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.tcard .quick { display: grid; grid-template-columns: 90px 1fr auto auto; gap: 6px; margin-top: 8px; align-items: center; }
.cols3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.colhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.count { background: var(--gray-soft); border-radius: 999px; padding: 0 8px; font-size: 0.75rem; font-weight: 600; }

/* Chi tiết */
.info { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.info dt { color: var(--muted); } .info dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline li.k-system::before { background: #9ca3af; } .timeline li.k-extend::before { background: #f59e0b; } .timeline li.k-complete::before { background: var(--green); } .timeline li.k-state::before, .timeline li.k-reopen::before { background: var(--purple); }
.timeline .when { font-size: 0.75rem; color: var(--muted); }
.issue { background: var(--yellow-soft); border-radius: 6px; padding: 6px 8px; margin-top: 4px; }
.directive { background: var(--primary-soft); border-left: 3px solid var(--primary); padding: 8px 10px; border-radius: 6px; }
.directive + .directive { margin-top: 8px; }
.ms { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.ms.done .mt { text-decoration: line-through; color: var(--muted); }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--yellow-soft); color: var(--yellow-ink); margin-bottom: 14px; }
.alert.red { background: var(--red-soft); color: var(--red-ink); }
.alert.blue { background: var(--blue-soft); color: var(--blue-ink); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--link); border-color: var(--link); font-weight: 600; text-decoration: none; }

/* Lịch */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { font-size: 0.75rem; color: var(--muted); text-align: center; padding: 4px; }
.cal .day { background: var(--card); border: 1px solid var(--line); border-radius: 6px; min-height: 92px; padding: 4px; font-size: 0.75rem; }
.cal .day.other { background: var(--th-bg); color: var(--muted); }
.cal .day.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal .ev { display: block; padding: 1px 4px; border-radius: 4px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

/* Hộp thoại */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 12px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal header { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; justify-content: space-between; }
.modal .body { padding: 16px; }
.modal footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 200; max-width: 90vw; }
.toast.err { background: var(--red); }

/* Đăng nhập */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, var(--primary-2), var(--primary) 50%, var(--primary-3)); width: 100%; }
.login { background: var(--card); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login h1 { font-size: 1.125rem; text-align: center; }
.login .org { text-align: center; color: var(--muted); margin-bottom: 18px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; }
.secret { font-family: Consolas, monospace; background: var(--gray-soft); padding: 6px 8px; border-radius: 6px; word-break: break-all; }
.pw-box { font-family: Consolas, monospace; font-size: 1.25rem; text-align: center; background: var(--green-soft); padding: 10px; border-radius: 8px; letter-spacing: 1px; user-select: all; }
.chart-box { position: relative; height: 280px; }

/* Điện thoại, máy tính bảng */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g-main, .cols3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { display: none; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); z-index: 50; padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; text-align: center; padding: 8px 2px 6px; font-size: 0.6875rem; color: var(--muted); }
  .bottomnav a .ico { display: block; font-size: 1.125rem; width: auto; }
  .bottomnav a.active { color: var(--link); font-weight: 600; }
  .main { padding: 12px 12px 80px; }
  .topbar { padding: 10px 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px; } .kpi .val { font-size: 1.375rem; }
  .g2, .g3, .form-grid { grid-template-columns: 1fr; }
  .info { grid-template-columns: 1fr; gap: 0; } .info dt { margin-top: 8px; }
  .hide-m { display: none !important; }
  .filters > * { min-width: 0; flex: 1 1 45%; }
  .tcard .quick { grid-template-columns: 70px 1fr; }
  .cal .day { min-height: 60px; font-size: 0.625rem; }
  .chart-box { height: 240px; }
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal { border-radius: 14px 14px 0 0; }
}
@media (min-width: 761px) { .show-m { display: none !important; } }
@media print {
  .sidebar, .topbar, .bottomnav, .no-print, .btn { display: none !important; }
  :root { --bg: #fff; --card: #fff; --text: #000; --muted: #444; --line: #ccc; } body { background: #fff; } .card { box-shadow: none; }
}
a.kpi { color: inherit; text-decoration: none; display: block; }
.grid > .card + .card, .grid > .tcard + .tcard { margin-top: 0; }

/* Chân trang */
.footer { margin-top: auto; padding: 14px 20px; color: var(--muted); font-size: 0.75rem; border-top: 1px solid var(--line); line-height: 1.6; }
.footer span + span::before, .login-foot span + span::before { content: " · "; }
.login-foot a { color: #fff; text-decoration: underline; }
.login-foot { color: #fff; opacity: .9; font-size: 0.75rem; text-align: center; margin-top: 14px; line-height: 1.6; max-width: 380px; }
.login-col { display: flex; flex-direction: column; align-items: center; width: 100%; }
/* Lịch: kỳ dự kiến, ngày nghỉ */
.cal .ev.proj { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }
.cal .day.hol { background: var(--red-soft); }
.cal .day .hn { display: block; font-size: 0.625rem; color: var(--red); }
/* Bảng chọn tông màu */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches label { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; color: var(--text); margin: 0; }
.swatches .sw { width: 18px; height: 18px; border-radius: 50%; display: inline-block; }
.periods td, .periods th { padding: 6px 8px; }
@media (max-width: 760px) { .footer { padding: 12px 12px 84px; } }
