/* Money Note — mobile-first, dark mặc định giống app iOS; light theo prefers-color-scheme. */

:root {
  color-scheme: dark;
  --bg: #000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-3: #3a3a3c;
  --text: #fff;
  --text-2: #98989f;
  --text-3: #636366;
  --sep: rgba(255, 255, 255, 0.08);
  --accent: #4caf50;
  --accent-text: #5cc463;
  --expense: #e5534b;
  --income: #4a9eda;
  --warn: #f0a33e;
  --chart-grid: rgba(255, 255, 255, 0.14);
  --chart-compare: #8e8e93;
  --scrim: rgba(0, 0, 0, 0.55);
  --glass-bg: rgba(38, 38, 42, 0.42);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-highlight: rgba(255, 255, 255, 0.28);
  --glass-shade: rgba(0, 0, 0, 0.25);
  --glass-active: rgba(255, 255, 255, 0.14);

  --radius: 22px;
  --radius-sm: 12px;
  --gutter: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  /* Vùng iOS 26 làm mờ ở mép trên app cài từ màn hình chính (Liquid Glass edge effect): lan quá
     status bar vài pt. Chỉ để nền đặc ở đó; mọi thứ bám mép trên dùng --top-inset. */
  --edge-blur: 0px;
  --top-inset: calc(var(--safe-top) + var(--edge-blur));
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
  /* Tab bar nằm sát vạch home indicator giống app iOS (máy không có safe area: cách đáy 8px). */
  --tabbar-bottom: max(8px, calc(var(--safe-bottom) - 12px));
  --content-max: 640px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f2f2f7;
    --surface: #fff;
    --surface-2: #f2f2f7;
    --surface-3: #e5e5ea;
    --text: #000;
    --text-2: #6e6e73;
    --text-3: #aeaeb2;
    --sep: rgba(0, 0, 0, 0.08);
    --accent: #34a853;
    --accent-text: #2e9b45;
    --expense: #d93a32;
    --income: #1a7fd1;
    --chart-grid: rgba(0, 0, 0, 0.12);
    --chart-compare: #aeaeb2;
    --scrim: rgba(0, 0, 0, 0.35);
    --glass-bg: rgba(255, 255, 255, 0.5);
    --glass-border: rgba(255, 255, 255, 0.75);
    --glass-highlight: rgba(255, 255, 255, 0.95);
    --glass-shade: rgba(0, 0, 0, 0.06);
    --glass-active: rgba(0, 0, 0, 0.07);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; } /* tắt double-tap zoom */
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
/* iOS tự phóng to khi chạm vào ô nhập có chữ < 16px. */
input, select, textarea { font-size: 16px; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.num { font-variant-numeric: tabular-nums; }
.expense { color: var(--expense); }
.income { color: var(--income); }
.muted { color: var(--text-2); }
.link { color: var(--accent-text); font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; }
.link-center { display: flex; justify-content: center; width: 100%; }

/* ------------------------------------------------------------ khung trang */

#view {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: calc(var(--top-inset) + 4px) 0 calc(var(--tabbar-bottom) + var(--tabbar-h) + 16px);
}
#view.no-tabbar { padding-bottom: calc(var(--safe-bottom) + 12px); }
.screen { padding: 0 var(--gutter); }
.screen.full-bleed { padding-left: 0; padding-right: 0; }

/* Chuyển màn kiểu iOS (hiệu ứng chạy bằng JS trong app.js):
   - frozen: màn cũ ghim tại chỗ đang thấy, để đổi vị trí cuộn trang không làm nó nhảy;
   - slide-over: màn nằm trên (đang trượt vào / trượt ra), nền đặc che màn bên dưới;
   - prebuild: màn phụ đang dựng — ẩn nhưng vẫn có kích thước (biểu đồ đo được). */
.screen.frozen { position: fixed; z-index: 1; margin: 0; pointer-events: none; }
.screen.slide-over {
  position: relative; z-index: 2;
  min-height: 100vh; background: var(--bg);
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.35);
}
.screen.frozen.slide-over { position: fixed; }
.screen.prebuild {
  position: fixed; top: 0; left: 0; right: 0; max-width: var(--content-max); margin: 0 auto;
  visibility: hidden; pointer-events: none;
}
.pad { padding-left: var(--gutter); padding-right: var(--gutter); }

/* Nền đặc phủ status bar + vùng mờ của iOS: nội dung cuộn lên sẽ chui dưới dải này, nên lớp mờ
   chỉ làm nhoè một màu nền đặc (trông như không có). Class ios-standalone gắn trong index.html. */
/* Đo trên iPhone thật (16/10/2026): 0/1/4px còn mờ, 8/16px hết mờ, 44px tụt quá sâu so với
   Dynamic Island → 8px là mức thấp nhất không mờ. */
html.ios-standalone { --edge-blur: 8px; }
#status-bg {
  position: fixed; z-index: 40; top: 0; left: 0; right: 0;
  height: var(--top-inset);
  background: var(--bg);
  pointer-events: none;
}

#offline-banner {
  position: fixed; z-index: 60; left: 0; right: 0; top: 0;
  padding: calc(var(--top-inset) + 6px) 16px 8px;
  background: var(--expense); color: #fff;
  text-align: center; font-weight: 600; font-size: 12px;
}

.icon { width: 22px; height: 22px; flex: none; display: block; }
.icon-sm { width: 17px; height: 17px; }

.circle-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2);
}
.icon-btn {
  min-width: 44px; height: 44px; border-radius: 22px;
  display: inline-flex; align-items: center; justify-content: center;
}
.pill-group {
  display: inline-flex; align-items: center; height: 44px; padding: 0 4px;
  border-radius: 24px; background: var(--surface-2);
}
.pill-group .icon-btn { min-width: 44px; }

/* Thanh trên (tab Tổng quan, Sổ giao dịch; màn Báo cáo, Tìm kiếm) dính dưới status bar khi cuộn; nội dung chui bên dưới.
   4px đệm phía trên (padding-top của #view) chuyển vào thanh để lúc dính không bị nhích. */
.sticky-top {
  position: sticky; z-index: 20; top: var(--top-inset);
  margin-top: -4px; padding-top: 4px;
  background: var(--bg);
}
/* Thanh trên của màn phụ (Báo cáo, Tìm kiếm): nền phủ cả lề hai bên. */
.page-bar { margin-left: calc(-1 * var(--gutter)); margin-right: calc(-1 * var(--gutter)); padding: 4px var(--gutter) 10px; }
.page-bar .page-head:last-child { padding-bottom: 0; }

/* ------------------------------------------------------------ tab bar (liquid glass) */

#tabbar {
  position: fixed; z-index: 30;
  left: 50%; bottom: var(--tabbar-bottom);
  transform: translateX(-50%);
  width: calc(100% - 2 * var(--gutter)); max-width: 360px;
  height: var(--tabbar-h); padding: 5px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  border-radius: 31px;
  background: var(--glass-bg);
  border: 0.5px solid var(--glass-border);
  -webkit-backdrop-filter: blur(16px) saturate(190%) brightness(1.08);
  backdrop-filter: blur(16px) saturate(190%) brightness(1.08);
  box-shadow:
    inset 0 1px 1px var(--glass-highlight),
    inset 0 -1px 2px var(--glass-shade),
    0 10px 30px rgba(0, 0, 0, 0.28),
    0 1px 3px rgba(0, 0, 0, 0.18);
  transition: transform 0.35s cubic-bezier(0.2, 0.85, 0.25, 1), opacity 0.25s;
}
/* Vệt sáng khúc xạ trên mặt kính. */
#tabbar::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background:
    radial-gradient(120% 90% at 20% -20%, rgba(255, 255, 255, 0.22), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.10), transparent 40%, rgba(255, 255, 255, 0.05));
}
body.bar-hidden #tabbar {
  transform: translate(-50%, calc(100% + var(--tabbar-bottom) + 8px));
  opacity: 0;
}
#tabbar a {
  position: relative; height: 100%; border-radius: 26px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10px; font-weight: 600; color: var(--text-2);
  transition: background 0.2s, color 0.2s;
}
#tabbar a.active {
  color: var(--text);
  background: var(--glass-active);
  box-shadow: inset 0 1px 0.5px var(--glass-highlight), inset 0 -0.5px 1px var(--glass-shade);
}
#tabbar a:active { transform: scale(0.96); }
.tab-add {
  position: relative; width: 50px; height: 50px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
  background: var(--accent); /* xanh phẳng, không bóng */
  transition: transform 0.15s;
}
.tab-add .icon { width: 26px; height: 26px; stroke-width: 2.4; }
.tab-add:active { transform: scale(0.92); }

/* ------------------------------------------------------------ khối chung */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.card + .card, .card + .section-head, .section-head { margin-top: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px; min-height: 50px;
  border-bottom: 1px solid var(--sep);
}
.card-title { font-size: 15px; font-weight: 600; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.section-title { font-size: 14px; font-weight: 600; color: var(--text-2); }

.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 54px; padding: 8px 16px;
  width: 100%; text-align: left;
}
.row + .row { border-top: 1px solid var(--sep); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 11px; color: var(--text-2); margin-top: 3px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.row-sub > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-note { font-size: 11px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amount { font-size: 14px; font-weight: 500; white-space: nowrap; align-self: flex-start; padding-top: 2px; }
button.row:active, a.row:active { background: var(--surface-2); }

.bubble {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 19px; line-height: 1;
  background: var(--surface-3);
}
.bubble.lg { width: 40px; height: 40px; font-size: 21px; }
.bubble.sm { width: 28px; height: 28px; font-size: 15px; }
.bubble.xl { width: 64px; height: 64px; font-size: 34px; }
.bubble.empty { background: var(--text-3); opacity: 0.6; }

.avatar {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: #fff;
}
.avatar.lg { width: 28px; height: 28px; font-size: 13px; }

.skeleton {
  border-radius: var(--radius); margin-bottom: 12px;
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-2); }
.loading { padding: 40px 0; display: flex; justify-content: center; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.segmented {
  display: flex; padding: 3px; border-radius: 20px; background: var(--surface-2);
}
.segmented button {
  flex: 1; min-height: 34px; border-radius: 17px;
  font-size: 12px; font-weight: 500; color: var(--text-2);
}
.segmented button.active { background: var(--surface-3); color: var(--text); font-weight: 600; }
.segmented button:disabled { opacity: 0.4; }

/* ------------------------------------------------------------ Tổng quan */

/* padding-top 0 như .tx-top: nút tròn ở góc phải cùng vị trí với thanh trên của Sổ giao dịch. */
.ov-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  /* nền thanh dính phủ cả lề hai bên */
  margin: -4px calc(-1 * var(--gutter)) 6px; padding: 4px var(--gutter) 8px;
}
.ov-header > .circle-btn { flex: none; }
.ov-balance { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ov-balance-value { font-size: clamp(22px, 7vw, 28px); font-weight: 700; letter-spacing: -0.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-balance-label { display: flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 14px; }
.help-dot {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-3); color: var(--text-2); font-size: 10px; font-weight: 700;
  position: relative;
}
.help-dot::after { content: ""; position: absolute; inset: -11px; }

.wallet-amount { font-size: 14px; font-weight: 500; white-space: nowrap; }

.chart-box { position: relative; height: 200px; }

.top-row .bar { height: 5px; border-radius: 3px; background: var(--surface-3); margin-top: 6px; overflow: hidden; }
.top-row .bar i { display: block; height: 100%; border-radius: 3px; background: var(--expense); }
.top-row .pct { font-size: 10px; color: var(--text-2); text-align: right; margin-top: 2px; }
.top-toggle { width: 180px; }
.top-row[aria-expanded="true"] .expander { transform: rotate(180deg); }
.top-child { gap: 10px; padding-right: 46px; } /* số tiền thẳng cột với nhóm cha (chừa chỗ nút mở rộng) */
.top-child-amount { text-align: right; font-size: 13px; }
.top-child-amount .pct { font-size: 10px; color: var(--text-2); margin-top: 1px; }
.loan-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px 16px; }
.loan-stats .muted { font-size: 12px; }

/* Màn Vay nợ (#/loans) */
.loan-item + .loan-item { border-top: 1px solid var(--sep); }
.loan-item { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.loan-item:active:not(:has(.pay-chip:active)) { background: var(--surface-2); }
.loan-item .row { align-items: flex-start; }
.loan-bar { height: 4px; border-radius: 2px; background: var(--surface-3); margin-top: 7px; overflow: hidden; }
.loan-bar i { display: block; height: 100%; border-radius: 2px; }
.loan-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.loan-rem-label { font-size: 11px; }
.loan-rem { font-size: 15px; font-weight: 600; white-space: nowrap; }
.loan-actions { display: flex; justify-content: flex-end; padding: 0 16px 12px; margin-top: -4px; }
.chip.pay-chip { color: var(--accent-text); font-weight: 600; }
.loan-hero { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0 4px; text-align: center; }
.loan-hero-name { font-size: 18px; font-weight: 600; margin-top: 6px; }
.loan-stat { display: block; font-size: 18px; font-weight: 600; margin-top: 2px; }

/* ------------------------------------------------------------ Sổ giao dịch */

.tx-top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 4px var(--gutter) 6px;
}
.wallet-switch {
  height: 44px; padding: 0 12px 0 5px; border-radius: 22px;
  display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: 52vw;
  background: var(--surface-2); font-size: 14px; font-weight: 500;
}
.wallet-switch .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallet-switch .bubble { width: 34px; height: 34px; font-size: 17px; }
.tx-balance { text-align: center; padding: 4px 0 2px; }
.tx-balance .label { color: var(--text-2); font-size: 12px; }
.tx-balance .value { font-size: 18px; font-weight: 700; margin-top: 2px; }

.period-tabs {
  display: flex; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--sep);
  scroll-padding: 0 30%;
}
.period-tabs::-webkit-scrollbar { display: none; }
.period-tabs button {
  flex: none; min-width: 31%; padding: 11px 10px 9px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.3px; color: var(--text-2);
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.period-tabs button.active { color: var(--text); border-bottom-color: var(--text); }

.tx-summary { background: var(--surface); padding: 10px var(--gutter) 8px; }
.tx-summary .line { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; }
.tx-summary .line .muted { font-size: 14px; }
/* Hàng cuối: nút "Báo cáo" bên trái, chênh lệch bên phải. */
.tx-summary .foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.tx-summary .total { margin-left: auto; width: 50%; text-align: right; border-top: 1px solid var(--sep); padding: 8px 0 2px; font-weight: 600; font-size: 14px; }
.report-btn {
  position: relative; flex: none; height: 30px; padding: 0 12px; border-radius: 15px;
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); color: var(--accent-text); font-size: 13px; font-weight: 500;
}
.report-btn::after { content: ""; position: absolute; inset: -7px -4px; } /* vùng chạm 44px */

.tx-groups { padding: 16px var(--gutter) 0; }
/* Nội dung kỳ trượt ngang khi vuốt chuyển kỳ: cắt phần tràn để không sinh cuộn ngang.
   Cao tối thiểu gần hết màn hình: kỳ ít giao dịch thì vuốt vào khoảng trống bên dưới vẫn chuyển kỳ. */
.tx-body { overflow: hidden; min-height: 70vh; }
.group { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.group + .group { margin-top: 12px; }
.group-head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px 8px; border-bottom: 1px solid var(--sep);
}
.group-head .day { font-size: 29px; font-weight: 300; min-width: 38px; line-height: 1; }
.group-head .day-info { flex: 1; min-width: 0; }
.group-head .day-info div:first-child { font-weight: 500; }
.group-head .day-info div:last-child { font-size: 11px; color: var(--text-2); }
.group-head .month-title { flex: 1; font-size: 24px; font-weight: 600; letter-spacing: -0.5px; }
.group-head .net { font-size: 14px; font-weight: 500; white-space: nowrap; }
.group .row { padding-top: 10px; padding-bottom: 10px; }

/* ------------------------------------------------------------ Trang phụ */

.page-head {
  display: flex; align-items: center; gap: 8px;
  padding: 0 0 10px;
}
.page-head h1 { flex: 1; margin: 0; font-size: 16px; font-weight: 600; text-align: center; }
.page-head .spacer { width: 44px; flex: none; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 12px; border-radius: 12px; background: var(--surface-2);
}
.search-box input { flex: 1; border: 0; background: none; outline: none; font-size: 16px; min-width: 0; }

.period-nav { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 12px; }
.period-nav .label { font-size: 14px; font-weight: 600; text-align: center; flex: 1; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 18px;
  background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 500;
}
.chip.active { background: var(--text); color: var(--bg); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.stat { background: var(--surface); border-radius: var(--radius-sm); padding: 14px 16px; }
.stat .label { color: var(--text-2); font-size: 11px; }
.stat .value { font-size: 16px; font-weight: 600; margin-top: 4px; }
.stat.wide { grid-column: 1 / -1; }
.child-row { padding-left: 64px; min-height: 44px; font-size: 12px; }
/* Ô cố định cho nút mở rộng nhóm con: có hay không có nút thì số tiền vẫn thẳng hàng. */
.expander { width: 18px; flex: none; display: inline-flex; justify-content: center; color: var(--text-3); transition: transform 0.2s; }
.row[aria-expanded="true"] .expander { transform: rotate(180deg); }

.member-row { display: flex; gap: 12px; padding: 12px 16px; }
.member-row + .member-row { border-top: 1px solid var(--sep); }
.member-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.member-top .link { min-height: 0; padding: 2px 0 8px 8px; }
.member-count { font-size: 12px; margin-top: 2px; }
.member-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; font-size: 12px; }
.member-stats .num { font-size: 16px; margin-top: 2px; }
.avatar.xl { width: 44px; height: 44px; font-size: 18px; }

.notice-row .row-title { white-space: normal; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 10px; font-weight: 600; background: var(--surface-3); color: var(--text-2); }
.tag.danger { background: rgba(229, 83, 75, 0.18); color: var(--expense); }
.tag.warn { background: rgba(240, 163, 62, 0.18); color: var(--warn); }

/* ------------------------------------------------------------ Đăng nhập */

.login {
  min-height: calc(100vh - var(--top-inset) - 60px);
  display: flex; flex-direction: column; justify-content: center; gap: 14px;
  max-width: 380px; margin: 0 auto;
}
.login h1 { margin: 0 0 4px; font-size: 24px; text-align: center; }
.login .logo { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto; display: block; }
.login p { margin: 0 0 12px; text-align: center; color: var(--text-2); }

.field {
  width: 100%; height: 46px; padding: 0 14px;
  border-radius: 12px; border: 1px solid transparent;
  background: var(--surface-2); font-size: 16px; outline: none;
}
.field:focus { border-color: var(--accent); }
.form-error { color: var(--expense); font-size: 12px; min-height: 20px; text-align: center; }

.btn {
  width: 100%; min-height: 48px; border-radius: 24px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
}
.btn:disabled { background: var(--surface-3); color: var(--text-2); }
.btn.secondary { background: var(--surface-2); color: var(--accent-text); font-weight: 500; }
.btn.danger { background: var(--surface-2); color: var(--expense); }

/* ------------------------------------------------------------ Sheet / modal */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.18s ease-out;
}
.sheet {
  width: 100%; max-width: var(--content-max);
  max-height: calc(100% - var(--top-inset) - 8px);
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  border-radius: 20px 20px 0 0;
  padding-bottom: max(8px, calc(var(--safe-bottom) - 14px));
  animation: slide-up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.full { height: calc(100% - var(--top-inset) - 6px); border-radius: 24px 24px 0 0; background: var(--bg); }
@media (prefers-color-scheme: dark) { .sheet.full { background: #18181a; } }
.sheet-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px 8px; flex: none;
}
.sheet-head h2 { flex: 1; margin: 0; font-size: 15px; font-weight: 600; text-align: center; }
.sheet-head .side { width: 88px; flex: none; display: flex; }
.sheet-head .side.right { justify-content: flex-end; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet-body.pad-b { padding-bottom: 16px; }
.cancel-btn {
  height: 38px; padding: 0 16px; border-radius: 19px;
  background: var(--surface-2); font-size: 14px; font-weight: 500;
}
.sheet .row + .row { border-top: 1px solid var(--sep); }
.sheet .check { color: var(--accent-text); }
.menu-periods { margin: 0 16px 4px; }
.sheet-group-title { padding: 16px 20px 6px; font-size: 10px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.4px; }
.dialog-msg { padding: 8px 24px 20px; text-align: center; color: var(--text-2); font-size: 13px; }
.dialog-actions { display: flex; flex-direction: column; gap: 10px; padding: 0 16px 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

#toasts {
  position: fixed; z-index: 70; left: 0; right: 0;
  top: calc(var(--top-inset) + 6px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px;
  background: var(--surface-3); color: var(--text); font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  animation: fade 0.2s ease-out;
}
.toast.error { background: var(--expense); color: #fff; }
.toast.success { background: var(--accent); color: #fff; }

/* ------------------------------------------------------------ Thêm / cài đặt ví */

.pad-form { padding: 0 var(--gutter) 20px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-2); margin: 16px 4px 6px; }
.choice-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.choice {
  aspect-ratio: 1; border-radius: 12px; font-size: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 2px solid transparent;
}
.choice.active { border-color: var(--text); }
.choice.swatch { border-radius: 50%; }
.choice:disabled { opacity: 0.6; }
.cat-child { padding-left: 40px; min-height: 46px; }
/* Dòng nhóm có nút con mắt (ẩn / hiện) bên trái icon; nhóm đang ẩn thì icon, chữ, mũi tên mờ đi. */
.cat-row { display: flex; align-items: center; }
.cat-row + .cat-row, .cat-row + .row { border-top: 1px solid var(--sep); }
.cat-row > .row { flex: 1; min-width: 0; padding-left: 2px; }
.cat-row.child > .row { padding-left: 34px; min-height: 46px; }
.cat-row.is-hidden > .row > * { opacity: 0.38; }
.eye-btn {
  width: 44px; height: 44px; margin-left: 6px; flex: none; border-radius: 22px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-2);
}
.eye-btn.off { color: var(--text-3); }
.eye-btn:disabled { opacity: 0.4; }
.toggle-hidden { color: var(--text-2); }
.cat-wallet { display: flex; align-items: center; gap: 8px; margin: 0 4px 10px; font-weight: 600; }
.select-field { display: flex; align-items: center; gap: 10px; text-align: left; }
.select-field:disabled { opacity: 0.6; }
.switch-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2);
}
/* Công tắc kiểu iOS */
.switch {
  position: relative; width: 51px; height: 31px; flex: none; border-radius: 16px;
  background: var(--surface-3); transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch:disabled { opacity: 0.5; }
.template-list { display: grid; gap: 8px; }
.template-card {
  text-align: left; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 2px solid transparent;
}
.template-card.active { border-color: var(--accent); }
.template-top { display: flex; justify-content: space-between; align-items: center; }
.template-top .check { color: var(--accent-text); }
.template-desc { font-size: 12px; margin-top: 3px; }
.template-preview { font-size: 18px; margin-top: 6px; letter-spacing: 2px; }
/* Xem trước file import trong form Thêm ví */
.import-line { min-height: 0; padding-top: 10px; padding-bottom: 10px; font-size: 13px; display: block; }
.warn-text { color: var(--warn); }
.wallet-row { display: flex; align-items: center; }
.wallet-row .row { flex: 1; min-width: 0; }
.wallet-row + .wallet-row, .wallet-row + .row { border-top: 1px solid var(--sep); }
.wallet-row .icon-btn { margin-right: 8px; color: var(--text-2); }

/* ------------------------------------------------------------ Form giao dịch */

.txf { padding: 2px var(--gutter) 12px; }
.txf-card { background: var(--surface); border-radius: var(--radius); padding: 10px 0 2px; }
.txf-card .segmented { margin: 0 16px 8px; }
.txf-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 0 16px 0 0; width: 100%; text-align: left;
}
.txf-row .lead { width: 60px; flex: none; display: flex; justify-content: center; }
.txf-row .body {
  flex: 1; min-width: 0; align-self: stretch;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--sep);
}
.txf-row:last-child .body { border-bottom: 0; }
.txf-row .value { flex: 1; min-width: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txf-row .placeholder { color: var(--text-3); }
.txf-row .chev { color: var(--text-3); }
.txf-row input.inline {
  flex: 1; min-width: 0; height: 48px; border: 0; background: none; outline: none; font-size: 16px;
}
.txf-row input.inline::placeholder { color: var(--text-3); }
.txf-amount .body { flex-direction: column; align-items: stretch; justify-content: center; gap: 0; padding: 6px 0; }
.amount-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-2); }
.amount-preview { font-size: 13px; color: var(--text-2); }
.amount-line { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.amount-display {
  flex: 1; min-width: 0; display: flex; align-items: center;
  font-size: 32px; font-weight: 500; white-space: nowrap; overflow: hidden; outline: none; cursor: text;
}
.amount-display .amount-text { overflow: hidden; text-overflow: ellipsis; }
.amount-display.long { font-size: 24px; }
.amount-display.xlong { font-size: 18px; }
.amount-display .placeholder { color: var(--text-3); }
.txf-amount.expense .amount-text:not(.placeholder) { color: var(--expense); }
.txf-amount.income .amount-text:not(.placeholder) { color: var(--income); }
.amount-display .caret {
  width: 2px; height: 34px; margin-left: 2px; flex: none; border-radius: 1px;
  background: var(--income); animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }
.amount-clear {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-3); color: var(--text-2);
}
.amount-clear .icon-sm { width: 14px; height: 14px; }

/* Bàn phím số (giống ref-numkey.png). */
.txf-foot-wrap { flex: none; background: var(--surface); border-radius: 22px 22px 0 0; }
.numpad { padding: 0 8px 4px; }
.numpad-suggest {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 0 0 8px; min-height: 48px;
}
.numpad-suggest::-webkit-scrollbar { display: none; }
.numpad-suggest.empty { visibility: hidden; }
.numpad-chip {
  flex: none; height: 40px; padding: 0 18px; border-radius: 20px;
  background: var(--surface-2); font-size: 16px;
}
.numpad-grid { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 46px; gap: 7px; }
.numpad-key {
  border-radius: 12px; background: var(--surface-2);
  font-size: 22px; font-weight: 400;
  display: inline-flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.numpad-key:active { background: var(--surface-3); }
.numpad-key.op { color: var(--accent-text); }
.numpad-key.done { grid-row: span 2; background: var(--accent); color: #fff; font-size: 16px; font-weight: 700; }
.numpad-key.wide { grid-column: span 2; }
.numpad-chip:active { background: var(--surface-3); }
.cur-badge {
  padding: 6px 8px; border-radius: 8px; border: 1px solid var(--surface-3);
  font-size: 12px; font-weight: 600; color: var(--text-2);
}
.txf-category .value { font-size: 21px; }
.date-ctl { flex: 1; display: flex; align-items: center; gap: 6px; padding: 6px 0; min-width: 0; }
.date-ctl .nav { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.date-pill {
  position: relative; flex: 1; min-width: 0; height: 38px; border-radius: 10px;
  background: var(--surface-2); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px;
}
.date-pill input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; -webkit-appearance: none; appearance: none;
}
.txf-more { margin-top: 16px; }
.txf-foot {
  flex: none; display: flex; gap: 12px; align-items: center;
  padding: 8px var(--gutter) 6px;
}
.txf-foot .btn { flex: 1; }
.pay-btn {
  height: 48px; padding: 0 18px; border-radius: 24px; flex: none;
  background: var(--surface-2); color: var(--accent-text); font-size: 14px; font-weight: 600;
}
.round-btn {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--expense);
}

/* ------------------------------------------------------------ Trang quản trị /admin */

#admin {
  max-width: 760px; margin: 0 auto;
  padding: calc(var(--top-inset) + 12px) var(--gutter) calc(var(--safe-bottom) + 24px);
}
a.btn { display: inline-flex; align-items: center; justify-content: center; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.admin-head h1 { margin: 0 0 2px; font-size: 22px; }
.admin-actions { display: flex; gap: 8px; }
.admin-actions .chip { display: inline-flex; align-items: center; }
.admin-user { display: flex; gap: 12px; padding: 14px 16px; }
.admin-user + .admin-user { border-top: 1px solid var(--sep); }
.admin-user-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.admin-meta { font-size: 12px; margin-top: 4px; }
.admin-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.danger-chip { color: var(--expense); }
.admin-pass { display: flex; gap: 8px; align-items: center; }
.admin-pass .field { flex: 1; font-variant-numeric: tabular-nums; letter-spacing: 0.5px; }
.admin-pass .chip { flex: none; height: 46px; }

/* ------------------------------------------------------------ màn hình lớn */

@media (min-width: 700px) {
  :root { --gutter: 24px; }
  .period-tabs button { min-width: 25%; }
  .screen.full-bleed { padding-left: var(--gutter); padding-right: var(--gutter); }
  .tx-top, .tx-summary, .tx-groups { padding-left: 0; padding-right: 0; }
  .tx-summary { border-radius: var(--radius); padding: 14px 20px 6px; margin-top: 12px; }
  .overlay { align-items: center; }
  .sheet { border-radius: 20px; max-height: 86vh; }
  .sheet.full { height: 86vh; border-radius: 24px; }
}
