:root {
  --hd-blue: #123885;
  --hd-blue-dark: #0e2c68;
  --hd-teal: #12897d;
  --hd-bg: #f4f6f9;
  --hd-card: #ffffff;
  --hd-text: #1c2733;
  --hd-muted: #6b7785;
  --hd-border: #e2e7ee;
  --hd-danger: #c0392b;
  --hd-success: #1e8e5a;
  --hd-radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-height: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--hd-bg);
  color: var(--hd-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--hd-blue); text-decoration: none; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--hd-blue);
  color: #fff;
  padding: 14px 16px;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  box-sizing: border-box;
}

.app-header .brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.2px;
}
.app-header .brand small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  opacity: 0.85;
}

.app-header button.link-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(90px + var(--safe-bottom));
}

.container.narrow { max-width: 420px; }

.container.wide { max-width: 1180px; }
@media (min-width: 900px) {
  .container.wide { padding-left: 32px; padding-right: 32px; }
  .container.wide .card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
  .container.wide .card-grid > .card { margin-bottom: 0; }
}

/* Admin pages: fill the whole screen width instead of centering with a cap */
.container.full { max-width: none; }
@media (min-width: 900px) {
  .container.full { padding-left: 28px; padding-right: 28px; }
}

.split-layout { display: flex; gap: 16px; align-items: flex-start; }
.split-left { flex: 0 0 360px; }
.split-left .card { margin-bottom: 14px; }
.split-right {
  flex: 1;
  min-width: 0;
  max-height: calc(100vh - 230px);
  overflow-y: auto;
  padding-right: 6px;
}
.split-folder-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
}
.split-folder-item:hover { background: #f4f6f9; }
.split-folder-item.active { background: #e3ecf6; border-color: var(--hd-blue); color: var(--hd-blue-dark); font-weight: 600; }
@media (max-width: 860px) {
  .split-layout { flex-direction: column; }
  .split-left { width: 100%; flex: none; }
  .split-right { max-height: none; overflow-y: visible; padding-right: 0; }
}

.split-3col { display: flex; gap: 16px; align-items: flex-start; }
.split-3col > .split-col {
  flex: 1;
  min-width: 0;
  max-height: calc(100vh - 230px);
  overflow-y: auto;
  padding-right: 6px;
}
.split-3col > .split-col:first-child { flex: 0 0 320px; }
.split-3col > .split-col > h4 { margin-top: 0; }
@media (max-width: 1100px) {
  .split-3col { flex-direction: column; }
  .split-3col > .split-col { width: 100%; flex: none; max-height: none; overflow-y: visible; padding-right: 0; }
}

.center-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--hd-card);
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(20,30,50,0.04);
}

.card h2, .card h3 { margin-top: 0; }

.stack { display: flex; flex-direction: column; gap: 10px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 6px;
  color: var(--hd-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--hd-border);
  border-radius: 10px;
  font-size: 16px;
  background: #fff;
  color: var(--hd-text);
}

textarea { min-height: 80px; resize: vertical; }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--hd-blue);
  color: #fff;
  width: 100%;
}
button:active { background: var(--hd-blue-dark); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary { background: #e9eef5; color: var(--hd-blue); }
.btn-danger { background: var(--hd-danger); }
.btn-outline { background: transparent; color: var(--hd-blue); border: 1px solid var(--hd-blue); }
.btn-sm { padding: 8px 12px; font-size: 13px; width: auto; }
.btn-block-group { display: flex; gap: 10px; }

.muted { color: var(--hd-muted); font-size: 13px; }
.error-text { color: var(--hd-danger); font-size: 13px; margin-top: 8px; }
.success-text { color: var(--hd-success); font-size: 13px; margin-top: 8px; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #e3ecf6;
  color: var(--hd-blue);
}
.badge.level-1 { background: #fdecea; color: #c0392b; }
.badge.level-2 { background: #fdf3e3; color: #b9770e; }
.badge.level-3 { background: #eef7e6; color: #4c8a2c; }
.badge.level-4 { background: #e3f2ee; color: #12897d; }
.badge.level-5 { background: #e9e3f7; color: #5b3fa6; }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--hd-border);
  gap: 10px;
}
.list-item:last-child { border-bottom: none; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--hd-border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 10px 4px 8px;
  font-size: 12px;
  color: var(--hd-muted);
  font-weight: 600;
}
.bottom-nav a.active { color: var(--hd-blue); }
.bottom-nav a .icon { display: block; font-size: 20px; margin-bottom: 2px; }

.progress-bar {
  height: 8px;
  background: var(--hd-border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}
.progress-bar > div {
  height: 100%;
  background: var(--hd-teal);
  transition: width 0.25s ease;
}

.option-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--hd-border);
  background: #fff;
  color: var(--hd-text);
  font-size: 15px;
  margin-bottom: 10px;
  font-weight: 500;
}
.option-btn.selected {
  border-color: var(--hd-blue);
  background: #eaf1fa;
  color: var(--hd-blue-dark);
}
.option-btn.correct { border-color: var(--hd-success); background: #eaf7f0; }
.option-btn.incorrect { border-color: var(--hd-danger); background: #fbeceb; }

.top-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  position: sticky;
  top: var(--header-height);
  z-index: 8;
  background: var(--hd-bg);
  padding: 10px 0;
}
.top-tabs a {
  padding: 8px 14px;
  border-radius: 999px;
  background: #e9eef5;
  color: var(--hd-blue);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.top-tabs a.active { background: var(--hd-blue); color: #fff; }

.sub-tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.sub-tabs a {
  padding: 8px 14px;
  border-radius: 999px;
  background: #e9eef5;
  color: var(--hd-blue);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.sub-tabs a.active { background: var(--hd-blue); color: #fff; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
tr.f-summary-row:hover { background: #eef1f6; }
tr.f-detail-row td { padding: 14px 12px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--hd-border); }
th { color: var(--hd-muted); font-size: 12px; text-transform: uppercase; }

tr.group-row td { font-size: 12px; padding: 10px 6px 6px; border-bottom: 2px solid var(--hd-text); }
tr.f-competency-row:hover td { border-bottom-color: var(--hd-text); }
tr.f-competency-row.active td { border-bottom: 2px solid var(--hd-text); font-weight: 600; }
#matrix-table { white-space: nowrap; }
#matrix-table td:nth-child(2), #matrix-table th:nth-child(2) { white-space: normal; min-width: 220px; }

.tests-3col > .split-col:nth-child(1) { flex: 0 0 250px; }
.tests-3col > .split-col:nth-child(2) { flex: 0 0 280px; }
.tests-3col > .split-col:nth-child(3) { flex: 1; min-width: 0; }

.test-list-item { padding: 7px 8px; margin-bottom: 1px; gap: 8px; }
.test-list-item .test-item-info { min-width: 0; }
.test-list-item .test-item-code { font-size: 10.5px; font-weight: 700; color: var(--hd-muted); letter-spacing: 0.3px; }
.test-list-item.active .test-item-code { color: var(--hd-blue); }
.test-list-item .test-item-name { font-size: 12.5px; }
.test-list-item .test-item-name .bi-en,
.test-list-item .test-item-name .bi-vi { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.test-list-item .test-item-name .bi-vi { font-size: 0.85em; }
.test-list-item .test-item-btn { padding: 4px 8px; font-size: 11px; flex: 0 0 auto; }

.test-level-sublist { margin: 0 0 4px 12px; padding-left: 8px; border-left: 2px solid var(--hd-border); }
.test-level-item { cursor: pointer; padding: 5px 8px; font-size: 11.5px; border-left: 2px solid transparent; color: var(--hd-muted); }
.test-level-item:hover { border-left-color: var(--hd-border); }
.test-level-item.active { border-left-color: var(--hd-blue); color: var(--hd-blue-dark); font-weight: 700; }

.org-row { padding: 6px 8px; font-size: 13px; cursor: pointer; border-left: 2px solid transparent; }
.org-row:hover { border-left-color: var(--hd-border); }
.org-row.active { border-left-color: var(--hd-blue); font-weight: 600; color: var(--hd-blue-dark); }
tr.jt-row.active td { border-bottom: 2px solid var(--hd-text); font-weight: 600; }

.level-question-group { margin-bottom: 6px; }
.level-group-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 4px 6px;
  border-bottom: 2px solid var(--hd-text);
  font-weight: 700;
  font-size: 13px;
  margin-top: 14px;
}
.level-question-group:first-child .level-group-header { margin-top: 0; }

#level-tree details { margin-bottom: 2px; }
#level-tree summary { cursor: pointer; padding: 6px 2px; font-size: 12px; font-weight: 700; list-style-position: outside; }
#level-tree details details summary { font-weight: 600; font-size: 12px; padding-left: 4px; }
#level-tree ul { list-style: none; margin: 0; padding-left: 16px; }
#level-tree .tree-leaf { cursor: pointer; padding: 5px 4px; font-size: 12.5px; border-left: 2px solid transparent; }
#level-tree .tree-leaf:hover { border-left-color: var(--hd-border); }
#level-tree .tree-leaf.active { border-left-color: var(--hd-blue); font-weight: 700; color: var(--hd-blue-dark); }
#level-tree .tree-onboarding { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--hd-border); }

.empty-state { text-align: center; padding: 40px 16px; color: var(--hd-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 8px; }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bi-en {
  display: block;
  font-weight: inherit;
}
.bi-vi {
  display: block;
  font-size: 0.8em;
  font-weight: 400;
  color: var(--hd-muted);
  line-height: 1.3;
}
button .bi-vi, .btn .bi-vi { color: rgba(255,255,255,0.75); }
button.btn-secondary .bi-vi, button.btn-outline .bi-vi { color: var(--hd-muted); }
.badge .bi-vi { color: inherit; opacity: 0.75; }
.bi-inline { display: inline; }
.bi-inline .bi-vi { display: inline; font-size: 0.85em; color: var(--hd-muted); }
.bi-inline .bi-vi::before { content: " / "; }

.no-copy { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.no-copy iframe { print-color-adjust: exact; }
@media print {
  .no-copy { display: none !important; }
}

.watermark-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-around;
  opacity: 0.16;
  transform: rotate(-25deg) scale(1.3);
  z-index: 5;
}
.watermark-overlay span {
  font-size: 12px;
  font-weight: 700;
  color: #000;
  text-align: center;
  white-space: nowrap;
  line-height: 1.3;
}

.logo-circle {
  width: 64px; height: 64px;
  border-radius: 18px;
  background: var(--hd-blue);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 800;
  margin: 0 auto 16px;
  object-fit: cover;
}
