/* Vạn Lịch Gia Tộc — mobile-first, chữ mặc định 18px, nút tối thiểu 48px. */
:root {
  --red: #7a1f17;
  --red-2: #9b2c20;
  --gold: #b8892b;
  --gold-soft: #f3e3bd;
  --ink: #2a1d16;
  --muted: #6b5a4e;
  --paper: #fbf6ec;
  --card: #ffffff;
  --line: #e4d6bd;
  --warn-bg: #fff3d6;
  --warn-ink: #7a4b00;
  --ok: #2f6b3a;
  --err: #a32020;
  --radius: 14px;
  --tap: 48px;
  font-size: 18px;
  color-scheme: light;
}
html.large-text { font-size: 22px; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.2rem; color: var(--red); }
h3 { font-size: 1.08rem; }
h4 { font-size: 1rem; }
p { margin: .25rem 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: #fff; padding: .5rem; z-index: 100; min-height: var(--tap); display: inline-flex; align-items: center; }
.skip-link:focus { left: .5rem; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.icon { width: 24px; height: 24px; fill: currentColor; flex: none; }

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--red), var(--red-2));
  color: #fff;
  padding: .75rem 1rem;
  display: flex; gap: .5rem; align-items: flex-start; justify-content: space-between;
  border-bottom: 3px solid var(--gold);
}
@media (min-width: 760px) { .app-header { position: sticky; top: 0; z-index: 20; } }
.brand { min-width: 0; }
.brand-app { margin: 0; font-size: 1rem; letter-spacing: .08em; text-transform: uppercase; color: var(--gold-soft); }
.family-name { margin: 0; font-size: 1.1rem; color: #fff; overflow-wrap: anywhere; }
.motto { margin: 0; font-size: 1rem; font-style: italic; color: var(--gold-soft); }
.header-actions { display: flex; gap: .25rem; flex: none; }
.btn-icon {
  min-width: var(--tap); min-height: var(--tap);
  background: transparent; border: 0; color: inherit; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font: inherit;
}
.btn-icon.labeled { flex-direction: column; font-size: 1rem; padding: .2rem .35rem; gap: 2px; }
.btn-icon:hover { background: rgba(255,255,255,.12); }
.sim-banner { background: var(--warn-bg); color: var(--warn-ink); padding: .5rem 1rem; font-weight: 600; text-align: center; border-bottom: 1px solid #e8c77a; font-size: 1rem; }

/* Layout */
:root { --main-pad: 1rem; }
.app-main { max-width: 860px; margin: 0 auto; padding: var(--main-pad); outline: none; }
.view { display: flex; flex-direction: column; gap: 1rem; }
.group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.group .count { color: var(--muted); font-weight: normal; font-size: 1rem; }
.warn-group { background: var(--warn-bg); border-color: #e8c77a; }
.warn-line { margin: .35rem 0; }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 2px solid var(--gold);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 1rem; font-weight: 600;
}
.tab.active { color: var(--red); background: var(--gold-soft); }

/* Buttons */
.btn {
  min-height: var(--tap); padding: .5rem 1rem; border-radius: 12px;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-align: center;
}
.btn:hover { border-color: var(--gold); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-2); }
.btn-soft { background: var(--gold-soft); border-color: #e6cf98; }
.btn-small { min-height: var(--tap); font-size: 1rem; padding: .35rem .75rem; margin-top: .4rem; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.actions .btn { flex: 1 1 140px; }

/* Today */
.today-card {
  background: linear-gradient(160deg, #fffaf0, var(--gold-soft)); border: 1.5px solid #e6cf98;
  border-radius: var(--radius); padding: 1rem; text-align: center;
}
.today-solar { font-size: 1.15rem; font-weight: 700; color: var(--red); }
.today-lunar { font-size: 1rem; }

/* Cards */
.cards { display: grid; gap: .65rem; }
.card {
  width: 100%; text-align: left; background: #fff; border: 1.5px solid var(--line); border-left: 6px solid var(--gold);
  border-radius: 12px; padding: .75rem .9rem; font: inherit; color: inherit; cursor: pointer; min-height: var(--tap);
}
.card:hover { border-color: var(--gold); }
.card.needs { border-left-color: #d08b00; background: #fffaf0; }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.card-name { font-size: 1.05rem; color: var(--ink); overflow-wrap: anywhere; }
.days { font-weight: 700; color: var(--red); white-space: nowrap; font-size: 1rem; }
.days.today { background: var(--red); color: #fff; border-radius: 999px; padding: 0 .6rem; }
.card-branch { color: var(--muted); font-size: 1rem; }
.card-date { font-size: 1rem; }
.card-years { font-size: 1rem; color: var(--ok); font-weight: 600; }
.badge { display: inline-block; background: var(--gold-soft); color: var(--ink); border-radius: 8px; padding: .1rem .5rem; font-size: 1rem; margin: .25rem .25rem 0 0; }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid #e8c77a; }
/* Ngày chưa chốt: không dùng màu/kiểu của đếm ngược chính thức. */
.days.pending { color: var(--warn-ink); background: var(--warn-bg); border: 1px dashed #d08b00; border-radius: 999px; padding: 0 .6rem; }
.badge-tentative { background: #fff; color: var(--warn-ink); border: 1px dashed #d08b00; font-weight: 700; margin: 0 .25rem 0 0; }
.card-date.tentative { color: var(--muted); font-style: italic; }

/* States */
.state { padding: 1.25rem; text-align: center; color: var(--muted); }
.state-error { color: var(--err); }
.state-error .btn { margin-top: .5rem; }
.spinner { display: inline-block; width: 1.1rem; height: 1.1rem; margin-right: .5rem; border: 3px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.notice { background: #fff8e8; border: 1px dashed var(--gold); border-radius: 10px; padding: .6rem .75rem; font-size: 1rem; }
.hint { color: var(--muted); font-size: 1rem; }

/* Sheet */
.sheet-root { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(30, 15, 10, .45); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh;
  background: var(--paper); border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
  box-shadow: 0 -8px 30px rgba(0,0,0,.25);
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: .5rem .5rem .5rem 1rem; border-bottom: 1px solid var(--line); gap: .5rem; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
.sheet-head .btn-icon { color: var(--ink); }
.sheet-body { overflow-y: auto; padding: 1rem; padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); }
@media (min-width: 760px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 6vh; transform: translateX(-50%); width: 640px; max-height: 88vh; border-radius: 18px; }
}

/* Forms */
.form { display: flex; flex-direction: column; gap: .6rem; }
.field { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.field label { font-weight: 600; font-size: 1rem; }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=date], input[type=time], select, textarea {
  font: inherit; min-height: var(--tap); padding: .45rem .65rem; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); width: 100%; max-width: 100%;
}
textarea { min-height: 96px; resize: vertical; }
input[type=file] { font: inherit; min-height: var(--tap); max-width: 100%; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--err); background: #fff6f6; }
.field-error { color: var(--err); font-size: 1rem; margin: 0; min-height: 0; }
.form-error { color: var(--err); font-weight: 600; margin: 0; }
.form-error:empty, .field-error:empty { display: none; }
.check { display: flex; align-items: center; gap: .5rem; min-height: var(--tap); cursor: pointer; }
.check input { width: 24px; height: 24px; flex: none; accent-color: var(--red); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: .5rem; }
.field-group { display: flex; flex-direction: column; gap: .3rem; }
.result { margin-top: .4rem; }
.detail-list { display: grid; grid-template-columns: minmax(96px, 34%) 1fr; gap: .35rem .75rem; margin: 0; }
.detail-list dt { color: var(--muted); font-weight: 600; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.warn-box { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: .6rem .8rem; margin-top: .75rem; }

/* Genealogy */
.toolbar { display: flex; flex-direction: column; gap: .5rem; }
.toolbar-row { display: flex; gap: .5rem; }
.toolbar-row select { flex: 1; min-width: 0; }
.toolbar-row .btn { flex: none; }
.tree-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; overflow-x: auto; }
.tree, .tree-children { list-style: none; margin: 0; padding: 0; }
.tree-children { margin-left: 1rem; padding-left: .6rem; border-left: 2px solid var(--gold-soft); }
.tree-node { margin: .25rem 0; }
.tree-row { display: flex; align-items: flex-start; gap: .35rem; }
.tree-people { display: flex; flex-direction: column; gap: .15rem; min-width: 0; flex: 1; }
.btn-toggle {
  width: var(--tap); height: var(--tap); flex: none; border-radius: 10px; border: 1.5px solid var(--line); background: var(--gold-soft);
  font-size: 1.3rem; font-weight: 700; cursor: pointer; color: var(--red);
}
.btn-toggle.placeholder { visibility: hidden; }
.person-btn {
  min-height: var(--tap); width: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: 10px; padding: .3rem .5rem; font: inherit; color: inherit; cursor: pointer;
}
.person-btn:hover { background: #fff8e8; border-color: var(--line); }
.p-name { font-weight: 700; overflow-wrap: anywhere; }
.p-years { color: var(--muted); font-size: 1rem; }
.gen { font-size: 1rem; background: var(--gold-soft); border-radius: 6px; padding: 0 .35rem; }
.spouse { display: flex; align-items: center; gap: .25rem; padding-left: .5rem; }
.spouse-mark { font-size: 1rem; color: var(--muted); flex: none; }
.person-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
.person-list.compact .person-btn { min-height: var(--tap); }
.person-head { display: flex; gap: .9rem; align-items: center; margin-bottom: .75rem; }
.portrait { width: 96px; height: 96px; border-radius: 12px; object-fit: cover; border: 3px solid var(--gold); flex: none; background: var(--gold-soft); }
.portrait.placeholder { display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; color: var(--red); }
.p-title { margin: 0; font-size: 1.2rem; overflow-wrap: anywhere; }
.rel { margin-top: .9rem; }
.bio { margin-top: .9rem; }
.pre { white-space: pre-wrap; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.gallery figcaption { font-size: 1rem; color: var(--muted); }
.upload { margin-top: 1rem; padding-top: .75rem; border-top: 1px dashed var(--line); }

/* Prayers */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.chip { min-height: var(--tap); padding: .35rem .9rem; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.chip.active { background: var(--red); color: #fff; border-color: var(--red); }
.prayer-list { display: grid; gap: .4rem; }
.prayer-item { justify-content: flex-start; text-align: left; }
.prayer-item.active { border-color: var(--red); box-shadow: inset 4px 0 0 var(--red); }
.prayer-text {
  white-space: pre-wrap; background: #fffdf7; border: 1.5px solid #e6cf98; border-radius: 12px; padding: 1rem;
  font-family: "Noto Serif", "Times New Roman", "Segoe UI", system-ui, serif; line-height: 1.75; margin-top: .6rem; overflow-wrap: anywhere;
}
.checklist, .plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.plain-list li { padding: .4rem 0; border-bottom: 1px dashed var(--line); }
.services { background: #fbfbfb; }

/* Calendar month list */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: .4rem; margin-bottom: .5rem; flex-wrap: wrap; }
.month-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); gap: .3rem; }
.month-list li { display: flex; gap: .4rem; align-items: center; padding: .3rem .5rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 1rem; }
.month-list li.ram, .month-list li.mung-mot { background: var(--gold-soft); border-color: #e6cf98; font-weight: 700; }
.month-list li.is-today { outline: 2px solid var(--red); }
.m-lunar { color: var(--red); margin-left: auto; }
.tag { font-size: 1rem; background: var(--red); color: #fff; border-radius: 6px; padding: 0 .3rem; }

/* Fund / inbox / menu */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin: .75rem 0 .25rem; }
.total { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .5rem; text-align: center; min-width: 0; }
.total span { display: block; font-size: 1rem; color: var(--muted); }
.total strong { display: block; font-size: 1rem; white-space: nowrap; }
.total.in strong { color: var(--ok); }
.total.out strong { color: var(--err); }
.ledger, .inbox { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .5rem; }
.ledger-item, .inbox-item { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; }
.ledger-item.in { border-left: 5px solid var(--ok); }
.ledger-item.out { border-left: 5px solid var(--err); }
.amount { font-weight: 700; white-space: nowrap; }
.inbox-item.read { opacity: .75; }
.inbox-item.cancelled, .inbox-item.missed { background: #f6f3ee; }
.menu { display: flex; flex-direction: column; gap: .4rem; }
.menu-item {
  min-height: 56px; display: flex; align-items: center; gap: .75rem; padding: .5rem .9rem; border-radius: 12px;
  border: 1.5px solid var(--line); background: #fff; font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}
.menu-item:hover { border-color: var(--gold); }
.dev { border-style: dashed; }

/* Login */
.login { max-width: 560px; margin: 0 auto; text-align: center; display: flex; flex-direction: column; gap: .5rem; }
.login .brand-app { color: var(--gold); }
.login-title { color: var(--red); font-size: 1.4rem; }
.login .motto { color: var(--gold); font-size: 1rem; }
.account-list { display: grid; gap: .6rem; margin-top: .5rem; text-align: left; }
.account { min-height: 64px; display: flex; flex-direction: column; gap: .15rem; padding: .7rem .9rem; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; font: inherit; cursor: pointer; text-align: left; }
.account:hover { border-color: var(--gold); }
.account-role { color: var(--muted); font-size: 1rem; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 60; max-width: calc(100vw - 2rem); transition: .2s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--err); }

@media (max-width: 380px) {
  :root { --main-pad: .75rem; }
  .tree-children { margin-left: .6rem; padding-left: .3rem; }
  .quick-actions { grid-template-columns: 1fr 1fr; }
  .row3 { grid-template-columns: 1fr 1fr; }
  .row3 .field:last-child { grid-column: span 2; }
  .btn { padding: .5rem .6rem; }
}
@media (min-width: 760px) {
  .quick-actions { grid-template-columns: repeat(4, 1fr); }
  .cards { grid-template-columns: 1fr 1fr; }
  .toolbar { flex-direction: row; flex-wrap: wrap; }
  .toolbar-row { flex: 1 1 300px; }
  body { padding-bottom: 0; }
  .tabbar { position: sticky; top: auto; bottom: 0; max-width: 860px; margin: 0 auto; border: 2px solid var(--gold); border-bottom: 0; border-radius: 14px 14px 0 0; }
}

/* Màn hẹp: ô tổng quỹ xếp dọc để số tiền 18px không bị cắt. */
@media (max-width: 520px) {
  .totals { grid-template-columns: 1fr; }
  .total { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; text-align: left; }
  .total span, .total strong { display: inline; }
}

/* ===== Điều hướng màn con ===== */
.screen-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.screen-title { margin: 0; flex: 1 1 160px; font-size: 1.25rem; }
.btn-back { gap: .25rem; }
.btn-back span { font-size: 1.4rem; line-height: 1; }
.link-btn { text-decoration: none; }
.link-btn.wide { width: 100%; justify-content: flex-start; text-align: left; }
.btn-danger { color: var(--err); border-color: #e3b3b3; }
.card.static { cursor: default; }
.tab { font-size: 1rem; }

/* ===== Trang chủ ===== */
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); gap: .5rem; }
.feature {
  min-height: 96px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  padding: .6rem .4rem; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
  text-decoration: none; text-align: center; font-weight: 600;
}
.feature:hover { border-color: var(--gold); }
.feature .icon { width: 30px; height: 30px; color: var(--red); }
.feature.soon { background: #faf7f1; }
.feature-soon { font-size: 1rem; font-weight: 600; color: var(--warn-ink); background: var(--warn-bg); border: 1px dashed #d08b00; border-radius: 999px; padding: 0 .5rem; }
@media (max-width: 380px) { .feature-grid { grid-template-columns: 1fr 1fr; } }

/* ===== Nút phân đoạn ===== */
.seg-group { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.seg-group .seg { flex: 1 1 140px; }
.seg.active { background: var(--red); border-color: var(--red); color: #fff; }

/* ===== Lịch tổng hợp ===== */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.cal-title { margin: 0; text-align: center; flex: 1; }
.cal-filters { border: 1px solid var(--line); border-radius: var(--radius); padding: .25rem .75rem .5rem; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); background: #fff; }
.cal-filters legend { font-weight: 700; padding: 0 .3rem; }
.mark { display: inline-block; width: 1.1em; text-align: center; font-size: 1rem; line-height: 1; }
.m-memorial { color: #9b2c20; }
.m-special { color: #8a6100; }
.m-holiday { color: #1f5f8b; }
.m-personal { color: #5a3e8f; }
/* Lưới tràn viền: ở 360px mỗi ô rộng 360/7 ≈ 51px (≥ 48px) nhờ bỏ lề trang. */
.cal-grid-wrap { margin: 0 calc(-1 * var(--main-pad)); background: #fff; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
@media (min-width: 900px) { .cal-grid-wrap { margin: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; } }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-wd { text-align: center; font-weight: 700; padding: .3rem 0; color: var(--muted); border-bottom: 1px solid var(--line); }
.cal-cell {
  min-height: 78px; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 1px;
  padding: .3rem 0; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: #fff; font: inherit; color: var(--ink); cursor: pointer; line-height: 1.2;
}
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell.blank { background: #faf7f1; cursor: default; }
.cal-solar { font-weight: 700; font-size: 1rem; }
.cal-lunar { font-size: 1rem; color: var(--muted); letter-spacing: -.02em; white-space: nowrap; }
.cal-marks { display: flex; gap: 0; justify-content: center; min-height: 1.2em; white-space: nowrap; }
.cal-marks .mark { width: auto; }
.cal-cell.is-today { box-shadow: inset 0 0 0 3px var(--gold); }
.cal-cell.is-selected { background: var(--red); color: #fff; }
.cal-cell.is-selected .cal-lunar, .cal-cell.is-selected .mark { color: #fff; }
.cal-items, .cal-list { list-style: none; margin: .5rem 0; padding: 0; display: grid; gap: .5rem; }
.cal-item { display: flex; gap: .5rem; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem; background: #fff; }
.cal-item .mark { margin-top: .2rem; }
.cal-list-day {
  width: 100%; min-height: var(--tap); display: flex; flex-direction: column; align-items: flex-start; gap: .15rem; text-align: left;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff; font: inherit; color: inherit; padding: .5rem .7rem; cursor: pointer;
}
.cal-list-day.is-selected { border-color: var(--red); box-shadow: inset 4px 0 0 var(--red); }
.cal-list-item { display: block; }

/* ===== Checklist ===== */
.ck-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.ck-item { border-bottom: 1px dashed var(--line); padding-bottom: .4rem; }
.ck-item .row2 { margin-top: .3rem; }
.save-status { font-weight: 600; }
.p-title-line { display: block; }
.prayer-item { flex-direction: column; align-items: flex-start; }
.keepsakes figcaption { display: flex; flex-direction: column; gap: .2rem; }

/* ===== Ảnh nền: lớp phủ màu giấy 88% để chữ luôn đủ tương phản; ảnh tĩnh, không animation ===== */
body.has-bg {
  background-image: linear-gradient(rgba(251, 246, 236, .88), rgba(251, 246, 236, .88)), var(--bg-image);
  background-size: cover; background-position: center; background-attachment: fixed;
}
.quote-card {
  background: rgba(255, 255, 255, .94); border: 1.5px solid #e6cf98; border-radius: var(--radius); padding: 1rem 1.1rem;
}
.quote-text { white-space: pre-line; font-family: "Noto Serif", "Times New Roman", "Segoe UI", serif; font-size: 1.1rem; line-height: 1.6; margin: 0; }
.quote-source { color: var(--muted); margin-top: .4rem; text-align: right; }
.img-missing { display: flex; align-items: center; justify-content: center; text-align: center; background: #f1ece2; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; min-height: 96px; padding: .4rem; }
.qr { display: block; margin: .5rem auto; width: 240px; height: 240px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }

/* ===== Chat theo đơn ===== */
.chat-list { list-style: none; margin: .5rem 0; padding: 0; display: grid; gap: .4rem; }
.chat-msg { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .4rem .7rem; max-width: 92%; overflow-wrap: anywhere; }
.chat-msg.mine { justify-self: end; background: #fff8e8; }
.chat-msg.blocked { border-style: dashed; background: #f6f3ee; }

/* ===== Hướng dẫn sử dụng ===== */
.guide-list { display: grid; gap: .5rem; margin-top: .5rem; }
.guide { border: 1.5px solid var(--line); border-radius: 12px; background: #fff; padding: 0 .8rem; }
.guide summary { min-height: var(--tap); display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-weight: 700; cursor: pointer; padding: .4rem 0; }
.guide[open] { padding-bottom: .8rem; }
.guide-steps { margin: .4rem 0; padding-left: 1.5rem; display: grid; gap: .4rem; }
.guide-ui { display: flex; flex-wrap: wrap; gap: .3rem; margin: .2rem 0; }
.guide-chip { display: inline-block; border: 1.5px solid var(--red); color: var(--red); background: #fff; border-radius: 10px; padding: .1rem .55rem; font-weight: 700; }
.guide-result { background: #eef6ef; border-radius: 10px; padding: .5rem .7rem; margin: .4rem 0; }
.guide-fail { background: var(--warn-bg); border-radius: 10px; padding: .5rem .7rem; margin: .4rem 0; }
.guide-note { border-left: 4px solid var(--gold); padding: .2rem .7rem; margin: .5rem 0; }
.guide-btn { width: 100%; }
.help-link { margin: .2rem 0; align-self: flex-start; }
.first-run .actions { margin-top: .5rem; }

/* ===== Thiền & Tu tập ===== */
.med-script { display: grid; gap: .5rem; padding-left: 1.2rem; }
.med-script li { padding: .25rem .4rem; border-radius: 8px; }
.med-script li.active { background: #fff4d6; box-shadow: inset 4px 0 0 var(--red); }
.today-card input[type="range"], .group input[type="range"] { width: 100%; min-height: var(--tap); accent-color: var(--red); }
.guide-shots { display: grid; gap: .8rem; margin: .6rem 0; }
.guide-shot { margin: 0; }
.guide-shot img { display: block; width: 100%; max-width: 360px; height: auto; border: 1.5px solid var(--line); border-radius: 12px; }
.guide-shot figcaption { margin-top: .35rem; }

/* ===== Tra ngày & Giờ ===== */
.trad-hours li { padding: .2rem 0; }
.trad-advice { margin: .4rem 0; }
.detail-list dd .hint { margin: .1rem 0 .4rem; }
.trad-chip { display: inline-block; padding: .05rem .55rem; border-radius: 999px; border: 1.5px solid var(--line); background: #f4f1ea; color: #3d3a33; font-weight: 600; }
.trad-chip.trad-hd { background: #fff4d6; border-color: #d9b45a; color: #4a3a10; }

.trad-method { margin: .2rem 0 .4rem; }

/* ===== Điện thoại & Zalo Mini App (chỉ bố cục, không đổi nghiệp vụ) ===== */
/* Vùng an toàn trên (tai thỏ/đảo động) khi trang chiếm toàn màn hình (viewport-fit=cover). */
.app-header { padding-top: calc(.75rem + env(safe-area-inset-top)); padding-left: calc(1rem + env(safe-area-inset-left)); padding-right: calc(1rem + env(safe-area-inset-right)); }
/* Cuộn: không kéo dài cuộn ra ngoài bảng trượt / không cuộn trang nền khi đang mở bảng. */
.sheet-body { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet:focus { outline: none; }
body.no-scroll { overscroll-behavior: none; }
/* Bảng trượt vừa phần màn hình còn lại khi bàn phím mở (iOS không thu vh theo bàn phím). */
.sheet { max-height: min(92vh, calc(var(--vvh, 100vh) * .92)); }
@supports (height: 100dvh) { .sheet { max-height: min(92dvh, calc(var(--vvh, 100dvh) * .92)); } }
/* Bàn phím đang mở: ẩn thanh tab (để không che ô nhập), bỏ khoảng đệm dưới dành cho thanh tab. */
html.kb-open .tabbar { display: none; }
html.kb-open body { padding-bottom: 0; }
html.kb-open .toast { bottom: 1rem; }
/* Ô nhập trên điện thoại: chữ >= 16px để iOS không tự phóng to trang (ứng dụng dùng 18px). */
input, select, textarea { font-size: max(16px, 1rem); }

/* Trong Zalo Mini App: Zalo đã có thanh điều hướng riêng (tiêu đề, nút Trở lại, menu ••• ✕ ở góc phải).
   Thu gọn tiêu đề ứng dụng để không lặp tên, vẫn giữ nút Gia tộc/Cài đặt (không nằm dưới menu Zalo). */
html.in-zalo .app-header { padding-top: .5rem; }
html.in-zalo .brand-app, html.in-zalo .motto { display: none; }
html.in-zalo .skip-link { display: none; }

/* MÔ PHỎNG thanh Zalo (chỉ khi ?zmp-preview=1) — để soát chồng lấn trên trình duyệt, không phải Zalo thật. */
.zmp-preview-bar { position: sticky; top: 0; z-index: 40; height: calc(48px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) .5rem 0;
  display: flex; align-items: center; gap: .5rem; background: var(--red); color: #fff; border-bottom: 1px dashed var(--gold-soft); }
.zmp-preview-back { width: 40px; text-align: center; font-size: 1.6rem; }
.zmp-preview-title { flex: 1; font-weight: 700; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.zmp-preview-capsule { border: 1px solid rgba(255,255,255,.7); border-radius: 999px; padding: .1rem .7rem; font-size: 1rem; letter-spacing: .05em; }
.zmp-preview-note { margin: 0; padding: .35rem 1rem; background: #fff3d6; color: var(--warn-ink); font-size: 1rem; text-align: center; border-bottom: 1px solid #e8c77a; }

/* Lịch tháng thu gọn trên Trang chủ */
.mini-week, .mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.mini-week span { font-size: 1rem; font-weight: 700; color: var(--muted); }
.mini-cell { min-height: var(--tap); display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 8px;
  color: var(--ink); text-decoration: none; line-height: 1.1; padding: 2px 0; background: #fff; border: 1px solid transparent; }
.mini-cell.blank { background: transparent; }
.mini-cell.is-special { background: var(--gold-soft); }
.mini-cell.is-today { background: var(--red); color: #fff; }
.mini-cell.is-today .mark { color: #fff; }
.mini-solar { font-weight: 700; font-size: 1rem; }
.mini-lunar { font-size: 1rem; color: var(--muted); letter-spacing: -.02em; white-space: nowrap; }
.mini-cell.is-today .mini-lunar { color: #fff; }
.mini-marks { display: flex; justify-content: center; white-space: nowrap; min-height: 1em; }
.mini-marks .mark { width: auto; }
.mini-legend { display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin: .5rem 0; font-size: 1rem; color: var(--muted); }
.mini-cal h3 { margin-top: .5rem; }
.account-scope { font-size: 1rem; color: var(--ink); background: #fffaf0; border-radius: 8px; padding: .2rem .5rem; margin-top: .2rem; }
.account-full { border-color: var(--gold); border-width: 2px; }
.account-full .account-scope { background: var(--gold-soft); font-weight: 600; }
.account-guest { border-style: dashed; }
.login-section { margin-top: 1rem; }
.quote-original, .quote-ref, .quote-gloss { font-size: 1rem; color: var(--muted); margin: .2rem 0 0; }

/* Ảnh thật: lớp phủ ≥ 88% màu giấy — tính cho điểm ảnh ĐEN TUYỆT ĐỐI, chữ phụ (--muted) vẫn ≥ 4.5:1 (test daily-library kiểm). */
body.has-bg.has-photo { background-image: linear-gradient(rgba(251, 246, 236, .88), rgba(251, 246, 236, .90)), var(--bg-image); }
.bg-credit { font-size: 1rem; color: var(--ink); background: rgba(255, 255, 255, .94); border-radius: 8px; padding: .25rem .6rem; margin: .4rem 0 0; overflow-wrap: anywhere; }
/* Bản dùng thử: luôn hiện, không che nội dung (nằm trong luồng trang, dính trên cùng khi cuộn). */
.trial-banner { position: sticky; top: 0; z-index: 35; background: #7a4b00; color: #fff; font-weight: 700; text-align: center; padding: .4rem 1rem; padding-top: calc(.4rem + env(safe-area-inset-top)); font-size: 1rem; }
