:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --border: #e5e7eb;
  --danger: #dc2626;
  --green: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  background: #111827;
  color: #fff;
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand a { color: #fff; font-weight: 700; font-size: 17px; }
.nav { display: flex; gap: 10px; align-items: center; }
.nav > a, .dropbtn {
  color: #d1d5db;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
.nav > a:hover, .dropbtn:hover { background: #1f2937; color: #fff; text-decoration: none; }
.dropdown { position: relative; }
.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #fff;
  min-width: 190px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  border-radius: 8px;
  padding: 6px;
  z-index: 30;
}
.dropdown:hover .dropdown-content { display: block; }
.dropdown-content a { display: block; color: var(--text); padding: 8px 10px; border-radius: 6px; }
.dropdown-content a:hover { background: #f3f4f6; text-decoration: none; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.uname { color: #e5e7eb; font-size: 14px; }
.uname em { color: #9ca3af; font-style: normal; }

/* Layout */
.container { max-width: 1200px; margin: 24px auto; padding: 0 20px; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 28px 0 12px; }
h3 { font-size: 16px; margin: 0 0 12px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1, .page-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; }

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card.center { text-align: center; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.stat { text-align: center; padding: 18px; }
.stat .num { display: block; font-size: 30px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.green .num { color: var(--green); }
.stat.blue .num { color: var(--primary); }
.stat.gray .num { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.group-card .group-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.group-card .group-head a { font-weight: 600; }

/* Progress bar */
.progress { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.progress .bar { height: 100%; background: var(--primary); }
.progress .bar.green { background: var(--green); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.badge { background: #eef2ff; color: #3730a3; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; }
.pill { background: #f3f4f6; border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 12px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:hover { background: #f9fafb; }
.table.kv th { width: 160px; color: var(--muted); font-weight: 500; }
.actions { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; }
.actions select { width: auto; max-width: 150px; margin-top: 0; }
.actions input { margin-top: 0; }
.actions .inline { display: inline-flex; }
code { background: #f1f5f9; padding: 1px 6px; border-radius: 5px; font-size: 90%; }

/* Forms */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
input[type=text], input[type=password], input[type=number], input[type=color], select, textarea {
  width: 100%;
  padding: 8px 10px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input[type=color] { width: 44px; height: 38px; padding: 2px; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-inline input, .form-inline select { width: auto; margin-top: 0; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.inline { display: inline; }

/* Alerts */
.alert { border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* Login */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.login-card { width: 360px; padding: 28px; }
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card .muted { text-align: center; margin-top: 0; }

/* Viewer */
.viewer { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

@media (max-width: 800px) {
  .form-grid, .two-col { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 14px; gap: 8px; }
  .actions { flex-wrap: wrap; }
}

/* Members & phase detail */
.members { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.members h4 { margin: 0 0 8px; font-size: 14px; }
.members form { align-items: flex-start; }
select[multiple] { min-width: 240px; height: auto; }
.two-col .card h3 { margin-top: 0; }

/* Modal (dialog) */
dialog.modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(720px, 94vw);
  max-height: 90vh;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .35);
  color: var(--text);
}
dialog.modal::backdrop { background: rgba(15, 23, 42, .5); }
.modal-form { display: flex; flex-direction: column; max-height: 90vh; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; }
.modal-x {
  border: none; background: transparent; font-size: 18px; line-height: 1;
  cursor: pointer; padding: 4px 9px; border-radius: 6px; color: var(--muted);
}
.modal-x:hover { background: #f1f5f9; color: var(--text); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--border);
}

/* Files page: pager + checkbox */
.pager { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.pager .btn { min-width: 38px; text-align: center; padding: 6px 10px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 0; }
.chk input { width: auto; margin: 0; }

/* Files page: header actions + upload */
.head-actions { flex-wrap: wrap; justify-content: flex-end; }
.head-actions input[type=file] { font-size: 13px; max-width: 220px; }

/* List footer + pager window */
.list-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.pager-gap { color: var(--muted); padding: 0 4px; }

/* Group tasks list */
.tasks-box { margin: 12px 0; border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; }
.tasks-box > summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.tasks-box .table { margin-top: 6px; }

/* Unified phase + tasks blocks */
.phase-block { border: 1px solid var(--border); border-radius: 8px; margin: 10px 0; overflow: hidden; }
.phase-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; background: #f8fafc; border-bottom: 1px solid var(--border); }
.phase-order { color: var(--muted); font-weight: 600; }
.phase-name { font-size: 15px; }
.phase-assign, .phase-docs { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.phase-head .actions { margin-left: auto; }
.phase-block .table td { padding: 7px 12px; }
.phase-block .table tr:last-child td { border-bottom: none; }

/* Group tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 0; border-bottom: 2px solid var(--border); }
.tab {
  border: 1px solid transparent; border-bottom: none;
  background: #eef2f7; color: var(--text);
  padding: 8px 14px; border-radius: 8px 8px 0 0; cursor: pointer;
  font: inherit; font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { background: #e2e8f0; }
.tab.active { background: #fff; border-color: var(--border); color: #3730a3; font-weight: 600; position: relative; top: 2px; }
.group-panel { margin-top: 14px; }

/* Print-friendly */
.print-only { display: none; }
@media print {
  .topbar, .footer, .filters, .actions, .pager, .list-foot, .no-print,
  button, .btn, .tabs { display: none !important; }
  .container { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; padding: 0; margin: 0; }
  .print-only { display: block; }
  .print-head h2 { margin: 0 0 4px; }
  .print-head p { margin: 0 0 10px; font-size: 12px; }
  .table { font-size: 11px; width: 100%; }
  .table th, .table td { border: 1px solid #999; padding: 4px 6px; }
  .table tbody tr:hover { background: transparent; }
  a { color: #000; text-decoration: none; }
  body { background: #fff; }
  @page { size: A4 landscape; margin: 10mm; }
}

@media print {
  .phase-block, .group-panel { page-break-inside: avoid; }
  .group-panel { border: none; margin: 0 0 14px; }
  .phase-head { background: #fff !important; }
}

/* Reports */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-label { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; }
.inline-label select { width: auto; min-width: 280px; }
.report-title { margin: 0; }

@media print {
  .person-report { page-break-after: always; }
  .person-report:last-child { page-break-after: auto; }
}

/* Assignment tree (D3) */
.tree-card { padding: 6px; overflow: hidden; }
#tree { width: 100%; }
#tree .node text { pointer-events: none; }
#tree .node:hover circle { stroke-width: 3; }

/* Tree: fullscreen + edge labels */
#treecard:fullscreen { background: #fff; padding: 8px; }
#treecard:fullscreen #tree { height: calc(100vh - 16px); }
.edge-label {
  paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round;
  pointer-events: none; font-size: 11px;
}
.node-label {
  paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round;
  pointer-events: none; font-size: 14px;
}

.field-check { flex-direction: row; align-items: center; gap: 8px; }
.field-check input { width: auto; margin: 0; }

/* Logout button trên thanh tối: tăng tương phản */
.topbar .btn-ghost {
  color: #e5e7eb;
  border-color: rgba(255, 255, 255, 0.4);
  background: transparent;
}
.topbar .btn-ghost:hover {
  color: #ffffff;
  border-color: #ffffff;
  background: #374151;
}
.userbox .uname { color: #e5e7eb; text-decoration: none; }
.userbox .uname:hover { color: #ffffff; text-decoration: underline; }
