/* Kế toán Thiên An – giao diện theo ảnh tham chiếu: nền trắng / xanh xám nhạt, thanh tiêu đề xanh đậm, ô chức năng nhiều màu */
:root {
  --navy: #1f3a5f; --navy2: #163052; --accent: #2b6cb0; --bg: #f4f7fa; --line: #d6dee6; --text: #1e2a36; --muted: #5a6b7b;
  --green: #5e9e6e; --purple: #8a76bc; --orange: #c2662a; --steel: #5a8ab3; --red: #b0504e; --mustard: #b08a30;
  --teal: #3c7ca3; --gray: #8a949e; --brown: #8a6436; --maroon: #8c3b3b; --violet: #6c4e9b; --dnavy: #36628a;
  --olive: #77732f; --dgreen: #2f7d52; --slate: #55657a; --plum: #8e4a6e; --rust: #a65a32;
  --ok: #2f7d52; --warn: #c2862a; --err: #b0504e; --info: #5a8ab3;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 13px/1.35 "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); }
.hidden { display: none !important; }

/* ---------- khung ứng dụng ---------- */
#app { display: grid; grid-template-rows: 58px 1fr 26px; grid-template-columns: var(--side, 210px) 1fr; height: 100vh; }
#topbar { grid-column: 1 / 3; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: #fff;
  border-bottom: 2px solid var(--navy); overflow: hidden; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 175px; }
.brand .logo { width: 38px; height: 38px; border-radius: 50%; background: var(--navy); border: 3px solid #e8742c; color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 14px; flex: none; }
.brand b { display: block; color: var(--navy); font-size: 16px; letter-spacing: .5px; }
.brand small { color: var(--muted); font-size: 10px; }
.tb-field { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.tb-field select, .tb-field input { font-variant-numeric: tabular-nums; height: 26px; border: 1px solid #b9c6d3; border-radius: 3px; padding: 0 4px; background: #fff; }
.btn { height: 28px; padding: 0 10px; border: 1px solid #b9c6d3; border-radius: 3px; background: #fff; white-space: nowrap; }
.btn:hover:not(:disabled) { background: #eaf1f8; border-color: var(--accent); }
.btn:disabled { color: #a0a8b0; background: #f2f4f6; border-color: #dde2e7; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; border: none; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #24599a; }
.btn.primary:disabled { background: #c9cfd6; color: #f4f4f4; }
.btn.teal { background: #2f8c7a; color: #fff; border: none; }
.btn.orange { background: #e8742c; color: #fff; border: none; }
.btn.orange:disabled, .btn.teal:disabled { background: #c9cfd6; color: #f4f4f4; }
.btn.danger { color: #a33a37; }
.btn.big { height: 44px; line-height: 1.1; }
.stack { display: flex; flex-direction: column; gap: 2px; }
.stack .btn { height: 21px; font-size: 11px; }
.company { flex: 1; min-width: 160px; overflow: hidden; display: flex; align-items: center; gap: 8px; }
.company select { border: none; font-weight: 700; color: var(--navy); font-size: 13.5px; max-width: 100%; background: transparent; }
.company small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-link { border: none; background: none; color: var(--navy); padding: 4px 6px; white-space: nowrap; }
.tb-link:hover { background: #eef3f9; border-radius: 3px; }

#sidebar { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
#menu { flex: 1; overflow-y: auto; padding: 4px 0; }
.mi { display: flex; align-items: center; gap: 9px; padding: 7px 10px; cursor: pointer; font-size: 13.5px; white-space: nowrap; }
.mi:hover { background: #eef3f9; }
.mi.active { background: #dce8f5; color: var(--navy); font-weight: 600; }
.mi .ic { width: 20px; height: 20px; border-radius: 3px; color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.mi .chev { margin-left: auto; color: #9aa4ae; transition: transform .15s; }
.mi.open .chev { transform: rotate(90deg); }
.sub { display: none; }
.sub.open { display: block; }
.sub .mi { padding-left: 39px; font-size: 12.5px; }
.sub .mi.todo { color: #9aa4ae; }
#collapse { border: none; border-top: 1px solid var(--line); background: #fff; text-align: left; padding: 7px 12px; color: var(--muted); }
.side-foot { background: var(--navy); color: #fff; font-size: 11px; padding: 5px 10px; white-space: nowrap; }
#app.collapsed { --side: 46px; }
#app.collapsed .mi span.t, #app.collapsed .mi .chev, #app.collapsed .sub, #app.collapsed .side-foot { display: none; }

#main { display: flex; flex-direction: column; overflow: hidden; }
#tabbar { display: flex; gap: 2px; padding: 6px 8px 0; background: var(--bg); overflow-x: auto; flex: none; }
.tab { display: flex; align-items: center; gap: 6px; padding: 5px 10px; background: #e9eef3; border: 1px solid var(--line);
  border-bottom: none; border-radius: 3px 3px 0 0; cursor: pointer; white-space: nowrap; max-width: 240px; }
.tab span { overflow: hidden; text-overflow: ellipsis; }
.tab.active { background: #fff; color: var(--navy); font-weight: 600; }
.tab .x { border: none; background: none; color: #8a949e; padding: 0 2px; font-size: 14px; line-height: 1; }
.tab .x:hover { color: var(--err); }
#pages { flex: 1; overflow: hidden; background: #fff; border-top: 1px solid var(--line); position: relative; }
.page { position: absolute; inset: 0; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }

#statusbar { grid-column: 1 / 3; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 18px; padding: 0 10px; font-size: 12px; white-space: nowrap; overflow: hidden; }
#statusbar .right { margin-left: auto; }
#statusbar .click { cursor: pointer; text-decoration: underline dotted; }

/* ---------- tổng quan: ô chức năng ---------- */
.section-title { display: flex; align-items: center; gap: 10px; margin: 6px 0 4px; }
.section-title b { color: var(--navy); font-size: 14px; text-transform: uppercase; border-left: 4px solid var(--navy); padding-left: 8px; white-space: nowrap; }
.section-title i { flex: 1; height: 1px; background: var(--line); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.tile { position: relative; height: 84px; min-width: 0; border: none; color: #fff; font-weight: 600; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 4px; text-align: center; font-size: 11.5px; line-height: 1.2; }
.tile:hover { filter: brightness(.9); }
.tile svg { width: 30px; height: 30px; flex: none; stroke: #fff; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tile.todo { opacity: .5; }
.tile .phase { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.45); font-size: 9px; padding: 1px 4px; border-radius: 2px; }
.dash-row { display: grid; grid-template-columns: 5fr 4fr; gap: 16px; }
.legend { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ---------- bảng ---------- */
.toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar input[type=search], .toolbar input[type=text], .toolbar select, .toolbar input.date { height: 28px; border: 1px solid #b9c6d3; border-radius: 3px; padding: 0 6px; }
.tablewrap { flex: 1; overflow: auto; border: 1px solid var(--line); min-height: 120px; }
table.grid { border-collapse: collapse; width: max-content; min-width: 100%; }
table.grid th { position: sticky; top: 0; z-index: 1; background: #e4ecf4; color: var(--navy); font-weight: 600; padding: 5px 6px;
  border-right: 1px solid #cdd8e3; border-bottom: 1px solid #cdd8e3; text-align: left; white-space: nowrap; }
table.grid td { padding: 3px 6px; border-right: 1px solid #e8edf2; border-bottom: 1px solid #e8edf2; white-space: nowrap; }
table.grid tbody tr:nth-child(even) { background: #f7fafc; }
table.grid tbody tr:hover { background: #eaf2fb; }
table.grid tbody tr.sel { background: #cfe2f7; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tr.bold td { font-weight: 700; }
table.grid tfoot td { position: sticky; bottom: 0; background: #e4ecf4; font-weight: 700; border-top: 1px solid #cdd8e3; }
table.grid td.wrap { white-space: normal; min-width: 260px; }
.totalbox { background: #eef3f8; border: 1px solid var(--line); padding: 5px 9px; font-weight: 600; }
.ok { color: var(--ok); } .bad { color: var(--err); } .warn { color: #8a6d00; } .muted { color: var(--muted); }
.badge { display: inline-block; border-radius: 3px; padding: 2px 9px; color: #fff; font-weight: 700; font-size: 12px; }
.pill { display: inline-block; padding: 0 6px; border-radius: 9px; font-size: 11px; color: #fff; }

/* ---------- chứng từ ---------- */
.vhead { display: grid; grid-template-columns: 105px 1fr 105px 1fr 105px 1fr 105px 1fr; gap: 4px 8px; align-items: center; }
.vhead label { color: var(--muted); }
.vhead input, .vhead select { height: 26px; border: 1px solid #b9c6d3; border-radius: 2px; padding: 0 5px; width: 100% !important; }
.vhead input[readonly] { background: #f1f4f7; }
.vhead .span3 { grid-column: span 3; } .vhead .span7 { grid-column: span 7; }
table.entry { border-collapse: collapse; width: max-content; min-width: 100%; }
table.entry th { position: sticky; top: 0; z-index: 1; background: #e4ecf4; color: var(--navy); padding: 4px; border: 1px solid #cdd8e3; white-space: nowrap; font-weight: 600; }
table.entry td { border: 1px solid #e1e7ed; padding: 0; }
table.entry td.stt { text-align: center; color: #6a7a8a; width: 36px; background: #f7fafc; }
table.entry input { width: 100%; height: 24px; border: none; padding: 0 4px; background: transparent; outline: none; }
table.entry input:focus { background: #fffbe6; box-shadow: inset 0 0 0 1px var(--accent); }
table.entry input.num { text-align: right; }
table.entry input.err { color: var(--err); font-weight: 700; }
table.entry tr.cur td.stt { background: var(--accent); color: #fff; }
.issues { border: 1px solid var(--line); min-height: 52px; max-height: 120px; overflow: auto; padding: 4px 8px; }
.issues div { padding: 1px 0; cursor: pointer; }
.subtabs { display: flex; gap: 2px; }
.subtabs button { border: 1px solid var(--line); background: #e9eef3; padding: 4px 10px; border-bottom: none; }
.subtabs button.on { background: #fff; color: var(--navy); font-weight: 600; }
.totals { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- hộp thoại, đăng nhập ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,30,50,.38); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.25); min-width: 380px; max-width: min(960px, 95vw);
  max-height: 90vh; display: flex; flex-direction: column; }
.modal h3 { margin: 0; padding: 10px 14px; background: var(--navy); color: #fff; border-radius: 6px 6px 0 0; font-size: 14px; }
.modal .body { padding: 12px 14px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.modal .foot { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.form { display: grid; grid-template-columns: 160px 1fr; gap: 6px 10px; align-items: center; }
.form label { color: var(--muted); }
.form input, .form select, .form textarea { height: 28px; border: 1px solid #b9c6d3; border-radius: 3px; padding: 0 6px; }
.form textarea { height: 120px; padding: 6px; }
.form .req::after { content: " *"; color: var(--err); }
.center-screen { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #e9f0f7, #f7f9fb); }
.card { background: #fff; border-radius: 8px; box-shadow: 0 6px 30px rgba(31,58,95,.15); padding: 24px 28px; width: 420px; max-width: 94vw; }
.card h2 { margin: 6px 0 2px; color: var(--navy); }
.card .form { grid-template-columns: 1fr; }
.card .btn { width: 100%; height: 34px; margin-top: 6px; }
.note { background: #fff8e6; border: 1px solid #f0d58c; padding: 8px 10px; border-radius: 4px; font-size: 12px; }
#toast { position: fixed; right: 16px; bottom: 36px; z-index: 60; display: flex; flex-direction: column; gap: 6px; }
#toast div { background: var(--navy); color: #fff; padding: 8px 12px; border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 420px; white-space: pre-line; }
#toast div.err { background: var(--err); }
.loading { position: fixed; top: 0; left: 0; height: 3px; background: #e8742c; z-index: 70; animation: load 1s linear infinite; width: 30%; }
@keyframes load { from { left: -30%; } to { left: 100%; } }

/* ---------- in ấn ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; font: 10pt Arial, sans-serif; }
  #print-area table { border-collapse: collapse; width: 100%; }
  #print-area th, #print-area td { border: 1px solid #888; padding: 2px 4px; font-size: 9pt; }
  #print-area th { background: #dce6f1 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print-area .num { text-align: right; }
  #print-area h2 { text-align: center; color: #1f3a5f; margin: 6px 0; }
  @page { size: A4 landscape; margin: 10mm; }
}
@media (max-width: 1000px) {
  #app { --side: 46px; }
  #app .mi span.t, #app .mi .chev, #app .sub, #app .side-foot { display: none; }
  .vhead { grid-template-columns: 95px 1fr 95px 1fr; }
  .vhead .span7 { grid-column: span 3; } .dash-row { grid-template-columns: 1fr; }
}
