/* Giao diện mới (docs/KE_HOACH_GIAO_DIEN_MOI.md mục 1). Màu theo bản thiết kế: nền kem, mực nâu đen, 1 nút vàng / trang */
:root {
  --ink: #1A1712;
  --ink-2: #4F493F;
  --muted: #635C51;
  --ground: #F5F3EE;
  --surface: #FFFFFF;
  --surface-2: #F9F7F2;
  --line: #E2DCCF;
  --line-strong: #D5CDBD;
  --gold: #D6A53C;
  --gold-ink: #8A5D0B;
  --gold-soft: #FBF3DF;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --ok: #0F5733;
  --ok-soft: #E7F4EC;
  --wait: #17497F;
  --wait-soft: #E8F0FA;
  --none: #3F3A32;
  --none-soft: #EDEAE3;
  --nav-bg: #1A1712;
  --nav-fg: #CFC6B4;
  --nav-icon: #9C9384;
  --nav-active: #2B2721;
  --nav-line: #2E2A24;
  --badge: #D9443A;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(26, 23, 18, 0.12);
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --nav-w: 248px;
  --nav-w-closed: 76px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }  /* .btn / .badge có display riêng, hidden vẫn phải ẩn */
html, body { margin: 0; }
body.app {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
body.app a { color: var(--gold-ink); }
body.app :focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

/* ============================== Khung trang ============================== */
.app-shell { display: flex; min-height: 100vh; }
.app-nav {
  position: sticky; top: 0; height: 100vh; flex: 0 0 var(--nav-w); width: var(--nav-w);
  display: flex; flex-direction: column; gap: 12px; padding: 16px 14px;
  background: var(--nav-bg); color: #FFFFFF; overflow: hidden; z-index: 30;
}
.app-nav__brand { display: flex; align-items: center; gap: 10px; }
.app-nav__logo {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; background: var(--gold); color: var(--ink);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.app-nav__title { flex: 1; min-width: 0; line-height: 1.3; }
.app-nav__title b { display: block; font-size: 15px; white-space: nowrap; }
.app-nav__title span { display: block; font-size: 12px; color: var(--nav-icon); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-nav__toggle {
  width: 32px; height: 32px; flex-shrink: 0; border: 1px solid #3A352D; border-radius: var(--radius-sm);
  background: transparent; color: var(--nav-fg); display: flex; align-items: center; justify-content: center; cursor: pointer;
}
/* Menu vừa 1 màn hình, không cuộn (màn thấp thì thu nhỏ dòng, xem @media max-height). Logo + tài khoản luôn cố định,
   chỉ màn quá thấp (điện thoại xoay ngang) mới cuộn riêng phần menu */
.app-nav__menu {
  flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1px; overflow-y: auto;
  scrollbar-width: none;
}
.app-nav__menu::-webkit-scrollbar { display: none; }
.app-nav__group { padding: 8px 12px 2px; font-size: 11px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--nav-icon); }
.app-nav__link {
  position: relative; height: 34px; flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  border-radius: var(--radius-sm); color: var(--nav-fg); text-decoration: none; font-weight: 500; white-space: nowrap;
}
body.app .app-nav__link { color: var(--nav-fg); }
.app-nav__link svg { flex-shrink: 0; color: var(--nav-icon); }
.app-nav__link:hover { background: #24201B; color: #FFFFFF; }
.app-nav__link[aria-current="page"] { background: var(--nav-active); color: #FFFFFF; font-weight: 600; box-shadow: inset 3px 0 0 var(--gold); }
.app-nav__link[aria-current="page"] svg { color: var(--gold); }
.app-nav__label { flex: 1; }
.app-nav__badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--badge); color: #FFFFFF;
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.app-nav__user { display: flex; align-items: center; gap: 10px; padding-top: 12px; border-top: 1px solid var(--nav-line); }
.app-nav__avatar {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%; background: #3A352D; color: #F2D28A;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
}
.app-nav__who { flex: 1; min-width: 0; line-height: 1.3; background: none; border: 0; padding: 0; text-align: left; color: #FFFFFF; font: inherit; cursor: pointer; }
.app-nav__who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-nav__who span { display: block; font-size: 12px; color: var(--nav-icon); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-nav__icon-btn {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: var(--radius-sm); border: 0; background: transparent;
  display: flex; align-items: center; justify-content: center; color: #F4B4AC; cursor: pointer;
}
body.app .app-nav__icon-btn { color: #F4B4AC; }
body.app .app-nav__icon-btn--muted { color: var(--nav-fg); }
.app-nav__icon-btn:hover { background: #24201B; }

/* Thu gọn còn icon (desktop) */
.nav-collapsed .app-nav { flex-basis: var(--nav-w-closed); width: var(--nav-w-closed); padding: 16px 12px; }
.nav-collapsed .app-nav__title, .nav-collapsed .app-nav__label, .nav-collapsed .app-nav__group,
.nav-collapsed .app-nav__who, .nav-collapsed .app-nav__avatar { display: none; }
.nav-collapsed .app-nav__brand, .nav-collapsed .app-nav__user { flex-direction: column; gap: 6px; }
.nav-collapsed .app-nav__link { justify-content: center; padding: 0; }
.nav-collapsed .app-nav__group-gap { display: block; flex-shrink: 0; height: 1px; margin: 8px 12px; background: var(--nav-line); }
.app-nav__group-gap { display: none; }
.nav-collapsed .app-nav__badge {
  position: absolute; top: 7px; right: 12px; min-width: 8px; width: 8px; height: 8px; padding: 0; font-size: 0;
}

/* Màn thấp (laptop 1366×768 trừ thanh trình duyệt còn ~650px): dòng menu thấp lại để vẫn không cuộn */
@media (max-height: 680px) {
  .app-nav, .nav-collapsed .app-nav { padding-top: 12px; padding-bottom: 12px; gap: 8px; }
  .app-nav__link { height: 30px; }
  .app-nav__group { padding: 6px 12px 1px; }
  .nav-collapsed .app-nav__group-gap { margin: 5px 12px; }
  .app-nav__user { padding-top: 8px; }
}
/* Màn rất thấp: bỏ tên nhóm, ngăn nhóm bằng vạch như khi thu gọn */
@media (max-height: 560px) {
  .app-nav__link { height: 28px; }
  .app-nav__group { display: none; }
  .app-nav__group-gap { display: block; flex-shrink: 0; height: 1px; margin: 4px 12px; background: var(--nav-line); }
  .nav-collapsed .app-nav__logo { display: none; }
}

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 20px 28px 8px;
}
.app-header h1 { flex: 1 1 260px; margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.2px; }
.app-header__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.app-content { flex: 1; padding: 8px 28px 28px; min-width: 0; }

/* Thanh dưới cùng + ngăn kéo menu (mobile) */
.app-tabbar { display: none; }
.app-scrim { display: none; }
@media (max-width: 767px) {
  .app-shell { display: block; }
  .app-nav {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); height: 100%; transform: translateX(-105%);
    transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .nav-collapsed .app-nav { width: min(300px, 86vw); padding: 16px 14px; }
  .nav-collapsed .app-nav__title, .nav-collapsed .app-nav__label, .nav-collapsed .app-nav__group,
  .nav-collapsed .app-nav__who { display: block; }
  .nav-collapsed .app-nav__avatar { display: flex; }
  .nav-collapsed .app-nav__brand, .nav-collapsed .app-nav__user { flex-direction: row; gap: 10px; }
  .nav-collapsed .app-nav__group-gap { display: none; }
  .nav-collapsed .app-nav__link { justify-content: flex-start; padding: 0 12px; }
  .nav-drawer-open .app-nav { transform: none; }
  .nav-drawer-open .app-scrim { display: block; position: fixed; inset: 0; background: rgba(26, 23, 18, 0.55); z-index: 25; }
  .app-nav__toggle { display: none; }
  .app-header { padding: 14px 16px 6px; }
  .app-header h1 { font-size: 20px; }
  .app-content { padding: 8px 16px 96px; }
  .app-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
    height: 64px; padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line);
  }
  .app-tabbar a, .app-tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: none;
    color: var(--muted); text-decoration: none; font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
  }
  body.app .app-tabbar a { color: var(--muted); }
  .app-tabbar [aria-current="page"] { color: var(--ink); }
  body.app .app-tabbar a[aria-current="page"] { color: var(--ink); }
  .app-tabbar [aria-current="page"] svg { color: var(--gold-ink); }
}

/* ============================== Thành phần ============================== */
.btn {
  height: 40px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
body.app a.btn { color: var(--ink); }
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn--primary:hover { background: #C9972E; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #FFFFFF; }
.btn--danger:hover { background: #912018; border-color: #912018; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn[disabled], .btn.is-busy { opacity: 0.55; cursor: not-allowed; }
.btn.is-busy::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.card__head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card__head h2 { flex: 1; margin: 0; font-size: 15px; font-weight: 700; }
.card__body { padding: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi__label { font-size: 13px; color: var(--muted); }
.kpi__value { margin-top: 2px; font-size: 22px; font-weight: 700; }
.kpi__unit { font-size: 13px; font-weight: 500; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 6px;
  font-size: 12px; font-weight: 600; background: var(--none-soft); color: var(--none); white-space: nowrap;
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--wait { background: var(--wait-soft); color: var(--wait); }
.badge--err { background: var(--danger-soft); color: #9A1D14; }
.badge--gold { background: var(--gold-soft); color: var(--gold-ink); }

.tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: #E9E3D6; border-radius: var(--radius); margin-bottom: 16px; }
.tabs a, .tabs button {
  height: 36px; padding: 0 16px; display: flex; align-items: center; border: 0; border-radius: 9px; background: transparent;
  color: var(--ink); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
body.app .tabs a { color: var(--ink); }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { background: var(--surface); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input {
  height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface);
  color: var(--ink); font: inherit; font-size: 15px; width: 100%;
}
.input:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.input[aria-invalid="true"] { border-color: #E0A39B; }
.field__hint { font-size: 12px; color: var(--muted); }
.field__error { font-size: 12px; color: #9A1D14; }

.table-wrap { overflow-x: auto; position: relative; }  /* nhãn ẩn (sr-only) trong bảng rộng không đẩy trang tràn ngang */
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid #EFEAE0; vertical-align: middle; }
.table .num { text-align: right; }
.table tbody tr:hover { background: #FCFBF8; }

/* Phân trang (ui.js pager) */
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.pager__info { flex: 1 1 200px; }
.pager__size { display: flex; align-items: center; gap: 6px; }
.pager__size select { height: 32px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font: inherit; background: var(--surface); }
.pager__pages { display: flex; align-items: center; gap: 4px; }
.pager__pages button {
  min-width: 34px; height: 34px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
}
.pager__pages button[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #FFFFFF; font-weight: 700; }
.pager__pages button:disabled { opacity: 0.4; cursor: default; }
.pager__more { width: 100%; }
@media (max-width: 767px) { .pager__pages, .pager__size { display: none; } }
@media (min-width: 768px) { .pager__more { display: none; } }

/* Trạng thái chung (D-TrangThai) */
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; margin-bottom: 4px; font-size: 16px; color: var(--ink); }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, #EFEAE0 25%, #F7F4EE 50%, #EFEAE0 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Hộp thoại: desktop giữa màn hình, mobile là sheet từ dưới lên */
dialog.modal {
  width: min(480px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 16px; background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
}
dialog.modal::backdrop { background: rgba(26, 23, 18, 0.55); }
.modal__head { display: flex; align-items: center; gap: 8px; padding: 18px 20px 6px; }
.modal__head h2 { flex: 1; margin: 0; font-size: 19px; }
.modal__body { padding: 8px 20px; display: flex; flex-direction: column; gap: 12px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px 20px; }
@media (max-width: 767px) {
  dialog.modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; }
  .modal__foot { display: grid; grid-template-columns: 1fr 1fr; }
  .modal__foot .btn { height: 48px; }
}

/* Thông báo góc phải (toast). Giữ id alertContainer: code cũ ghi vào đây */
#alertContainer {
  position: fixed; bottom: 16px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px;  /* góc dưới: không che nút ở đầu trang */
  max-width: min(420px, calc(100vw - 32px)); pointer-events: none;
}
#alertContainer .alert, #alertContainer .toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; margin: 0; padding: 12px 14px;
  border-radius: var(--radius); background: var(--ink); color: #FFFFFF; box-shadow: var(--shadow);
  font-family: var(--font); font-size: 14px; line-height: 1.4; animation: toast-in 0.2s ease;
}
#alertContainer .alert::before, #alertContainer .toast::before {
  content: ""; flex-shrink: 0; width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: #8C8576;
}
#alertContainer .alert-success::before, #alertContainer .toast--success::before { background: #3CC27A; }
#alertContainer .alert-error::before, #alertContainer .toast--error::before { background: #F0645A; }
#alertContainer .alert-warning::before, #alertContainer .toast--info::before { background: #6FA8E8; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }
@media (max-width: 767px) { #alertContainer { top: 12px; bottom: auto; left: 16px; right: 16px; max-width: none; } }  /* đáy đã có thanh tổng tiền + menu */

/* Lớp chờ cũ (#loading): giữ id cho code cũ */
body.app .loading { display: none; position: fixed; inset: 0; z-index: 900; background: rgba(245, 243, 238, 0.6); }
body.app .loading .f-loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
body.app .loading .spin-loading {
  width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--gold); animation: spin 0.8s linear infinite;
}

/* Sheet gửi lệnh in (M23, static/assets/js/print-sheet.js) */
.ps { gap: 14px; }
.ps p { margin: 0; font-size: 13px; color: var(--muted); }
.ps fieldset { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; border: 0; }
.ps legend { margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.ps-option { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); font: inherit; color: var(--ink); text-align: left; cursor: pointer; }
.ps-option:has(input:checked), .ps-option[aria-checked="true"] { border: 2px solid var(--gold); padding: 9px 11px; background: #FFFBF2; }
.ps-option input { width: 20px; height: 20px; accent-color: var(--gold); }
.ps-option b { flex: 1; }
.ps-option span { font-size: 12px; color: var(--muted); }
.ps-option:disabled { opacity: 0.55; cursor: not-allowed; }
.ps-option__text { flex: 1; min-width: 0; }
.ps-option__text b, .ps-option__text span { display: block; }
.ps-dot { width: 10px; height: 10px; flex: 0 0 10px; border-radius: 50%; background: #8C8576; }
.ps-dot.is-on { background: #1F9D57; }
.ps-copies { display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 600; }
.ps-copies div { display: flex; align-items: center; gap: 12px; }
.ps-copies .btn { width: 40px; padding: 0; }
.ps-done { display: flex; align-items: center; gap: 12px; }
.ps-done h3 { margin: 0; font-size: 17px; }
.ps-done__icon { width: 44px; height: 44px; flex: 0 0 44px; display: flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--ok-soft); color: var(--ok); font-size: 22px; font-weight: 700; }
.ps-progress { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; font-weight: 600; }

/* Điện thoại và màn cảm ứng (kể cả xoay ngang, máy tính bảng): ô nhập 16px để iPhone không tự phóng to khi chạm,
   nút / ô tích đủ lớn để bấm bằng ngón tay */
@media (max-width: 767px), (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea { font-size: 16px !important; }
  .btn--sm { height: auto; min-height: 40px; min-width: 40px; }
  .app-nav__icon-btn, .app-nav__toggle { width: 40px; height: 40px; }
  .pager__pages button { min-width: 40px; height: 40px; }
  .pager__size select { height: 40px; }
  body.app input[type="checkbox"], body.app input[type="radio"] { width: 22px; height: 22px; }  /* thắng CSS riêng 18px của từng trang */
}

