/* Giao diện theo mockup quan-ly-quy-y.html: nền kem, nâu vàng làm màu nhấn,
   chữ Be Vietnam Pro cho nội dung, Noto Serif cho tiêu đề và con số. */

:root {
  --bg: #F7F3EC;
  --surface: #FFFFFF;
  --surface-hover: #FBF7F0;
  --surface-head: #FAF6EF;
  --line: #E8DFD1;
  --line-soft: #EFE7DA;
  --line-strong: #DCCFBB;
  --ink: #2A1F14;
  --muted: #6E604F;
  --placeholder: #A39581;
  --accent: #9A5B08;
  --accent-ink: #6F4105;
  --accent-soft: #F6E7CC;
  --gold: #F2C66D;
  --warn-bg: #FDF6E9;
  --hover: #F3EBDD;
  --danger: #A8321A;
  --danger-ink: #8A2A12;
  --danger-soft: #F8E1DA;
  --success: #2F7A55;

  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-lg: 0 18px 40px -12px rgba(42, 31, 20, .28);

  --serif: 'Noto Serif', Georgia, serif;
  --sans: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 32px; height: 32px; stroke-width: 1.4; }

.wrap { padding-inline: 32px; }

/* ---------- Nút ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); font-weight: 500; white-space: nowrap;
  transition: background-color .15s, color .15s;
}
.btn:hover { background: var(--surface-hover); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { border: 0; padding: 0 20px; background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 1px 0 rgba(42, 31, 20, .12); }
.btn-primary:hover { background: var(--accent-ink); }
.btn-danger { border: 0; background: var(--danger); color: #fff; font-weight: 600; }
.btn-danger:hover { background: var(--danger-ink); }
.btn-block { width: 100%; }

.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger-ink); }

.link-btn { align-self: flex-start; padding: 0; border: 0; background: none; font-size: 12px; font-weight: 600; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--accent-ink); }

/* ---------- Ô nhập ---------- */

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 500; }
.req { margin-left: 2px; color: var(--danger); }
.hint { font-size: 12px; color: var(--muted); }
.input {
  width: 100%; height: 44px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--placeholder); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(154, 91, 8, .15); }
.input[aria-invalid='true'] { border-color: var(--danger); }
.input[aria-invalid='true']:focus { box-shadow: 0 0 0 3px rgba(168, 50, 26, .15); }
.error-text { font-size: 12px; color: var(--danger); }
.error-text:empty { display: none; }

/* ---------- Thanh trên cùng ---------- */

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 14px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; }
.brand:hover { color: inherit; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--ink); color: var(--gold); }
.brand-mark .icon { width: 22px; height: 22px; stroke-width: 1.6; }
.brand-name { display: block; font-family: var(--serif); font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }

.user-menu { position: relative; }
.user-menu summary {
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 12px 0 6px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); list-style: none; cursor: pointer; user-select: none;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover, .user-menu[open] summary { background: var(--surface-hover); }
.user-menu summary .icon { width: 16px; height: 16px; }
.avatar-sm { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; text-transform: uppercase; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 0; border-radius: var(--radius-sm); background: none; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu hr { margin: 6px 0; border: 0; border-top: 1px solid var(--line-soft); }

/* ---------- Đầu trang ---------- */

main.wrap { display: flex; flex-direction: column; gap: 28px; padding-top: 40px; padding-bottom: 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 8px 0; font-family: var(--serif); font-size: 36px; font-weight: 600; line-height: 1.15; letter-spacing: -.02em; }
.lead { max-width: 620px; color: var(--muted); font-size: 15px; line-height: 1.6; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Thống kê ---------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.stat { display: flex; flex-direction: column; gap: 6px; padding: 20px 24px; border-right: 1px solid var(--line-soft); }
.stat:last-child { border-right: 0; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-family: var(--serif); font-size: 30px; font-weight: 600; line-height: 1.1; }
.stat-hint { font-size: 12px; color: var(--muted); }
.stat.warn { background: var(--warn-bg); }
.stat.warn .stat-label { color: var(--accent-ink); font-weight: 500; }
.stat.warn .stat-value { color: var(--accent-ink); }

/* ---------- Bảng ---------- */

.card { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.search { display: flex; align-items: center; gap: 10px; flex: 1 1 320px; max-width: 440px; height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--muted); }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--ink); }
.search input::placeholder { color: var(--placeholder); }
kbd { padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 5px; font-family: inherit; font-size: 11px; color: var(--muted); }
.filter { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); font-size: 13px; color: var(--muted); white-space: nowrap; }
.filter select { border: 0; background: transparent; font-weight: 600; color: var(--ink); cursor: pointer; }
.filter select:focus { outline: none; }
.filter:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.reset { height: 44px; padding: 0 10px; border: 0; background: none; font-size: 13px; font-weight: 600; color: var(--accent); }
.reset:hover { color: var(--accent-ink); }
.count { margin-left: auto; font-size: 13px; color: var(--muted); }

.table-box { overflow-x: auto; }
table { width: 100%; min-width: 820px; border-collapse: collapse; }
th { padding: 12px; background: var(--surface-head); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; text-align: right; }
td { padding: 14px 12px; border-top: 1px solid var(--line-soft); vertical-align: middle; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-hover); }
.col-index { color: var(--muted); }
.sort { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: inherit; font-weight: 600; }
.sort:hover, th[aria-sort='ascending'] .sort, th[aria-sort='descending'] .sort { color: var(--ink); }

.person { display: flex; align-items: center; gap: 14px; }
.ava { position: relative; display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 12px; font-family: var(--serif); font-size: 15px; font-weight: 600; }
.ava img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.ava.missing { outline: 1px dashed #D9B675; outline-offset: -1px; }
.ava .badge { position: absolute; right: -4px; bottom: -4px; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 999px; background: #fff; border: 1px solid #E8C98F; color: var(--accent); }
.ava .badge .icon { width: 12px; height: 12px; stroke-width: 2; }
/* Bốn tông màu xoay vòng theo id để ảnh tạm của mỗi người dễ phân biệt. */
.t0 { background: #F6E7CC; color: #6F4105; }
.t1 { background: #E9E1F2; color: #4A3570; }
.t2 { background: #DDEBE4; color: #25503D; }
.t3 { background: #F3DCD3; color: #7A3420; }
.p-name { display: block; font-size: 15px; font-weight: 600; }
.p-dharma { font-size: 13px; color: var(--muted); }
.p-dharma em { font-family: var(--serif); font-weight: 500; color: var(--accent-ink); }
.sub { display: block; font-size: 12px; color: var(--muted); }
.dash { color: var(--placeholder); }
.row-actions { display: inline-flex; gap: 4px; }

.skeleton { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--line-soft), var(--surface-hover), var(--line-soft)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty { display: grid; justify-items: center; gap: 6px; padding: 56px 24px; text-align: center; border-top: 1px solid var(--line-soft); }
.empty .icon-lg { margin-bottom: 4px; color: var(--muted); }
.empty strong { font-family: var(--serif); font-size: 18px; }
.empty span { color: var(--muted); }
.empty .btn { margin-top: 12px; }

.foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line-soft); font-size: 13px; color: var(--muted); }
.pager { display: flex; gap: 8px; }
.pager button { min-width: 40px; height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); font-size: 13px; color: var(--ink); }
.pager button:hover:not(:disabled):not([aria-current]) { background: var(--surface-hover); }
.pager button[aria-current] { padding: 0; border: 0; background: var(--ink); color: #fff; font-weight: 600; }
.pager button:disabled { color: #8A7C6A; cursor: default; }
.pager .gap { align-self: center; color: var(--muted); }

/* Danh sách dạng thẻ thay cho bảng trên màn hình hẹp. */
.m-list { display: none; }
.m-item { display: flex; align-items: center; gap: 14px; padding: 14px; border-top: 1px solid var(--line-soft); cursor: pointer; }
.m-item:first-child { border-top: 0; }
.m-info { flex: 1; min-width: 0; }
.call { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); }
.fab { display: none; }

/* ---------- Hộp thoại ---------- */

dialog { padding: 0; border: 0; color: var(--ink); background: var(--surface); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(42, 31, 20, .45); }

.modal { width: min(440px, calc(100vw - 32px)); border-radius: var(--radius-lg); }
.modal-body { display: grid; gap: 14px; padding: 24px; }
.modal-body h2 { font-family: var(--serif); font-size: 20px; font-weight: 600; }
.modal-body > p { margin-top: -6px; color: var(--muted); line-height: 1.6; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; background: var(--surface-head); border-top: 1px solid var(--line-soft); }

/* Form thêm/sửa trượt ra từ cạnh phải, danh sách vẫn nằm phía sau để không mất chỗ đang xem. */
.sheet { position: fixed; inset: 0 0 0 auto; margin: 0; width: min(560px, 100vw); height: 100vh; max-width: 100vw; max-height: 100vh; }
.sheet[open] { display: flex; animation: slide-in .22s ease-out; }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.sheet form { display: flex; flex-direction: column; width: 100%; height: 100%; }
.sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 24px; border-bottom: 1px solid var(--line-soft); }
.sheet-header h2 { margin-top: 4px; font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.sheet-header p { margin-top: 4px; font-size: 13px; color: var(--muted); }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 24px 24px; }
.sheet-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; background: var(--surface-head); border-top: 1px solid var(--line-soft); }

.section { padding: 22px 0; border-bottom: 1px solid var(--line-soft); }
.section:last-child { border-bottom: 0; }
.section-title { margin-bottom: 14px; font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 16px; }
.stack { display: grid; gap: 16px; }

.photo-field { display: flex; align-items: center; gap: 20px; }
.photo-preview { display: grid; place-items: center; flex: none; width: 108px; height: 140px; overflow: hidden; border: 1px dashed #D9B675; border-radius: 12px; background: var(--warn-bg); color: var(--accent); }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: grid; gap: 8px; justify-items: start; }

/* ---------- Thông báo ---------- */

.toasts { position: fixed; right: 24px; bottom: 24px; z-index: 100; display: grid; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 10px; min-width: 280px; max-width: 420px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
.toast.success .icon { color: var(--success); }
.toast.error .icon { color: var(--danger); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Trang đăng nhập ---------- */

.login-page { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.login-aside { position: relative; display: flex; flex-direction: column; justify-content: space-between; padding: 48px; overflow: hidden; background: var(--ink); color: #F4ECDF; }
.login-aside .brand-mark { width: 52px; height: 52px; border-radius: 14px; background: rgba(242, 198, 109, .12); }
.login-aside .brand-mark .icon { width: 28px; height: 28px; }
.login-aside .eyebrow { display: block; margin-top: 32px; color: var(--gold); }
.login-aside h1 { max-width: 440px; color: #fff; }
.login-aside p { max-width: 440px; color: #CDBFA8; font-size: 15px; line-height: 1.6; }
.login-aside blockquote { max-width: 420px; margin: 0; padding-left: 16px; border-left: 2px solid var(--gold); font-family: var(--serif); font-style: italic; color: #E6D9C3; }
.login-lotus { position: absolute; right: -60px; bottom: -40px; width: 340px; height: 340px; color: rgba(242, 198, 109, .1); stroke-width: .8; }
.login-main { display: grid; place-items: center; padding: 48px 32px; background: var(--bg); }
.login-form { display: grid; gap: 18px; width: min(400px, 100%); padding: 32px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.login-form h2 { font-family: var(--serif); font-size: 26px; font-weight: 600; }
.login-form > p { margin-top: -10px; color: var(--muted); }
.form-alert { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger-ink); font-size: 13px; }

/* ---------- Màn hình hẹp ---------- */

@media (max-width: 760px) {
  .wrap { padding-inline: 16px; }
  main.wrap { gap: 16px; padding-top: 20px; padding-bottom: 110px; }
  .brand-sub, .user-menu .u-name, .user-menu summary .icon { display: none; }
  .user-menu summary { justify-content: center; width: 44px; padding: 0; border: 0; }
  h1 { font-size: 26px; }
  .page-head .eyebrow { display: none; }
  .actions .btn-primary { display: none; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat-value { font-size: 22px; }
  .stat-hint { display: none; }
  .toolbar { padding: 12px; }
  .search { flex-basis: 100%; max-width: none; }
  .search kbd { display: none; }
  .filter { flex: 1; }
  .count { width: 100%; margin-left: 0; }
  .table-box { display: none; }
  .m-list { display: block; }
  .fab { position: fixed; right: 16px; bottom: 24px; z-index: 20; display: inline-flex; height: 52px; border-radius: 16px; font-size: 15px; box-shadow: 0 8px 20px rgba(42, 31, 20, .22); }
  .grid-2 { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-aside { display: none; }
}

/* ---------- Ngày sinh / ngày quy y, nút in ---------- */

.footer-left { margin-right: auto; }
.input[type='date'] { min-width: 0; }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.field-head label { font-size: 13px; font-weight: 500; }
.mode-toggle { padding: 0; border: 0; background: none; color: var(--accent); font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.mode-toggle:hover { color: var(--accent-ink); }

/* ---------- Dung lượng lưu trữ ---------- */

.banner { margin-bottom: 16px; padding: 12px 16px; border-radius: var(--radius); font-size: 14px; border: 1px solid var(--line); }
.banner.warn { background: var(--warn-bg); border-color: #E8C98F; color: var(--accent-ink); }
.banner.lock { background: var(--danger-soft); border-color: #E9B5A8; color: var(--danger-ink); }
.meter { height: 10px; margin: 12px 0 6px; overflow: hidden; border-radius: 999px; background: var(--line-soft); }
.meter span { display: block; height: 100%; min-width: 2px; border-radius: 999px; background: var(--success); transition: width .25s; }
.meter span.warn { background: #D19A2A; }
.meter span.lock { background: var(--danger); }
.meter-text { margin-bottom: 16px; font-size: 13px; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
