/* ==========================================================================
   Sổ quỹ cô Kim – giao diện
   Bảng màu lấy từ avatar: hồng viền, hồng đậm chữ, vàng chanh vương miện,
   nâu mực nét vẽ, nền kem hồng. Xanh/đỏ chỉ dùng cho thu/chi.
   ========================================================================== */
:root {
  --paper: #fff7f9;
  --sheet: #fffdfb;
  --pink: #fda4b6;
  --pink-ink: #d6467a;
  --pink-tint: #ffe4ec;
  --lemon: #f9d65a;
  --lemon-tint: #fff3c4;
  --ink: #4a2c38;
  --muted: #9b7583;
  --rule: #f4d4df;
  --thu: #1e9c6a;
  --thu-tint: #e3f5ec;
  --chi: #e24c64;
  --chi-tint: #fde6ea;
  --shadow: 0 8px 24px rgba(214, 70, 122, 0.10);
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Baloo 2', 'Be Vietnam Pro', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  background-image:
    radial-gradient(circle at 0% 0%, #ffe4ec 0, transparent 38%),
    radial-gradient(circle at 100% 100%, #fff3c4 0, transparent 32%);
  background-attachment: fixed;
}
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-family: var(--display); font-weight: 800; line-height: 1.15; }
h2 { font-size: 22px; color: var(--pink-ink); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
:focus-visible { outline: 3px solid rgba(214, 70, 122, 0.45); outline-offset: 2px; }

.brand-title { font-family: var(--display); font-weight: 800; color: var(--pink-ink); }
.brand-title em {
  font-style: normal;
  color: #b8860b;
  background: linear-gradient(transparent 55%, var(--lemon-tint) 55%);
  padding: 0 3px;
  border-radius: 4px;
}

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 10px 16px;
  font-weight: 700; line-height: 1.2; cursor: pointer; text-decoration: none;
  background: var(--pink-tint); color: var(--pink-ink);
  transition: transform 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(0.97); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn.primary { background: var(--pink-ink); color: #fff; box-shadow: 0 6px 16px rgba(214, 70, 122, 0.28); }
.btn.big { width: 100%; padding: 13px; font-size: 16px; }
.btn.ghost { background: #fff; border: 1.5px solid var(--rule); color: var(--pink-ink); }
.btn.thu { background: var(--thu); color: #fff; }
.btn.chi { background: var(--chi); color: #fff; }
.btn.danger { background: var(--chi); color: #fff; }
.btn.danger-ghost { background: #fff; border: 1.5px solid #f4bcc5; color: var(--chi); }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 10px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--rule);
  background: #fff; color: var(--pink-ink); cursor: pointer; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:hover { background: var(--pink-tint); }
.link-btn { border: 0; background: none; color: var(--pink-ink); cursor: pointer; font-size: 12px; font-weight: 600; padding: 0 4px; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Đăng nhập ---------- */
body.login-bg { display: flex; align-items: center; justify-content: center; }
body.login-bg #app { width: 100%; display: flex; justify-content: center; }
.login-wrap { width: 100%; max-width: 420px; padding: 24px 16px; }
.login-card { background: #fff; border-radius: 28px; padding: 30px 28px 26px; text-align: center; box-shadow: var(--shadow); }
.login-logo { width: 156px; height: 156px; border-radius: 50%; box-shadow: 0 12px 28px rgba(214, 70, 122, 0.28); margin-bottom: 8px; }
.login-card h1 { font-size: 36px; }
.login-card form { margin-top: 18px; display: grid; gap: 12px; text-align: left; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }

/* ---------- Thanh trên ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); }
.topbar-inner, .tabs-inner, .main { max-width: 1080px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { width: 44px; height: 44px; border-radius: 50%; box-shadow: 0 2px 8px rgba(214, 70, 122, 0.25); }
.brand .brand-title { font-size: 22px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip { text-align: right; line-height: 1.15; }
.user-chip b { display: block; font-size: 14px; }
.user-chip small { color: var(--muted); font-size: 12px; }
.tabs { background: #fff; border-bottom: 1px solid var(--rule); }
.tabs-inner { display: flex; gap: 4px; overflow-x: auto; align-items: center; }
.tab { border: 0; background: none; padding: 12px 14px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--pink-ink); border-bottom-color: var(--pink-ink); }
.viewing-label { font-size: 14px; color: var(--muted); padding: 8px 0; }
.main { padding-top: 18px; padding-bottom: 96px; }

/* ---------- Dải tổng hợp (một dải, không phải 4 thẻ) ---------- */
.strip {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-radius: 16px; box-shadow: var(--shadow);
  margin: 14px 0; overflow: hidden;
}
.strip-cell { padding: 14px 18px; border-left: 1px solid var(--rule); min-width: 0; }
.strip-cell:first-child { border-left: 0; }
.strip-label { font-size: 13px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.strip-value { font-family: var(--display); font-size: 23px; font-weight: 800; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip-note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.strip-cell.thu .strip-value { color: var(--thu); }
.strip-cell.chi .strip-value { color: var(--chi); }
.strip-cell.closing { background: var(--lemon-tint); }
.strip-cell.closing .strip-value { color: var(--pink-ink); }
.strip.totals { grid-template-columns: repeat(3, 1fr); }
.strip.totals .strip-cell.total { background: var(--lemon-tint); }
.strip.totals .strip-cell.total .strip-value { color: var(--pink-ink); }

/* ---------- Trang sổ quỹ ---------- */
.fund-tabs { display: flex; gap: 8px; }
.fund-tab {
  flex: 1; border: 2px solid var(--rule); background: #fff; border-radius: 14px; padding: 11px 12px;
  font-family: var(--display); font-weight: 800; font-size: 17px; color: var(--muted); cursor: pointer;
}
.fund-tab.active { background: var(--pink-ink); border-color: var(--pink-ink); color: #fff; box-shadow: 0 6px 16px rgba(214, 70, 122, 0.28); }
.fund-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.period-nav { display: flex; align-items: center; gap: 6px; }
.period-label { position: relative; font-family: var(--display); font-weight: 800; font-size: 21px; color: var(--pink-ink); padding: 4px 10px; cursor: pointer; border-radius: 10px; }
.period-label:hover { background: var(--pink-tint); }
.period-label input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.fund-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.fund-meta { margin-top: 12px; padding: 8px 12px; border-radius: 12px; background: #fff; border: 1.5px dashed var(--rule); font-size: 14px; color: var(--muted); }
.fund-meta b { color: var(--ink); }

/* Trang sổ kiểu vở kẻ ngang: lề hồng bên trái, dòng kẻ hồng nhạt */
.ledger {
  position: relative; background: var(--sheet); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
}
.ledger::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 44px; width: 6px;
  border-left: 2px solid var(--pink); border-right: 1px solid var(--pink); z-index: 1; pointer-events: none;
}
.ledger-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tx-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.tx-table th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 13px;
  padding: 10px 12px; background: var(--pink-tint); border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.tx-table td { padding: 11px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.tx-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-table .c-idx { width: 46px; min-width: 46px; text-align: center; color: var(--muted); padding-left: 0; padding-right: 0; }
.tx-table th.c-idx { text-align: center; }
.tx-table .c-date { white-space: nowrap; }
.tx-table .c-doc { color: var(--muted); white-space: nowrap; }
.tx-table .c-desc small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.tx-table .c-thu { color: var(--thu); font-weight: 700; }
.tx-table .c-chi { color: var(--chi); font-weight: 700; }
.tx-table .c-bal { color: var(--muted); }
.tx-row { cursor: pointer; }
.tx-row:hover td { background: #fff3f7; }
.tx-table tfoot td { background: var(--lemon-tint); font-weight: 700; border-top: 2px solid var(--pink); border-bottom: 0; }
.tx-table tfoot .thu { color: var(--thu); }
.tx-table tfoot .chi { color: var(--chi); }
.ledger-hint { padding: 8px 12px 10px 58px; font-size: 12px; color: var(--muted); }

@media (max-width: 640px) {
  .fund-tab { font-size: 15px; padding: 10px 8px; }
  .fund-head .fund-actions { display: none; }
  .ledger::before { left: 12px; }
  .tx-table, .tx-table tbody { display: block; width: 100%; }
  .tx-table thead, .tx-table tfoot { display: none; }
  .tx-table tr.tx-row {
    display: grid; grid-template-columns: 1fr auto; column-gap: 10px;
    grid-template-areas: "date amt" "desc desc" "doc bal";
    padding: 10px 12px 10px 22px; border-bottom: 1px solid var(--rule);
  }
  .tx-table tr.tx-row td { display: block; padding: 0; border: 0; min-width: 0; }
  .tx-table .c-idx { display: none; }
  .tx-table .c-date { grid-area: date; font-size: 13px; color: var(--muted); }
  .tx-table .c-desc { grid-area: desc; margin-top: 2px; }
  .tx-table .c-doc { grid-area: doc; font-size: 12px; }
  .tx-table .c-thu, .tx-table .c-chi { grid-area: amt; font-size: 16px; text-align: right; }
  .tx-row.thu .c-chi, .tx-row.chi .c-thu { display: none; }
  .tx-table .c-thu:not(:empty)::before { content: '+'; }
  .tx-table .c-chi:not(:empty)::before { content: '−'; }
  .tx-table .c-bal { grid-area: bal; text-align: right; font-size: 12px; }
  .tx-table .c-bal::before { content: 'Tồn: '; }
  .ledger-hint { padding-left: 22px; }
}

/* Thanh thao tác dính đáy màn hình trên điện thoại */
.action-dock { display: none; }
@media (max-width: 640px) {
  .action-dock {
    display: flex; gap: 8px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px); border-top: 1px solid var(--rule);
  }
  .action-dock .btn { flex: 1; padding: 12px 6px; font-size: 14px; }
}

/* ---------- Tổng quan quản trị: danh sách sổ ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.roster { background: var(--sheet); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; margin-top: 8px; }
.roster-row {
  display: grid; grid-template-columns: 64px 1.4fr 1fr 1fr; gap: 12px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--rule);
}
.roster-row:last-child { border-bottom: 0; }
.roster-row.locked { opacity: 0.6; }
.tq-code {
  display: inline-block; background: var(--pink-tint); color: var(--pink-ink); font-family: var(--display); font-weight: 800;
  padding: 3px 10px; border-radius: 999px; font-size: 13px; white-space: nowrap;
}
.roster-name b { display: block; }
.roster-name span { display: block; font-size: 13px; color: var(--muted); }
.roster-fund { display: grid; gap: 2px; justify-items: start; }
.roster-fund .lbl { font-size: 12px; color: var(--muted); }
.roster-fund .val { font-family: var(--display); font-weight: 800; font-size: 18px; white-space: nowrap; }
.roster-fund .month { font-size: 12px; color: var(--muted); }
.roster-fund .month .thu { color: var(--thu); }
.roster-fund .month .chi { color: var(--chi); }
.roster-fund .btn { margin-top: 4px; }
@media (max-width: 760px) {
  .strip { grid-template-columns: 1fr 1fr; }
  .strip-cell { border-left: 0; border-top: 1px solid var(--rule); }
  .strip-cell:nth-child(-n + 2) { border-top: 0; }
  .strip-cell:nth-child(2n) { border-left: 1px solid var(--rule); }
  .strip-value { font-size: 19px; }
  .strip.totals { grid-template-columns: 1fr; }
  .strip.totals .strip-cell { border-left: 0; border-top: 1px solid var(--rule); }
  .strip.totals .strip-cell:first-child { border-top: 0; }
  .roster-row { grid-template-columns: 1fr 1fr; grid-template-areas: "code name" "cash bank"; }
  .roster-code { grid-area: code; }
  .roster-name { grid-area: name; }
  .roster-fund.cash { grid-area: cash; }
  .roster-fund.bank { grid-area: bank; }
}

/* ---------- Bảng thủ quỹ ---------- */
.table-wrap { background: #fff; border-radius: 16px; box-shadow: var(--shadow); overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; padding: 10px 12px; background: var(--pink-tint); border-bottom: 1px solid var(--rule); white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tr.locked td { opacity: 0.6; }
.data-table .actions { white-space: nowrap; text-align: right; }
.data-table .actions .btn { margin-left: 4px; }
.badge { display: inline-block; background: #eee; color: #666; font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--thu-tint); color: var(--thu); }

/* ---------- Sao lưu ---------- */
.backup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.panel { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 20px; display: grid; gap: 12px; align-content: start; }
.panel h2 { font-size: 20px; }
input[type='file'] { font-size: 14px; max-width: 100%; }
@media (max-width: 760px) { .backup-grid { grid-template-columns: 1fr; } }

/* ---------- Trạng thái ---------- */
.empty { background: #fff; border-radius: 16px; padding: 30px 20px; text-align: center; color: var(--muted); box-shadow: var(--shadow); }
.empty.err { color: var(--chi); }
.loading { opacity: 0.55; }

/* ---------- Form & hộp thoại ---------- */
.form-grid { display: grid; gap: 12px; }
.form-grid label, .login-card label, .report-form label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
label small { font-weight: 400; }
.field {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--rule); border-radius: 12px; background: #fff;
  font-size: 15px; color: var(--ink); outline: none; transition: border-color 0.15s, box-shadow 0.15s; min-width: 0;
}
.field:focus { border-color: var(--pink-ink); box-shadow: 0 0 0 3px rgba(214, 70, 122, 0.16); }
.field.big-amount { font-family: var(--display); font-size: 24px; font-weight: 800; text-align: right; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 14px; }
label.check input { width: 18px; height: 18px; accent-color: var(--pink-ink); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--paper); padding: 4px; border-radius: 14px; }
.seg-btn { border: 0; background: transparent; padding: 10px; border-radius: 11px; font-family: var(--display); font-weight: 800; font-size: 17px; color: var(--muted); cursor: pointer; }
.seg-btn.thu.active { background: var(--thu); color: #fff; }
.seg-btn.chi.active { background: var(--chi); color: #fff; }

.modal-back {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(74, 44, 56, 0.45); backdrop-filter: blur(2px);
}
.modal {
  background: #fff; border-radius: 20px; padding: 22px 22px 18px; width: 100%; max-width: 460px;
  max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 24px 60px rgba(120, 40, 70, 0.25);
  animation: pop 0.18s ease-out;
}
.modal-back.wide .modal { max-width: 920px; }
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .modal { animation: none; } }
.modal h3 { font-size: 20px; color: var(--pink-ink); margin-bottom: 8px; }
.modal p { margin-bottom: 8px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { border-radius: 20px 20px 0 0; max-height: 92vh; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .modal-back.wide .modal { max-height: 96vh; }
}

/* ---------- Báo cáo ---------- */
.report-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 8px; }
.report-form .field { padding: 8px 10px; font-size: 14px; }
.report-form .spacer { flex: 1; }
.sheet-scroll { margin-top: 12px; overflow: auto; -webkit-overflow-scrolling: touch; background: #f3dfe6; padding: 12px; border-radius: 12px; max-height: calc(100vh - 210px); }
.sheet {
  width: 794px; min-height: 420px; margin: 0 auto; background: #fff; color: #111;
  padding: 34px 40px 28px; font-family: var(--font); font-size: 13px; line-height: 1.4;
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.sheet-facility { font-weight: 700; font-size: 15px; }
.sheet-logo { width: 62px; height: 62px; border-radius: 50%; flex: none; }
.sheet-title { text-align: center; font-family: var(--font); font-weight: 800; font-size: 20px; letter-spacing: 0.4px; margin: 16px 0 4px; color: #111; }
.sheet-sub { text-align: center; margin-bottom: 14px; }
.sheet-table { width: 100%; border-collapse: collapse; }
.sheet-table th, .sheet-table td { border: 1px solid #444; padding: 5px 6px; vertical-align: top; }
.sheet-table th { background: #fbe3ec; font-weight: 700; text-align: center; }
.sheet-table td.r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sheet-table td.c { text-align: center; }
.sheet-table tr.sum td { background: #fff7fa; }
.sheet-date { text-align: right; font-style: italic; margin: 18px 0 6px; }
.sheet-sign { display: grid; grid-template-columns: 1fr 1fr 1fr; text-align: center; gap: 12px; }
.sheet-sign i { font-size: 12px; }
.sign-name { margin-top: 64px; font-weight: 600; }
.sheet-brand { margin-top: 26px; text-align: center; font-size: 11px; color: #999; }
.export-stage { position: fixed; left: -12000px; top: 0; width: 794px; background: #fff; z-index: -1; }

/* ---------- Thông báo ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100; transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; font-size: 14px; text-align: center;
  background: var(--ink); color: #fff; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { background: var(--thu); }
#toast.err { background: var(--chi); }
@media (max-width: 640px) { #toast { bottom: 84px; } }

/* ---------- In ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  body > *:not(.modal-back) { display: none !important; }
  .modal-back { position: static; display: block; background: #fff; padding: 0; backdrop-filter: none; }
  .modal { box-shadow: none; max-width: none; max-height: none; overflow: visible; padding: 0; border-radius: 0; animation: none; }
  .report-top { display: none; }
  .sheet-scroll { overflow: visible; max-height: none; padding: 0; background: #fff; margin: 0; }
  .sheet { width: 100%; padding: 0; zoom: 1 !important; }
}
