/* Mau lay tu logo Bach Khoa Song Khoe: xanh la cay dam #3E7140.
   Nen va vien deu nga xanh nhe cho diu mat, khong dung xam lanh. */
:root {
  --bg: #f4f7f1;
  --surface: #ffffff;
  --surface-2: #f2f6ee;
  --border: #e0e8d9;
  --border-strong: #c8d6be;
  --text: #1c2a1b;
  --muted: #57654f;
  --faint: #879077;
  --brand: #3e7140;
  --brand-dark: #2f5731;
  --brand-soft: #e7f0e3;
  --green: #3e7140;
  --green-soft: #e2efdd;
  --red: #a63a2f;
  --red-soft: #f8e8e5;
  --amber: #96702a;
  --amber-soft: #f7efdc;
  --blue: #3a5f8a;
  --blue-soft: #e4ecf4;
  --radius: 13px;
  --shadow: 0 1px 2px rgba(28,42,27,.05), 0 6px 18px rgba(28,42,27,.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.58;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Dang nhap ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(155deg, #4a8149 0%, #356035 50%, #24421f 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: 14px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card { text-align: center; }
.login-card .field, .login-card .err-box { text-align: left; }
/* Co file public/logo.png thi hien logo that, khong co thi tu an di, con lai phan chu */
.login-card .brand-logo { display: block; width: 132px; height: auto; margin: 0 auto 16px; }
.login-card .logo { font-size: 25px; font-weight: 700; color: var(--brand-dark); letter-spacing: -.02em; }
.login-card .logo em {
  display: block; font-style: normal; font-size: 11.5px; font-weight: 500;
  letter-spacing: .34em; text-transform: uppercase; color: var(--brand); margin-top: 4px;
}
.login-card .tagline { color: var(--muted); margin: 12px 0 26px; font-size: 13px; }

/* Dau la trong thanh menu, goi lai chiec la tren logo */
.sidebar .brand { display: flex; align-items: center; gap: 11px; }
.sidebar .brand .wm { line-height: 1.22; }
.sidebar .brand .wm em {
  display: block; font-style: normal; font-weight: 400; font-size: 10px;
  color: #9db892; letter-spacing: .2em; text-transform: uppercase; margin-top: 2px;
}

/* ---------- Khung ---------- */
.app { display: none; min-height: 100vh; grid-template-columns: 224px 1fr; }
.app.on { display: grid; }

.sidebar {
  background: #24421f; color: #d3e2ca; padding: 16px 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 4px 18px 18px; font-size: 16px; font-weight: 700; color: #fff; line-height: 1.25; }
.sidebar .brand small { display: block; font-weight: 400; font-size: 11px; color: #9db892; letter-spacing: .04em; text-transform: uppercase; margin-top: 3px; }
.nav { flex: 1; overflow-y: auto; }
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 18px; background: none; border: 0; color: #b6cdad; cursor: pointer;
  font-size: 13.5px; border-left: 3px solid transparent;
}
.nav button:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav button.active { background: rgba(255,255,255,.09); color: #fff; border-left-color: #9ed48f; font-weight: 600; }
.nav .ico { width: 18px; text-align: center; font-size: 14px; opacity: .9; }
.nav .badge {
  margin-left: auto; background: #dc2626; color: #fff; border-radius: 9px;
  padding: 1px 6px; font-size: 11px; font-weight: 700;
}
.sidebar .foot { padding: 14px 18px 2px; border-top: 1px solid rgba(255,255,255,.09); font-size: 12px; }
.sidebar .foot .who { color: #fff; font-weight: 600; }
.sidebar .foot .role { color: #9db892; font-size: 11px; }
.sidebar .foot a { color: #9db892; cursor: pointer; text-decoration: none; }
.sidebar .foot a:hover { color: #fff; text-decoration: underline; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; }
.topbar .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.topbar .spacer { flex: 1; }
.content { padding: 20px 24px 60px; }

/* ---------- Thanh phan ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card-head h3 { font-size: 14.5px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 760px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 25px; font-weight: 700; margin-top: 5px; letter-spacing: -.02em; }
.kpi .hint { color: var(--faint); font-size: 12px; margin-top: 3px; }
.kpi.good .value { color: var(--green); }
.kpi.bad .value { color: var(--red); }
.kpi.brand .value { color: var(--brand); }

/* ---------- Bang ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  background: var(--surface-2); font-size: 11.5px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
}
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
.empty { padding: 52px 20px; text-align: center; color: var(--faint); }
.empty .big { font-size: 30px; opacity: .5; display: block; margin-bottom: 8px; }

/* ---------- Nut & form ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: 9px; cursor: pointer; font-size: 13.5px; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: var(--red); border-color: #e3c6c1; }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field .help { font-size: 11.5px; color: var(--faint); margin-top: 3px; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong);
  border-radius: 9px; background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 72px; font-family: inherit; }
.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline > * { flex: 1; min-width: 130px; }
.inline > .fixed { flex: 0 0 auto; min-width: 0; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13.5px; }
.check input { width: auto; }

.toolbar {
  display: flex; gap: 9px; flex-wrap: wrap; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.toolbar .search { flex: 1; min-width: 180px; max-width: 380px; }
.toolbar select { width: auto; min-width: 130px; }

/* ---------- Nhan ---------- */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.tag.gray { background: #e6ece0; color: #4e5a46; }
.tag.green { background: var(--green-soft); color: #14532d; }
.tag.red { background: var(--red-soft); color: #7f1d1d; }
.tag.amber { background: var(--amber-soft); color: #78350f; }
.tag.blue { background: var(--blue-soft); color: #1e3a8a; }
.tag.brand { background: var(--brand-soft); color: var(--brand-dark); }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.pos { color: var(--green); font-weight: 600; }
.money.neg { color: var(--red); font-weight: 600; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 12px; }

/* ---------- Cua so ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(16,33,30,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3); overflow: hidden;
}
.modal.wide { max-width: 940px; }
.modal.xwide { max-width: 1180px; }
.modal-head {
  padding: 15px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal-head h3 { font-size: 16px; }
.modal-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.modal-head .x {
  margin-left: auto; background: none; border: 0; font-size: 22px; line-height: 1;
  color: var(--faint); cursor: pointer; padding: 0 4px;
}
.modal-head .x:hover { color: var(--text); }
.modal-body { padding: 20px; max-height: calc(100vh - 220px); overflow-y: auto; }
.modal-body.tight { padding: 0; }
.modal-foot {
  padding: 13px 20px; border-top: 1px solid var(--border); background: var(--surface-2);
  display: flex; gap: 9px; justify-content: flex-end;
}

/* ---------- Tab ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 16px; background: var(--surface-2); overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 13px;
  cursor: pointer; color: var(--muted); font-size: 13.5px; font-weight: 500; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 650; }

/* ---------- Bieu do thanh ---------- */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding: 10px 4px 0; }
.bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.bars .bar { width: 100%; max-width: 48px; background: linear-gradient(180deg, #7cb474, var(--brand)); border-radius: 5px 5px 0 0; min-height: 3px; }
.bars .cap { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars .val { font-size: 11px; font-weight: 650; color: var(--brand-dark); }

.hbar { background: #e6ece0; border-radius: 5px; height: 8px; overflow: hidden; }
.hbar > i { display: block; height: 100%; background: var(--brand); border-radius: 5px; }

/* ---------- Danh sach ---------- */
.list-item { padding: 11px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .meta { color: var(--muted); font-size: 12.5px; margin-top: 1px; }

.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline .ev { position: relative; padding: 0 0 16px; }
.timeline .ev::before {
  content: ''; position: absolute; left: -19px; top: 5px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--brand); border: 2px solid var(--surface);
}
.timeline .ev .when { font-size: 12px; color: var(--faint); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #16211e; color: #fff; padding: 11px 20px; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 999; font-size: 13.5px; max-width: 90vw;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

.spin { padding: 40px; text-align: center; color: var(--faint); }
.err-box { background: var(--red-soft); color: #7f1d1d; padding: 10px 13px; border-radius: 8px; font-size: 13px; margin-bottom: 13px; }
.ok-box { background: var(--green-soft); color: #14532d; padding: 10px 13px; border-radius: 8px; font-size: 13px; margin-bottom: 13px; }
.info-box { background: var(--brand-soft); color: var(--brand-dark); padding: 11px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 13px; }

.menu-btn { display: none; }
.sidebar-backdrop { display: none; }

/* ---------- May tinh bang & dien thoai ---------- */
@media (max-width: 860px) {
  .app.on { grid-template-columns: 1fr; }
  /* Menu trai thanh ngan keo, giu nguyen danh sach doc + ten nguoi dung + dang xuat */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 264px; height: 100%; z-index: 60;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  .menu-open .sidebar { transform: none; }
  .menu-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(16,33,30,.45); z-index: 50; }
  .nav button { padding: 11px 18px; font-size: 14.5px; }
  .menu-btn {
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
    width: 40px; height: 40px; border: 1px solid var(--border-strong); border-radius: 10px;
    background: var(--surface); font-size: 19px; cursor: pointer; color: var(--brand-dark);
  }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar .title-box { flex: 1; min-width: 0; }
  .topbar .spacer { display: none; }
}

@media (max-width: 760px) {
  /* So lieu tong quan: 2 o mot hang thay vi moi o mot hang */
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
  .kpi { padding: 11px 12px; }
  .kpi .label { font-size: 10.5px; }
  .kpi .value { font-size: 19px; }
  .kpi .hint { font-size: 11px; }
  .grid { gap: 12px; }

  .topbar { position: static; }
  .topbar h1 { font-size: 16.5px; }
  .topbar .sub { font-size: 12px; }
  .topbar .btn-row { width: 100%; }
  .topbar .btn-row .btn { flex: 1; justify-content: center; }

  /* Chu 16px de iPhone khong tu phong to khi bam vao o nhap */
  input[type=text], input[type=password], input[type=number], input[type=date], select, textarea { font-size: 16px; padding: 9px 11px; }
  .btn { padding: 9px 13px; }
  .btn.sm { padding: 6px 10px; }

  .toolbar { padding: 10px 12px; }
  .toolbar .search { min-width: 100%; max-width: none; }
  .toolbar select { flex: 1 1 140px; min-width: 0; }
  .tabs { padding: 0 8px; }
  .card-body { padding: 14px; }

  /* Cua so nhap lieu: chiem tron man hinh, nut luu luon nam o day */
  .overlay { padding: 0; align-items: stretch; }
  .modal, .modal.wide, .modal.xwide { max-width: none; border-radius: 0; min-height: 100%; display: flex; flex-direction: column; }
  .modal-head { padding: 12px 14px; position: sticky; top: 0; background: var(--surface); z-index: 3; }
  .modal-body { padding: 14px; max-height: none; flex: 1; }
  .modal-foot { padding: 10px 14px; position: sticky; bottom: 0; z-index: 3; }
  .modal-foot .btn { flex: 1; justify-content: center; }
  .inline { gap: 0 10px; }
  .inline > * { min-width: 100%; }
  .inline > .fixed { min-width: 0; }

  /* Bang -> tung the: moi dong mot khung, moi o mot hang "Ten cot ..... gia tri" */
  table.xep-the thead { display: none; }
  table.xep-the, table.xep-the tbody, table.xep-the tfoot, table.xep-the tr, table.xep-the td { display: block; width: 100%; }
  table.xep-the tr { border-bottom: 6px solid var(--bg); padding: 6px 0; }
  table.xep-the td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border: 0; padding: 4px 14px; text-align: right; min-height: 28px;
  }
  table.xep-the td::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 45%; text-align: left;
    font-size: 11.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .03em;
  }
  table.xep-the td:not([data-label])::before { content: none; }
  table.xep-the td:not([data-label]) { justify-content: flex-start; text-align: left; }
  /* O dau tien (thuong la ten) lam tieu de cua the */
  table.xep-the td.the-tieu-de {
    font-weight: 650; font-size: 15px; justify-content: flex-start; text-align: left; padding-top: 6px;
  }
  table.xep-the td.the-tieu-de::before { content: none; }
  table.xep-the td.the-an { display: none; }
  table.xep-the td:empty, table.xep-the td[data-label]:not(:has(*)):empty { display: none; }
  table.xep-the td.nowrap:last-child { justify-content: flex-end; }
  table.xep-the td.nowrap:last-child::before { content: none; }
  tbody tr:hover { background: transparent; }
}

@media print {
  .sidebar, .topbar, .toolbar, .btn, .tabs { display: none !important; }
  body, .app.on { display: block; background: #fff; }
  .card { box-shadow: none; border-color: #ccc; page-break-inside: avoid; }
}
