:root {
  --color-primary: #1d4ed8;
  --color-primary-dark: #1e3a8a;
  --color-accent: #ea580c;
  --color-bg: #f5f7fb;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-green: #16a34a;
  --color-green-bg: #dcfce7;
  --color-red: #dc2626;
  --color-red-bg: #fee2e2;
  --color-amber: #d97706;
  --color-amber-bg: #fef3c7;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --max-width: 980px;
}

* { box-sizing: border-box; }

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

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

/* ============ Nav ============ */
header.topnav {
  background: var(--color-primary-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.topnav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  gap: 8px;
}
.brand {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}
.brand small { display: block; font-weight: 400; font-size: 11px; opacity: 0.8; }
nav.nav-links {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
nav.nav-links a {
  color: #dbe4ff;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  white-space: nowrap;
}
nav.nav-links a.active, nav.nav-links a:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
  text-decoration: none;
}
.hamburger {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
}

@media (max-width: 720px) {
  nav.nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    padding-top: 8px;
  }
  nav.nav-links.open { display: flex; }
  .topnav-inner { flex-wrap: wrap; }
  .hamburger { display: block; }
}

/* ============ Layout ============ */
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
}
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
h1 { font-size: 22px; margin: 4px 0 6px; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p.muted, .muted { color: var(--color-text-muted); font-size: 14px; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
  min-height: 44px;
}
.btn:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--color-primary); border-color: var(--color-primary); }
.btn.secondary:hover { background: #eef2ff; }
.btn.accent { background: var(--color-accent); }
.btn.accent:hover { background: #c2410c; }
.btn.ghost { background: transparent; color: var(--color-text-muted); border-color: var(--color-border); }
.btn.danger { background: var(--color-red); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }

/* Nút upload file lớn, dễ bấm trên di động */
.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  border: 2px dashed var(--color-primary);
  border-radius: var(--radius);
  color: var(--color-primary);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  background: #f0f5ff;
  width: 100%;
  text-align: center;
}
.upload-btn input[type="file"] { display: none; }
.upload-btn:active { background: #dbe6ff; }

/* ============ Forms ============ */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; color: var(--color-text); }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--color-text-muted); margin-top: 3px; }
input[type="text"], input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--color-text);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--color-primary); outline-offset: 1px; }
.radio-row { display: flex; gap: 16px; align-items: center; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-weight: 500; margin: 0; }
.field.invalid input, .field.invalid textarea, .field.invalid select { border-color: var(--color-red); background: #fff5f5; }
.field-error { color: var(--color-red); font-size: 12px; margin-top: 4px; display: none; }
.field.invalid .field-error { display: block; }

/* ============ Badges ============ */
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.pv, .badge.completed, .badge.ok { background: var(--color-green-bg); color: var(--color-green); }
.badge.no-pv, .badge.draft { background: #f1f5f9; color: var(--color-text-muted); }
.badge.over { background: var(--color-red-bg); color: var(--color-red); }
.badge.under { background: var(--color-amber-bg); color: var(--color-amber); }
.badge.unprocessed { background: var(--color-red-bg); color: var(--color-red); }
.badge.processed { background: var(--color-green-bg); color: var(--color-green); }

/* ============ Stat tiles ============ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat-tile .num { font-size: 26px; font-weight: 800; color: var(--color-primary-dark); }
.stat-tile.highlight .num { color: var(--color-accent); }
.stat-tile .label { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

/* ============ Tables (responsive -> cards on mobile) ============ */
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th, table.data-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
table.data-table th { color: var(--color-text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }

@media (max-width: 680px) {
  table.data-table thead { display: none; }
  table.data-table, table.data-table tbody, table.data-table tr, table.data-table td { display: block; width: 100%; }
  table.data-table tr {
    border: 1px solid var(--color-border);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 8px 10px;
    background: #fff;
  }
  table.data-table td {
    border-bottom: none;
    padding: 5px 0;
    display: flex;
    justify-content: space-between;
    gap: 10px;
  }
  table.data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 12px;
    flex-shrink: 0;
  }
}

/* toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background-color: #cbd5e1; transition: .2s; border-radius: 999px;
}
.switch .slider::before {
  position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px;
  background-color: #fff; transition: .2s; border-radius: 50%;
}
.switch input:checked + .slider { background-color: var(--color-green); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* file chip list */
.file-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li {
  display: flex; flex-direction: column; gap: 6px;
  background: #f1f5f9; border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.file-list li a { word-break: break-all; margin-right: 8px; }
.file-item-main { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.file-mota {
  width: 100%; border: 1px solid var(--color-border); border-radius: 6px;
  padding: 6px 8px; font-size: 12.5px; background: #fff; font-family: inherit;
}
.file-mota::placeholder { color: #94a3b8; }

.section-divider { border: none; border-top: 1px solid var(--color-border); margin: 18px 0; }

.flex-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.toast.error { background: var(--color-red); }
.toast.success { background: var(--color-green); }

footer.pagefooter {
  text-align: center; color: var(--color-text-muted); font-size: 12px; padding: 24px 16px 40px;
}

.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.quick-link-card {
  display: block; background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); color: var(--color-text);
}
.quick-link-card:hover { border-color: var(--color-primary); text-decoration: none; }
.quick-link-card .icon { font-size: 26px; }
.quick-link-card h3 { margin: 8px 0 4px; color: var(--color-primary-dark); }

.deadline-banner {
  background: linear-gradient(90deg, #fff7ed, #fef2f2);
  border: 1px solid #fed7aa;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 16px;
}
.deadline-banner b { color: var(--color-accent); }

.checkbox-cell { width: 28px; }

.pill-filter {
  display: inline-flex; gap: 6px; flex-wrap: wrap;
}
.pill-filter button {
  border: 1px solid var(--color-border); background: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.pill-filter button.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.empty-state { text-align: center; color: var(--color-text-muted); padding: 24px 12px; font-size: 14px; }

/* banner bao co ban cap nhat moi, dinh o day trang */
.update-banner {
  position: sticky; top: 0; z-index: 60;
  background: var(--color-accent); color: #fff;
  padding: 10px 16px; text-align: center; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
}
.update-banner button {
  background: #fff; color: var(--color-accent); border: none; border-radius: 8px;
  padding: 6px 14px; font-weight: 700; cursor: pointer; font-size: 13px;
}
.update-banner button:hover { background: #fff7ed; }

/* 3 khoi Truoc/Trong/Sau phong van xep doc, mau nen khac nhau de lam 1 mach tu tren xuong */
.phase-panel {
  border-radius: var(--radius);
  padding: 16px 16px 4px;
  margin-bottom: 18px;
  border: 1px solid var(--color-border);
}
.phase-panel[data-phase="truoc"] { background: #eff6ff; border-color: #bfdbfe; }
.phase-panel[data-phase="trong"] { background: #fffbeb; border-color: #fde68a; }
.phase-panel[data-phase="sau"] { background: #f0fdf4; border-color: #bbf7d0; }
.phase-panel > h3:first-child { margin-top: 0; }

/* thanh pill dinh tren, bam la cuon toi dung khoi mau tuong ung */
#phase-tabs { position: sticky; top: 54px; z-index: 40; background: var(--color-bg); padding: 6px 0; }

/* main rộng hơn cho trang chọn đơn vị (lưới nhiều cột) */
main.wide { max-width: 1180px; }

/* lưới chọn đơn vị — 2-3 cột thay vì bảng 1 cột */
.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 10px;
}
.unit-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  min-height: 56px;
}
.unit-card .unit-info { min-width: 0; }
.unit-card .unit-name { font-size: 14px; font-weight: 600; line-height: 1.3; }
.unit-card .unit-parent { font-size: 11.5px; color: var(--color-text-muted); margin-top: 2px; }
.unit-card .unit-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.unit-card .badge { white-space: nowrap; }

@media (max-width: 560px) {
  .unit-grid { grid-template-columns: 1fr; }
}

/* gan Chinh/Thu ky ngay tren the don vi (tab Chon don vi khao sat) */
.unit-card { flex-wrap: wrap; }
.unit-assign {
  width: 100%; display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--color-border);
}
.unit-assign label {
  display: flex; align-items: center; gap: 4px; font-size: 11.5px;
  font-weight: 600; color: var(--color-text-muted); margin: 0; flex: 1; min-width: 110px;
}
.unit-assign select.assign-select {
  font-size: 12px; padding: 4px 6px; border-radius: 6px;
  border: 1px solid var(--color-border); background: #fff; flex: 1; min-width: 0;
}

/* ma trận trạng thái biên bản: xám = chưa làm, vàng = đang nháp, xanh = hoàn thành */
.unit-card.status-yellow { border-color: var(--color-amber); background: var(--color-amber-bg); }
.unit-card.status-green { border-color: var(--color-green); background: var(--color-green-bg); }

/* pill bấm thẳng vào ma trận đơn vị (tab Khảo sát) — cả thẻ là 1 nút bấm */
.unit-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  padding: 10px 16px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  transition: transform .1s, box-shadow .1s;
}
.unit-pill:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.unit-pill:active { transform: translateY(0); }
.unit-pill-name { font-size: 14px; font-weight: 700; color: var(--color-text); }
.unit-pill-parent { font-size: 11.5px; color: var(--color-text-muted); }
.unit-pill.status-yellow { border-color: var(--color-amber); background: var(--color-amber-bg); }
.unit-pill.status-yellow .unit-pill-name { color: #92400e; }
.unit-pill.status-green { border-color: var(--color-green); background: var(--color-green-bg); }
.unit-pill.status-green .unit-pill-name { color: #14532d; }
.legend-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 4px; vertical-align: middle;
}
.legend-dot.gray { background: #cbd5e1; }
.legend-dot.yellow { background: var(--color-amber); }
.legend-dot.green { background: var(--color-green); }

/* đăng nhập inline trong 1 card */
.login-box { max-width: 320px; }
.login-box .field { margin-bottom: 10px; }

/* người đang đăng nhập, hiện trong nav */
.nav-user {
  display: flex; align-items: center; gap: 8px;
  color: #dbe4ff; font-size: 13px; margin-left: 8px;
}
.nav-user .btn.ghost { color: #dbe4ff; border-color: rgba(255,255,255,0.4); min-height: 30px; padding: 4px 10px; }
.nav-user .btn.ghost:hover { background: rgba(255,255,255,0.1); }
@media (max-width: 720px) {
  .nav-user { margin: 8px 0 0; }
}
