:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #f1efea; --line: #e4e1da;
  --text: #1c1a17; --muted: #6f6a61; --accent: #c2410c; --accent-soft: #fdebe1;
  --good: #15803d; --good-soft: #e3f4e8; --warn: #b45309; --warn-soft: #fdf2dc; --bad: #b91c1c; --bad-soft: #fde4e4;
  --blue: #1d4ed8; --blue-soft: #e3ebfd;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  font-family: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412; --surface: #1e1c1a; --surface-2: #272522; --line: #34312d;
    --text: #efece6; --muted: #a39d93; --accent: #f97316; --accent-soft: #3a2415;
    --good: #4ade80; --good-soft: #16301f; --warn: #fbbf24; --warn-soft: #33290f; --bad: #f87171; --bad-soft: #3a1818;
    --blue: #93b4ff; --blue-soft: #1c2640; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; display: flex; min-height: 100vh; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; word-break: break-all; }

/* Khung */
#side { width: 232px; flex: none; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 18px 18px 14px; }
.brand.big { font-size: 22px; padding: 0 0 4px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }
#nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
#nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 8px 4px; }
#nav a { display: flex; gap: 10px; align-items: center; padding: 7px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
#nav a:hover { background: var(--surface-2); }
#nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#nav a .n { margin-left: auto; font-size: 11px; background: var(--bad); color: #fff; border-radius: 10px; padding: 0 6px; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 18px; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
#top h1 { font-size: 18px; flex: 1; }
#actions { display: flex; gap: 8px; flex-wrap: wrap; }
#menu { display: none; }
#view { padding: 20px 24px 60px; }

/* Nút & ô nhập */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: wait; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; }
label { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); font-size: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; font-weight: 400; }

/* Thanh lọc */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 260px; }
.toolbar select { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; font: inherit; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Thẻ & lưới */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.cols2 { grid-template-columns: 1fr 1fr; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .d { font-size: 12px; margin-top: 2px; }
.up { color: var(--good); } .down { color: var(--bad); }
.empty { color: var(--muted); padding: 18px 0; text-align: center; font-size: 13px; }

/* Bảng */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; cursor: pointer; white-space: nowrap; user-select: none; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 360px; }
tr.bad td { background: var(--bad-soft); }

/* Nhãn */
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.t-good { background: var(--good-soft); color: var(--good); }
.tag.t-warn { background: var(--warn-soft); color: var(--warn); }
.tag.t-bad { background: var(--bad-soft); color: var(--bad); }
.tag.t-blue { background: var(--blue-soft); color: var(--blue); }
.tag.t-accent { background: var(--accent-soft); color: var(--accent); }

/* Kanban */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { background: var(--surface-2); border-radius: var(--radius); width: 272px; flex: none; padding: 8px; }
.col h3 { font-size: 13px; padding: 4px 6px 8px; display: flex; justify-content: space-between; }
.col.over { outline: 2px dashed var(--accent); }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.kcard .t { font-weight: 600; margin-bottom: 6px; }
.kcard .m { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

/* Lịch */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--line); gap: 1px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal .h { background: var(--surface-2); padding: 6px; font-size: 12px; color: var(--muted); text-align: center; }
.cal .d { background: var(--surface); min-height: 108px; padding: 6px; font-size: 12px; }
.cal .d.out { background: var(--surface-2); opacity: .6; }
.cal .d.today .num { background: var(--accent); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: inline-grid; place-items: center; }
.cal .ev { display: block; margin-top: 3px; padding: 2px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--text); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal .ev.done { background: var(--good-soft); }

/* Ngăn kéo chi tiết */
#drawer { position: fixed; inset: 0; z-index: 20; }
#drawer .scrim { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
#drawer .panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(720px, 100%); background: var(--bg); overflow-y: auto; box-shadow: -8px 0 30px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.panel header { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 20px; display: flex; gap: 10px; align-items: center; z-index: 2; }
.panel header h2 { flex: 1; font-size: 16px; }
.panel .body { padding: 18px 20px 40px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.form .grp { grid-column: 1 / -1; font-size: 12px; font-weight: 700; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: .05em; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin-top: 20px; }
.ai-box { background: var(--blue-soft); border-radius: var(--radius); padding: 12px; margin-top: 16px; }
.ai-box .row { display: flex; gap: 6px; flex-wrap: wrap; }
.ai-out { white-space: pre-wrap; background: var(--surface); border-radius: 8px; padding: 12px; margin-top: 10px; max-height: 360px; overflow-y: auto; font-size: 13px; }
.timeline { margin-top: 20px; }
.note { border-left: 3px solid var(--line); padding: 4px 0 10px 12px; }
.note .who { font-size: 12px; color: var(--muted); }
.note .b { white-space: pre-wrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }

/* Thanh tiến độ & biểu đồ */
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 44px; gap: 10px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.chart svg { width: 100%; height: 190px; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.list-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.alert { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 8px; }
.okbox { background: var(--good-soft); color: var(--good); padding: 10px 12px; border-radius: 8px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 50; box-shadow: var(--shadow); max-width: 90vw; }

/* Đăng nhập */
body.auth { display: grid; place-items: center; padding: 16px; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(400px, 100%); display: grid; gap: 14px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

@media (max-width: 860px) {
  #side { position: fixed; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open #side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  #menu { display: block; }
  #top, #view { padding-left: 16px; padding-right: 16px; }
  .cols2, .form { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .v { font-size: 19px; }
  .card { padding: 12px; }
  #top { padding-top: 10px; padding-bottom: 10px; gap: 8px; }
  #top h1 { font-size: 16px; }
  #actions .btn { padding: 6px 10px; font-size: 13px; }
  .toolbar input[type=search] { max-width: none; }
  .cal .d { min-height: 70px; }
  .cal .ev { font-size: 10px; padding: 1px 3px; }
  .funnel-row { grid-template-columns: 100px 1fr 36px; }
}
.form > * { min-width: 0; }
.settings { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); align-items: start; }
@media (max-width: 1100px) { .settings { grid-template-columns: 1fr; } }

/* Thêm theo lệnh thầy Mạnh */
.cols3 { grid-template-columns: repeat(3, 1fr); }
.cols2r { grid-template-columns: 3fr 2fr; }
.report { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 12px 14px; font-size: 13.5px; line-height: 1.6; overflow: auto; max-height: 70vh; margin: 8px 0; }
.card.approve { margin-bottom: 14px; }
.card.approve h2 { display: block; margin: 4px 0 8px; font-size: 16px; }
.card.approve p { margin: 6px 0; }
@media (max-width: 1100px) { .cols3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) { .cols3, .cols2r { grid-template-columns: 1fr; } }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
