/* ==========================================================================
   Giao diện chung phần mềm kế toán. Các phân hệ dùng lại lớp ở đây;
   CSS riêng của phân hệ đặt ở static/<app>/<app>.css, không sửa file này.
   ========================================================================== */
@font-face { font-family: "Be Vietnam Pro"; src: url("../fonts/BeVietnamPro-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Be Vietnam Pro"; src: url("../fonts/BeVietnamPro-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Be Vietnam Pro"; src: url("../fonts/BeVietnamPro-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Be Vietnam Pro"; src: url("../fonts/BeVietnamPro-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  /* Màu: nền giấy xanh xám, mực xanh than, điểm nhấn xanh mực sổ cái */
  --nen: #F2F5F4;
  --giay: #FFFFFF;
  --giay-2: #F7F9F8;
  --muc: #132026;
  --mo: #55666C;
  --vien: #D5DCDA;
  --vien-dam: #B9C4C1;
  --chinh: #0D6A64;
  --chinh-dam: #09524D;
  --chinh-nhat: #DCEEEB;
  --loi: #B3261E;  --loi-nhat: #FBE8E6;
  --canh-bao: #9A5410; --canh-bao-nhat: #FAEFDF;
  --tot: #2A7548;  --tot-nhat: #E3F2E8;
  --font: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-so: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  --bo: 8px;
  --cao-o: 34px;
  --rong-ben: 236px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--nen); color: var(--muc); font-family: var(--font); font-size: 14px; line-height: 1.5; }
a { color: var(--chinh); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--chinh); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 21px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0 0 10px; }
.mo { color: var(--mo); }
.nho { font-size: 12.5px; }
.so, td.so, th.so { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.giua { text-align: center; }
.an { display: none !important; }

/* ---------- Khung trang ---------- */
.khung { display: grid; grid-template-columns: var(--rong-ben) minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr); min-height: 100vh; }
.thanh-tren { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 0 16px; background: var(--giay); border-bottom: 1px solid var(--vien); position: sticky; top: 0; z-index: 30; }
.thuong-hieu { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; color: var(--muc); min-width: calc(var(--rong-ben) - 32px); }
.thuong-hieu .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--chinh); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.chon-nhanh { display: flex; align-items: center; gap: 8px; }
.chon-nhanh select { height: 32px; border: 1px solid var(--vien); border-radius: 7px; background: var(--giay-2); padding: 0 8px; font: inherit; font-size: 13px; color: var(--muc); max-width: 280px; }
.chon-nhanh .nhan-che-do { font-size: 12px; }
.tim-nhanh { flex: 1; display: flex; justify-content: center; }
.tim-nhanh input { width: min(440px, 100%); height: 32px; border: 1px solid var(--vien); border-radius: 16px; padding: 0 14px; background: var(--giay-2); font: inherit; font-size: 13px; }
.nguoi-dung { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.nguoi-dung .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--muc); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 12px; }
.thanh-tren .nut-menu { display: none; }

.thanh-ben { background: var(--giay); border-right: 1px solid var(--vien); padding: 10px 8px 30px; overflow-y: auto; position: sticky; top: 52px; height: calc(100vh - 52px); }

/* Menu bên: chỉ tên phân hệ; phân hệ đang làm việc mở sẵn; bấm để mở/đóng; rê chuột hiện bảng mục bên cạnh */
.phan-he { margin-bottom: 1px; }
.dau-phan-he { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 6px 10px; border: 0; border-radius: 8px; background: none; color: var(--muc); font: inherit; font-size: 13.5px; font-weight: 500; text-align: left; cursor: pointer; text-decoration: none !important; }
.dau-phan-he:hover, .phan-he.bay > .dau-phan-he { background: var(--giay-2); }
.dau-phan-he .bt { width: 18px; height: 18px; flex: none; color: var(--mo); }
.dau-phan-he .ten { flex: 1; min-width: 0; }
.dau-phan-he .mui { width: 14px; height: 14px; flex: none; color: var(--vien-dam); transition: transform .15s; }
.dau-phan-he:hover .mui, .phan-he.bay .mui { color: var(--mo); }
.phan-he.mo > .dau-phan-he .mui { transform: rotate(90deg); color: var(--mo); }
.phan-he.co-mo > .dau-phan-he { color: var(--chinh-dam); font-weight: 600; }
.phan-he.co-mo > .dau-phan-he .bt { color: var(--chinh); }
a.dau-phan-he.dang-mo { background: var(--chinh-nhat); box-shadow: inset 3px 0 0 var(--chinh); }
.muc-phan-he { display: none; }
.phan-he.mo > .muc-phan-he { display: block; margin: 1px 0 8px 19px; padding-left: 8px; border-left: 1px solid var(--vien); }
.tieu-de-bay { display: none; }
.nhom-con .ten-con { font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--mo); padding: 8px 10px 3px; }
.phan-he.mo .nhom-con:first-child .ten-con { padding-top: 4px; }
.muc-phan-he a { display: block; padding: 5px 10px; border-radius: 7px; color: var(--muc); font-size: 13px; line-height: 1.4; }
.muc-phan-he a:hover { background: var(--giay-2); text-decoration: none; }
.muc-phan-he a.dang-mo { background: var(--chinh-nhat); color: var(--chinh-dam); font-weight: 600; box-shadow: inset 3px 0 0 var(--chinh); }
/* Bảng mục bay ra khi rê chuột (máy tính); vị trí dọc do app.js đặt theo tên phân hệ */
@media (min-width: 901px) {
  .phan-he.bay:not(.mo) > .muc-phan-he { display: block; position: fixed; z-index: 60; left: calc(var(--rong-ben) - 4px); top: var(--bay-tren, 60px); max-width: calc(100vw - var(--rong-ben) - 16px); max-height: calc(100vh - 70px); overflow: auto; padding: 10px 12px 12px; background: var(--giay); border: 1px solid var(--vien); border-radius: 10px; box-shadow: 0 14px 34px rgba(19, 32, 38, .16), 0 2px 6px rgba(19, 32, 38, .06); }
  .phan-he.bay:not(.mo) .tieu-de-bay { display: block; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--chinh-dam); padding: 2px 10px 6px; border-bottom: 1px solid var(--vien); margin-bottom: 4px; }
  .phan-he.bay:not(.mo) .cot-bay { display: flex; gap: 6px 14px; align-items: flex-start; }
  .phan-he.bay:not(.mo) .nhom-con { min-width: 200px; max-width: 260px; }
}

.noi-dung { padding: 18px 24px 60px; min-width: 0; }
.tieu-de-trang { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.tieu-de-trang .phu { color: var(--mo); font-size: 13px; margin-top: 3px; }
.tieu-de-trang .hanh-dong { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .khung { grid-template-columns: 1fr; }
  .thanh-ben { position: fixed; left: 0; top: 52px; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
  .khung.mo-menu .thanh-ben { transform: none; }
  .thanh-tren .nut-menu { display: inline-flex; }
  .thuong-hieu { min-width: 0; }
  .tim-nhanh { display: none; }
  .chon-nhanh .nhan-che-do { display: none; }
  .noi-dung { padding: 14px 14px 60px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Nút ---------- */
.nut { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--cao-o); padding: 0 14px; border-radius: 7px; border: 1px solid var(--vien-dam); background: var(--giay); color: var(--muc); font: inherit; font-weight: 500; font-size: 13.5px; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.nut:hover { background: var(--giay-2); border-color: var(--mo); }
.nut[hidden] { display: none; }     /* .nut đặt display: inline-flex, che mất thuộc tính hidden */
.nut-chinh { background: var(--chinh); border-color: var(--chinh); color: #fff; }
.nut-chinh:hover { background: var(--chinh-dam); border-color: var(--chinh-dam); }
.nut-phu { border-color: var(--chinh); color: var(--chinh); }
.nut-nguy { color: var(--loi); border-color: #E3B5B1; }
.nut-nguy:hover { background: var(--loi-nhat); border-color: var(--loi); }
.nut-nho { height: 28px; padding: 0 10px; font-size: 12.5px; }
.nut-trong { border-color: transparent; background: transparent; }
.nut[disabled] { opacity: .5; cursor: not-allowed; }
.phim { font-size: 11px; color: inherit; opacity: .7; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; line-height: 16px; }

/* ---------- Ô nhập ---------- */
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input[type=search], input:not([type]), select, textarea {
  height: var(--cao-o); border: 1px solid var(--vien-dam); border-radius: 7px; padding: 0 10px; background: var(--giay); color: var(--muc); font: inherit; font-size: 13.5px; width: 100%;
}
textarea { height: auto; min-height: 70px; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--chinh); box-shadow: 0 0 0 3px var(--chinh-nhat); }
input[readonly] { background: var(--giay-2); }
input.o-tien, input.o-so { text-align: right; font-variant-numeric: tabular-nums; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--chinh); }
label { font-size: 12.5px; color: var(--mo); font-weight: 500; }
.truong { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.truong .goi-y-truong { font-size: 12px; color: var(--mo); }
.truong .loi-truong { font-size: 12px; color: var(--loi); }
.truong.co-loi input, .truong.co-loi select { border-color: var(--loi); }
.truong-hop { flex-direction: row; align-items: center; gap: 8px; }
.luoi-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.luoi-form .rong-2 { grid-column: span 2; }
.luoi-form .rong-het { grid-column: 1 / -1; }
@media (max-width: 600px) { .luoi-form .rong-2 { grid-column: auto; } }

/* ---------- Thẻ, bảng ---------- */
.the { background: var(--giay); border: 1px solid var(--vien); border-radius: 12px; padding: 16px 18px; }
.the + .the { margin-top: 14px; }
.the > h2 { margin-bottom: 10px; }
.luoi-the { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.chi-so { background: var(--giay); border: 1px solid var(--vien); border-radius: 12px; padding: 13px 16px; }
.chi-so .nhan-cs { font-size: 12.5px; color: var(--mo); }
.chi-so .gia-tri { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
a.chi-so-lien-ket { display: block; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s; }
a.chi-so-lien-ket[href]:hover { border-color: var(--chinh); box-shadow: 0 1px 6px rgba(13, 106, 100, .12); }
.hanh-dong.nut-nhanh { flex-wrap: wrap; justify-content: flex-end; }
input.o-ngay-chung { font-variant-numeric: tabular-nums; }
input.o-ngay-chung.sai { border-color: var(--loi, #b42318); background: #fff6f5; }

.vung-bang { background: var(--giay); border: 1px solid var(--vien); border-radius: 12px; overflow-x: auto; }
table.bang { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.bang th, table.bang td { padding: 8px 10px; border-bottom: 1px solid var(--vien); text-align: left; vertical-align: top; }
table.bang th { background: var(--giay-2); color: var(--mo); font-weight: 600; font-size: 12.5px; white-space: nowrap; position: sticky; top: 0; }
table.bang tbody tr:hover { background: #F4F8F7; }
table.bang tr.dong-tong td { font-weight: 600; background: var(--giay-2); }
table.bang tr.cap-1 td { font-weight: 600; }
table.bang td.ma { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.bang td.so, table.bang th.so { text-align: right; }
table.bang tr:last-child td { border-bottom: 0; }
table.bang.dac td, table.bang.dac th { padding: 5px 8px; }

/* ---------- Nhãn trạng thái ---------- */
.nhan { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.7; white-space: nowrap; background: var(--giay-2); color: var(--mo); border: 1px solid var(--vien); }
.nhan-chinh { background: var(--chinh-nhat); color: var(--chinh-dam); border-color: transparent; }
.nhan-tot { background: var(--tot-nhat); color: var(--tot); border-color: transparent; }
.nhan-canh-bao { background: var(--canh-bao-nhat); color: var(--canh-bao); border-color: transparent; }
.nhan-loi { background: var(--loi-nhat); color: var(--loi); border-color: transparent; }

/* ---------- Thông báo ---------- */
.thong-bao { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.thong-bao li { padding: 10px 14px; border-radius: 9px; background: var(--giay); border: 1px solid var(--vien); border-left: 4px solid var(--chinh); }
.thong-bao li.success { border-left-color: var(--tot); }
.thong-bao li.warning { border-left-color: var(--canh-bao); background: var(--canh-bao-nhat); }
.thong-bao li.error { border-left-color: var(--loi); background: var(--loi-nhat); }
.hop-loi { border: 1px solid #E3B5B1; background: var(--loi-nhat); border-radius: 9px; padding: 10px 14px; margin-bottom: 12px; }
.hop-thong-tin { border: 1px solid #B8DAD5; background: var(--chinh-nhat); color: var(--chinh-dam); border-radius: 9px; padding: 9px 14px; margin-bottom: 12px; }
.hop-canh-bao { border: 1px solid #EBCFA4; background: var(--canh-bao-nhat); border-radius: 9px; padding: 10px 14px; margin-bottom: 12px; }
.hop-loi ul, .hop-canh-bao ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Thanh công cụ lọc ---------- */
.thanh-loc { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.thanh-loc .truong { min-width: 150px; }
.thanh-loc .truong.rong { min-width: 260px; flex: 1; }

/* ---------- Trạng thái trống, phân trang ---------- */
.trong { text-align: center; padding: 40px 20px; color: var(--mo); }
.trong b { display: block; color: var(--muc); font-size: 15px; margin-bottom: 4px; }
.phan-trang { display: flex; gap: 6px; justify-content: flex-end; align-items: center; padding: 10px 12px; font-size: 13px; }

/* ---------- Ô gõ để tìm (tra cứu) ---------- */
.tra-cuu { position: relative; }
.danh-sach-goi-y { position: absolute; z-index: 60; left: 0; top: calc(100% + 2px); min-width: 100%; width: max-content; max-width: 520px; max-height: 300px; overflow-y: auto; background: var(--giay); border: 1px solid var(--vien-dam); border-radius: 9px; box-shadow: 0 12px 28px rgba(19,32,38,.16); padding: 4px; }
.danh-sach-goi-y .muc-goi-y { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; padding: 6px 9px; border-radius: 6px; cursor: pointer; font-size: 13px; align-items: baseline; }
.danh-sach-goi-y .muc-goi-y .ma-gy { font-weight: 600; font-variant-numeric: tabular-nums; }
.danh-sach-goi-y .muc-goi-y .phu-gy { color: var(--mo); font-size: 12px; }
.danh-sach-goi-y .muc-goi-y.dang-chon, .danh-sach-goi-y .muc-goi-y:hover { background: var(--chinh-nhat); }
.ten-da-chon { font-size: 12px; color: var(--mo); margin-top: 2px; min-height: 16px; }

/* ---------- Trang đăng nhập ---------- */
.trang-dang-nhap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.hop-dang-nhap { width: min(380px, 100%); background: var(--giay); border: 1px solid var(--vien); border-radius: 14px; padding: 28px; }
.hop-dang-nhap h1 { margin: 12px 0 4px; }

/* ---------- In ---------- */
@media print {
  .thanh-tren, .thanh-ben, .khong-in, .tieu-de-trang .hanh-dong, .thanh-loc { display: none !important; }
  .khung { display: block; }
  .noi-dung { padding: 0; }
  body { background: #fff; }
  .vung-bang, .the { border: 0; }
}

/* ---------- Hướng dẫn (F1, nút ? trên thanh trên), bảng phím tắt (phím ?) ---------- */
.nut-huong-dan { flex: none; margin-left: auto; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--vien-dam); display: grid; place-items: center; color: var(--mo); font-weight: 700; font-size: 15px; line-height: 1; }
.nut-huong-dan:hover { color: var(--chinh-dam); border-color: var(--chinh); background: var(--chinh-nhat); text-decoration: none; }
kbd { display: inline-block; min-width: 22px; padding: 0 6px; border: 1px solid var(--vien-dam); border-bottom-width: 2px; border-radius: 5px; background: var(--giay); color: var(--muc); font: 600 12px/19px var(--font); text-align: center; white-space: nowrap; vertical-align: 1px; }
.hop-phim-tat { width: min(900px, calc(100vw - 24px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--vien); border-radius: 14px; background: var(--giay); color: var(--muc); box-shadow: 0 24px 64px rgba(19, 32, 38, .28); }
.hop-phim-tat::backdrop { background: rgba(19, 32, 38, .35); }
.dau-hop-phim { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px 12px 20px; border-bottom: 1px solid var(--vien); background: var(--giay); }
.dau-hop-phim .hanh-dong { display: flex; gap: 6px; align-items: center; }
.than-hop-phim { padding: 14px 20px 18px; }
.than-hop-phim:focus { outline: none; }
.bang-phim-tat { columns: 2 360px; column-gap: 28px; }
.nhom-phim { break-inside: avoid; margin-bottom: 16px; }
.nhom-phim h3 { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--chinh-dam); margin: 0 0 4px; }
.nhom-phim table { width: 100%; border-collapse: collapse; font-size: 13px; }
.nhom-phim td { padding: 5px 0; border-bottom: 1px solid var(--vien); vertical-align: top; }
.nhom-phim tr:last-child td { border-bottom: 0; }
.nhom-phim td.cot-phim { width: 40%; padding-right: 12px; color: var(--mo); }
.nhom-phim code { font: 12.5px/1.4 ui-monospace, Consolas, monospace; background: var(--giay-2); border: 1px solid var(--vien); border-radius: 4px; padding: 0 4px; color: var(--muc); }
/* Trang không có menu (hướng dẫn mở khi chưa đăng nhập): bỏ cột menu trống */
.khung.khong-menu { grid-template-columns: minmax(0, 1fr); }
.khung.khong-menu .thanh-ben, .khung.khong-menu .nut-menu { display: none !important; }

/* ---------- Bảng sổ, báo cáo (table[data-bang-so]): dòng đang chọn, gợi ý phím, nút quay ra (app.js) ---------- */
table[data-bang-so] tr[data-chi-tiet] { cursor: default; }
table[data-bang-so] tbody tr[data-chi-tiet]:hover td { background: #F3F7F6; }
table[data-bang-so] tbody tr.dang-chon td, table[data-bang-so] tbody tr.dang-chon:hover td { background: #FFF1B8; }
table[data-bang-so] tbody tr.dang-chon td:first-child { box-shadow: inset 3px 0 0 #D49A1A; }
.goi-y-bang-so { font-size: 12px; color: var(--mo); margin: 0 0 6px; }
.goi-y-bang-so kbd { min-width: 18px; padding: 0 4px; font-size: 11px; line-height: 16px; }
.nut-quay-ra .phim { margin-left: 2px; }
@media print {
  table[data-bang-so] tr.dang-chon td { background: none !important; box-shadow: none !important; }
  .nut-quay-ra, .goi-y-bang-so { display: none !important; }
}
