* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: #f4f5f7;
    color: #1a1a1a;
}

#app-header {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 20px;
    background: #1e293b;
    color: #fff;
}
#app-header .brand { font-weight: bold; }
#app-header #app-nav { display: flex; gap: 16px; flex: 1; }
#app-header .nav-link { color: #cbd5e1; text-decoration: none; padding: 4px 8px; border-radius: 4px; }
#app-header .nav-link.active, #app-header .nav-link:hover { background: #334155; color: #fff; }
#app-header .user-box { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #cbd5e1; }
#app-header button { cursor: pointer; border: none; border-radius: 4px; padding: 6px 12px; background: #475569; color: #fff; }
#app-header button:hover { background: #64748b; }

#app-content { padding: 20px; max-width: 1100px; margin: 0 auto; }
/* GĐ23 — version frontend, chỉ hỗ trợ debug, không nổi bật */
#app-footer { padding: 8px 20px; font-size: 11px; color: #94a3b8; text-align: center; }
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

.card { background: #fff; border-radius: 8px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 16px; }
.card h2 { margin-top: 0; font-size: 18px; }
.card h3 { font-size: 15px; color: #475569; }

.page-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.page-toolbar h1 { font-size: 20px; margin: 0; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #e2e8f0; }
table.data-table th { background: #f1f5f9; font-weight: 600; }
table.data-table tr:hover td { background: #f8fafc; cursor: pointer; }

.form-row { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-size: 13px; font-weight: 600; color: #334155; }
.form-row input, .form-row select, .form-row textarea {
    padding: 8px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 14px;
}
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

button.btn { cursor: pointer; border: none; border-radius: 4px; padding: 8px 16px; font-size: 14px; background: #e2e8f0; }
button.btn.primary { background: #2563eb; color: #fff; }
button.btn.primary:hover { background: #1d4ed8; }
button.btn.danger { background: #dc2626; color: #fff; }
button.btn.danger:hover { background: #b91c1c; }
button.btn:hover { background: #cbd5e1; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.badge.draft { background: #e2e8f0; color: #334155; }
.badge.pending_approval { background: #fef3c7; color: #92400e; }
.badge.approved, .badge.active, .badge.available { background: #dcfce7; color: #166534; }
.badge.rejected { background: #fee2e2; color: #991b1b; }
.badge.superseded { background: #f1f5f9; color: #64748b; }
/* GĐ56 — trạng thái bộ giấy tờ trong kho (intake_item). */
.badge.queued { background: #fef3c7; color: #92400e; }
.badge.processing { background: #dbeafe; color: #1e40af; }
.badge.processed { background: #dcfce7; color: #166534; }
.badge.needs_review { background: #ffedd5; color: #9a3412; }
.badge.discarded { background: #f1f5f9; color: #64748b; }

.login-box { width: 340px; }
.login-box h1 { font-size: 22px; margin-bottom: 4px; }
.login-box p { color: #64748b; font-size: 13px; margin-top: 0; }

.item-row { display: flex; gap: 8px; margin-bottom: 8px; }
.item-row input { flex: 1; }

.file-list { list-style: none; padding: 0; margin: 8px 0; font-size: 13px; }
.file-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #eee; }

/* GĐ35 (xem plan/done/35_xoa_file_dinh_kem.md) — nút xóa 1 file đính kèm:
   nhẹ hơn .btn.danger (dành cho xóa cả 1 thực thể) vì đây là thao tác nhỏ,
   tần suất cao (gỡ file chọn nhầm), không nên gây cảm giác "nguy hiểm" quá mức. */
.file-remove-btn {
    background: transparent;
    border: 1px solid #cbd5e1;
    color: #64748b;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 12px;
    cursor: pointer;
}
.file-remove-btn:hover { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }

/* GĐ43 (xem plan/todo/43_giay_to_nhan_vien.md) — giấy tờ nhân viên: danh sách
   file chờ upload kèm metadata, và dòng file có metadata (nhiều dòng thông tin). */
.form-hint { font-size: 12px; color: #64748b; margin: 4px 0; }
.pending-file-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.pending-file-row { border: 1px solid #e2e8f0; border-radius: 6px; padding: 8px; background: #f8fafc; }
.pending-file-head { display: flex; align-items: center; gap: 8px; }
.pending-file-head strong { flex: 1; word-break: break-all; font-size: 13px; }
.pending-file-size { font-size: 12px; color: #64748b; }
.pending-file-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-top: 8px; }
.pending-file-meta label { display: flex; flex-direction: column; font-size: 12px; color: #475569; gap: 2px; }
.pending-file-meta input { width: 100%; box-sizing: border-box; }
.file-list li.file-list-item-meta { align-items: flex-start; gap: 12px; }
.file-meta-info { flex: 1; min-width: 0; }
.file-meta-title { font-weight: 600; word-break: break-word; }
.file-meta-detail { font-size: 12px; color: #64748b; word-break: break-word; }
.file-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; }
@media (max-width: 640px) {
    .pending-file-meta { grid-template-columns: 1fr; }
    .file-list li.file-list-item-meta { flex-direction: column; }
}

/* GĐ17 — panel lọc gọn, có thể ẩn/hiện (xem plan/todo/17_gon_filter.md) */
.filter-panel { margin-bottom: 16px; }
.filter-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; padding: 8px 4px; user-select: none; font-size: 14px; font-weight: 600; color: #334155;
}
.filter-toolbar:hover { color: #1d4ed8; }
.filter-toggle-icon { font-size: 12px; color: #64748b; }
.filter-body { padding-top: 4px; }
.filter-fields { display: flex; flex-wrap: wrap; gap: 12px 16px; }
.filter-field { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.filter-field label { font-size: 12px; font-weight: 600; color: #334155; }
.filter-field input, .filter-field select {
    padding: 8px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 14px;
}
.filter-actions { display: flex; gap: 8px; margin-top: 12px; }

/* GĐ20 — sub-tab cho trang Quản trị (xem plan/todo/20_admin_subtab.md) */
.tab-bar { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid #e2e8f0; flex-wrap: wrap; }
.tab-button {
    padding: 10px 18px; border: none; background: none; cursor: pointer;
    font-size: 14px; font-weight: 600; color: #64748b;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab-button:hover { color: #1d4ed8; }
.tab-button.active { color: #2563eb; border-bottom-color: #2563eb; }

/* GĐ26 — menu account dạng dropdown (xem plan/done/26_api_doi_mat_khau.md).
   UI dropdown ĐẦU TIÊN trong dự án — theo đúng mẫu .autocomplete-dropdown
   bên dưới (position:absolute trên 1 wrapper position:relative). */
.account-menu { position: relative; }
#app-header .account-menu-trigger {
    background: none; border: none; padding: 0; border-radius: 0;
    color: inherit; font: inherit; cursor: pointer;
}
#app-header .account-menu-trigger:hover { background: none; text-decoration: underline; }
.account-menu-dropdown {
    position: absolute; top: 100%; right: 0; margin-top: 6px; z-index: 20;
    background: #fff; border: 1px solid #cbd5e1; border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); min-width: 160px; overflow: hidden;
}
.account-menu-dropdown[hidden] { display: none; }
#app-header .account-menu-item {
    display: block; width: 100%; text-align: left; padding: 8px 12px;
    background: none; border: none; border-radius: 0; color: #1a1a1a; font-size: 13px; cursor: pointer;
}
#app-header .account-menu-item:hover { background: #f1f5f9; color: #1a1a1a; }
#app-header .account-menu-item[hidden] { display: none; }

/* GĐ16 — autocomplete (đối tác/phòng ban/chi nhánh/nhân viên) */
.autocomplete-wrap { position: relative; }
.autocomplete-wrap .autocomplete-input { width: 100%; }
.autocomplete-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
    background: #fff; border: 1px solid #cbd5e1; border-top: none;
    border-radius: 0 0 4px 4px; max-height: 220px; overflow-y: auto;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.autocomplete-item { padding: 8px 10px; font-size: 13px; cursor: pointer; }
.autocomplete-item:hover { background: #f1f5f9; }

/* toplayer (modal) — CSS gợi ý từ doc/top_layer.md */
.toplayer { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,0.45); z-index: 1000; }
.toplayer.active { display: flex; }
.toplayer .container { min-width: 360px; max-width: 640px; width: 90%; max-height: 85vh; overflow-y: auto; background: #fff; color: #1a1a1a; border-radius: 8px; }
.toplayer .head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid #e2e8f0; }
.toplayer .title { font-weight: bold; font-size: 16px; }
.toplayer .btn-close { cursor: pointer; font-size: 18px; background: none; border: none; }
.toplayer .content { padding: 18px; }
.toplayer .foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid #e2e8f0; }

/* GĐ40 (xem plan/todo/40_modal_xem_file_nhieu_tab.md) — modal xem file
   nhiều tab (PDF/XML), kích thước lớn, layout full-height: head/tabs/body/foot. */
.toplayer .container.file-viewer-modal {
    max-width: 90vw; width: 90vw; max-height: 90vh; height: 90vh;
    display: flex; flex-direction: column; overflow: hidden;
}
.toplayer .container.file-viewer-modal .content {
    padding: 0; overflow: hidden; display: flex; flex-direction: column; flex: 1; min-height: 0;
}
.file-viewer-root { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.file-viewer-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid #e2e8f0; overflow-x: auto; flex-shrink: 0; }
.file-viewer-tab { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid #e2e8f0; border-radius: 6px; background: #f8fafc; cursor: pointer; white-space: nowrap; }
.file-viewer-tab.active { background: #e2e8f0; font-weight: bold; }
.file-viewer-tab-close { cursor: pointer; color: #64748b; }
.file-viewer-body { display: flex; flex: 1; min-height: 0; }
.file-viewer-info { width: 220px; flex-shrink: 0; padding: 12px; border-right: 1px solid #e2e8f0; overflow-y: auto; font-size: 13px; }
.file-viewer-iframe { flex: 1; border: none; }
.file-viewer-image { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; background: #f1f5f9; padding: 8px; }
.file-viewer-image img { max-width: 100%; height: auto; }

/* toast — CSS gợi ý từ doc/toast.md */
.toast-item { position: fixed; right: 24px; bottom: 24px; padding: 12px 16px; border-radius: 6px; background: #334155; color: #fff; margin-top: 8px; font-size: 14px; max-width: 320px; }
.toast-item.success { background: #16a34a; }
.toast-item.error { background: #dc2626; }
.toast-item.warning { background: #d97706; }
.toast-item.info { background: #2563eb; }

/* GĐ50 (xem plan/done/50_sao_luu_khoi_phuc_quan_tri.md) — banner bảo trì
   toàn trang (hiện cả ở màn đăng nhập) + tab Sao lưu & Khôi phục. */
.maintenance-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 2000; padding: 10px 20px; background: #b45309; color: #fff; font-size: 14px; text-align: center; }
.maintenance-banner.recovered { background: #15803d; }
.maintenance-banner .btn { margin-left: 8px; padding: 4px 12px; }
body.has-maintenance-banner { padding-top: 42px; }
.backup-summary { font-size: 13px; color: #334155; display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.backup-warning { color: #b45309; font-weight: 600; }
.backup-success { color: #15803d; font-weight: 600; }
.backup-create-row { display: flex; align-items: flex-end; gap: 8px; }
.backup-create-row .form-row { flex: 1; margin-bottom: 0; }
.backup-create-row + .backup-create-row { margin-top: 12px; }
.backup-actions { white-space: nowrap; }
.backup-actions .btn { padding: 4px 8px; font-size: 12px; margin-right: 4px; }
.backup-restore-warning { background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }
.backup-job-steps { padding-left: 20px; font-size: 13px; }
.backup-job-step { padding: 3px 0; color: #64748b; }
.backup-job-step.running { color: #1d4ed8; font-weight: 600; }
.backup-job-step.done { color: #15803d; }
.backup-job-step.failed { color: #b91c1c; font-weight: 600; }
.backup-cli-hint { white-space: pre-wrap; background: #0f172a; color: #e2e8f0; padding: 10px; border-radius: 6px; font-size: 12px; }

/* #075 — khung (outline) hợp đồng: cây Phần → Điều → Khoản (modules/contracts/contract-outlines.js). */
.outline-tree { list-style: none; margin: 4px 0; padding-left: 18px; }
.outline-tree > li { margin: 4px 0; }
.outline-node-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.outline-section > .outline-node-head { font-weight: 600; color: #1e3a8a; }
.outline-node-help { margin: 2px 0 4px 0; font-size: 12px; }
.outline-node-help pre { white-space: pre-wrap; background: #f8fafc; padding: 6px; margin: 4px 0; }
.outline-node-help textarea { width: 100%; margin: 2px 0; }
.outline-title-input { flex: 1 1 220px; min-width: 160px; }
.outline-key-input { width: 160px; font-family: monospace; font-size: 12px; }
.outline-node-tools { display: inline-flex; gap: 2px; }
.btn.small { padding: 2px 6px; font-size: 12px; }
.outline-clause-text { white-space: pre-wrap; background: #f8fafc; border-left: 3px solid #cbd5e1; padding: 4px 8px; margin: 2px 0; }
.outline-clause-text.missing { border-left-color: #f59e0b; color: #92400e; }
.outline-error { color: #991b1b; background: #fee2e2; padding: 6px 8px; border-radius: 4px; margin: 6px 0; }
.outline-actions { margin: 8px 0; }
.outline-extra { margin: 6px 0; }
