:root {
  --crm-primary: #0b6bcb;
  --crm-accent: #f26b21;
  --crm-sidebar: #13253d;
  --crm-sidebar-2: #1b3354;
  --crm-bg: #f3f5f9;
  --bs-primary: #0b6bcb;
  --bs-primary-rgb: 11, 107, 203;
  --bs-body-font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
body { background: var(--crm-bg); font-size: .925rem; }
.btn-primary { --bs-btn-bg: var(--crm-primary); --bs-btn-border-color: var(--crm-primary);
  --bs-btn-hover-bg: #0957a6; --bs-btn-hover-border-color: #0957a6; }
.btn-accent { background: var(--crm-accent); color: #fff; border-color: var(--crm-accent); }
.btn-accent:hover { background: #d95a14; color: #fff; }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--crm-sidebar); color: #c9d4e3; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 1040; }
.brand { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.1rem; color: #fff;
  text-decoration: none; font-weight: 700; font-size: 1.05rem; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; background: var(--crm-accent);
  display: grid; place-items: center; }
.brand-has-logo { padding: .75rem .8rem; }
.brand-logo-img { display: block; width: 100%; padding: .2rem .1rem; }
.brand-logo-img img { display: block; width: 100%; height: auto; max-height: 64px; object-fit: contain; }
.sidebar .nav { padding: .5rem; }
.sidebar .nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: #7f93ad; padding: 1rem .75rem .35rem; }
.sidebar .nav-link { color: #c9d4e3; border-radius: 6px; padding: .5rem .75rem; display: flex;
  align-items: center; gap: .7rem; }
.sidebar .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.sidebar .nav-link:hover { background: var(--crm-sidebar-2); color: #fff; }
.sidebar .nav-link.active { background: var(--crm-primary); color: #fff; }
.sidebar .nav-link.disabled { color: #5d7290; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid #e3e8ef; padding: .7rem 1.5rem;
  display: flex; align-items: center; position: sticky; top: 0; z-index: 1020; }
.page-title { font-size: 1.2rem; font-weight: 600; margin: 0; }
.content { padding: 1.25rem 1.5rem 2rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--crm-accent); color: #fff;
  display: inline-grid; place-items: center; font-weight: 600; font-size: .85rem; }

.card { border: 1px solid #e3e8ef; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: #fff; font-weight: 600; border-bottom: 1px solid #eef1f5; }
.table > :not(caption) > * > * { padding: .55rem .65rem; }
.table thead th { font-size: .78rem; text-transform: uppercase; color: #64748b; font-weight: 600;
  background: #f8fafc; white-space: nowrap; }
.table-hover tbody tr { cursor: default; }
.text-money { font-variant-numeric: tabular-nums; white-space: nowrap; }

.kpi { padding: 1rem 1.1rem; display: flex; gap: .9rem; align-items: center; height: 100%; }
.kpi-icon { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center;
  font-size: 1.3rem; flex-shrink: 0; }
.kpi-label { color: #64748b; font-size: .8rem; }
.kpi-value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }

.filter-bar .form-control, .filter-bar .form-select { min-width: 140px; }

/* Kanban */
.kanban { display: flex; gap: .9rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.kanban-col { background: #e9edf3; border-radius: 10px; min-width: 270px; width: 270px; flex-shrink: 0;
  display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.kanban-col.over { outline: 2px dashed var(--crm-primary); background: #dde7f5; }
.kanban-head { padding: .7rem .8rem; border-top: 4px solid; border-radius: 10px 10px 0 0; }
.kanban-body { padding: 0 .6rem .6rem; overflow-y: auto; min-height: 80px; flex: 1; }
.kanban-card { background: #fff; border-radius: 8px; padding: .65rem .75rem; margin-bottom: .55rem;
  box-shadow: 0 1px 2px rgba(16,24,40,.08); cursor: grab; border-left: 3px solid transparent; }
.kanban-card.dragging { opacity: .5; }
.kanban-card.overdue { border-left-color: #dc3545; }
.kanban-card a { color: inherit; text-decoration: none; }

.order-items td { vertical-align: top; }
.order-items input, .order-items select { min-width: 70px; }
.summary-table td { padding: .3rem 0; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: -260px; transition: left .2s; }
  body.sidebar-open .sidebar { left: 0; }
  body.sidebar-open .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1030; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
}
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
}

/* tinh chỉnh */
.card.kpi { flex-direction: row; }
.table td:first-child a { white-space: nowrap; }
.summary-table td:first-child { white-space: nowrap; padding-right: .75rem; }
.sidebar .nav-toggle { background: none; border: 0; width: 100%; text-align: left; display: flex;
  justify-content: space-between; align-items: center; cursor: pointer; }
.sidebar .nav-toggle:hover { color: #c9d4e3; }
.sidebar .nav-toggle i { transition: transform .15s; font-size: .7rem; }
.sidebar .nav-toggle.collapsed i { transform: rotate(-90deg); }
.sidebar .nav-group.collapsed { display: none; }

/* Tiền về tài khoản: phân biệt dòng đã xác nhận / bỏ qua */
.bank-row-done > td { background-color: rgba(25, 135, 84, .06); }
.bank-row-done > td:first-child { box-shadow: inset 3px 0 0 #198754; }
.bank-row-ignored > td { color: #8a8f98; }
.bank-row-ignored > td:first-child { box-shadow: inset 3px 0 0 #adb5bd; }

/* Nhân sự */
.avatar-lg { width: 56px; height: 56px; border-radius: 50%; background: var(--crm-accent); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 1.5rem; font-weight: 600; flex-shrink: 0; }
.att-table { font-size: 12px; }
.att-table th, .att-table td { padding: 2px !important; text-align: center; min-width: 26px; }
.att-table .att-name { text-align: left; min-width: 170px; position: sticky; left: 0; background: var(--bs-body-bg); z-index: 1; }
.att-table th.off, .att-table td.off { background: #f3f4f6; }
.att-table th.today { background: #fff3cd; }
.att-cell { cursor: pointer; border-radius: 4px; font-weight: 600; display: block; width: 24px; height: 22px; line-height: 22px; margin: auto; user-select: none; }
.att-cell:hover { outline: 2px solid var(--crm-accent); }
.att-cell.empty { color: #c0c4cc; }
.att-X { background: #d1e7dd; color: #0f5132; } .att-N { background: #cff4fc; color: #055160; }
.att-P { background: #cfe2ff; color: #084298; } .att-L { background: #e2e3e5; color: #41464b; }
.att-O { background: #fff3cd; color: #664d03; } .att-K { background: #f8d7da; color: #842029; }
.payroll-table input { min-width: 90px; text-align: right; }
.payroll-table td, .payroll-table th { white-space: nowrap; }

/* App cũ nhúng tạm */
.legacy-app-frame { height: calc(100vh - 150px); min-height: 520px; border: 1px solid var(--bs-border-color); border-radius: .5rem; overflow: hidden; background: #fff; }
.legacy-app-frame iframe { width: 100%; height: 100%; border: 0; }

/* Quản lý công đoạn */
.qa-table td, .qa-table th { vertical-align: top; }
.qa-info td { border-bottom: 0; }
.qa-info.tone-1 td, .qa-stage-row.tone-1 td { background: #fbfcfe; }
.qa-stage-row td { border-top: 0; padding-top: 0; }
.qa-stages { display: flex; flex-wrap: wrap; gap: 6px; }
.qa-st { border: 1px solid var(--bs-border-color); border-radius: 10px; padding: 6px 8px; min-width: 128px; max-width: 170px; font-size: 12px; background: #fff; }
.qa-st .nm { font-weight: 600; color: #334155; line-height: 1.2; margin-bottom: 4px; }
.qa-st .nm small { color: #94a3b8; font-weight: 500; margin-right: 3px; }
.qa-st.is-done { background: #ecfdf3; border-color: #a7e3c0; }
.qa-st.is-done .ok { color: #0f9158; font-weight: 700; }
.qa-st.is-skipped { background: #f6f7f9; color: #94a3b8; border-style: dashed; }
.qa-st.is-pending.checked { background: #eef3ff; border-color: #1f4fd8; }
.qa-st.saving { opacity: .6; }
.qa-st .def { display: inline-block; margin-top: 3px; background: #fdeceb; color: #d12c1f; border-radius: 6px; padding: 1px 6px; font-weight: 600; }
.qa-st .who { color: #475569; white-space: pre-line; }
.qa-days .bar { height: 5px; background: #e5e7eb; border-radius: 3px; overflow: hidden; margin: 3px 0; }
.qa-days .bar div { height: 100%; }
.qa-cmt { font-size: 12px; line-height: 1.35; max-width: 260px; }
.qa-cmt .ln { margin-bottom: 3px; }
.qa-cmt .ln b { color: #334155; }
.qa-cancelled td { opacity: .72; }
.qa-savebar { position: sticky; bottom: 12px; z-index: 5; display: flex; justify-content: flex-end; pointer-events: none; }
.qa-savebar { margin-top: 8px; }
.qa-savebar .btn:disabled { opacity: 0; visibility: hidden; }
.qa-savebar .btn { pointer-events: auto; box-shadow: 0 6px 18px rgba(15, 23, 42, .2); }
.qa-chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--bs-border-color); border-radius: 999px; padding: 2px 10px; font-size: 13px; text-decoration: none; color: inherit; background: #fff; }
.qa-chip.on { background: var(--bs-primary); border-color: var(--bs-primary); color: #fff; }
.qa-chip .n { font-weight: 700; }
.qa-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; }
.qa-tl .item { border-left: 3px solid #e2e8f0; padding: 4px 0 8px 10px; margin-left: 4px; }
.qa-tl .item.sys { border-left-color: #16a34a; }
.qa-label { border: 1.5px solid #000; border-radius: 3mm; padding: 4mm; min-height: 47mm; display: flex; gap: 4mm; page-break-inside: avoid; background: #fff; }
.qa-label .qr { width: 35mm; height: 35mm; flex-shrink: 0; }
.qa-label .qr img, .qa-label .qr canvas, .qa-label .qr svg { width: 100%; height: 100%; }
.qa-labels { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; }
@media print { .qa-noprint { display: none !important; } .sidebar, .topbar { display: none !important; } .main { margin: 0 !important; } }

/* ---- Nhân sự: tổng quan ---- */
.ov-hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; padding: 1.25rem 1.4rem;
  border-radius: 16px; color: #fff; background: linear-gradient(135deg, #312e81 0%, #4f46e5 55%, #0ea5e9 100%); }
.ov-kpi { padding: 1rem 1.1rem; border-radius: 16px; border-top: 3px solid var(--tone, #4f46e5); }
.ov-kpi[data-tone="indigo"] { --tone: #4f46e5; } .ov-kpi[data-tone="sky"] { --tone: #0ea5e9; } .ov-kpi[data-tone="emerald"] { --tone: #10b981; }
.ov-kpi[data-tone="amber"] { --tone: #f59e0b; } .ov-kpi[data-tone="violet"] { --tone: #8b5cf6; } .ov-kpi[data-tone="rose"] { --tone: #ef4444; }
.ov-kpi-l { font-size: .78rem; color: #64748b; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.ov-kpi-v { font-size: 1.55rem; font-weight: 700; color: #0f172a; line-height: 1.25; font-variant-numeric: tabular-nums; }
.ov-kpi-s { font-size: .78rem; color: #64748b; }
.hr-note-CP { color: #0f9158; font-weight: 700; } .hr-note-KP { color: #dc2626; font-weight: 700; }
.hr-req-pending { background: #fffbeb; } .hr-req-rejected { background: #fef2f2; }
.hr-sticky th:nth-child(2), .hr-sticky td:nth-child(2) { position: sticky; left: 0; background: var(--bs-body-bg); z-index: 1; }
.hr-guide summary { cursor: pointer; font-weight: 600; }
.hr-guide { font-size: .85rem; }
.notice-card { border-left: 4px solid #cbd5e1; cursor: pointer; }
.notice-card.p-Khẩn { border-left-color: #dc2626; } .notice-card.p-Quan { border-left-color: #f59e0b; }
.notice-content table { border-collapse: collapse; } .notice-content td, .notice-content th { border: 1px solid #cbd5e1; padding: 4px 8px; }
.notice-content blockquote { border-left: 4px solid #0ea5e9; background: #f0f9ff; padding: .5rem .9rem; }
.rich-editor { min-height: 220px; border: 1px solid var(--bs-border-color); border-radius: .375rem; padding: .6rem .8rem; background: #fff; }
.slip { border: 1px solid #cbd5e1; border-radius: 10px; padding: 1rem 1.2rem; break-inside: avoid; }
.slip table td { padding: 2px 4px; }
@media print { .slip { page-break-inside: avoid; margin-bottom: 8mm; } }
