/* ╔══════════════════════════════════════════════════════════════════════╗
   ║  LAYER 1 — GLOBAL LAYOUT                                             ║
   ║  Header · Tabs · Main · Section title                                ║
   ╚══════════════════════════════════════════════════════════════════════╝ */

/* ── 1.1 Header — gradient navy→teal với dải gradient 4 màu phía dưới ── */
header {
  position: relative;
  z-index: 20;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy2) 60%, var(--teal) 100%);
  padding: 0 var(--sp-xl);
  display: flex;
  align-items: center;
  gap: 16px;
  height: 72px;
  box-shadow: 0 4px 24px rgba(26,47,110,.25);
}
header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--teal2), var(--green));
}
.hdr-emblem {
  width: 56px; height: 56px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.hdr-emblem img { width: 100%; height: 100%; object-fit: contain; }
.hdr-text h1   { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: .05em; }
.hdr-text p    { font-size: 11px; color: rgba(255,255,255,.65); letter-spacing: .08em; margin-top: 2px; }
.hdr-badge {
  margin-left: auto;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 11px; color: rgba(255,255,255,.9); font-weight: 600;
  display: flex; align-items: center; gap: 7px; letter-spacing: .06em;
}
.dot-live {
  width: 7px; height: 7px; border-radius: 50%;
  background: #06d6a0; box-shadow: 0 0 8px #06d6a0;
  animation: blink 2s infinite;
}

/* ── 1.2 Tabs bar ── */
.tabs-bar {
  position: relative; z-index: 15;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 0 24px;
  display: flex; gap: 2px;
  box-shadow: 0 2px 12px var(--shadow);
}
.tab-btn {
  padding: 13px 20px;
  border: none; background: transparent;
  color: var(--text2);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; position: relative;
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap; transition: color .2s;
}
.tab-btn:hover  { color: var(--navy); }
.tab-btn.active { color: var(--navy); font-weight: 700; }
.tab-btn.active::after {
  content: ''; position: absolute; bottom: -2px; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--teal), var(--navy2));
  border-radius: 2px 2px 0 0;
}
.tab-count {
  background: var(--navy); color: #fff;
  border-radius: 10px; padding: 1px 8px;
  font-size: 10px; font-family: 'Space Mono', monospace; font-weight: 700;
  display: none;
}

/* ── 1.3 Main container ── */
main {
  position: relative; z-index: 5;
  max-width: 1600px; margin: 0 auto;
  padding: var(--sp-lg) var(--sp-lg) 48px;
}
.tab-panel        { display: none; }
.tab-panel.active { display: block; animation: fadeUp .3s ease; }

/* ── 1.4 Section title ── */
.sec-title {
  font-size: 11px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--text3); margin-bottom: 14px;
  display: flex; align-items: center; gap: 10px;
}
.sec-title::before {
  content: ''; width: 3px; height: 14px;
  background: linear-gradient(var(--teal), var(--navy));
  border-radius: 2px;
}
.sec-title::after  {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ╔══════════════════════════════════════════════════════════════════════╗
   ║  LAYER 2 — SHARED COMPONENTS                                         ║
   ╚══════════════════════════════════════════════════════════════════════╝ */

/* ── 2.1 Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 2px 16px var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  flex-wrap: wrap;
}
.card-header h3 { font-size: 13px; font-weight: 700; color: var(--navy); }
.card-body      { padding: 18px; }

/* ── 2.2 Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge-red    { background: rgba(230,57,70,.12);  border: 1px solid rgba(230,57,70,.35);  color: #c0392b; }
.badge-orange { background: rgba(244,162,97,.15); border: 1px solid rgba(244,162,97,.4);  color: #d35400; }
.badge-gold   { background: rgba(249,199,79,.2);  border: 1px solid rgba(249,199,79,.5);  color: #7a5000; }
.badge-blue   { background: rgba(0,119,182,.1);   border: 1px solid rgba(0,119,182,.3);   color: var(--teal); }
.badge-green  { background: rgba(6,214,160,.12);  border: 1px solid rgba(6,214,160,.35);  color: var(--green2); }
.badge-gray   { background: rgba(138,148,166,.12);border: 1px solid rgba(138,148,166,.3); color: var(--text3); }
.badge-navy   { background: rgba(26,47,110,.1);   border: 1px solid rgba(26,47,110,.25);  color: var(--navy); }

/* ── 2.3 Stat cards ── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 20px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: 0 2px 10px var(--shadow);
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--shadow); }
.stat-ico  { font-size: 28px; }
.stat-num  { font-size: 26px; font-weight: 700; font-family: 'Space Mono', monospace; line-height: 1; color: var(--navy); }
.stat-lbl  { font-size: 11px; color: var(--text3); margin-top: 3px; text-transform: uppercase; letter-spacing: .05em; }

/* ── 2.4 Grids ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; }

/* ── 2.5 Form controls ── */
.btn {
  padding: 9px 18px;
  border: none; border-radius: var(--rs);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .2s;
  letter-spacing: .03em;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn-primary  { background: linear-gradient(135deg,var(--navy),var(--navy2)); color: #fff; box-shadow: 0 3px 12px rgba(26,47,110,.25); }
.btn-primary:hover  { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(26,47,110,.3); }
.btn-teal     { background: linear-gradient(135deg,var(--teal),var(--teal2)); color: #fff; box-shadow: 0 3px 12px rgba(0,119,182,.25); }
.btn-teal:hover     { transform: translateY(-1px); }
.btn-secondary{ background: var(--surface2); border: 1.5px solid var(--border); color: var(--text2); }
.btn-secondary:hover{ background: var(--bg2); border-color: var(--navy); }
.btn-danger   { background: rgba(230,57,70,.08); border: 1.5px solid rgba(230,57,70,.3); color: var(--accent); }
.btn-danger:hover   { background: rgba(230,57,70,.14); }
.btn-gold     { background: linear-gradient(135deg,var(--gold),#f9c74f); color: #7a3500; box-shadow: 0 3px 12px rgba(244,162,97,.35); }
.btn-success  { background: rgba(6,214,160,.1); border: 1.5px solid rgba(6,214,160,.35); color: var(--green2); }
.btn-success:hover  { background: rgba(6,214,160,.18); }
.btn-info     { background: rgba(0,119,182,.08); border: 1.5px solid rgba(0,119,182,.3); color: var(--teal); }
.btn-info:hover     { background: rgba(0,119,182,.14); }
.btn:disabled { opacity: .38; cursor: not-allowed; transform: none; }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], textarea, select {
  font-family: 'Lexend', sans-serif;
  font-size: 13px; color: var(--text);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--rs);
  padding: 9px 13px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0,119,182,.12);
}
input::placeholder, textarea::placeholder { color: var(--text3); }
textarea { resize: vertical; line-height: 1.7; min-height: 120px; }
select   { cursor: pointer; }

/* ── Search bar ── */
.search-wrap       { position: relative; }
.search-wrap input { width: 100%; padding-left: 42px; background: #fff; box-shadow: 0 2px 8px var(--shadow); }
.search-ico        { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); font-size: 17px; pointer-events: none; color: var(--text3); }

/* ── Radio pills ── */
.radio-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.radio-pills label {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--text2); cursor: pointer;
  padding: 6px 13px;
  border: 1.5px solid var(--border); border-radius: 20px;
  transition: all .2s; background: var(--surface2);
}
.radio-pills label:has(input:checked) {
  border-color: var(--teal); color: var(--teal);
  background: rgba(0,119,182,.07); font-weight: 600;
}
.radio-pills input { accent-color: var(--teal); }

/* ── Map row (cho UI ánh xạ cột nhập Excel) ── */
.map-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; flex-wrap: wrap; }
.map-lbl { font-size: 13px; color: var(--navy); font-weight: 600; min-width: 180px; }

/* ── 2.6 Upload zone ── */
.upload-zone {
  border: 2.5px dashed var(--border); border-radius: var(--rs);
  padding: 32px 20px; text-align: center; cursor: pointer;
  transition: all .25s; position: relative; background: var(--surface2);
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--teal); background: rgba(0,119,182,.05); }
.upload-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.upload-zone h4    { font-size: 13px; font-weight: 600; color: var(--navy); margin-bottom: 5px; }
.upload-zone p     { font-size: 12px; color: var(--text3); }
.upload-hint {
  margin-top: 10px; font-size: 11px; color: var(--teal);
  background: rgba(0,119,182,.07); border: 1px solid rgba(0,119,182,.2);
  border-radius: 6px; padding: 7px 12px; display: inline-block;
}
.upload-zone-btn {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 10px; padding: 10px 18px;
  background: linear-gradient(135deg, var(--teal) 0%, var(--navy2) 100%);
  color: #fff; border: none; border-radius: 8px; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600;
  box-shadow: 0 3px 10px rgba(0,119,182,.25);
  transition: transform .15s, box-shadow .15s; pointer-events: auto;
}
.upload-zone-btn:hover, .upload-zone-btn:active {
  transform: translateY(-1px); box-shadow: 0 5px 14px rgba(0,119,182,.35);
}

/* ── 2.7 Alerts ── */
.alert         { border-radius: var(--rs); padding: 10px 14px; display: flex; align-items: flex-start; gap: 10px; font-size: 13px; margin-bottom: 12px; }
.alert-info    { background: rgba(0,119,182,.08);   border: 1px solid rgba(0,119,182,.25);   color: var(--teal); }
.alert-warn    { background: rgba(244,162,97,.10);  border: 1px solid rgba(244,162,97,.35);  color: #c35a00; }
.alert-success { background: rgba(6,214,160,.10);   border: 1px solid rgba(6,214,160,.3);    color: var(--green2); }
.alert-error   { background: rgba(230,57,70,.08);   border: 1px solid rgba(230,57,70,.3);    color: var(--accent); }

/* ── 2.8 Progress ── */
.prog-bar  { height: 8px; background: var(--bg2); border-radius: 4px; overflow: hidden; margin-top: 10px; }
.prog-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg,var(--teal),var(--navy2)); transition: width .4s; }

/* ── 2.9 Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(26,47,110,.45);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--surface); border-radius: var(--r);
  width: 100%; max-width: 1100px; max-height: 90vh;
  box-shadow: 0 20px 60px rgba(26,47,110,.3);
  animation: scaleIn .25s ease;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  flex-shrink: 0; padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(135deg, var(--navy), var(--navy2)); color: #fff;
  border-radius: var(--r) var(--r) 0 0;
}
.modal-header h3 { font-size: 14px; font-weight: 700; }
.modal-close {
  background: rgba(255,255,255,.15); border: none; border-radius: 50%;
  width: 28px; height: 28px; cursor: pointer; font-size: 15px; color: #fff;
  display: flex; align-items: center; justify-content: center; transition: background .2s;
}
.modal-close:hover { background: rgba(255,255,255,.28); }
.modal-input-panel {
  flex-shrink: 0; padding: 18px 20px 14px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  box-shadow: 0 4px 14px -5px var(--shadow); z-index: 2;
}
.modal-results-panel { flex: 1; overflow-y: auto; padding: 18px 20px; }
.detail-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
.detail-key  { font-size: 12px; color: var(--text3); font-weight: 600; padding-top: 2px; }
.detail-val  { font-size: 12px; color: var(--text); word-break: break-word; }

/* ── 2.10 Toast ── */
#toast-box {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--rs); padding: 11px 16px;
  font-size: 13px; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 8px 24px var(--shadow);
  animation: slideIn .3s ease;
  max-width: 370px; color: var(--text);
}

/* ── 2.11 Pagination ── */
.pagination {
  display: flex; justify-content: center; align-items: center; gap: 6px;
  padding: 14px 8px; flex-wrap: wrap;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
.pagination button {
  min-width: 34px; height: 32px; padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 12px; font-weight: 500;
  border-radius: 6px; cursor: pointer; transition: all .15s;
}
.pagination button:hover:not(:disabled) { background: var(--bg2); border-color: var(--teal); }
.pagination button.active { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 700; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination .page-info { font-size: 12px; color: var(--text2); margin: 0 8px; font-family: 'Space Mono',monospace; }
.pagination select { height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font-family: inherit; font-size: 12px; cursor: pointer; }

/* ── 2.12 Highlight marks (cho kết quả tìm kiếm) ── */
mark.hl-exact {
  background: rgba(244,162,97,.55); color: #6b2e00;
  border-radius: 3px; padding: 0 2px; font-weight: 700;
  text-decoration: underline; text-decoration-color: #c76b00;
}
mark:not([class]) {
  background: rgba(244,162,97,.35); color: #6b2e00;
  border-radius: 3px; padding: 0 2px;
}
mark.hl-dash {
  background: rgba(0,180,216,.25); color: #003a5c;
  border-radius: 3px; padding: 0 2px; font-weight: 600;
  text-decoration: underline dotted #0077b6; text-underline-offset: 2px;
}
mark.hl-fuzzy {
  background: rgba(230,57,70,.18); color: #7a1020;
  border-radius: 3px; padding: 0 2px; font-weight: 700; font-style: italic;
  text-decoration: underline; text-decoration-style: dashed;
  text-decoration-color: #e63946; text-underline-offset: 2px;
}
mark.hl-nospace {
  background: rgba(6,214,160,.22); color: #054d3a;
  border-radius: 3px; padding: 0 2px; font-weight: 600;
  text-decoration: underline solid #06d6a0; text-underline-offset: 2px;
}

/* ── 2.13 Empty state ── */
.empty-st     { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty-st .ico{ font-size: 42px; margin-bottom: 12px; opacity: .4; }
.empty-st p   { font-size: 13px; }

/* ── 2.14 Filter pills ── */
.filter-pills       { display: flex; gap: 5px; flex-wrap: wrap; }
.filter-pills .btn  { padding: 5px 13px; font-size: 12px; border-radius: 20px; }

/* ── 2.15 Bảng chung ── */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table thead th {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy2) 100%);
  color: #fff; padding: 10px; text-align: left;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  position: sticky; top: 0; z-index: 2;
}
table tbody tr { border-bottom: 1px solid var(--border); transition: background .15s; }
table tbody tr:hover { background: rgba(0,119,182,.04); }
table tbody tr:nth-child(even) { background: rgba(240,244,255,.5); }
table tbody tr:nth-child(even):hover { background: rgba(0,119,182,.06); }
table tbody td {
  padding: 9px 10px; vertical-align: top;
  word-break: break-word; overflow-wrap: break-word; line-height: 1.5;
}

/* ── 2.16 Utilities ── */
.mb-16{margin-bottom:16px;} .mb-12{margin-bottom:12px;} .mt-14{margin-top:14px;}
.flex{display:flex;} .gap-8{gap:8px;} .gap-10{gap:10px;}
.items-center{align-items:center;} .justify-between{justify-content:space-between;}
.flex-wrap{flex-wrap:wrap;} .flex-1{flex:1;} .w-full{width:100%;}
.mono{font-family:'Space Mono',monospace;font-size:11.5px;}
.text-center{text-align:center;} .text-right{text-align:right;}
.hidden{display:none;}

/* ── Debug panel (dùng cho admin/developer xem chỉ số thuật toán) ── */
#debug-panel {
  display: none;
  position: fixed; right: 12px; bottom: 12px; z-index: 9000;
  width: 360px; max-height: 60vh;
  background: #0d1117; border: 1px solid #30363d; border-radius: 8px;
  font-family: 'Space Mono', monospace; font-size: 11px; color: #c9d1d9;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
#debug-panel.visible  { display: flex; flex-direction: column; }
#debug-panel .dp-head { padding: 8px 12px; background: #161b22; border-bottom: 1px solid #30363d; display: flex; justify-content: space-between; align-items: center; border-radius: 8px 8px 0 0; }
#debug-panel .dp-head strong { color: #58a6ff; font-size: 11px; }
#debug-panel .dp-close { background: transparent; border: none; color: #c9d1d9; cursor: pointer; font-size: 14px; }
#debug-panel .dp-body  { padding: 10px 12px; overflow-y: auto; flex: 1; line-height: 1.5; }
#debug-panel .dp-row   { margin-bottom: 4px; }
#debug-panel .dp-key   { color: #7ee787; }
#debug-panel .dp-val   { color: #ffa657; }
