/* ===== QLBH Trang Hậu Phương — giao diện navy / cam đất, mobile-first cho iPhone, Android, iPad ===== */
:root {
  --navy: #0F2742;
  --navy-2: #1F3D63;
  --navy-line: #3A5375;
  --on-navy: #FFFFFF;
  --on-navy-muted: #B8C4D6;
  --accent: #E0682E;
  --accent-ink: #9A3D14;
  --accent-soft: #FDF1EB;
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --field: #F6F8FB;
  --ink: #0F1B2D;
  --ink-2: #3B4A5E;
  --muted: #5B6B80;
  --line: #E4E8EE;
  --line-soft: #EEF1F5;
  --pos: #17663A;
  --pos-soft: #E6F4EC;
  --neg: #B4431A;
  --neg-soft: #FCEBE4;
  --warn: #7A4F00;
  --warn-soft: #FFF3DC;
  --info-soft: #E7EEF7;
  --total-bg: #FBF8F5;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(15, 39, 66, .10);
  --tabbar-h: 62px;
  --sidebar-w: 248px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent-ink); text-decoration: none; }
small { font-size: 12.5px; }
h1, h2, h3 { letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.num { font-variant-numeric: tabular-nums; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic-sm { width: 18px; height: 18px; }

/* ---------- Khung ứng dụng ---------- */
.shell { min-height: 100dvh; }
.sidebar { display: none; }
.main { min-width: 0; padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 10px;
  padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.topbar .t-page { display: none; }
.avatar {
  width: 38px; height: 38px; border-radius: 19px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14px;
}

.segmented {
  display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg);
  overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented a {
  flex: 1 0 auto; min-height: 36px; padding: 0 10px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.segmented a.active { background: var(--surface); color: var(--navy); font-weight: 700; box-shadow: 0 1px 3px rgba(15, 39, 66, .12); }

.content { padding: 14px calc(14px + var(--safe-right)) 14px calc(14px + var(--safe-left)); max-width: 1180px; display: flex; flex-direction: column; gap: 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 4px var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(255, 255, 255, .94);
  -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 500; color: var(--muted); min-width: 0;
}
.tabbar a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tabbar a.active { color: var(--accent); font-weight: 700; }
.tabbar a.active .ic { stroke-width: 2.2; }

/* iPad ngang / máy tính: thanh bên navy thay cho thanh tab dưới */
@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: calc(var(--sidebar-w) + var(--safe-left)) minmax(0, 1fr); }
  .tabbar { display: none; }
  .main { padding-bottom: 28px; }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    padding: calc(24px + var(--safe-top)) 14px 20px calc(14px + var(--safe-left));
    background: var(--navy); color: #DCE4EF;
  }
  .brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 22px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
  .brand div { display: flex; flex-direction: column; min-width: 0; }
  .brand b { color: #fff; }
  .brand small { color: #9FB0C6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-nav { display: flex; flex-direction: column; gap: 4px; }
  .side-head { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 12px; color: #DCE4EF; font-size: 14.5px; }
  .side-head:hover { background: rgba(255, 255, 255, .06); }
  .side-head.active { background: var(--navy-2); color: #fff; font-weight: 700; }
  .side-head.active .ic { color: #F2A27C; }
  .side-sub { display: flex; flex-direction: column; padding: 2px 0 6px 46px; }
  .side-sub a { min-height: 34px; display: flex; align-items: center; color: #9FB0C6; font-size: 13.5px; border-radius: 8px; }
  .side-sub a.active { color: #fff; font-weight: 600; }
  .side-logout { margin-top: auto; color: #9FB0C6; }
  .topbar { position: static; background: transparent; border: 0; padding: 26px 28px 4px; }
  .topbar .t-mod { display: none; }
  .topbar .t-page { display: inline; }
  .topbar .segmented { display: none; }
  .content { padding: 12px 28px; }
}

/* ---------- Thẻ, nút, ô nhập ---------- */
.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.card-pad { padding: 16px; }
.card.stack { padding: 22px; display: grid; gap: 14px; max-width: 420px; margin: 24px auto; }

input, select, button { font: inherit; color: inherit; }
input[type=date], input[type=text], input[type=search], input[type=password], input:not([type]), select {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1.5px solid #DCE2EA; border-radius: 14px; background: var(--field);
  font-size: 16px; /* >=16px để iOS không tự phóng to */
  -webkit-appearance: none; appearance: none;
}
input[type=date] { min-width: 0; font-weight: 500; }
input:focus, select:focus { outline: none; border-color: var(--navy); background: var(--surface); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1.5px solid #DCE2EA;
  background: var(--surface); font-weight: 600; cursor: pointer; color: var(--ink);
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.btn-navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-block { width: 100%; }
.btn:active, .chip:active { transform: scale(.98); }
.chip {
  min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid #DCE2EA;
  background: var(--surface); font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }

.badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 7px; white-space: nowrap; }
.badge-info { background: var(--info-soft); color: var(--navy); }
.badge-gray { background: var(--bg); color: var(--ink-2); }
.badge-pos { background: var(--pos-soft); color: var(--pos); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-neg { background: var(--neg-soft); color: var(--accent-ink); }

/* ---------- Bộ lọc (gọn cho điện thoại, tự áp dụng khi đổi) ---------- */
.filter {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--surface); border-radius: var(--radius); padding: 12px;
}
.filter-dates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; flex: 1 1 280px; min-width: 0; }
.filter label, .field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); min-width: 0; }
.filter-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 1 1 260px; min-width: 0; }
.filter-actions .btn { margin-left: auto; min-width: 96px; }

/* Ô ngày: hiện dd/MM/yyyy gọn trên một dòng; ô chọn ngày gốc của iOS/Android nằm phủ lên trên, trong suốt */
.filter .date-field {
  position: relative; flex-direction: column; align-items: flex-start; justify-content: center; gap: 1px;
  min-height: 52px; min-width: 0; padding: 6px 12px; border: 1.5px solid #DCE2EA; border-radius: 12px; background: var(--field);
}
.date-field .date-cap { font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.date-field .date-display { font-size: 16px; font-weight: 700; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.date-field input[type=date] {
  position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; padding: 0; margin: 0;
  opacity: 0; border: 0; cursor: pointer; font-size: 16px;
}
.date-field:focus-within { border-color: var(--navy); background: var(--surface); }
.filter-actions .chip { flex: 1 1 0; min-width: 0; }
@media (min-width: 640px) { .filter-actions .chip { flex: 0 0 auto; } }

/* Thanh báo đang tải */
body.is-loading::before {
  content: ""; position: fixed; z-index: 100; top: 0; left: 0; height: 3px; width: 40%;
  background: var(--accent); animation: loadbar 1.1s ease-in-out infinite;
}
@keyframes loadbar { 0% { left: -40%; } 100% { left: 100%; } }
.filter .switch { flex-direction: row; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; font-weight: 500; min-height: 48px; }
.switch input { width: 20px; height: 20px; accent-color: var(--navy); margin: 0; }
.filter-extra .grow { flex: 1 1 240px; }

/* ---------- Danh sách, bảng ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; }
.toolbar .search { flex: 1; }
.toolbar > span, .toolbar > b { flex: none; }

.summary {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 2px 4px;
  color: var(--muted); font-size: 13px;
}
.summary b { color: var(--ink); font-size: 15px; }
.summary b em { font-style: normal; color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; background: var(--surface); border-radius: var(--radius); margin: 0; }
.section-title { font-size: 17px; font-weight: 700; margin: 4px 2px 0; }
.section-title small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.section-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 12px 16px 6px; }

.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--surface); border-radius: var(--radius); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 11px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
.tbl thead th {
  position: sticky; top: 0; z-index: 1; background: var(--field);
  color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
.tbl tbody tr:last-child > * { border-bottom: 0; }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl .sub { display: block; color: var(--muted); font-size: 12.5px; }
.tbl tr.total > * { background: var(--total-bg); font-weight: 700; }
.tbl tr.grand > * { background: var(--accent-soft); color: var(--accent-ink); font-weight: 800; }
.tbl tr.group th { background: var(--field); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tbl .vlabel { font-weight: 700; background: var(--total-bg); white-space: nowrap; }
.tbl .pos { color: var(--pos); font-weight: 600; }
.tbl .neg { color: var(--neg); font-weight: 600; }
.tbl.compact th, .tbl.compact td { padding: 7px 0; font-size: 13.5px; border-bottom: 0; }
.tbl.compact thead th { background: none; font-size: 10.5px; position: static; }
.ledger th:first-child { width: 1%; white-space: nowrap; }
.ledger th, .ledger td { padding-left: 8px; padding-right: 8px; }
@media (max-width: 480px) {
  .tbl th, .tbl td { padding: 9px 7px; }
  .tbl th:first-child, .tbl td:first-child { padding-left: 12px; }
  .tbl th:last-child, .tbl td:last-child { padding-right: 12px; }
  .ledger { font-size: 13px; }
  .ledger thead th { font-size: 10.5px; letter-spacing: 0; }
  .ledger .vlabel, .ledger tr.total th { font-size: 12px; }
}

.show-sm { display: block; }
.hide-sm { display: none; }
@media (min-width: 640px) { .show-sm { display: none !important; } .hide-sm { display: table-cell; } }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.list li:last-child { border-bottom: 0; }
.list b { display: block; font-weight: 600; }
.list small { color: var(--muted); }
.mono-avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--info-soft); color: var(--navy); font-weight: 700; font-size: 13px;
}
.list li:nth-child(even) .mono-avatar { background: var(--neg-soft); color: var(--neg); }
.phone {
  flex: none; min-height: 40px; padding: 0 12px; border-radius: 12px; display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; font-size: 13px;
}

/* Phiếu xuất/nhập dạng thẻ */
.cards { display: grid; gap: 12px; }
@media (min-width: 700px) { .cards { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); align-items: start; } }
.phieu > header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 16px 10px; }
.phieu > header > div { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.phieu > header b.name { font-size: 15px; font-weight: 700; }
.phieu .tags { display: flex; gap: 6px; flex-wrap: wrap; }
.phieu .amount { font-size: 16px; font-weight: 800; white-space: nowrap; }
.phieu .lines { border-top: 1px dashed #DCE2EA; padding: 4px 16px 10px; }
.phieu .lines td:first-child { font-weight: 600; }

/* Thẻ số liệu */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--surface); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stat .stat-ic { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--info-soft); color: var(--navy); }
a.stat { color: var(--ink); }
.stat span { color: var(--muted); font-size: 12.5px; }
.stat b { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.in .stat-ic { background: var(--pos-soft); color: var(--pos); }
.stat.in b { color: var(--pos); }
.stat.out .stat-ic { background: var(--neg-soft); color: var(--neg); }
.stat.out b { color: var(--neg); }
.stat.gold .stat-ic { background: var(--warn-soft); color: #8A5A00; }
.stat.dark { background: var(--navy); color: #fff; }
.stat.dark span { color: var(--on-navy-muted); }

/* Thẻ tóm tắt nền navy (công nợ, tổng quan) */
.hero-card { background: var(--navy); color: #fff; border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.hero-card .label { font-size: 13px; color: var(--on-navy-muted); }
.hero-card .big { font-size: 30px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-card .parts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.hero-card .parts div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hero-card .parts span { font-size: 11.5px; color: var(--on-navy-muted); }
.hero-card .parts b { font-size: 14px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-card .parts b.pos { color: #8EE0AE; }

/* Tồn kho dạng thẻ */
.stock { display: grid; gap: 10px; }
@media (min-width: 700px) { .stock { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); } }
.stock article { background: var(--surface); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.stock .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.stock .head div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stock .head b { font-size: 15px; }
.stock .head small { color: var(--muted); }
.stock .qty { display: flex; gap: 20px; align-items: baseline; }
.stock .qty b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stock .qty span { font-size: 13px; color: var(--muted); margin-left: 4px; }
.stock .zero b { color: var(--muted); }

[hidden-by-filter] { display: none !important; }

/* ---------- Tổng quan ---------- */
.hero {
  background: var(--navy); color: #fff;
  padding: calc(18px + var(--safe-top)) calc(18px + var(--safe-right)) 70px calc(18px + var(--safe-left));
  display: flex; flex-direction: column; gap: 16px;
}
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hero-top div { display: flex; flex-direction: column; gap: 2px; }
.hero-top span { font-size: 13px; color: var(--on-navy-muted); }
.hero-top b { font-size: 22px; font-weight: 700; }
.hero .chip { background: transparent; border-color: var(--navy-line); color: #DCE4EF; }
.hero .chip.active { background: #fff; color: var(--navy); border-color: #fff; }
.hero-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.hero + .content { margin-top: -54px; }
.kpi { background: var(--surface); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); }
.kpi span { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi b { font-size: 32px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; }
.card-head b { font-size: 15px; }
.card-head a { font-size: 13px; font-weight: 600; }
@media (min-width: 900px) {
  .hero { margin: 0; padding: 28px 28px 74px; border-radius: 0 0 0 0; }
  .hero + .content { margin-top: -58px; }
}

/* ---------- Đăng nhập: canh giữa, nền xanh than trang trọng ---------- */
body.bare {
  min-height: 100dvh; background-color: #0A1A2F;
  background-image:
    radial-gradient(120% 70% at 50% -10%, rgba(59, 99, 150, .45) 0%, rgba(10, 26, 47, 0) 60%),
    radial-gradient(90% 60% at 50% 115%, rgba(196, 160, 98, .16) 0%, rgba(10, 26, 47, 0) 60%),
    linear-gradient(180deg, #0D223D 0%, #0A1A2F 100%);
  background-attachment: fixed;
}
.login {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: calc(24px + var(--safe-top)) calc(20px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(20px + var(--safe-left));
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; color: #fff; }
.login-brand .brand-mark {
  width: 60px; height: 60px; border-radius: 16px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 30px rgba(224, 104, 46, .35);
}
.login-brand .brand-mark .ic { width: 32px; height: 32px; }
.login-brand .eyebrow { margin: 0; font-size: 11.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: #C9B48A; }
.login-brand h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }
.login-brand p { margin: 0; color: var(--on-navy-muted); font-size: 14px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 22px;
  padding: 26px 22px; display: grid; gap: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}
.login-card h2 { margin: 0; font-size: 20px; }
.login-card .lead { margin: -10px 0 0; color: var(--muted); font-size: 13.5px; }
.login-foot { margin: 0; text-align: center; font-size: 12px; line-height: 1.6; color: #8FA0B8; }
.login-foot b { color: #C9D3E0; font-weight: 600; }
.alert { padding: 10px 12px; border-radius: 12px; background: var(--neg-soft); color: var(--neg); font-size: 14px; font-weight: 500; }
.notice-card { margin: auto; max-width: 420px; width: calc(100% - 32px); }

/* ---------- In / PDF ---------- */
@media print {
  .sidebar, .tabbar, .topbar .avatar, .segmented, .filter, .no-print { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .main { padding: 0; }
  .topbar { position: static; border: 0; }
  .tbl-wrap, .card { border: 1px solid #ccc; }
}
