@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700&display=swap');

/* KH Kế toán — giao diện "sổ cái": gáy sổ xanh sẫm, giấy kẻ dòng, điểm nhấn vàng đồng K&H.
   Số liệu luôn dùng chữ số đều cột; dòng tổng gạch đôi theo lối kế toán. */
:root {
  --spine: #0e3b34;        /* xanh gáy sổ */
  --spine-2: #175046;
  --spine-ink: #cfe0d9;
  --paper: #f2f5f3;        /* nền trang */
  --card: #ffffff;
  --rule: #d3ded8;         /* đường kẻ sổ */
  --rule-soft: #e6eeea;
  --head: #e7efeb;         /* nền tiêu đề bảng */
  --ink: #14211d;
  --muted: #5a6a64;
  --brass: #c8952c;        /* vàng đồng K&H */
  --brass-soft: #f6ecd2;
  --neg: #b3261e;
  --pos: #1e7a4e;
  --focus: #c8952c;
  --r-sm: 6px; --r: 8px; --r-lg: 12px;
  font-family: 'Be Vietnam Pro', 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 14px; line-height: 1.5;
  color: var(--ink); background: var(--paper);
  font-variant-numeric: tabular-nums;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--spine-2); text-underline-offset: 2px; }
h1 { font-size: 1.6rem; font-weight: 700; margin: 0 0 .2rem; letter-spacing: -.02em; line-height: 1.25; }
h2 { font-size: 1.08rem; font-weight: 600; margin: 1.8rem 0 .7rem; letter-spacing: -.01em; }
.sub { color: var(--muted); margin: 0 0 1.2rem; max-width: 78ch; }
.ic { flex: none; }
.num, td.money, td.qty, th.money, th.qty { text-align: right; white-space: nowrap; }

/* ---------- khung ---------- */
.shell { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--spine); color: var(--spine-ink); position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; padding: 0 .7rem 1rem; scrollbar-width: thin; scrollbar-color: #2b5f55 transparent; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem .5rem 1rem; color: #fff; text-decoration: none; }
.mark { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r); background: var(--brass);
  color: var(--spine); font-weight: 700; font-size: .82rem; letter-spacing: -.02em; flex: none; }
.mark.big { width: 64px; height: 64px; font-size: 1.25rem; border-radius: var(--r-lg); }
.brand-txt { min-width: 0; }
.brand b { display: block; font-size: 1.02rem; font-weight: 700; letter-spacing: -.01em; }
.brand small { display: block; color: #9fbfb4; font-size: .75rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.new-menu { margin: .1rem .2rem .9rem; position: relative; }
.new-menu summary { list-style: none; display: flex; align-items: center; justify-content: center; gap: .4rem; cursor: pointer;
  background: var(--brass); color: var(--spine); font-weight: 600; border-radius: var(--r); padding: .58rem .8rem; }
.new-menu summary::-webkit-details-marker { display: none; }
.new-menu summary:hover { background: #d6a43a; }
.new-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 6px; background: var(--spine-2); padding: 6px; border-radius: var(--r); }
.new-grid a { display: flex; align-items: center; gap: .45rem; padding: .5rem .55rem; color: #e6f0ec; text-decoration: none; border-radius: var(--r-sm); font-size: .85rem; }
.new-grid a:hover { background: rgba(255,255,255,.08); }

.side .nav { display: flex; align-items: center; gap: .6rem; color: #d7e6e0; text-decoration: none; border-radius: var(--r-sm); padding: .42rem .6rem .42rem 2.45rem; font-size: .92rem; position: relative; }
.side .nav.top { padding-left: .6rem; font-weight: 500; margin-bottom: .3rem; }
.side .nav:hover { background: rgba(255,255,255,.06); color: #fff; }
.side .nav.on { background: rgba(200,149,44,.16); color: #fff; font-weight: 600; }
.side .nav.on::before { content: ''; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 2px; background: var(--brass); }
.side details.grp summary { list-style: none; display: flex; align-items: center; gap: .6rem; padding: .48rem .6rem; border-radius: var(--r-sm);
  cursor: pointer; color: #c3d6cf; font-weight: 500; user-select: none; }
.side details.grp summary::-webkit-details-marker { display: none; }
.side details.grp summary:hover { background: rgba(255,255,255,.06); color: #fff; }
.side details.grp summary span { flex: 1; }
.side details.grp summary .ic:last-child { opacity: .55; transition: transform .15s; }
.side details.grp[open] summary .ic:last-child { transform: rotate(90deg); }
.side details.grp[open] { padding-bottom: .3rem; }
.side-foot { margin-top: auto; padding: 1rem .6rem 0; font-size: .74rem; color: #86a89d; }
.side-mask { display: none; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: .65rem 2rem;
  background: rgba(255,255,255,.92); backdrop-filter: saturate(1.4) blur(6px); border-bottom: 1px solid var(--rule); min-height: 58px; }
.crumb { display: flex; align-items: center; gap: .4rem; min-width: 0; color: var(--muted); font-size: .9rem; }
.crumb b { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: .55rem; }
.scope select { height: 2.1rem; width: auto; max-width: 260px; border-radius: 999px; padding: 0 2rem 0 .9rem; background-color: var(--paper); font-weight: 500; }
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 500; white-space: nowrap; text-decoration: none; }
.pill.lock { background: #eef2f0; color: var(--muted); }
.pill.warn { background: #fdecea; color: var(--neg); }
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: .5rem; cursor: pointer; padding: .2rem .3rem .2rem .2rem; border-radius: 999px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--paper); }
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--spine); color: #fff; font-size: .78rem; font-weight: 600; }
.uname { font-size: .88rem; font-weight: 500; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--rule); border-radius: var(--r); padding: 5px; min-width: 210px;
  box-shadow: 0 10px 30px -12px rgba(14,59,52,.35); }
.menu-pop a { display: flex; align-items: center; gap: .55rem; padding: .5rem .65rem; border-radius: var(--r-sm); color: var(--ink); text-decoration: none; }
.menu-pop a:hover { background: var(--paper); }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--rule); border-radius: var(--r); background: #fff; color: var(--ink); cursor: pointer; }
.menu-btn { display: none; }
.main { padding: 1.6rem 2rem 4rem; width: 100%; max-width: 1480px; }

/* ---------- thành phần ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--rule); background: #fff; color: var(--ink);
  padding: .5rem .95rem; border-radius: var(--r); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #9db8ae; background: #fbfcfb; }
.btn.primary { background: var(--spine); border-color: var(--spine); color: #fff; }
.btn.primary:hover { background: var(--spine-2); }
.btn.gold { background: var(--brass); border-color: var(--brass); color: var(--spine); font-weight: 600; }
.btn.gold:hover { background: #d6a43a; }
.btn.danger { color: var(--neg); }
.btn.danger:hover { border-color: #e7a7a2; background: #fff6f5; }
.btn.sm { padding: .25rem .6rem; font-size: .84rem; border-radius: var(--r-sm); }
.btn.block { width: 100%; padding: .7rem; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--rule); border-radius: var(--r-sm); padding: .45rem .6rem; background: #fff; width: 100%; }
input:hover, select:hover, textarea:hover { border-color: #b7cbc3; }
input:focus, select:focus, textarea:focus { border-color: var(--spine-2); outline: none; box-shadow: 0 0 0 3px rgba(23,80,70,.12); }
input[readonly] { background: var(--paper); }
input[type=checkbox], input[type=radio] { width: auto; height: auto; accent-color: var(--spine); }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select { height: 2.4rem; }
input[type=file] { padding: .35rem; }
.entry input, .entry select { height: 2.1rem; }
label { display: block; font-size: .84rem; color: var(--muted); font-weight: 500; }
label > input, label > select, label > textarea { margin-top: .3rem; color: var(--ink); font-weight: 400; }
label:has(> input[type=checkbox]) { display: flex; align-items: center; gap: .45rem; color: var(--ink); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .9rem 1.1rem; margin-bottom: 1rem; }
.fields .w2 { grid-column: span 2; }
fieldset { border: 1px solid var(--rule); border-radius: var(--r); padding: .9rem 1.1rem 1.1rem; margin: 0 0 1rem; display: grid; gap: .75rem; }
legend { padding: 0 .35rem; font-weight: 600; color: var(--ink); }
code { background: var(--paper); border: 1px solid var(--rule-soft); border-radius: 4px; padding: .05rem .35rem; font-size: .88em; }

.alert { display: flex; gap: .6rem; padding: .7rem 1rem; border-radius: var(--r); margin: 0 0 1rem; border: 1px solid; border-left-width: 4px; max-width: 980px; }
.alert.ok { background: #eef8f2; border-color: #b9dfc9; border-left-color: var(--pos); color: #155c3a; }
.alert.err { background: #fdf1f0; border-color: #f0c6c1; border-left-color: var(--neg); color: #8f1f19; }
.alert.info { background: #fcf6e6; border-color: #ecd9a6; border-left-color: var(--brass); color: #5d4710; }

.panel { background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 1.1rem 1.25rem; }
.panel + .panel { margin-top: 1rem; }

/* ---------- bảng: kẻ dòng như giấy sổ ---------- */
.tbl-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-lg); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; }
.grid th { position: sticky; top: 0; background: var(--head); font-weight: 600; font-size: .8rem; color: #3f5650; text-align: left;
  padding: .6rem .75rem; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.grid th:first-child { border-top-left-radius: var(--r-lg); }
.grid th:last-child { border-top-right-radius: var(--r-lg); }
.grid td { padding: .5rem .75rem; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: #f6faf8; }
.grid tr.lvl1 td { font-weight: 600; background: #fafcfb; }
.grid tr.ind1 td:first-child { padding-left: 1.5rem; }
.grid tr.ind2 td:first-child { padding-left: 2.5rem; }
.grid tr.ind3 td:first-child { padding-left: 3.5rem; color: var(--muted); }
.grid tr.sub td { color: var(--muted); font-style: italic; }
.grid tr.cr td:nth-child(4) { padding-left: 1.6rem; }
/* dòng tổng: gạch đôi như sổ kế toán */
.grid tfoot td { font-weight: 700; background: #f7faf8; border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); }
.grid td.neg, .neg { color: var(--neg); }
.grid a.row-link { color: var(--spine-2); font-weight: 500; text-decoration: none; }
.grid a.row-link:hover { text-decoration: underline; }
.grid .void td { color: #9aa8a3; text-decoration: line-through; }
.empty { padding: 2.6rem 1rem; text-align: center; color: var(--muted); }

/* lưới nhập chứng từ */
table.entry { border-collapse: collapse; width: 100%; min-width: 720px; }
.entry th { font-size: .8rem; color: #3f5650; font-weight: 600; text-align: left; padding: .45rem .35rem; border-bottom: 1px solid var(--rule); background: var(--head); }
.entry td { padding: .3rem .35rem; border-bottom: 1px solid var(--rule-soft); }
.entry input, .entry select { padding: .32rem .45rem; }
.entry .money input, .entry input.money { text-align: right; }
.entry .x { width: 2rem; text-align: center; }
.entry tfoot td { font-weight: 700; padding-top: .7rem; }
.total-line { display: flex; justify-content: flex-end; gap: 2rem; padding: .9rem .4rem 0; font-weight: 600; }

/* ---------- số liệu nhanh ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem; margin-bottom: 1.6rem; }
.kpi { background: #fff; border: 1px solid var(--rule); border-radius: var(--r-lg); padding: .95rem 1.1rem; text-decoration: none; color: inherit; display: block; }
a.kpi:hover { border-color: #9db8ae; }
.kpi span { font-size: .82rem; color: var(--muted); }
.kpi b { display: block; font-size: 1.35rem; margin-top: .15rem; letter-spacing: -.01em; }
.kpi.profit b { color: var(--pos); }
.kpi.profit.loss b { color: var(--neg); }
.quick { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.6rem; }

/* ---------- Tổng quan ---------- */
.dash-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.dash-head .sub { margin: 0; }
.ledger { background: var(--spine); color: #fff; border-radius: var(--r-lg); padding: 1.4rem 1.6rem 1.2rem; position: relative; overflow: hidden;
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, rgba(255,255,255,.05) 31px 32px); }
.ledger::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--brass); }
.ledger-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ledger-cell { padding: .2rem 1.2rem .4rem; border-left: 1px solid rgba(255,255,255,.12); text-decoration: none; color: inherit; display: block; border-radius: var(--r-sm); }
.ledger-cell:first-child { border-left: 0; padding-left: .4rem; }
.ledger-cell:hover { background: rgba(255,255,255,.05); }
.ledger-cell span { display: block; font-size: .82rem; color: #a9c7bc; }
.ledger-cell b { display: block; font-size: clamp(1.3rem, 2.2vw, 1.9rem); font-weight: 700; letter-spacing: -.02em; margin-top: .15rem; white-space: nowrap; }
.ledger-cell small { color: #8db3a6; font-size: .76rem; }
.ledger-foot { display: flex; flex-wrap: wrap; gap: .4rem 2rem; margin-top: 1.1rem; padding-top: .9rem; border-top: 1px solid rgba(255,255,255,.14); font-size: .88rem; color: #cfe0d9; }
.ledger-foot b { color: #fff; font-weight: 600; margin-left: .35rem; }
.ledger-foot .up b { color: #f0c25e; }
.ledger-foot .down b { color: #ff9a92; }

.dash-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 1rem; margin-top: 1rem; }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 1.1rem 1.25rem; min-width: 0; }
.card h2 { margin: 0 0 .8rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.card h2 a { font-size: .84rem; font-weight: 500; }
.chart { width: 100%; height: auto; display: block; }
.chart .bar-rev { fill: var(--spine-2); }
.chart .bar-exp { fill: #d6c08c; }
.chart .gridline { stroke: var(--rule-soft); }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.legend { display: flex; gap: 1.2rem; font-size: .82rem; color: var(--muted); margin-top: .5rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }

.todo { list-style: none; margin: 0; padding: 0; }
.todo li { display: flex; gap: .7rem; align-items: flex-start; padding: .65rem 0; border-bottom: 1px solid var(--rule-soft); }
.todo li:last-child { border-bottom: 0; }
.todo .dot { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; flex: none; }
.todo .dot.warn { background: #fdecea; color: var(--neg); }
.todo .dot.task { background: var(--brass-soft); color: #8a6417; }
.todo .dot.done { background: #e5f3ec; color: var(--pos); }
.todo b { display: block; font-weight: 600; font-size: .92rem; }
.todo a { font-size: .84rem; }
.todo p { margin: .1rem 0 0; color: var(--muted); font-size: .84rem; }

.quick-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin: 1rem 0 0; }
.quick-tiles a { display: flex; align-items: center; gap: .6rem; padding: .75rem .9rem; background: var(--card); border: 1px solid var(--rule); border-radius: var(--r);
  color: var(--ink); text-decoration: none; font-weight: 500; }
.quick-tiles a:hover { border-color: var(--spine-2); }
.quick-tiles .ic { color: var(--spine-2); }

/* báo cáo */
.report-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1.5rem; }
.report-nav { background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: .6rem; align-self: start; position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow-y: auto; }
.report-nav a { display: block; padding: .38rem .6rem; color: var(--ink); text-decoration: none; border-radius: var(--r-sm); font-size: .9rem; }
.report-nav a:hover { background: var(--paper); }
.report-nav a.on { background: var(--brass-soft); font-weight: 600; }
.report-nav .grp { font-size: .78rem; color: var(--muted); margin: .9rem 0 .2rem .6rem; font-weight: 600; }
.report-nav .grp:first-child { margin-top: .3rem; }
.filters { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; margin-bottom: 1.1rem; padding: .9rem 1rem; background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-lg); }
.filters label { min-width: 150px; }
.panel .filters, .filters .filters { padding: 0; border: 0; background: none; }

/* ---------- đăng nhập / cài đặt ---------- */
body.auth { min-height: 100vh; margin: 0; display: grid; place-items: center; padding: 1.2rem; background: var(--paper); }
.auth-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); width: min(880px, 100%); min-height: 480px; background: #fff; border-radius: 16px;
  overflow: hidden; border: 1px solid var(--rule); box-shadow: 0 30px 60px -30px rgba(14,59,52,.35); }
.auth-side { background: var(--spine); color: #fff; padding: 2.6rem 2.4rem; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.auth-side h1 { margin: 1.4rem 0 .3rem; font-size: 2rem; }
.auth-side p { color: #a9c7bc; margin: 0; max-width: 30ch; }
.ledger-lines { margin-top: auto; display: grid; gap: 14px; }
.ledger-lines i { display: block; height: 1px; background: rgba(255,255,255,.14); }
.ledger-lines i:nth-child(3) { background: var(--brass); width: 40%; height: 2px; }
.auth-card { padding: 2.6rem 2.4rem; display: grid; gap: 1rem; align-content: center; }
.auth-card h2 { margin: 0 0 .3rem; font-size: 1.35rem; }
body.auth > .auth-card { background: #fff; border-radius: 16px; border: 1px solid var(--rule); width: min(420px, 100%); border-top: 5px solid var(--brass); }
body.auth > .auth-card.wide { width: min(600px, 100%); }

/* ---------- in ---------- */
.print-only { display: none; }
@media print {
  .side, .topbar, .no-print, .filters, .report-nav, .side-mask { display: none !important; }
  .shell, .report-layout { display: block; }
  .main { padding: 0; max-width: none; }
  .print-only { display: block; }
  .tbl-wrap { border: 0; overflow: visible; border-radius: 0; }
  .grid th { position: static; background: #fff; border-bottom: 1px solid #000; }
  body, :root { background: #fff; font-size: 11.5px; }
}
.voucher-print { max-width: 760px; margin: 0 auto; background: #fff; padding: 1.6rem 2rem; border: 1px solid var(--rule); border-radius: var(--r); }
.voucher-print .head { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; }
.voucher-print h1 { text-align: center; margin: 1.2rem 0 .1rem; font-size: 1.5rem; }
.voucher-print .center { text-align: center; }
.voucher-print .line { margin: .45rem 0; }
.voucher-print .signs { display: grid; grid-template-columns: repeat(5, 1fr); text-align: center; margin-top: 1.6rem; font-size: .85rem; }
.voucher-print .signs b { display: block; }
.voucher-print .signs i { color: var(--muted); font-size: .78rem; }

/* ---------- màn hình nhỏ ---------- */
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: 1fr; }
  .ledger-row { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 1rem; }
  .ledger-cell:nth-child(3) { border-left: 0; padding-left: .4rem; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s ease; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side.open + .side-mask { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(10,30,26,.35); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: .55rem 1rem; }
  .uname, .pill.lock { display: none; }
  .main { padding: 1.1rem 1rem 3rem; }
  .report-layout { grid-template-columns: 1fr; }
  .report-nav { position: static; max-height: none; }
  .fields .w2 { grid-column: auto; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { padding: 1.6rem; }
  .auth-side .ledger-lines { display: none; }
  .ledger-row { grid-template-columns: 1fr; }
  .ledger-cell { border-left: 0; padding-left: .4rem; }
}
@media (prefers-reduced-motion: reduce) { .side, .side details.grp summary .ic { transition: none; } }
