* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #f2f5f9;
  color: #22303e;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Đăng nhập ===== */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1b3a6b 0%, #264678 55%, #2e5aa8 100%);
  padding: 20px;
}
.login-box {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 16px;
  padding: 32px 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  text-align: center;
}
.logo {
  width: 64px; height: 64px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: #264678;
  color: #fff;
  font-weight: 800;
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
}
.login-box h1 { font-size: 20px; color: #264678; }
.login-box .sub { font-size: 13px; color: #7a8699; margin: 4px 0 22px; }
.login-box input {
  width: 100%;
  padding: 13px 14px;
  margin-bottom: 12px;
  border: 1px solid #d5dce6;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
.login-box input:focus { border-color: #264678; }
.login-box .chk { justify-content: flex-start; margin: 2px 0 14px; font-size: 13.5px; color: #5b6b80; }
.err { color: #c0392b; font-size: 13px; margin-bottom: 10px; text-align: left; }

/* ===== Nút ===== */
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: #264678; color: #fff; }
.btn-primary:disabled { opacity: .6; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: #dbe6f5; border: 1px solid #3d5c8f; padding: 7px 12px; font-size: 13px; }

/* ===== App layout ===== */
.app-view { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: #264678;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.brand { font-weight: 700; font-size: 16px; }
.brand-sub { font-weight: 400; font-size: 12px; opacity: .85; margin-left: 6px; }
.user-box { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 13px; opacity: .95; }

.content { flex: 1; padding: 16px 12px 76px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* ===== Trang chủ ===== */
.welcome { background: #fff; border-radius: 14px; padding: 20px; margin-bottom: 14px; box-shadow: 0 2px 10px rgba(20,40,80,.06); }
.welcome h2 { color: #264678; font-size: 19px; margin-bottom: 6px; }
.welcome p { color: #5b6b80; font-size: 14px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card {
  background: #fff;
  border-radius: 14px;
  padding: 16px 14px;
  box-shadow: 0 2px 10px rgba(20,40,80,.06);
  cursor: pointer;
  position: relative;
  transition: transform .1s;
}
.card:active { transform: scale(.97); }
.card-ico { font-size: 26px; margin-bottom: 6px; }
.card-t { font-weight: 600; color: #22303e; margin-bottom: 3px; }
.card-d { font-size: 12.5px; color: #7a8699; }
.card-tag {
  position: absolute;
  top: 10px; right: 10px;
  font-size: 11px;
  background: #eef3fa;
  color: #264678;
  padding: 3px 8px;
  border-radius: 20px;
}

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  display: flex;
  border-top: 1px solid #e2e8f0;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 11px;
  color: #7a8699;
  padding: 8px 0 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.nav-btn span:first-child { font-size: 20px; }
.nav-btn.active { color: #264678; font-weight: 600; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #22303e;
  color: #fff;
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  max-width: 90%;
}

/* ===== Desktop ===== */
@media (min-width: 900px) {
  .bottom-nav { display: none; }
  .content { padding-bottom: 24px; }
  .cards { grid-template-columns: repeat(3, 1fr); }
  .topbar { padding: 14px 28px; }
}

/* ===== Quản lý người dùng ===== */
.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.view-head h2 { font-size: 18px; color: #264678; }
.btn-ghost2 {
  background: #fff;
  color: #264678;
  border: 1px solid #264678;
  padding: 9px 14px;
  font-size: 13px;
}
.btn-sm { padding: 9px 14px; font-size: 13px; }
.user-list { display: flex; flex-direction: column; gap: 10px; }
.user-row {
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 2px 10px rgba(20,40,80,.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.user-info { flex: 1; min-width: 160px; }
.user-info .u-name { font-weight: 600; color: #22303e; }
.user-info .u-login { font-size: 12.5px; color: #7a8699; }
.badge {
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-admin { background: #264678; color: #fff; }
.badge-thukho { background: #e8f0fb; color: #264678; }
.badge-kythuat { background: #fdf3e3; color: #9a6700; }
.badge-off { background: #fbeaea; color: #c0392b; }
.user-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.user-actions .btn { padding: 8px 12px; font-size: 12.5px; }
.panel {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin-top: 14px;
  box-shadow: 0 2px 10px rgba(20,40,80,.06);
}
.panel h3 { color: #264678; margin-bottom: 12px; font-size: 16px; }
.panel input, .panel select {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid #d5dce6;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
  background: #fff;
}
.panel input:focus, .panel select:focus { border-color: #264678; }
.row-2 { display: flex; gap: 10px; margin-top: 4px; }
.row-2 .btn { flex: 1; }
.row-3 { display: flex; gap: 10px; margin-top: 4px; align-items: center; }
.row-3 > * { flex: 1; min-width: 0; }
.table-wrap { overflow-x: auto; margin-top: 14px; background: #fff; border-radius: 12px; box-shadow: 0 2px 10px rgba(20,40,80,.06); }
.table-wrap .tbl { min-width: 640px; }
#bc-title { font-size: 14.5px; color: #264678; }
#bc-totals { font-size: 14px; color: #264678; }

/* ===== View chung ===== */
.view { padding: 16px 12px 76px; max-width: 1100px; width: 100%; margin: 0 auto; }
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select {
  padding: 10px 12px;
  border: 1px solid #d5dce6;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  background: #fff;
  min-width: 0;
}
.filter-bar input[type="search"] { flex: 1; min-width: 150px; }
.filter-bar select { max-width: 100%; }
.chk-sel { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: #5b6b80; padding: 4px 0; }
.chk-sel input { width: 16px; height: 16px; }
.row-check { display: flex; align-items: center; }
.row-check input { width: 17px; height: 17px; cursor: pointer; }
.row-link { cursor: pointer; transition: box-shadow .12s; }
.row-link:hover { box-shadow: 0 3px 14px rgba(38,70,120,.18); }
.link-hint { font-size: 12.5px; color: #264678; font-weight: 600; white-space: nowrap; }
.vt-ct-item { display:flex; align-items:center; gap:8px; padding:8px 0; border-bottom:1px solid #eef1f5; }
.vt-ct-item:last-child { border-bottom:none; }
.vt-ct-item input { width:18px; height:18px; cursor:pointer; }
.vt-ct-item label { flex:1; cursor:pointer; }
.list { display: flex; flex-direction: column; gap: 10px; }
.row-item {
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 2px 10px rgba(20,40,80,.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.row-info { flex: 1; min-width: 160px; }
.row-info .r-title { font-weight: 600; color: #22303e; }
.row-info .r-sub { font-size: 12.5px; color: #7a8699; margin-top: 2px; }
.row-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { padding: 8px 12px; font-size: 12.5px; }
.badge { font-size: 11.5px; padding: 4px 10px; border-radius: 20px; font-weight: 600; }
.badge-blue { background: #e8f0fb; color: #264678; }
.badge-green { background: #e6f6ec; color: #1e7d43; }
.badge-orange { background: #fdf3e3; color: #9a6700; }
.badge-red { background: #fbeaea; color: #c0392b; }
.badge-gray { background: #eef1f5; color: #5b6b80; }
.money { font-weight: 700; color: #264678; font-size: 14px; white-space: nowrap; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0 12px; }
.chk input { width: auto; margin: 0; }
.sub-title { font-size: 14px; color: #264678; margin: 12px 0 8px; }
.line-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr 90px 110px 36px;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}
.line-row select, .line-row input {
  width: 100%;
  padding: 10px 8px;
  border: 1px solid #d5dce6;
  border-radius: 10px;
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
  background: #fff;
}
.line-row .ton-info { font-size: 11.5px; color: #7a8699; text-align: right; }
.line-row .ln-del {
  border: none; background: none; cursor: pointer;
  font-size: 17px; color: #c0392b; padding: 4px;
}
.line-row .ln-tt { display: none; }
.line-row.px-line { grid-template-columns: 1fr 90px 36px; }
.line-row.px-line select { width: 100%; }
.line-row.px-line .px-sl { display: flex; flex-direction: column; gap: 3px; }
.line-row.px-line .ton-info { font-size: 11px; color: #9aa5b1; opacity: .8; text-align: center; }
.line-row.px-line .ton-info.ton-neg { color: #c0392b; opacity: 1; font-weight: 600; }
@media (max-width: 640px) {
  .line-row.px-line { grid-template-columns: 1fr 70px 30px; }
}
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(20,40,80,.06);
}
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #eef1f5; }
.tbl th { background: #f5f8fc; color: #264678; font-size: 12.5px; white-space: nowrap; }
.tbl th[data-sort]:hover { background: #e4ecf7; }
.tbl th .bc-filter { margin-left: 3px; font-size: 10px; color: #9aa5b1; cursor: pointer; padding: 1px 3px; border-radius: 4px; vertical-align: middle; }
.tbl th .bc-filter:hover { color: #1a73e8; background: #dbe7f5; }
.bc-fv { border: 1px solid #cfd8e3; background: #fff; border-radius: 14px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: #264678; }
.bc-fv:hover { background: #eef4fb; }
.bc-fv .bc-fc { color: #7a8699; font-size: 11px; margin-left: 2px; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }
.tbl .low { color: #c0392b; font-weight: 700; }
.detail-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed #e2e8f0; font-size: 14px; gap: 10px; }
.detail-line:last-child { border-bottom: none; }
.detail-line .d-t { color: #5b6b80; }
.detail-line .d-v { font-weight: 600; text-align: right; }
@media (max-width: 640px) {
  .line-row { grid-template-columns: 1fr 1fr 80px 90px 30px; }
  .line-row .ln-tt { display: none; }
}

  .code-ro {
    font-family: "Courier New", Consolas, monospace;
    font-weight: 700;
    letter-spacing: 1px;
    background: #eef1f5;
    color: #1a3a5c;
    text-align: center;
  }

/* ---- Vai trò "Xem toàn bộ" (chỉ đọc): ẩn nút thêm/sửa/xóa ---- */
body.view-only button[data-act="edit"],
body.view-only button[data-act="del"],
body.view-only button[data-act="delrole"],
body.view-only button[data-act="editrole"],
body.view-only button[data-act="toggle"],
body.view-only button[data-act="reset"],
body.view-only button[data-act="restore"],
body.view-only button[data-act="dk"],
body.view-only button[data-act="delline"],
body.view-only button[data-act="saverow"],
body.view-only button[data-act="cancelrow"],
body.view-only button[data-pact="edit"],
body.view-only button[data-pact="del"],
body.view-only button[data-pact="saverow"],
body.view-only button[data-pact="cancelrow"],
body.view-only button[data-doi-act="edit"],
body.view-only button[data-doi-act="del"],
body.view-only button[data-doi-act="saverow"],
body.view-only button[data-doi-act="cancelrow"],
body.view-only button[data-save],
body.view-only button[data-cancel],
body.view-only #btn-add-congtrinh,
body.view-only #btn-add-vattu,
body.view-only #btn-add-phieunhap,
body.view-only #btn-add-phieuxuat,
body.view-only #btn-add-tuyen,
body.view-only #btn-add-user,
body.view-only #btn-vt-nhom,
body.view-only #btn-vt-ct-multi,
body.view-only #btn-pn-addline,
body.view-only #btn-px-addline,
body.view-only #btn-td-add,
body.view-only #btn-td-add-day,
body.view-only #btn-ht-add,
body.view-only #btn-role-manage,
body.view-only #btn-save-role,
body.view-only #kctvt-add,
body.view-only #kctvt-nhom-btn,
body.view-only #kctpn-add,
body.view-only #kctpn-addline,
body.view-only #kctpx-add,
body.view-only #kctpx-addline,
body.view-only #cv-add {
  display: none !important;
}

/* ===== Đại Cồ Việt submenu ===== */
.btn-dcv { font-weight: 600; color: #fff; }
.btn-dcv.active { background: #3d5c8f; border-color: #7fa0d4; }
.btn-admin .t { margin-left: 4px; }
@media (max-width: 640px) {
  .user-name { display: none; }
  .btn-dcv { padding: 7px 9px; font-size: 12px; }
  .btn-admin .t { display: none; }
}
.dcv-submenu {
  position: fixed;
  top: 58px;
  right: 12px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
  z-index: 40;
  padding: 6px;
  min-width: 220px;
}
.dcv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 14px;
  color: #264678;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.dcv-item:hover { background: #f1f5fb; }
.dcv-item span:first-child { font-size: 18px; }

/* ===== Kho Công Ty tabs ===== */
.kct-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.kct-tab {
  flex: 1;
  min-width: 90px;
  padding: 9px 8px;
  border: 1px solid #d5dce6;
  background: #fff;
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  color: #5b6b80;
  cursor: pointer;
}
.kct-tab.active { background: #264678; color: #fff; border-color: #264678; font-weight: 600; }

.panel textarea {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid #d5dce6;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
  background: #fff;
  resize: vertical;
  box-sizing: border-box;
}
.panel textarea:focus { border-color: #264678; }