*{box-sizing:border-box;margin:0;padding:0}
body{font-family:"Segoe UI",Roboto,Arial,sans-serif;font-size:13px;color:#1f2937;background:#eef2f7;line-height:1.4}
a{color:#2563eb;text-decoration:none}
a:hover{text-decoration:underline}
button,input,select,textarea{font-family:inherit;font-size:inherit;color:inherit}
button{cursor:pointer}

.header{background:#0f172a;color:#fff;padding:10px 20px;display:flex;align-items:center;gap:14px;flex-wrap:wrap;position:sticky;top:0;z-index:100}
.header .logo{font-size:16px;font-weight:700;display:flex;align-items:center;gap:8px}
.header .ver{font-size:11px;background:#334155;padding:2px 7px;border-radius:10px;font-weight:400}
.header .company{color:#93c5fd;font-weight:600;flex:1;text-align:center}
.header .user-info{font-size:12.5px;color:#94a3b8;padding:5px 10px;background:#1e293b;border-radius:16px}
.header .btn-home{background:#2563eb;color:#fff;padding:6px 14px;border-radius:6px;font-size:12.5px;font-weight:600;text-decoration:none}
.header .btn-home:hover{background:#1d4ed8;text-decoration:none}

.nav-tabs{background:#1e293b;display:flex;padding:0 14px;overflow-x:auto;position:sticky;top:56px;z-index:99}
.nav-btn{background:transparent;border:0;color:#cbd5e1;padding:11px 18px;font-size:13.5px;border-bottom:3px solid transparent;white-space:nowrap;text-decoration:none;display:inline-block}
.nav-btn:hover{color:#fff;background:#334155;text-decoration:none}
.nav-btn.active{color:#fff;border-bottom-color:#60a5fa;background:#0f172a}

main{padding:16px 20px 80px;max-width:1600px;margin:0 auto}

.card{background:#fff;border:1px solid #e5e7eb;border-radius:8px;padding:16px;margin-bottom:14px;box-shadow:0 1px 3px rgba(0,0,0,.04)}
.card-head{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;margin-bottom:12px}
.card-head h2{font-size:14.5px;text-transform:uppercase;letter-spacing:.4px;color:#334155}

.btn{padding:7px 14px;border-radius:6px;border:1px solid #d1d5db;background:#fff;font-weight:500;font-size:13px;display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:inherit;cursor:pointer}
.btn:hover{background:#f9fafb;text-decoration:none}
.btn.primary{background:#2563eb;border-color:#2563eb;color:#fff}
.btn.primary:hover{background:#1d4ed8}
.btn.green{background:#16a34a;border-color:#16a34a;color:#fff}
.btn.green:hover{background:#15803d}
.btn.red{background:#fee2e2;border-color:#fecaca;color:#dc2626}
.btn.sm{padding:5px 11px;font-size:12px}
.btn.full{width:100%;justify-content:center;margin-top:14px}

.home-hero{background:linear-gradient(135deg,#1e3a8a,#2563eb);color:#fff;padding:28px 24px;border-radius:10px;margin-bottom:18px}
.home-hero h2{font-size:24px;font-weight:700;margin-bottom:8px}
.home-hero p{font-size:13.5px;color:#bfdbfe}

.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:12px;margin-bottom:14px}
.kpi{background:#fff;border:1px solid #e5e7eb;border-radius:8px;padding:14px 16px;border-left:4px solid #3b82f6}
.kpi .lbl{font-size:11.5px;color:#6b7280;text-transform:uppercase;letter-spacing:.4px;font-weight:700}
.kpi .val{font-size:21px;font-weight:700;margin-top:4px;font-variant-numeric:tabular-nums}
.kpi.g{border-left-color:#16a34a}.kpi.r{border-left-color:#dc2626}
.kpi.w{border-left-color:#d97706}.kpi.p{border-left-color:#8b5cf6}

table{width:100%;border-collapse:collapse;font-size:12.5px}
thead th{background:#e8f0e4;color:#374151;font-weight:600;text-align:left;padding:9px 8px;border-bottom:1px solid #d1d5db;white-space:nowrap;font-size:12px}
tbody td{padding:6px 8px;border-bottom:1px solid #f3f4f6;vertical-align:middle}
tbody tr:hover{background:#fafbfc}
td.num,th.num{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
tfoot td{padding:9px 10px;font-weight:700;background:#f9fafb;border-top:1px solid #e5e7eb;font-variant-numeric:tabular-nums}
.table-wrap{overflow:auto;border:1px solid #e5e7eb;border-radius:6px;background:#fff}
.empty{padding:30px;text-align:center;color:#9ca3af;font-style:italic}

.field{margin-bottom:10px}
.field label{display:block;font-size:12px;color:#374151;margin-bottom:4px;font-weight:500}
.field input,.field select,.field textarea{width:100%;padding:6px 10px;border:1px solid #d1d5db;border-radius:5px;font-size:13px;outline:none;background:#fff;height:32px}
.field input:focus,.field select:focus{border-color:#3b82f6;box-shadow:0 0 0 2px rgba(59,130,246,.12)}
.filter-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:12px;padding:10px;background:#f9fafb;border-radius:6px}
.filter-bar input,.filter-bar select{padding:6px 10px;border:1px solid #d1d5db;border-radius:5px;font-size:13px}

.grid2{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.grid3{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}
.grid4{display:grid;grid-template-columns:repeat(4,1fr);gap:12px}
@media(max-width:900px){.grid2,.grid3,.grid4{grid-template-columns:1fr 1fr}}
@media(max-width:600px){.grid2,.grid3,.grid4{grid-template-columns:1fr}}

.badge{display:inline-block;padding:2px 8px;border-radius:20px;font-size:11px;font-weight:700;background:#e2e8f0;color:#334155}
.badge.ok{background:#dcfce7;color:#166534}
.badge.err{background:#fee2e2;color:#991b1b}
.badge.blue{background:#dbeafe;color:#1e40af}
.badge.warn{background:#fef3c7;color:#92400e}
.badge.purple{background:#f3e8ff;color:#6b21a8}

/* Tab con khu vực Danh mục */
.sub-tabs{display:flex;gap:6px;flex-wrap:wrap;margin:-4px 0 14px;padding:8px;background:#fff;border:1px solid #e5e7eb;border-radius:8px}
.sub-tab{padding:6px 14px;border-radius:20px;background:#f1f5f9;color:#334155;font-size:12.5px;font-weight:600;text-decoration:none;border:1px solid transparent;white-space:nowrap}
.sub-tab:hover{background:#e2e8f0;text-decoration:none}
.sub-tab.active{background:#2563eb;color:#fff;border-color:#1d4ed8}
/* Tab con cấp 2 (nằm TRONG khu vực Công trình) — nhỏ, nền xanh nhạt để phân biệt cấp */
.sub-tabs.inner{margin:-8px 0 14px;padding:6px 8px;background:#f0f9ff;border-color:#bae6fd}
.sub-tabs.inner .sub-tab{background:#fff;border-color:#dbeafe;font-size:12px;padding:5px 12px}
.sub-tabs.inner .sub-tab:hover{background:#e0f2fe}
.sub-tabs.inner .sub-tab.active{background:#0369a1;border-color:#075985;color:#fff}

/* Nhập / xuất hàng loạt danh mục */
.bulk-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:12px;padding:10px 12px;background:#f0f9ff;border:1px solid #bae6fd;border-radius:8px}
.bulk-bar form{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin:0}
.bulk-bar input[type=file]{font-size:12.5px;max-width:260px}
.bulk-help{background:#fffbeb;border:1px solid #fde68a;border-radius:8px;padding:12px 14px;margin-bottom:12px;font-size:12.5px;line-height:1.7;color:#78350f}
.bulk-help code{background:#fff;padding:1px 6px;border-radius:3px;border:1px solid #e5e7eb;color:#1f2937}
.bulk-help table{background:#fff}
.bulk-err{max-height:320px;overflow:auto;font-family:Consolas,monospace;font-size:12px;line-height:1.6;background:#fef2f2;border:1px solid #fecaca;border-radius:6px;padding:10px 12px;margin-bottom:12px;color:#7f1d1d}
.bulk-warn{max-height:260px;overflow:auto;font-family:Consolas,monospace;font-size:12px;line-height:1.6;background:#fffbeb;border:1px solid #fde68a;border-radius:6px;padding:10px 12px;margin-bottom:12px;color:#78350f}
.bulk-warn code{background:#fff;padding:1px 5px;border-radius:3px;border:1px solid #e5e7eb}

/* Cây tài khoản (phân cấp 1,2,3...) */
.acc-indent{display:inline-block}
.tree-line{color:#94a3b8;font-family:Consolas,monospace}
.lvl-tag{display:inline-block;min-width:20px;padding:1px 6px;border-radius:10px;font-size:11px;font-weight:700;background:#e2e8f0;color:#475569}
.lvl-tag.lv1{background:#dbeafe;color:#1e40af}
.lvl-tag.lv2{background:#dcfce7;color:#166534}
.lvl-tag.lv3{background:#fef3c7;color:#92400e}
.lvl-tag.lv4{background:#f3e8ff;color:#6b21a8}
tbody tr.off td{opacity:.55;font-style:italic}
.stat-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:10px}
.hint-line{display:block;margin-top:4px;color:#6b7280;font-size:11.5px;font-style:italic}

.alert{padding:10px 14px;border-radius:6px;margin-bottom:12px;font-weight:500}
.alert.success{background:#dcfce7;color:#166534;border:1px solid #86efac}
.alert.error{background:#fee2e2;color:#991b1b;border:1px solid #fecaca}

.modal{position:fixed;inset:0;background:rgba(15,23,42,.65);display:none;align-items:center;justify-content:center;z-index:3000;padding:20px}
.modal.show{display:flex}
.modal-box{background:#fff;border-radius:10px;padding:22px;width:100%;max-width:520px;max-height:90vh;overflow:auto}
.modal-box.wide{max-width:760px}
.modal-box h3{font-size:17px;margin-bottom:12px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.modal-box .row{display:flex;gap:10px;justify-content:flex-end;margin-top:16px}
.modal-box .grid2,.modal-box .grid3{display:grid;gap:10px}
.modal-box .grid2{grid-template-columns:1fr 1fr}
.modal-box .grid3{grid-template-columns:1fr 1fr 1fr}

/* Login */
body.login-page{background:linear-gradient(135deg,#1e3a8a,#2563eb);min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}
.login-box{background:#fff;padding:32px;border-radius:12px;width:100%;max-width:400px;box-shadow:0 20px 60px rgba(0,0,0,.3)}
.login-box h1{font-size:22px;color:#1e40af;text-align:center;margin-bottom:4px}
.login-box .sub{text-align:center;color:#6b7280;font-size:13px;margin-bottom:20px}
.login-box label{display:block;margin:12px 0 4px;font-size:12.5px;font-weight:600;color:#374151}
.login-box input{width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:6px;font-size:14px}
.login-box .hint{text-align:center;color:#9ca3af;font-size:12px;margin-top:12px}

.float-home{position:fixed;bottom:22px;left:22px;width:48px;height:48px;border-radius:50%;background:#2563eb;color:#fff;border:0;font-size:20px;box-shadow:0 4px 14px rgba(37,99,235,.4);z-index:999;cursor:pointer}
.float-home:hover{background:#1d4ed8}

/* Voucher */
.v-head{background:#fff;border:1px solid #e5e7eb;border-radius:8px 8px 0 0;padding:12px 18px;display:flex;align-items:center;gap:12px;flex-wrap:wrap;border-bottom:0}
.v-head h3{font-size:15.5px;font-weight:700;white-space:nowrap}
.v-head .type-sel{background:#f9fafb;border:1px solid #e5e7eb;border-radius:5px;padding:5px 10px;min-width:280px}
.v-head .type-sel select{border:0;background:transparent;width:100%;outline:none;height:auto;padding:0}
.v-body{background:#fff;border:1px solid #e5e7eb;border-top:0;border-radius:0 0 8px 8px;padding:16px 18px}
.v-grid{display:grid;grid-template-columns:1.15fr 1.35fr 1fr;gap:12px 20px}
.v-tbl{margin-top:12px;border:1px solid #e5e7eb;border-radius:6px;overflow:auto;background:#fff}
.v-tbl input,.v-tbl select{width:100%;border:1px solid transparent;background:transparent;padding:4px 6px;font-size:12.5px;border-radius:3px;height:auto}
.v-tbl input:focus,.v-tbl select:focus{border-color:#3b82f6;background:#fff;box-shadow:0 0 0 2px rgba(59,130,246,.12)}
.v-foot{display:flex;gap:10px;padding:12px 18px;background:#fff;border:1px solid #e5e7eb;border-radius:8px;margin-top:12px;flex-wrap:wrap;align-items:center}
.row-num{width:22px;height:22px;border-radius:50%;background:#3b82f6;color:#fff;display:inline-flex;align-items:center;justify-content:center;font-size:11px;font-weight:600}
.btn-del-row{color:#dc2626;border:0;background:transparent;font-size:14px;padding:3px 8px;border-radius:4px;cursor:pointer}
.btn-del-row:hover{background:#fef2f2}
.btn-edit-row{color:#2563eb;border:0;background:transparent;font-size:14px;padding:3px 8px;border-radius:4px;cursor:pointer;text-decoration:none;display:inline-block}
.btn-edit-row:hover{background:#eff6ff;text-decoration:none}

/* ============================================================
 * QUẢN LÝ HỢP ĐỒNG
 * ============================================================ */
.ct-back{margin:-4px 0 10px}
.ct-back a{font-size:12.5px;color:#2563eb;text-decoration:none;font-weight:600}
.ct-back a:hover{text-decoration:underline}
/* Dòng thông tin công trình đang sửa (không còn ô chọn công trình trong tab) */
.ct-projbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;background:#f0f9ff;border:1px solid #bae6fd;
            border-radius:8px;padding:8px 12px;margin-bottom:12px;font-size:13px;color:#0f172a}
.ct-projbar-lbl{font-weight:600;color:#075985}
.ct-section{font-weight:700;font-size:13.5px;color:#1e293b;margin:6px 0 10px;padding-bottom:4px;border-bottom:1px solid #e5e7eb}
.ct-split{display:grid;grid-template-columns:minmax(0,2.2fr) minmax(260px,1fr);gap:16px;align-items:start}
.ct-split-main{min-width:0}
.ct-split-side{min-width:0}
.ct-panel{background:#f9fafb;border:1px solid #e5e7eb;border-radius:8px;padding:12px 14px}
.ct-panel h4{font-size:13.5px;font-weight:700;margin-bottom:10px;color:#1e293b}
.ct-total td{background:#f1f5f9;border-top:2px solid #cbd5e1}
.ct-addrow td{background:#f0f9ff;border-top:2px solid #bae6fd}
.ct-addrow input{width:100%;padding:5px 8px;border:1px solid #d1d5db;border-radius:5px;font-size:12.5px;height:30px}
.ct-wrap{white-space:normal;max-width:420px;font-size:12.5px;line-height:1.5}
.field textarea{height:auto;min-height:62px;resize:vertical;line-height:1.5}
.field input.ro,.field input[readonly]{background:#f3f4f6;color:#374151}

/* Ô ngày/ngày giờ kiểu Việt Nam (gõ tay dd/mm/yyyy) — xem date_field() */
.dt-wrap{position:relative;display:block}
.dt-wrap .dt-text{padding-right:34px}
.dt-wrap .dt-pick{position:absolute;right:8px;bottom:6px;width:1px;height:1px;opacity:0;border:0;padding:0;margin:0;pointer-events:none}
.dt-wrap .dt-btn{position:absolute;right:4px;top:50%;transform:translateY(-50%);border:0;background:transparent;
                 cursor:pointer;font-size:15px;line-height:1;padding:2px 4px;border-radius:4px}
.dt-wrap .dt-btn:hover{background:#eff6ff}
.dt-wrap .dt-btn:disabled{opacity:.4;cursor:not-allowed}
.field input.dt-bad{border-color:#dc2626;background:#fef2f2}
.field input.money,.ct-addrow input.money{text-align:right;font-variant-numeric:tabular-nums}
table td.num input.money{text-align:right}
@media(max-width:1000px){.ct-split{grid-template-columns:1fr}}

@media print{
  .header,.nav-tabs,.v-head,.v-foot,.float-home,.no-print,.filter-bar{display:none!important}
  body{background:#fff;padding:0}
  .card,.v-body{box-shadow:none;border:0;padding:0}
  .table-wrap{max-height:none;border:0}
  main{padding:0;max-width:none}
}