:root {
  --bg: #f4f6f8; --panel: #fff; --panel-2: #f8fafb; --line: #e2e7ec; --line-2: #cfd7de;
  --text: #1b2733; --muted: #66778a; --brand: #1f5f8b; --brand-2: #174a6d; --brand-soft: #e6f0f7;
  --green: #1d7a4c; --green-bg: #e3f4ea; --red: #b42318; --red-bg: #fde8e6; --amber: #9a5b00; --amber-bg: #fff2d6;
  --blue: #1f5f8b; --blue-bg: #e6f0f7; --violet: #5b3fa8; --violet-bg: #eee9fb; --teal: #0e6f6f; --teal-bg: #dff3f2;
  --gray: #56616d; --gray-bg: #eceff2;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --side: 232px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--green); } .neg { color: var(--red); }
.hidden { display: none !important; }

/* ---------- Khung ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: #13324a; color: #d6e2ec; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 16px 12px; color: #fff; font-weight: 600; }
.brand .logo { width: 30px; height: 30px; border-radius: 7px; background: #2b7ab0; display: grid; place-items: center; font-size: 13px; }
.brand small { display: block; font-weight: 400; color: #9fb6c8; font-size: 11.5px; }
.nav { padding: 4px 8px 16px; }
.nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7f9bb1; padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; border-radius: 6px; color: #d6e2ec; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a.on { background: #2b7ab0; color: #fff; }
.nav .count { background: #e8a33d; color: #1b1b1b; border-radius: 10px; font-size: 11px; padding: 0 6px; font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 8px 20px; }
.top .menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 520px; }
.search input { width: 100%; padding: 8px 12px 8px 32px; border: 1px solid var(--line-2); border-radius: 20px; background: var(--panel-2); }
.search::before { content: "⌕"; position: absolute; left: 11px; top: 5px; color: var(--muted); font-size: 17px; }
.search-results { position: absolute; top: 40px; left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 70vh; overflow: auto; }
.search-results .grp { font-size: 11px; color: var(--muted); padding: 8px 12px 2px; text-transform: uppercase; }
.search-results a { display: block; padding: 6px 12px; color: var(--text); }
.search-results a:hover, .search-results a.sel { background: var(--brand-soft); text-decoration: none; }
.top-right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.bell { position: relative; }
.bell .dot { position: absolute; top: 0; right: 0; background: var(--red); color: #fff; border-radius: 9px; font-size: 10.5px; padding: 0 5px; min-width: 16px; text-align: center; }
.dropdown { position: absolute; right: 0; top: 40px; width: 380px; max-width: 92vw; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.14); max-height: 70vh; overflow: auto; z-index: 30; }
.dropdown .item { display: block; padding: 9px 12px; border-bottom: 1px solid var(--line); color: var(--text); }
.dropdown .item.unread { background: #f3f8fc; }
.dropdown .item small { color: var(--muted); display: block; }
.content { padding: 18px 20px 40px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .sub { color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

/* ---------- Thành phần ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 6px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.busy::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 18px; padding: 6px 8px; border-radius: 6px; color: var(--text); }
.icon-btn:hover { background: var(--panel-2); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; }
.card > h2:first-child { display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); color: var(--text); display: block; }
a.kpi:hover { border-color: var(--brand); text-decoration: none; }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 21px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-value.red { color: var(--red); } .kpi-value.green { color: var(--green); } .kpi-value.amber { color: var(--amber); }
.kpi-sub { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.badge.green { background: var(--green-bg); color: var(--green); } .badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); } .badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.violet { background: var(--violet-bg); color: var(--violet); } .badge.teal { background: var(--teal-bg); color: var(--teal); }
.badge.gray { background: var(--gray-bg); color: var(--gray); }
.alert { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; border: 1px solid; }
.alert.warn { background: var(--amber-bg); border-color: #f1cf8a; color: #6b4000; }
.alert.err { background: var(--red-bg); border-color: #f4b4ad; color: var(--red); }
.alert.info { background: var(--blue-bg); border-color: #b8d3e6; color: #174a6d; }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: var(--panel-2); font-weight: 600; font-size: 12.5px; color: #3c4b59; white-space: nowrap; position: sticky; top: 0; }
.tbl tbody tr:hover { background: #fafcfd; }
.tbl tr.clickable { cursor: pointer; }
.tbl td.empty { text-align: center; color: var(--muted); padding: 22px; }
.tbl tfoot td { font-weight: 600; background: var(--panel-2); }
.tbl.small td, .tbl.small th { padding: 5px 8px; font-size: 12.5px; }
.tbl td.wrap { max-width: 320px; word-break: break-word; }
.tbl tr.sec td { background: #f1f5f8; font-weight: 600; }
.tbl tr.muted td { color: var(--muted); }
.tbl input, .tbl select { width: 100%; min-width: 60px; }

/* ---------- Form ---------- */
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 9px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e0; outline-offset: 0; border-color: var(--brand); }
textarea { resize: vertical; width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 12.5px; color: #3c4b59; font-weight: 500; }
.field small { color: var(--muted); font-size: 12px; }
.field input, .field select, .field textarea { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters input[type=search] { min-width: 240px; }
.check { display: inline-flex; gap: 6px; align-items: center; }
input.money { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Tab ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 13px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs .count { background: var(--gray-bg); border-radius: 9px; padding: 0 6px; font-size: 11.5px; }

/* ---------- Dòng thời gian, danh sách ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--line-2); }
.timeline li.done::before { background: var(--green); }
.timeline li.late::before { background: var(--red); }
.timeline .meta { color: var(--muted); font-size: 12.5px; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.progress { height: 7px; background: var(--gray-bg); border-radius: 4px; overflow: hidden; min-width: 70px; }
.progress > i { display: block; height: 100%; background: var(--brand); }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .bar i { display: block; width: 100%; max-width: 44px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar small { color: var(--muted); font-size: 11.5px; }
.bars .bar b { font-size: 11.5px; font-weight: 600; }
.hbar { display: grid; grid-template-columns: 140px 1fr 70px; gap: 8px; align-items: center; margin: 5px 0; font-size: 13px; }
.hbar .track { background: var(--gray-bg); height: 10px; border-radius: 5px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--brand); }

/* ---------- Modal, toast ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,25,35,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; z-index: 100; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 10px; width: 520px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 10px 10px; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1b2733; color: #fff; padding: 10px 14px; border-radius: 7px; box-shadow: 0 6px 18px rgba(0,0,0,.2); max-width: 420px; transition: opacity .4s, transform .4s; }
.toast.err { background: var(--red); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #13324a, #1f5f8b); padding: 16px; }
.login form { background: #fff; padding: 28px; border-radius: 12px; width: 360px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login h1 { margin-bottom: 4px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; margin-top: 6px; }

/* ---------- Soạn báo giá ---------- */
.qe-sec { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; background: var(--panel); }
.qe-sec-head { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--panel-2); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; flex-wrap: wrap; }
.qe-sec-head input[name=sname] { font-weight: 600; flex: 1; min-width: 180px; }
.qe-lines td { padding: 4px 5px; }
.qe-lines input { padding: 4px 6px; }
.qe-lines .desc { min-width: 220px; }
.qe-lines .w-num { width: 80px; }
.qe-lines .w-money { width: 120px; }
.qe-lines .w-pct { width: 58px; }
.totals-box { display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; max-width: 420px; margin-left: auto; }
.totals-box .big { font-size: 17px; font-weight: 700; }
.sticky-bar { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 10px 16px; margin: 0 -20px -40px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; z-index: 5; }
.sticky-bar .spacer { flex: 1; }
.suggest { position: absolute; background: #fff; border: 1px solid var(--line-2); border-radius: 6px; box-shadow: 0 8px 20px rgba(0,0,0,.14); z-index: 50; max-height: 260px; overflow: auto; min-width: 360px; }
.suggest div { padding: 6px 10px; cursor: pointer; }
.suggest div:hover, .suggest div.sel { background: var(--brand-soft); }

/* ---------- Lịch tổng, bảng theo dõi ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-h { background: var(--panel-2); padding: 6px; font-weight: 600; font-size: 12.5px; text-align: center; }
.cal-d { background: var(--panel); min-height: 96px; padding: 4px; display: flex; flex-direction: column; gap: 2px; }
.cal-d.other { background: var(--panel-2); opacity: .7; }
.cal-d.today { outline: 2px solid var(--brand); outline-offset: -2px; }
.cal-n { font-size: 12px; color: var(--muted); }
.cal-e { font-size: 11.5px; padding: 1px 4px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); border-left: 3px solid; }
.cal-e:hover { text-decoration: none; filter: brightness(.95); }
.cal-e.blue { background: var(--blue-bg); border-color: var(--blue); } .cal-e.violet { background: var(--violet-bg); border-color: var(--violet); }
.cal-e.teal { background: var(--teal-bg); border-color: var(--teal); } .cal-e.green { background: var(--green-bg); border-color: var(--green); }
.cal-e.amber { background: var(--amber-bg); border-color: var(--amber); } .cal-e.red { background: var(--red-bg); border-color: var(--red); }
.cal-e.done { opacity: .6; text-decoration: line-through; } .cal-e.late { font-weight: 700; }
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.kan-col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 200px; }
.kan-h { display: flex; justify-content: space-between; align-items: center; }
.kan-card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px; color: var(--text); display: block; font-size: 13px; }
.kan-card:hover { border-color: var(--brand); text-decoration: none; }
.kan-card.late { border-left: 4px solid var(--red); }

/* ---------- Điện thoại, máy tính bảng ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .top { padding: 8px 12px; }
  .top .menu-btn { display: inline-block; }
  .content { padding: 14px 12px 40px; }
  .grid2, .grid3, .form-grid, .form-grid.g3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 9px 10px; }
  .kpi-value { font-size: 16px; }
  .dl { grid-template-columns: 120px 1fr; }
  .sticky-bar { margin: 0 -12px -40px; }
  .hide-sm { display: none; }
  .cal-d { min-height: 64px; } .cal-e { font-size: 10px; }
  .btn { padding: 9px 13px; }
}
@media print {
  .side, .top, .sticky-bar, .page-head .actions, .btn { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; }
}
