:root {
  --nen: #f4f5f7;
  --hop: #ffffff;
  --chu: #1d2330;
  --chu-nhat: #5b6475;
  --vien: #d9dde4;
  --chinh: #0b5cad;
  --chinh-dam: #084a8c;
  --loi: #b42318;
  --nen-loi: #fdecea;
  --canh-bao: #8a5a00;
  --nen-canh-bao: #fff6e0;
  --ok: #157f3b;
  --bo: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--nen); color: var(--chu);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--chinh); }
h1 { font-size: 1.4rem; margin: 0.4rem 0 0.8rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.6rem; }
code { background: #eef0f3; padding: 0 4px; border-radius: 4px; font-size: 0.9em; word-break: break-word; }

/* Thanh trên */
header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  background: var(--chinh); color: #fff; padding: 8px 16px;
}
header a { color: #fff; text-decoration: none; }
.ten-app { font-weight: 700; font-size: 1.05rem; }
nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
nav a { padding: 6px 10px; border-radius: 6px; }
nav a:hover, nav a.dang-chon { background: rgba(255, 255, 255, 0.18); }
.tai-khoan { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.tai-khoan .nut-phu { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.6); padding: 4px 10px; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.hop { background: var(--hop); border: 1px solid var(--vien); border-radius: var(--bo); padding: 16px; margin-bottom: 16px; }
.hep { max-width: 420px; margin: 8vh auto; }
.mo-ta, .ghi-chu { color: var(--chu-nhat); }
.ghi-chu { font-size: 0.88rem; }
.dang-tai { color: var(--chu-nhat); }
.tieu-de-trang { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.ma { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 600; word-break: break-all; }

/* Nút, ô nhập */
button, .nut {
  display: inline-block; font: inherit; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--chinh); color: #fff; border: 1px solid var(--chinh); border-radius: 6px; padding: 8px 16px;
}
button:hover, .nut:hover { background: var(--chinh-dam); }
button:disabled { opacity: 0.6; cursor: wait; }
.nut-phu, button.nut-phu { background: #fff; color: var(--chinh); border-color: var(--vien); }
.nut-phu:hover { background: #eef3fa; }
.nhom-nut { display: flex; flex-wrap: wrap; gap: 8px; }
input, select {
  font: inherit; color: inherit; background: #fff; border: 1px solid var(--vien); border-radius: 6px;
  padding: 8px 10px; min-height: 40px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--chinh); outline-offset: -1px; }
input:disabled, select:disabled { background: #eef0f3; color: var(--chu-nhat); }
input[type="checkbox"] { width: auto; min-height: 0; }
label { display: block; margin-bottom: 10px; font-size: 0.92rem; color: var(--chu-nhat); }
label input, label select { margin-top: 4px; color: var(--chu); }
label.chon { display: flex; align-items: center; gap: 8px; color: var(--chu); }
form.hop button[type="submit"] { width: 100%; }
.form-ma button[type="submit"] { width: auto; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-weight: 600; margin-bottom: 8px; }
.luoi { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
.xem-ma { font-size: 1.05rem; }

.loi { color: var(--loi); background: var(--nen-loi); border-radius: 6px; padding: 8px 12px; }
.canh-bao { color: var(--canh-bao); background: var(--nen-canh-bao); border-radius: 6px; padding: 8px 12px; margin-top: 8px; }
.loi ul, .canh-bao ul { margin: 4px 0; padding-left: 20px; }
.chu-loi { color: var(--loi); }
.chu-canh-bao { color: var(--canh-bao); }

/* Bộ lọc danh mục */
.bo-loc { display: grid; grid-template-columns: 2fr repeat(6, minmax(110px, 1fr)) auto; gap: 8px; margin-bottom: 8px; }
.bo-loc input[type="search"] { min-width: 0; }

/* Bảng */
table { width: 100%; border-collapse: collapse; background: var(--hop); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--vien); vertical-align: top; }
th { background: #eef0f3; font-weight: 600; font-size: 0.88rem; position: sticky; top: 0; }
td.so, th.so { text-align: right; white-space: nowrap; }
.bang-danh-muc { border: 1px solid var(--vien); border-radius: var(--bo); }
.bang-danh-muc tbody tr { cursor: pointer; }
.bang-danh-muc tbody tr:hover { background: #f3f7fc; }
.bang-danh-muc .ten { color: var(--chu-nhat); font-size: 0.9rem; }
.bang-danh-muc .ma-cu { color: var(--chu-nhat); font-size: 0.85rem; }
.bang-danh-muc .ma a { text-decoration: none; }
.bang-danh-muc td[data-nhan="Mã"] { white-space: nowrap; }
.bang-danh-muc td[data-nhan="Mã"] .ma { word-break: normal; }
.ngung-dung td { opacity: 0.6; }
.nhan-ngung { font-size: 0.75rem; font-weight: 600; color: var(--loi); background: var(--nen-loi); border-radius: 4px; padding: 1px 6px; white-space: nowrap; font-family: inherit; }
.trong { text-align: center; color: var(--chu-nhat); padding: 24px; }

/* Chi tiết */
.hai-cot { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.hai-cot .hop { margin-bottom: 0; }
.hai-cot + .hop { margin-top: 16px; }
.thong-so { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.thong-so dt { color: var(--chu-nhat); }
.thong-so dd { margin: 0; }
.quy-doi { display: grid; grid-template-columns: 1fr 90px; gap: 8px; margin-bottom: 8px; }
.bang-quy-doi th { background: none; position: static; }
.bang-quy-doi td { text-align: right; font-weight: 600; }
.lich-su { padding-left: 18px; margin: 0; }
.lich-su li { margin-bottom: 6px; }
.tom-tat { padding-left: 18px; }
.bang-bao td:first-child { white-space: nowrap; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }

/* Thông báo nổi */
#thong-bao {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 150%);
  background: var(--ok); color: #fff; padding: 10px 18px; border-radius: 8px; max-width: calc(100% - 32px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); transition: transform 0.2s, visibility 0.2s; z-index: 10; visibility: hidden;
}
#thong-bao.hien { transform: translate(-50%, 0); visibility: visible; }
#thong-bao.loi { background: var(--loi); }

/* Máy tính bảng */
@media (max-width: 1000px) {
  .bo-loc { grid-template-columns: repeat(3, 1fr); }
  .bo-loc input[type="search"] { grid-column: 1 / -1; }
  .hai-cot { grid-template-columns: 1fr; }
}

/* Điện thoại: bảng chuyển thành thẻ */
@media (max-width: 700px) {
  main { padding: 12px; }
  header { padding: 8px 12px; }
  .tai-khoan { width: 100%; justify-content: space-between; }
  .bo-loc { grid-template-columns: 1fr 1fr; }
  .bang-danh-muc, .bang-nguoi-dung { border: 0; background: none; }
  .bang-danh-muc thead, .bang-nguoi-dung thead { display: none; }
  .bang-danh-muc tr, .bang-nguoi-dung tr {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
    background: var(--hop); border: 1px solid var(--vien); border-radius: var(--bo); padding: 10px 12px; margin-bottom: 8px;
  }
  .bang-danh-muc td, .bang-nguoi-dung td { border: 0; padding: 0; text-align: left; }
  .bang-danh-muc td[data-nhan="Mã"] { grid-column: 1; white-space: normal; }
  .bang-danh-muc td[data-nhan="Khối lượng"] { grid-column: 2; grid-row: 1; text-align: right; }
  .bang-danh-muc td.ten { grid-column: 1 / -1; }
  .bang-danh-muc td[data-nhan="Hãng"], .bang-danh-muc td[data-nhan="DN"], .bang-danh-muc td[data-nhan="OD"],
  .bang-danh-muc td[data-nhan="Dày"], .bang-danh-muc td[data-nhan="Đơn vị"] { display: none; }
  .bang-danh-muc td.ma-cu { grid-column: 1 / -1; }
  .bang-danh-muc td.ma-cu:not(:empty)::before { content: "Mã cũ: "; }
  .bang-danh-muc td.trong { grid-column: 1 / -1; }
  .bang-nguoi-dung tr { grid-template-columns: 1fr; }
  .bang-nguoi-dung td { padding: 2px 0; }
  .thong-so { grid-template-columns: 1fr 1.4fr; }
  .bang-bao { font-size: 0.85rem; }
  .bang-bao th, .bang-bao td { padding: 6px; }
}
