:root {
  --bg: #F5F4EF;
  --surface: #FFFFFF;
  --ink: #1B2621;
  --ink-soft: #5B6A61;
  --line: #DEDACB;
  --accent: #2F6F4E;
  --accent-dark: #234F38;
  --accent-ink: #FFFFFF;
  --status-moi-bg: #E7E5DD;
  --status-moi-fg: #55605A;
  --status-dang-bg: #FBEAD4;
  --status-dang-fg: #A15D14;
  --status-hoan-bg: #DEEEE2;
  --status-hoan-fg: #256B45;
  --status-huy-bg: #F5DEDA;
  --status-huy-fg: #A03F30;
  --font-ui: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(27, 38, 33, 0.06), 0 6px 20px rgba(27, 38, 33, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0 0 4px; }
p { margin: 0 0 8px; }
a { color: var(--accent-dark); }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(47,111,78,0.08), transparent 45%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
  font-size: 14px;
}
.login-sub { color: var(--ink-soft); margin-bottom: 24px; font-size: 14px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-soft); font-weight: 500; }

input, select, textarea {
  font-family: var(--font-ui);
  font-size: 14.5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 70px; }

.btn {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(0.97); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-danger { background: var(--status-huy-bg); border-color: var(--status-huy-bg); color: var(--status-huy-fg); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }

.error { color: var(--status-huy-fg); font-size: 13px; margin-top: 4px; }

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--font-mono); font-weight: 600; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13.5px; color: var(--ink-soft); }

.tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.tab {
  padding: 12px 14px; font-size: 13.5px; font-weight: 500; color: var(--ink-soft);
  border-bottom: 2px solid transparent; cursor: pointer; background: none; border-top: none; border-left: none; border-right: none;
  font-family: var(--font-ui);
}
.tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }

.content { flex: 1; padding: 24px; max-width: 1100px; width: 100%; margin: 0 auto; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; }
.filters select { min-width: 150px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--ink-soft); font-weight: 600; font-size: 12px; text-transform: none; }
tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover { background: var(--bg); }
tr.row-due-soon { background: var(--status-dang-bg); }
tr.row-due-soon:hover { background: var(--status-dang-bg); filter: brightness(0.97); }
tr.row-overdue { background: var(--status-huy-bg); }
tr.row-overdue:hover { background: var(--status-huy-bg); filter: brightness(0.97); }

tr.merge-row td { background: var(--bg); padding: 12px 8px; font-size: 13px; }
tr.merge-row select { margin: 0 6px; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 100px;
  font-size: 12px; font-weight: 600;
}
.badge-moi { background: var(--status-moi-bg); color: var(--status-moi-fg); }
.badge-chua_thuc_hien { background: var(--status-moi-bg); color: var(--status-moi-fg); }
.badge-dang_thuc_hien { background: var(--status-dang-bg); color: var(--status-dang-fg); }
.badge-hoan_thanh { background: var(--status-hoan-bg); color: var(--status-hoan-fg); }
.badge-huy { background: var(--status-huy-bg); color: var(--status-huy-fg); }

.taskid { font-family: var(--font-mono); color: var(--ink-soft); }

.progress-wrap { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.progress-bar { flex: 1; height: 6px; border-radius: 100px; background: var(--status-moi-bg); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--accent); }
.progress-pct { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); min-width: 30px; text-align: right; }

.empty { color: var(--ink-soft); font-size: 13.5px; padding: 20px 0; text-align: center; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.link-code-box {
  font-family: var(--font-mono); font-size: 22px; font-weight: 600; letter-spacing: 3px;
  background: var(--bg); border: 1px dashed var(--line); border-radius: 8px;
  padding: 12px 16px; text-align: center; margin: 10px 0;
}

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }

.back-link { display: inline-block; margin-bottom: 14px; font-size: 13.5px; color: var(--ink-soft); text-decoration: none; cursor: pointer; }
.back-link:hover { color: var(--accent-dark); }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.detail-meta { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--ink-soft); }
.detail-meta b { color: var(--ink); font-weight: 600; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: none; }
.timeline .t-head { display: flex; justify-content: space-between; font-size: 13px; }
.timeline .t-who { font-weight: 600; }
.timeline .t-when { color: var(--ink-soft); font-family: var(--font-mono); font-size: 11.5px; }
.timeline .t-note { margin-top: 4px; font-size: 13.5px; color: var(--ink-soft); }
.timeline .t-image { display: block; margin-top: 8px; max-width: 220px; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); }

/* ---------- Anh dinh kem ---------- */
.t-image { max-width: 220px; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); }
.image-picker { margin-top: 4px; }
.image-drop {
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 18px 12px; border: 1px dashed var(--line); border-radius: 8px;
  color: var(--ink-soft); font-size: 13px; cursor: pointer; font-weight: 400;
}
.image-drop:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.image-preview { display: flex; align-items: center; gap: 10px; }
.image-preview img { max-width: 160px; max-height: 160px; border-radius: 8px; border: 1px solid var(--line); }

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 8px;
  font-size: 13.5px; box-shadow: var(--shadow); z-index: 50;
  max-width: 320px;
}
.toast.err { background: var(--status-huy-fg); }

.channel-dot { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; }
.channel-dot::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--status-moi-fg); }
.channel-dot.on::before { background: var(--status-hoan-fg); }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
@media (max-width: 800px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-tile {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; text-align: center; cursor: pointer; transition: filter 0.12s ease;
}
.stat-tile:hover { filter: brightness(0.97); }
.stat-value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; color: var(--accent-dark); }
.stat-label { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; }

.locked-banner {
  margin-top: 12px; padding: 10px 14px; border-radius: 8px;
  background: var(--status-hoan-bg); color: var(--status-hoan-fg); font-size: 13px;
}

/* ---------- Gantt (chi tiet du an) ---------- */
.gantt-stage { border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; margin-bottom: 10px; }
.gantt-stage-head { font-weight: 600; font-size: 13.5px; margin-bottom: 6px; }
.gantt-tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.gantt-task {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--bg); border-radius: 8px; cursor: pointer; font-size: 13px;
}
.gantt-task:hover { filter: brightness(0.97); }
.gantt-task .progress-wrap { margin-left: auto; }

/* ---------- Nhom danh sach cong viec theo du an/giai doan hoac cha-con ---------- */
.task-group-stage { margin-bottom: 14px; }
.task-group-stage-head {
  font-weight: 600; font-size: 12.5px; color: var(--ink-soft); text-transform: uppercase;
  letter-spacing: 0.03em; margin-bottom: 6px;
}
tr.child-row { background: var(--bg); }
tr.child-row:hover { background: var(--bg); filter: brightness(0.97); }
tr.child-row td:nth-child(2) { color: var(--ink-soft); font-size: 12.5px; padding-left: 34px; }
.tree-branch { color: var(--ink-soft); margin-right: 6px; font-family: var(--font-mono); }
.tree-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; margin-right: 8px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-size: 12px; line-height: 1; color: var(--ink-soft); padding: 0; vertical-align: middle;
}
.tree-toggle:hover { background: var(--bg); border-color: var(--accent); color: var(--accent-dark); }
.tree-node-head { cursor: pointer; display: flex; align-items: center; gap: 6px; user-select: none; }
.tree-node-head:hover { color: var(--accent-dark); }
.tree-node-head h2 { display: flex; align-items: center; gap: 6px; }
.tree-caret { display: inline-block; width: 12px; font-size: 11px; color: var(--ink-soft); }
.tree-node { margin-bottom: 4px; }

.filter-tag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px;
  background: var(--status-dang-bg); color: var(--status-dang-fg);
  padding: 5px 10px; border-radius: 100px;
}
.filter-tag a { cursor: pointer; color: inherit; font-weight: 700; }

.table-scroll { overflow-x: auto; }

/* ---------- Combo box go de tim ---------- */
.combo { position: relative; }
.combo-input {
  width: 100%; font-size: 16px; /* 16px de iOS Safari khong tu zoom khi focus */
  padding-right: 28px; /* cho mui ten dropdown */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235B6A61' stroke-width='1.5' fill='none' fill-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.combo-input:disabled { background-color: var(--bg); color: var(--ink-soft); cursor: not-allowed; }
.combo-menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 240px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow);
}
.combo-item { padding: 10px 12px; font-size: 13.5px; cursor: pointer; }
.combo-item:hover, .combo-item.active { background: var(--bg); }
.combo-no-result { padding: 10px 12px; font-size: 13px; color: var(--ink-soft); }
