:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f7fbff;
  background: #06101a;
  font-synthesis: none;
  --panel: rgba(15, 30, 45, .88);
  --panel-soft: rgba(23, 43, 61, .72);
  --line: rgba(255,255,255,.09);
  --muted: #91a6b8;
  --accent: #62dbc8;
  --accent-2: #f4d38a;
  --danger: #ff9c9c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top right, #173348 0, #06101a 42%, #030910 100%); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { width: min(100%, 520px); min-height: 100vh; margin: 0 auto; padding: calc(18px + env(safe-area-inset-top)) 18px calc(96px + env(safe-area-inset-bottom)); }
.topbar, .section-heading, .dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
h1, h2, p { margin: 0; }
h1 { font-size: 27px; letter-spacing: -.04em; }
h2 { font-size: 18px; }
.eyebrow { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .13em; margin-bottom: 5px; }
.icon-button, .text-button { border: 0; background: transparent; color: inherit; }
.icon-button { width: 42px; height: 42px; border-radius: 14px; background: var(--panel-soft); font-size: 22px; }
.text-button { color: var(--accent); padding: 8px 0; }
.text-button.danger { color: var(--danger); }
main { display: grid; gap: 16px; margin-top: 20px; }
.hero-card, .plan-card, .transactions-card { border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(145deg, rgba(20,47,64,.95), rgba(10,23,35,.95)); box-shadow: 0 18px 50px rgba(0,0,0,.24); }
.hero-card { padding: 24px; overflow: hidden; position: relative; }
.hero-card::after { content:""; position:absolute; width:160px; height:160px; border-radius:50%; right:-55px; top:-65px; background: rgba(98,219,200,.13); filter: blur(2px); }
.hero-card > p { color: #b9c8d4; }
.hero-card > strong { display: block; margin: 8px 0 20px; font-size: 52px; letter-spacing: -.06em; color: var(--accent); }
.hero-meta { display:flex; justify-content:space-between; gap:12px; flex-wrap:wrap; color:var(--muted); font-size:13px; }
.hero-meta b { color: #fff; }
.grid-summary { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.summary-card { min-height: 105px; padding:17px; border-radius:20px; border:1px solid var(--line); background:var(--panel); display:flex; flex-direction:column; justify-content:space-between; }
.summary-card span { color:var(--muted); font-size:12px; }
.summary-card strong { font-size:20px; letter-spacing:-.03em; }
.plan-card, .transactions-card { padding:20px; }
.allocation-list { margin-top:16px; display:grid; gap:13px; }
.allocation-list > div { display:flex; justify-content:space-between; gap:15px; padding-bottom:12px; border-bottom:1px solid var(--line); color:var(--muted); }
.allocation-list b { color:#fff; }
.allocation-list .allocation-free { color:var(--accent); border-bottom:0; font-size:17px; }
.allocation-list .allocation-free b { color:var(--accent); }
.progress-row { margin-top:15px; padding-top:15px; border-top:1px solid var(--line); }
.progress-row > div:first-child { display:flex; justify-content:space-between; color:var(--muted); font-size:13px; }
.progress-track { height:8px; margin-top:12px; background:rgba(255,255,255,.08); border-radius:999px; overflow:hidden; }
.progress-track i { display:block; height:100%; width:0; border-radius:inherit; background:linear-gradient(90deg,var(--accent),var(--accent-2)); }
.actions { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.actions button { min-height:76px; border:1px solid var(--line); border-radius:20px; background:var(--panel-soft); color:#fff; display:flex; align-items:center; justify-content:center; gap:8px; font-weight:700; }
.actions span { color:var(--accent); font-size:20px; }
.transaction-list { display:grid; gap:10px; margin-top:15px; }
.transaction { display:grid; grid-template-columns:44px 1fr auto; align-items:center; gap:12px; padding:12px 0; border-bottom:1px solid var(--line); }
.transaction:last-child { border-bottom:0; }
.transaction-icon { width:42px; height:42px; display:grid; place-items:center; border-radius:14px; background:var(--panel-soft); }
.transaction h3 { margin:0 0 4px; font-size:14px; }
.transaction small { color:var(--muted); }
.transaction strong.income, .transaction strong.payment { color:var(--accent); }
.transaction strong.expense, .transaction strong.debt { color:var(--accent-2); }
.empty-state { text-align:center; color:var(--muted); padding:28px 0 12px; }
dialog { width:min(calc(100% - 24px), 480px); max-height:90vh; border:1px solid var(--line); border-radius:24px; padding:0; color:#fff; background:#0b1723; box-shadow:0 30px 80px rgba(0,0,0,.55); }
dialog::backdrop { background:rgba(0,0,0,.65); backdrop-filter:blur(8px); }
dialog form { padding:20px; display:grid; gap:15px; overflow:auto; max-height:90vh; }
label { display:grid; gap:7px; color:#b8c7d2; font-size:13px; }
input, textarea { width:100%; border:1px solid var(--line); border-radius:14px; background:#101f2d; color:#fff; padding:13px 14px; outline:none; }
input:focus, textarea:focus { border-color:rgba(98,219,200,.55); box-shadow:0 0 0 3px rgba(98,219,200,.1); }
.primary-button, .file-label { min-height:48px; border:0; border-radius:15px; display:grid; place-items:center; background:var(--accent); color:#06201d; font-weight:800; padding:12px; }
.file-label { background:var(--panel-soft); color:#fff; }
.file-label input { display:none; }
@media (max-width: 360px) { .hero-card > strong { font-size:44px; } .grid-summary { grid-template-columns:1fr; } }
.transaction-value { display:flex; align-items:center; justify-content:flex-end; gap:8px; }
.delete-entry { width:28px; height:28px; border:1px solid var(--line); border-radius:9px; background:transparent; color:var(--muted); }
.delete-entry:hover { color:var(--danger); border-color:rgba(255,156,156,.35); }
.app-footer { width:min(100%,520px); margin:-68px auto 0; padding:0 18px calc(24px + env(safe-area-inset-bottom)); text-align:center; color:var(--muted); font-size:11px; }

.transaction-cancelled{opacity:.62}.transaction-cancelled h3,.transaction-cancelled .transaction-value strong{text-decoration:line-through}.transaction-cancelled .transaction-icon{filter:grayscale(1)}


/* Alpha UI patch: identity and month navigation / Nhận diện và điều hướng tháng */
.topbar {
  position: relative;
  padding: 4px 2px 2px;
}
.topbar h1 {
  flex: 1 1 auto;
  min-width: 0;

  display: block;

  font-size: 30px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.045em;

  background: linear-gradient(
    105deg,
    #ffffff 18%,
    var(--accent) 58%,
    var(--accent-2)
  );

  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;

  white-space: nowrap;
  overflow: visible;

  text-shadow: 0 8px 28px rgba(98,219,200,.12);
}
.topbar .eyebrow {
  color: #9bc5d2;
  font-weight: 650;
}
.topbar #backupButton {
  border: 1px solid rgba(98,219,200,.18);
  color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
  flex: 0 0 auto;
}

.month-nav {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(15,30,45,.72);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
}
.month-nav button {
  width: 42px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: rgba(255,255,255,.045);
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.month-nav button:hover {
  background: rgba(98,219,200,.1);
  border-color: rgba(98,219,200,.28);
}
.month-nav button:active { transform: scale(.94); }
#periodLabel {
  min-width: 0;
  text-align: center;
  color: #f7fbff;
  font-size: 15px;
  font-weight: 750;
  text-transform: capitalize;
  letter-spacing: -.01em;
}

/* Dialog close buttons must never submit forms / Nút đóng không bao giờ submit form */
.dialog-close {
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.07);
  color: #dce8ef;
}
.dialog-close:hover {
  color: #fff;
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.14);
}
.dialog-header h2 { line-height: 1.2; }

@media (max-width: 420px) {
  .topbar h1 { font-size: 28px; }
  .month-nav { grid-template-columns: 38px minmax(0,1fr) 38px; gap: 7px; }
  .month-nav button { width: 38px; height: 36px; }
  #periodLabel { font-size: 14px; }
}


/* Structured financial plan / Kế hoạch tài chính có cấu trúc */
.field-help,.dialog-description{color:var(--muted);font-size:12px;line-height:1.5}.readonly-plan-total{display:grid;grid-template-columns:1fr auto;align-items:center;gap:12px;padding:14px;border:1px solid var(--line);border-radius:16px;background:rgba(255,255,255,.025)}.readonly-plan-total>div{display:grid;gap:5px}.readonly-plan-total span{color:var(--muted);font-size:12px}.readonly-plan-total strong{font-size:18px}.secondary-button{min-height:40px;border:1px solid rgba(98,219,200,.25);border-radius:12px;padding:9px 12px;background:rgba(98,219,200,.07);color:var(--accent);font-weight:750}.secondary-button:hover{background:rgba(98,219,200,.13)}.source-rows{display:grid;gap:10px}.source-row{display:grid;grid-template-columns:minmax(0,1fr) 128px 38px;gap:8px;align-items:center}.source-row input{padding:11px 12px}.source-remove{width:38px;height:42px;border:1px solid rgba(255,156,156,.2);border-radius:11px;background:rgba(255,156,156,.06);color:var(--danger);font-size:19px}.source-total{display:flex;justify-content:space-between;gap:12px;padding:14px 0;border-top:1px solid var(--line);color:var(--muted)}.source-total strong{color:var(--accent)}@media(max-width:420px){.readonly-plan-total{grid-template-columns:1fr}.source-row{grid-template-columns:minmax(0,1fr) 105px 36px}.source-row .source-name{grid-column:1/-1}.source-remove{width:36px}}

.readonly-current-balance{background:linear-gradient(135deg,rgba(98,219,200,.08),rgba(255,255,255,.025));}.readonly-current-balance>div{min-width:0}.readonly-current-balance strong{color:var(--accent);font-size:22px}.locked-badge{align-self:center;border:1px solid rgba(98,219,200,.25);border-radius:999px;padding:7px 10px;background:rgba(98,219,200,.08);color:var(--accent);font-size:12px;font-weight:800;white-space:nowrap}

.development-tools{display:grid;gap:14px;margin-top:6px;padding:16px;border:1px solid rgba(255,156,156,.24);border-radius:16px;background:rgba(255,156,156,.055)}.development-tools[hidden]{display:none}.development-tools h3{margin:2px 0 6px}.development-tools p{margin:0;color:var(--muted);font-size:12px;line-height:1.55}.danger-button{min-height:44px;border:1px solid rgba(255,156,156,.38);border-radius:13px;padding:11px 14px;background:rgba(255,156,156,.10);color:var(--danger);font-weight:800}.danger-button:hover{background:rgba(255,156,156,.17)}


/* Attendance module / Bảng chấm công */
.month-close{display:grid;grid-template-columns:1fr 1fr;gap:12px}.attendance-panel{display:grid;gap:16px}.attendance-toolbar{display:grid;grid-template-columns:1fr 1fr;gap:10px}.attendance-summary{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}.attendance-summary>div{padding:12px;border:1px solid var(--line);border-radius:14px;background:rgba(255,255,255,.025);display:grid;gap:6px}.attendance-summary span{color:var(--muted);font-size:11px}.attendance-summary strong{font-size:15px;color:var(--accent)}.attendance-legend{display:flex;gap:7px;flex-wrap:wrap}.attendance-legend span{padding:6px 8px;border-radius:999px;font-size:10px;font-weight:750}.legend-full{background:rgba(98,219,200,.16);color:var(--accent)}.legend-half{background:rgba(244,211,138,.18);color:var(--accent-2)}.legend-absence{background:rgba(145,166,184,.16);color:#c5d0d8}.legend-fixed{background:#010407;color:#d5dde2;border:1px solid rgba(255,255,255,.1)}.calendar-weekdays,.attendance-calendar{display:grid;grid-template-columns:repeat(7,1fr);gap:6px}.calendar-weekdays span{text-align:center;color:var(--muted);font-size:10px;font-weight:750}.attendance-day{min-width:0;aspect-ratio:.82;border:1px solid var(--line);border-radius:12px;padding:7px 3px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;color:#fff}.attendance-day strong{font-size:14px}.attendance-day small{font-size:8px;line-height:1.1}.status-full{background:rgba(98,219,200,.20);border-color:rgba(98,219,200,.35)}.status-half{background:rgba(244,211,138,.22);border-color:rgba(244,211,138,.42);color:#fff4cf}.status-absence{background:rgba(145,166,184,.18);border-color:rgba(145,166,184,.28)}.status-fixed{background:#010407;border-color:rgba(255,255,255,.12);color:#8998a3}.attendance-day:disabled{cursor:not-allowed}.calendar-blank{aspect-ratio:.82}.weekday-options{display:grid;grid-template-columns:1fr 1fr;gap:9px}.weekday-options label{display:flex;align-items:center;gap:8px;padding:11px;border:1px solid var(--line);border-radius:12px;background:rgba(255,255,255,.025)}.source-row-auto{grid-template-columns:minmax(0,1fr) auto;padding:12px;border:1px solid rgba(98,219,200,.22);border-radius:14px;background:rgba(98,219,200,.055)}.source-auto-main{display:grid;gap:3px}.source-auto-main span{color:var(--muted);font-size:11px}.attendance-link{width:max-content;border:0;padding:3px 0;background:transparent;color:var(--accent);font-size:11px;font-weight:750}.source-amount-auto{color:var(--accent);font-weight:800;align-self:center}.readonly-current-balance{grid-template-columns:1fr}.locked-badge{display:none}
@media(max-width:420px){.month-close{grid-template-columns:1fr 1fr}.attendance-summary{grid-template-columns:1fr}.attendance-day{border-radius:9px;padding:5px 2px}.attendance-day small{font-size:7px}.source-row-auto{grid-template-columns:1fr}.source-amount-auto{justify-self:start}.weekday-options{grid-template-columns:1fr}}

/* Attendance dialog final beta polish / Hoàn thiện hộp chấm công trước Beta */
#attendanceDialog {
  width: min(calc(100% - 24px), 560px);
}

#attendanceDialog .attendance-panel {
  scrollbar-gutter: stable;
}

#attendanceDialog .field-help {
  margin: 2px 0 0;
  padding-bottom: 2px;
}

.status-future {
  background: rgba(255,255,255,.018);
  border-color: rgba(255,255,255,.07);
  color: #657684;
}

.status-future small {
  color: #657684;
}

.attendance-day.is-today {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(98,219,200,.10);
}

.attendance-day.is-today small::after {
  content: " · Hôm nay";
}

/* Beta 1.0.1 mobile overflow fix / Sửa tràn ngang trên Safari iOS */
*,
*::before,
*::after {
  box-sizing: border-box;
}

dialog,
dialog form,
dialog label,
dialog section,
dialog input,
dialog textarea,
dialog select,
dialog button {
  min-width: 0;
  max-width: 100%;
}

#planDialog {
  width: min(calc(100% - 20px), 480px);
  max-width: calc(100vw - 20px);
}

#planDialog form {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

#planDialog label,
#planDialog input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

#planDialog input {
  display: block;
}

#plan-startMonth {
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
  appearance: none;
  -webkit-appearance: none;
}

/*
 * Dialog layout for iPhone / Bố cục dialog trên iPhone
 *
 * Chỉ trừ safe-area trong chiều cao khả dụng; không cộng safe-area
 * lần nữa vào margin hoặc padding để tránh đẩy nội dung xuống quá sâu.
 */
dialog {
  width: min(calc(100% - 24px), 480px);
  max-height: calc(
    100dvh
    - env(safe-area-inset-top, 0px)
    - env(safe-area-inset-bottom, 0px)
    - 16px
  );
  margin: auto;
  overflow: hidden;
}

dialog form,
#attendanceDialog .attendance-panel {
  box-sizing: border-box;
  max-height: calc(
    100dvh
    - env(safe-area-inset-top, 0px)
    - env(safe-area-inset-bottom, 0px)
    - 18px
  );
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

dialog .dialog-header,
#attendanceDialog .dialog-header {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: -20px -20px 0;
  padding: 20px 20px 12px;
  background: linear-gradient(
    180deg,
    #0b1723 82%,
    rgba(11, 23, 35, 0)
  );
}

dialog .dialog-close {
  position: relative;
  z-index: 11;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}

@media (max-height: 760px) {
  dialog form,
  #attendanceDialog .attendance-panel {
    padding: 16px;
    gap: 12px;
  }

  dialog .dialog-header,
  #attendanceDialog .dialog-header {
    margin: -16px -16px 0;
    padding: 16px 16px 10px;
  }

  .attendance-summary > div {
    padding: 10px;
  }

  .attendance-day {
    aspect-ratio: .88;
  }
}

@media (max-width: 420px) {
  #planDialog,
  #attendanceDialog {
    width: calc(100% - 12px);
    max-width: calc(100vw - 12px);
  }

  #planDialog form,
  #attendanceDialog .attendance-panel {
    padding: 14px;
  }

  dialog .dialog-header,
  #attendanceDialog .dialog-header {
    margin: -14px -14px 0;
    padding: 14px 14px 10px;
  }

  .attendance-day.is-today small::after {
    content: "";
  }
}

/* Prevent accidental double-tap zoom / Ngăn zoom khi chạm nhanh hai lần */
html {
  touch-action: manipulation;
}

body,
button,
a,
input,
textarea,
select,
label,
.icon-button,
.text-button,
.primary-button,
.secondary-button,
.danger-button,
.attendance-day {
  touch-action: manipulation;
}

button,
a,
.icon-button,
.text-button,
.primary-button,
.secondary-button,
.danger-button,
.attendance-day {
  -webkit-tap-highlight-color: transparent;
}

.salary-mode-options{border:1px solid var(--line);border-radius:14px;padding:12px;display:grid;grid-template-columns:1fr 1fr;gap:9px;background:rgba(255,255,255,.025)}
.salary-mode-options legend{padding:0 6px;color:var(--muted);font-size:12px}
.salary-mode-options label{display:flex;align-items:center;gap:8px;padding:10px;border:1px solid var(--line);border-radius:11px;background:rgba(255,255,255,.02)}
#attendanceHoursDate{margin:4px 0 0}
@media(max-width:420px){.salary-mode-options{grid-template-columns:1fr}}
.plan-goal-section{display:grid;gap:12px;padding:14px;border:1px solid var(--line);border-radius:16px;background:rgba(255,255,255,.025)}
.plan-goal-heading{display:flex;justify-content:space-between;gap:12px}.plan-goal-heading span{font-weight:800}.priority-options[hidden]{display:none!important}.priority-options{display:grid;gap:10px;padding:14px;border:1px solid var(--line);border-radius:16px}.priority-options label{display:flex!important;align-items:center;gap:9px}.priority-options input{width:auto!important}.plan-input-locked{opacity:.68}.plan-input-locked input{cursor:not-allowed}

/* Beta 1.0.9 recurring source visibility / Hiển thị trạng thái lịch nguồn thu chi */
.source-display-row{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:12px;align-items:center;padding:12px;border:1px solid var(--line);border-radius:14px;background:rgba(255,255,255,.025)}
.source-row-muted{opacity:.46;filter:grayscale(.45);background:rgba(255,255,255,.015);border-color:rgba(255,255,255,.07)}.source-row-muted>output{color:var(--muted)}.source-row-muted .source-schedule{color:var(--muted)}.source-row-muted .source-delete{opacity:.82}
.source-display-main{display:grid;gap:4px;min-width:0}.source-display-main>strong{overflow-wrap:anywhere}.source-display-main>span{color:var(--muted);font-size:11px}.source-display-row>output{font-weight:800;color:var(--accent);white-space:nowrap}.source-row-actions{display:flex;gap:12px;align-items:center;flex-wrap:wrap}.source-schedule,.source-period-edit,.source-delete{border:0;background:transparent;padding:2px 0;font-size:11px;font-weight:750}.source-schedule,.source-period-edit{color:var(--accent)}.source-delete{color:var(--danger)}.source-create{display:grid;grid-template-columns:minmax(0,1fr) 136px;gap:8px;align-items:end;padding-top:12px;border-top:1px solid var(--line)}.source-create label{gap:5px;min-width:0}.source-create input{width:100%}.source-create .primary-button{width:100%;min-height:42px;padding-inline:10px}.source-row-auto{grid-template-columns:minmax(0,1fr) auto}
.source-create .source-start-date{grid-column:1}.source-create .source-start-date input{width:100%}
@media(max-width:520px){.source-create{grid-template-columns:minmax(0,1fr) 136px}.source-display-row{grid-template-columns:1fr}.source-display-row>output{justify-self:start}}
@media(max-width:360px){.source-create{grid-template-columns:1fr}.source-create .source-start-date,.source-create .primary-button{grid-column:1}}

/* Beta 2.0 form balance / Cân đối chiều rộng biểu mẫu nguồn thu chi */

/* Beta 2.0 mobile source form hotfix / Sửa tràn ô ngày trên điện thoại */
.source-create {
  grid-template-columns: minmax(0, 1.35fr) minmax(112px, .95fr);
}

.source-create > *,
.source-create label,
.source-create input,
.source-create button {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.source-create input[type="date"] {
  display: block;
  width: 100%;
  min-inline-size: 0;
  overflow: hidden;
}

@media (max-width: 520px) {
  .source-create {
    grid-template-columns: minmax(0, 1.35fr) minmax(108px, .95fr);
    column-gap: 8px;
    row-gap: 10px;
  }

  .source-create .source-start-date {
    grid-column: 1;
  }

  .source-create .primary-button {
    grid-column: 2;
    align-self: end;
    white-space: normal;
    line-height: 1.15;
    overflow-wrap: anywhere;
  }

  .source-create input[type="date"] {
    font-size: 16px;
    padding-inline: 10px;
  }
}

@media (max-width: 340px) {
  .source-create {
    grid-template-columns: 1fr;
  }

  .source-create .source-start-date,
  .source-create .primary-button {
    grid-column: 1;
  }
}

/* Beta 2.0 definitive iPhone date layout fix / Sửa dứt điểm bố cục ngày trên iPhone */
@media (max-width: 520px) {
  /* Keep the first row balanced, but place the native iOS date control and
     save button on separate full-width rows to avoid Safari intrinsic-width overlap. */
  .source-create {
    grid-template-columns: minmax(0, 1.35fr) minmax(108px, .95fr);
  }

  .source-create .source-start-date {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    overflow: hidden;
  }

  .source-create .source-start-date input[type="date"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-inline-size: 0;
    inline-size: 100%;
    display: block;
  }

  .source-create .primary-button {
    grid-column: 1 / -1;
    width: 100%;
    max-width: 100%;
    justify-self: stretch;
  }
}


/* Beta 2.0 iOS date containment fix / Khóa ô ngày trong khung trên Safari iPhone */
@media (max-width: 520px) {
  .source-create .source-start-date {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
  }

  .source-create .source-date-control {
    display: block;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #101f2d;
  }

  .source-create .source-date-control input[type="date"] {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    inline-size: 100% !important;
    min-inline-size: 0 !important;
    box-sizing: border-box;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 13px 14px;
    font-size: 16px;
    text-align: center;
    -webkit-appearance: none;
    appearance: none;
  }

  .source-create .source-date-control:focus-within {
    border-color: rgba(98,219,200,.55);
    box-shadow: 0 0 0 3px rgba(98,219,200,.1);
  }

  .source-create .source-date-control input[type="date"]:focus {
    box-shadow: none;
  }
}

/* Beta 2.0 cross-device compatibility hardening
   VI: Chuẩn hóa dialog, biểu mẫu và bộ chọn ngày trên iOS, Android,
       trình duyệt Chromium/Firefox/Safari và màn hình ngang thấp.
   EN: Normalize dialogs, forms, and date controls across mobile/desktop engines. */

/* Viewport fallback for browsers without dynamic viewport units. */
dialog {
  max-height: calc(100vh - 16px);
  max-width: calc(100vw - 24px);
}

dialog form,
#attendanceDialog .attendance-panel {
  max-height: calc(100vh - 18px);
  scrollbar-width: thin;
}

@supports (height: 100dvh) {
  dialog {
    max-height: calc(
      100dvh
      - env(safe-area-inset-top, 0px)
      - env(safe-area-inset-bottom, 0px)
      - 16px
    );
  }

  dialog form,
  #attendanceDialog .attendance-panel {
    max-height: calc(
      100dvh
      - env(safe-area-inset-top, 0px)
      - env(safe-area-inset-bottom, 0px)
      - 18px
    );
  }
}

/* Every dialog follows the same phone width rule, not only plan/attendance. */
@media (max-width: 520px) {
  dialog {
    width: calc(100% - 12px);
    max-width: calc(100vw - 12px);
    border-radius: 20px;
  }

  dialog form,
  #attendanceDialog .attendance-panel {
    width: 100%;
    padding: 14px;
  }

  dialog .dialog-header,
  #attendanceDialog .dialog-header {
    margin-inline: -14px;
    padding-inline: 14px;
  }

  /* Avoid automatic page zoom on focus in Safari iOS. */
  dialog input,
  dialog textarea,
  dialog select {
    font-size: 16px;
  }
}

/* Shared native date/month containment for all supported engines. */
input[type="date"],
input[type="month"] {
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
}

.source-create .source-date-control {
  display: block;
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow: clip;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #101f2d;
}

@supports not (overflow: clip) {
  .source-create .source-date-control {
    overflow: hidden;
  }
}

.source-create .source-date-control input[type="date"] {
  display: block;
  inline-size: 100% !important;
  width: 100% !important;
  min-inline-size: 0 !important;
  min-width: 0 !important;
  max-inline-size: 100% !important;
  max-width: 100% !important;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 13px 14px;
  color: inherit;
  font: inherit;
  font-size: 16px;
  text-align: center;
  box-shadow: none;
}

.source-create .source-date-control input[type="date"]::-webkit-date-and-time-value {
  min-width: 0;
  text-align: center;
}

.source-create .source-date-control input[type="date"]::-webkit-calendar-picker-indicator {
  margin: 0;
  padding: 4px;
}

.source-create .source-date-control:focus-within {
  border-color: rgba(98,219,200,.55);
  box-shadow: 0 0 0 3px rgba(98,219,200,.1);
}

/* Preserve the approved mobile layout: two balanced fields, then date and save rows. */
@media (max-width: 520px) {
  .source-create {
    grid-template-columns: minmax(0, 1.35fr) minmax(108px, .95fr);
    column-gap: 8px;
    row-gap: 10px;
  }

  .source-create .source-start-date,
  .source-create .primary-button {
    grid-column: 1 / -1;
    width: 100%;
    max-width: 100%;
  }
}

/* Very narrow screens use one column without changing normal phone layout. */
@media (max-width: 320px) {
  .source-create {
    grid-template-columns: 1fr;
  }

  .source-create > label,
  .source-create .source-start-date,
  .source-create .primary-button {
    grid-column: 1;
  }
}

/* Landscape phones and devices with a short usable viewport. */
@media (orientation: landscape) and (max-height: 520px) {
  dialog {
    width: min(calc(100% - 16px), 720px);
    max-width: calc(100vw - 16px);
    border-radius: 18px;
  }

  dialog form,
  #attendanceDialog .attendance-panel {
    padding: 12px 16px;
    gap: 10px;
  }

  dialog .dialog-header,
  #attendanceDialog .dialog-header {
    margin: -12px -16px 0;
    padding: 12px 16px 8px;
  }
}

/* Keyboard/high-contrast accessibility and motion compatibility. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

.heading-actions{display:flex;gap:.5rem;align-items:center}select{width:100%;min-height:44px;border:1px solid var(--border);border-radius:12px;background:var(--surface);color:inherit;padding:.7rem}


/* Funds placement and dynamic dashboard cards / Vị trí quỹ và thẻ quỹ động */
.summary-card small{color:var(--muted);font-size:10px;line-height:1.35}.fund-summary-card strong{color:var(--accent)}
.plan-goal-heading{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}.compact-button{min-height:36px;padding:7px 11px;white-space:nowrap}.fund-list-section{display:grid;gap:13px}.fund-plan-list{display:grid;gap:10px}.fund-plan-item{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px 14px;align-items:center;padding:13px;border:1px solid var(--line);border-radius:15px;background:rgba(255,255,255,.025)}.fund-plan-main{display:grid;gap:4px;min-width:0}.fund-plan-main strong{overflow-wrap:anywhere}.fund-plan-main small{color:var(--muted);font-size:11px;line-height:1.45}.fund-plan-balance{display:grid;gap:3px;text-align:right}.fund-plan-balance span{color:var(--muted);font-size:10px}.fund-plan-balance b{color:var(--accent)}.fund-edit-button,.fund-locked-label{grid-column:1/-1;justify-self:end;font-size:11px}.fund-locked-label{color:var(--muted);padding:5px 0}.legacy-reserve-fields{display:none}
@media(max-width:390px){.plan-goal-heading{align-items:stretch;flex-direction:column}.compact-button{width:100%}.fund-plan-item{grid-template-columns:1fr}.fund-plan-balance{text-align:left}.fund-edit-button,.fund-locked-label{justify-self:start}}

.fund-add-link{padding:0;min-height:auto}.fund-cancel-button{justify-self:start;color:var(--danger,#d96b6b)}.fund-plan-item{grid-template-areas:'main balance' 'cancel action'}.fund-plan-main{grid-area:main}.fund-plan-balance{grid-area:balance}.fund-cancel-button{grid-area:cancel}.fund-edit-button,.fund-locked-label{grid-area:action;justify-self:end}@media(max-width:640px){.fund-plan-item{grid-template-areas:'main' 'balance' 'cancel' 'action'}.fund-edit-button,.fund-locked-label{justify-self:start}}

.fund-reserve-lock-note{display:block;margin-top:6px;color:var(--muted);font-size:11px}.fund-plan-actions{grid-area:cancel;display:flex;align-items:center;gap:14px;justify-self:start}.fund-detail-button{color:var(--accent)}.fund-detail-dialog{box-sizing:border-box;width:100%;min-width:0;padding:20px;display:grid;gap:15px;max-height:inherit;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}.fund-detail-list{display:grid;gap:12px;margin:18px 0 8px}.fund-detail-list>div{display:flex;justify-content:space-between;gap:20px;padding:12px 0;border-bottom:1px solid var(--border)}.fund-detail-list dt{color:var(--muted)}.fund-detail-list dd{margin:0;font-weight:700}.fund-detail-lock-note{margin-top:16px}


/* Beta 2.0.27 fund dialog containment / Sửa hộp chi tiết quỹ bị cắt góc */
@media (max-width:520px){.fund-detail-dialog{padding:14px}.fund-detail-dialog .dialog-header{margin:-14px -14px 0;padding:14px 14px 10px}}


/* Beta 2.0.33 planned-fund priority queue / Hàng đợi ưu tiên Quỹ kế hoạch */
.fund-sublist{display:grid;gap:10px}.fund-sublist+.fund-sublist{margin-top:10px;padding-top:14px;border-top:1px solid var(--border)}.fund-sublist>h3{margin:0;color:var(--muted);font-size:12px;letter-spacing:.06em;text-transform:uppercase}.fund-priority-order{display:flex!important;align-items:center;gap:8px;color:var(--muted);font-size:11px}.fund-priority-order input{width:68px;min-height:34px;padding:5px 8px}.priority-options{margin:0}.month-close{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}@media(max-width:420px){.month-close{grid-template-columns:1fr}.fund-priority-order{justify-content:flex-start}}

/* Beta 3.1 debt list and independent absolute priorities */
.priority-options input[type="checkbox"]{accent-color:var(--accent)}
#planDebtList .fund-plan-item{border-color:rgba(244,211,138,.18)}

/* Beta 3.3 — Dashboard Control Center */
.dashboard-overview{display:grid;gap:18px;padding:22px;border:1px solid var(--line);border-radius:26px;background:linear-gradient(145deg,rgba(20,47,64,.98),rgba(8,19,30,.98));box-shadow:0 18px 50px rgba(0,0,0,.26);position:relative;overflow:hidden}
.dashboard-overview::after{content:"";position:absolute;width:190px;height:190px;border-radius:50%;right:-80px;top:-90px;background:rgba(98,219,200,.1);pointer-events:none}
.dashboard-overview[data-state="attention"]{border-color:rgba(255,184,107,.5)}
.dashboard-overview[data-state="danger"]{border-color:rgba(255,111,125,.58)}
.dashboard-status-row{display:flex;justify-content:space-between;align-items:center;gap:12px;position:relative;z-index:1}
.dashboard-state,.dashboard-period-type{display:inline-flex;align-items:center;min-height:28px;padding:5px 10px;border-radius:999px;font-size:11px;font-weight:800;letter-spacing:.02em}
.dashboard-state{background:rgba(98,219,200,.12);color:var(--accent)}
.dashboard-overview[data-state="attention"] .dashboard-state{background:rgba(255,184,107,.14);color:#ffc47c}
.dashboard-overview[data-state="danger"] .dashboard-state{background:rgba(255,111,125,.14);color:#ff8d99}
.dashboard-period-type{background:rgba(255,255,255,.06);color:var(--muted)}
.dashboard-balance{position:relative;z-index:1}
.dashboard-balance>span{display:block;color:#b9c8d4;font-size:13px}
.dashboard-balance>strong{display:block;margin:7px 0 8px;font-size:48px;line-height:1;letter-spacing:-.055em;color:#fff;overflow-wrap:anywhere}
.dashboard-balance>p{margin:0;color:var(--muted);font-size:12px;line-height:1.55}
.dashboard-spendable{display:grid;grid-template-columns:1fr 1fr;gap:10px;position:relative;z-index:1}
.dashboard-spendable>div{padding:13px;border:1px solid rgba(255,255,255,.07);border-radius:16px;background:rgba(255,255,255,.035)}
.dashboard-spendable span{display:block;color:var(--muted);font-size:10px;line-height:1.35}
.dashboard-spendable strong{display:block;margin-top:5px;color:var(--accent);font-size:18px}
.dashboard-plan-status{position:relative;z-index:1;padding-top:14px;border-top:1px solid rgba(255,255,255,.08);font-size:12px;font-weight:700;line-height:1.5}
.dashboard-control-strip{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
.dashboard-control-strip article{min-width:0;padding:15px;border:1px solid var(--line);border-radius:19px;background:var(--panel)}
.dashboard-control-strip span,.dashboard-control-strip small{display:block;color:var(--muted);font-size:10px;line-height:1.35}
.dashboard-control-strip strong{display:block;margin:7px 0 5px;font-size:17px;letter-spacing:-.03em;overflow-wrap:anywhere}
.dashboard-summary .summary-card{min-height:118px}
.dashboard-summary .summary-card strong{font-size:19px}
.dashboard-plan-card .allocation-list>div{padding-block:13px}
.projection-hint{margin:14px 0 0;padding:12px 13px;border-radius:14px;background:rgba(98,219,200,.07);color:var(--muted);font-size:11px;line-height:1.5}
@media(max-width:430px){.dashboard-control-strip{grid-template-columns:1fr 1fr}.dashboard-control-strip article:first-child{grid-column:1/-1}.dashboard-balance>strong{font-size:43px}}
@media(max-width:360px){.dashboard-spendable{grid-template-columns:1fr}.dashboard-balance>strong{font-size:39px}.dashboard-control-strip{grid-template-columns:1fr}.dashboard-control-strip article:first-child{grid-column:auto}}

.source-priority-toggle,.source-create-priority{display:flex;align-items:center;gap:.5rem;font-size:.88rem;font-weight:600}.source-priority-toggle{margin-top:.45rem}.source-priority-toggle input,.source-create-priority input{width:1.1rem;height:1.1rem;accent-color:currentColor}
