/* ตัวแปรสี (ธีมสว่าง/มืด), พื้นฐาน, ปุ่ม, ช่องกรอก, card, segmented control */
:root {
  --bg: #eeecf6;
  --light: #ffffff;
  --dark: #cfcae3;
  --text: #3a3355;
  --muted: #8a84a3;
  --faint: #c3bed8;
  --primary: #7c5cff;
  --primary-2: #a78bfa;
  --income: #16a37a;
  --expense: #e5566f;
  --loan: #d97706;
  --grid: rgba(138, 132, 163, .15);
  --toast-bg: #3a3355;
  --toast-fg: #fff;
  --backdrop: rgba(58, 51, 85, .35);
  --dialog-shadow: 12px 12px 30px rgba(80, 60, 160, .25), -12px -12px 30px rgba(255, 255, 255, .6);
  --radius: 20px;
  --out: 8px 8px 16px var(--dark), -8px -8px 16px var(--light);
  --out-sm: 4px 4px 8px var(--dark), -4px -4px 8px var(--light);
  --in: inset 4px 4px 8px var(--dark), inset -4px -4px 8px var(--light);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #272535;
  --light: #332f45;
  --dark: #1b1a25;
  --text: #e8e5f7;
  --muted: #9c96b8;
  --faint: #57526e;
  --primary: #9179ff;
  --primary-2: #b6a1ff;
  --income: #34d399;
  --expense: #fb7185;
  --loan: #fbbf24;
  --grid: rgba(156, 150, 184, .12);
  --toast-bg: #e8e5f7;
  --toast-fg: #272535;
  --backdrop: rgba(0, 0, 0, .55);
  --dialog-shadow: 14px 14px 34px rgba(0, 0, 0, .55), -8px -8px 24px rgba(255, 255, 255, .03);
}
body, .card, .btn, input, .cal, dialog { transition: background-color .25s, color .25s, box-shadow .25s; }
/* animation สลับธีม: ใช้วงกลมแทน transition สีปกติ */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { z-index: 2; }
.theme-switching *, .theme-switching *::before, .theme-switching *::after { transition: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Prompt', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; }

/* ---------- controls ---------- */
.btn { border: 0; background: var(--bg); padding: 10px 18px; border-radius: 14px; cursor: pointer; box-shadow: var(--out-sm); transition: box-shadow .15s, transform .15s; }
.btn:hover { color: var(--primary); }
.btn:active { box-shadow: var(--in); }
.btn-primary { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; font-weight: 600; box-shadow: 6px 6px 14px rgba(124, 92, 255, .35), -6px -6px 14px var(--light); }
.btn-primary:hover { color: #fff; filter: brightness(1.05); }
.btn-primary:active { box-shadow: inset 3px 3px 8px rgba(0, 0, 0, .2); }
.btn-icon { width: 38px; height: 38px; padding: 0; display: inline-grid; place-items: center; border-radius: 12px; }
.btn-flat { box-shadow: none; background: transparent; padding: 6px 8px; color: var(--muted); }
.btn-flat:hover { box-shadow: var(--out-sm); }

input, select, textarea { width: 100%; padding: 12px 16px; border: 0; border-radius: 14px; background: var(--bg); box-shadow: var(--in); outline: none; }
textarea { display: block; resize: none; min-height: 72px; max-height: 200px; line-height: 1.5; field-sizing: content; }
input:focus, select:focus, textarea:focus { box-shadow: var(--in), 0 0 0 2px var(--primary-2); }
input::placeholder, textarea::placeholder { color: var(--muted); }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; }
.field { margin-bottom: 16px; }
.combo + .field-error { margin: -8px 4px 16px; }
.field-error { display: flex; align-items: center; gap: 6px; margin: 8px 4px 0; font-size: 13px; color: var(--expense); animation: field-error-in .2s ease-out; }
.field-error::before { content: '!'; width: 16px; height: 16px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; background: var(--expense); }
@keyframes field-error-in { from { opacity: 0; transform: translateY(-3px); } }
input[aria-invalid="true"], textarea[aria-invalid="true"] { box-shadow: var(--in), 0 0 0 2px var(--expense); }
/* checkbox แบบ neumorphism (ใช้ทั้งเว็บ) */
input[type=checkbox] { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; flex: none; margin: 0; padding: 0; border-radius: 7px; background: var(--bg); box-shadow: var(--in); cursor: pointer; transition: background .15s, box-shadow .15s; }
input[type=checkbox]:checked { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 14px no-repeat, linear-gradient(135deg, var(--primary-2), var(--primary)); box-shadow: 2px 2px 6px rgba(124, 92, 255, .35); }
input[type=checkbox]:focus-visible { outline: 2px solid var(--primary-2); outline-offset: 2px; }
input[type=checkbox]:disabled { opacity: .5; cursor: not-allowed; }
/* ซ่อนปุ่มลูกศรขึ้น-ลงของช่องตัวเลข */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.error { color: var(--expense); font-size: 14px; min-height: 21px; margin: 0 0 8px; }

.card { background: var(--bg); border-radius: var(--radius); padding: 20px; box-shadow: var(--out); }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; }

.seg { display: inline-flex; gap: 4px; padding: 5px; border-radius: 16px; box-shadow: var(--in); }
.seg button { white-space: nowrap; border: 0; background: transparent; padding: 6px 16px; border-radius: 12px; cursor: pointer; color: var(--muted); transition: all .15s; }
.seg button.active { background: var(--bg); color: var(--primary); font-weight: 600; box-shadow: var(--out-sm); }
.seg.sm button { padding: 3px 12px; font-size: 13px; }


/* ---------- utilities ---------- */
.income { color: var(--income); }
.expense { color: var(--expense); }
.purple { color: var(--primary); }
.loan { color: var(--loan); }
.card-head { flex-wrap: wrap; row-gap: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }
