/* My Money Farm — v1.0 styles
   โทนสี: ฟ้าใส-เขียวอ่อน (ดู PRD.md หัวข้อ Design tokens) */

@font-face { font-family: 'Mali'; font-weight: 400; font-display: swap; src: url(fonts/mali-thai-400-normal.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Mali'; font-weight: 400; font-display: swap; src: url(fonts/mali-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD, U+0E3F; }
@font-face { font-family: 'Mali'; font-weight: 600; font-display: swap; src: url(fonts/mali-thai-600-normal.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Mali'; font-weight: 600; font-display: swap; src: url(fonts/mali-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD, U+0E3F; }
@font-face { font-family: 'Mali'; font-weight: 700; font-display: swap; src: url(fonts/mali-thai-700-normal.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Mali'; font-weight: 700; font-display: swap; src: url(fonts/mali-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD, U+0E3F; }

:root {
  --bg: #EAF6F8;
  --card: #FFFFFF;
  --line: #D6EADF;
  --shadow: #C9E2D2;
  --track: #E3F1EA;
  --dash: #A9D3BC;
  --mint: #D9EEDC; --mint-line: #BFE0C6;
  --pink: #FDE1E4; --pink-line: #F7C3CA;
  --lav: #E9DDF7; --lav-line: #D6C4EE;
  --yellow: #FFF1C9; --yellow-line: #F2DC9C;
  --text: #684A3B; --text-strong: #4A3328; --muted: #7E6252;
  --green: #2F6B45; --green-dark: #1F4A2F;
  --red: #B83545;
  --coral: #DE5F6B; --coral-dark: #B8444F;
  --nav-h: 84px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: 'Mali', system-ui, sans-serif; overscroll-behavior: none; }
body { -webkit-font-smoothing: antialiased; -webkit-user-select: none; user-select: none; }
input, textarea, select { -webkit-user-select: text; user-select: text; }
button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
img { -webkit-user-drag: none; }
[v-cloak] { display: none; }

#app { position: fixed; inset: 0; max-width: 520px; margin: 0 auto; overflow: hidden; }

/* ----- screens ----- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; }
.screen.has-nav { padding-bottom: calc(var(--nav-h) + var(--safe-b)); }
.body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 0 16px 12px; display: flex; flex-direction: column; gap: 10px; scrollbar-width: none; }
.body::-webkit-scrollbar { display: none; }
.pad-top { padding-top: calc(var(--safe-t) + 12px); }

.hero { position: relative; flex: 0 0 auto; height: calc(150px + var(--safe-t)); overflow: hidden; }
.hero > img.scene { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 56px; background: linear-gradient(rgba(234,246,248,0), var(--bg)); }
.hero .bar { position: absolute; left: 16px; right: 16px; top: calc(var(--safe-t) + 12px); display: flex; align-items: center; gap: 8px; z-index: 2; }
.hero + .body { margin-top: -48px; position: relative; z-index: 3; }
.title-pill { font-size: 18px; font-weight: 700; background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 2px 14px; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 4px; background: rgba(255,255,255,.92); border: 2px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.pill img { width: 22px; height: 22px; object-fit: contain; margin-left: -6px; }
.brand { position: absolute; left: 18px; top: calc(var(--safe-t) + 54px); z-index: 2; font-size: 28px; font-weight: 700; color: var(--text-strong); text-shadow: 0 2px 0 #fff, 0 -2px 0 #fff, 2px 0 0 #fff, -2px 0 0 #fff; }

.topbar { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(var(--safe-t) + 10px) 16px 8px; }
.topbar h1 { font-size: 18px; font-weight: 700; text-align: center; flex: 1; }
.icon-btn { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 22px; background: #fff; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; padding: 0; color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ----- cards ----- */
.card { background: var(--card); border: 2px solid var(--line); border-radius: 22px; box-shadow: 0 3px 0 var(--shadow); padding: 12px 14px; }
.card.flat { box-shadow: none; }
.card.mint { background: var(--mint); border-color: var(--mint-line); box-shadow: none; }
.card.pink { background: var(--pink); border-color: var(--pink-line); box-shadow: none; }
.card.lav { background: var(--lav); border-color: var(--lav-line); box-shadow: none; }
.card.yellow { background: var(--yellow); border-color: var(--yellow-line); box-shadow: none; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; min-width: 0; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.xs { font-size: 11px; }
.b { font-weight: 700; }
.sb { font-weight: 600; }
.green { color: var(--green); }
.red { color: var(--red); }
.big { display: block; font-size: 38px; font-weight: 700; line-height: 1.1; color: var(--green); }
.h2 { font-size: 15px; font-weight: 700; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ic { object-fit: contain; flex-shrink: 0; }
.dot { width: 10px; height: 10px; border-radius: 5px; flex-shrink: 0; display: inline-block; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px; margin-bottom: -4px; }
.hint { font-size: 12px; font-weight: 600; color: var(--muted); }

/* horizontal scroller */
.hscroll { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; flex-shrink: 0; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { flex-shrink: 0; scroll-snap-align: start; }
.hgrid2 { display: grid; grid-auto-flow: column; grid-template-rows: repeat(2, 64px); grid-auto-columns: 78px; gap: 6px; overflow-x: auto; scroll-snap-type: x proximity; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; flex-shrink: 0; }
.hgrid2::-webkit-scrollbar { display: none; }
.hgrid2 > * { scroll-snap-align: start; }

/* bars */
.ratio { display: flex; height: 20px; border-radius: 12px; overflow: hidden; background: #fff; border: 2px solid #fff; }
.track { height: 9px; border-radius: 6px; background: var(--track); overflow: hidden; }
.track > div { height: 100%; border-radius: 6px; }

/* chips & tiles */
.chip { flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; border: 2px solid var(--line); background: #fff; white-space: nowrap; }
.chip.on { border-color: var(--text); background: var(--yellow); }
.chip.dashed { border-style: dashed; border-color: var(--dash); background: transparent; font-weight: 700; }
.tile { height: 64px; padding: 4px 2px; border-radius: 16px; font-size: 11px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 2px solid var(--line); background: #fff; position: relative; line-height: 1.15; text-align: center; }
.tile img { width: 32px; height: 32px; object-fit: contain; }
.tile.on { border-color: #F29AA6; background: var(--pink); }
.tile.on.inc { border-color: #9ED3AC; background: var(--mint); }
.tile .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 11px; background: var(--coral); color: #fff; border: 2px solid #fff; font-size: 13px; line-height: 16px; padding: 0; }
.tile.add { border-style: dashed; border-color: var(--dash); background: transparent; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--track); border-radius: 16px; padding: 3px; flex-shrink: 0; }
.seg button { height: 38px; border-radius: 13px; font-size: 14px; font-weight: 700; border: 2px solid transparent; background: transparent; display: flex; align-items: center; justify-content: center; gap: 4px; }
.seg button img { width: 22px; height: 22px; object-fit: contain; }
.seg button.on { background: #fff; border-color: var(--mint-line); }
.seg button.on.spend { background: var(--pink); border-color: #F29AA6; }
.seg button.on.income { background: var(--mint); border-color: #9ED3AC; }
.seg button.on.save { background: var(--lav); border-color: #C2A8E6; }

.badge { min-width: 40px; height: 40px; padding: 0 4px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; text-align: center; line-height: 1.1; }
.badge.sm { min-width: 30px; height: 26px; border-radius: 8px; font-size: 10px; }

/* inputs */
.label { font-size: 13px; font-weight: 700; display: flex; flex-direction: column; gap: 4px; }
.input { height: 44px; border: 2px solid var(--line); border-radius: 14px; background: #fff; padding: 0 12px; font-size: 16px; font-weight: 600; width: 100%; outline: none; }
.input:focus { border-color: #9ED3AC; }
select.input { appearance: none; -webkit-appearance: none; }

/* buttons */
.btn { height: 54px; border-radius: 27px; border: none; font-size: 18px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; flex-shrink: 0; text-decoration: none; }
.btn.coral { background: var(--coral); color: #fff; box-shadow: 0 4px 0 var(--coral-dark); }
.btn.green { background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-dark); }
.btn.ghost { background: #fff; border: 2px solid var(--line); color: var(--text); font-size: 15px; }
.btn.sm { height: 44px; font-size: 15px; }
.btn:disabled { opacity: .5; }
.link-btn { border: none; background: #fff; border-radius: 999px; padding: 4px 12px; font-size: 12px; font-weight: 700; }
.mini-btn { height: 38px; padding: 0 12px; border-radius: 19px; border: none; background: var(--green); color: #fff; box-shadow: 0 3px 0 var(--green-dark); font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

/* keypad */
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; flex-shrink: 0; }
.keypad button { height: 46px; border: 2px solid var(--line); border-radius: 16px; background: #fff; box-shadow: 0 3px 0 var(--shadow); font-size: 21px; font-weight: 700; }
.keypad button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }

/* nav */
.nav { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-b)); padding: 8px 4px var(--safe-b); background: #fff; border-top: 2px solid var(--line); border-radius: 26px 26px 0 0; box-shadow: 0 -4px 14px rgba(104,74,59,.08); display: flex; justify-content: space-around; align-items: flex-start; z-index: 20; }
.nav a, .nav button.tab { display: flex; flex-direction: column; align-items: center; min-width: 62px; padding: 4px 2px; border-radius: 16px; border: none; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; text-decoration: none; }
.nav .tab img { width: 30px; height: 30px; object-fit: contain; }
.nav .tab.on { background: var(--mint); color: var(--green); font-weight: 700; }
.nav .plus { width: 62px; height: 62px; margin-top: -30px; border-radius: 31px; background: var(--coral); border: 4px solid #fff; box-shadow: 0 4px 10px rgba(222,95,107,.45); color: #fff; display: flex; align-items: center; justify-content: center; padding: 0; }

/* sheets & dialogs */
.overlay { position: absolute; inset: 0; background: rgba(40,60,50,.35); z-index: 50; display: flex; align-items: flex-end; }
.sheet { width: 100%; max-height: 90%; background: var(--bg); border-radius: 26px 26px 0 0; padding: 10px 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; overflow-y: auto; scrollbar-width: none; }
.sheet::-webkit-scrollbar { display: none; }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--dash); align-self: center; }
.sheet h2 { font-size: 17px; font-weight: 700; }
.icon-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.icon-grid button { aspect-ratio: 1; border-radius: 12px; border: 2px solid var(--line); background: #fff; padding: 4px; }
.icon-grid button img { width: 100%; height: 100%; object-fit: contain; }
.icon-grid button.on { border-color: var(--text); background: var(--yellow); }

.toast { position: absolute; left: 50%; top: calc(var(--safe-t) + 64px); transform: translateX(-50%); background: var(--text-strong); color: #fff; padding: 10px 16px; border-radius: 16px; font-size: 14px; font-weight: 600; z-index: 80; max-width: 90%; text-align: center; box-shadow: 0 6px 18px rgba(0,0,0,.2); }

/* donut */
.donut { position: relative; width: 150px; height: 150px; flex-shrink: 0; }
.donut .ring { width: 150px; height: 150px; border-radius: 75px; }
.donut .center { position: absolute; left: 27px; top: 27px; width: 96px; height: 96px; border-radius: 48px; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 4px; }
.legend button { display: flex; align-items: center; gap: 6px; min-height: 20px; padding: 0 6px; border-radius: 8px; border: none; background: transparent; font-size: 12px; font-weight: 600; width: 100%; }
.legend button.on { background: var(--yellow); }

/* misc */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 8px; }
.empty img { width: 120px; height: 120px; object-fit: contain; }
.tx-card { width: 112px; background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 1px; text-align: center; }
.tx-card img { width: 40px; height: 40px; object-fit: contain; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-top: 2px dashed var(--track); background: none; border-left: none; border-right: none; border-bottom: none; width: 100%; text-align: left; }
.list-row:first-child { border-top: none; }
.progress-dots { display: flex; gap: 6px; justify-content: center; }
.progress-dots span { width: 8px; height: 8px; border-radius: 4px; background: var(--dash); }
.progress-dots span.on { width: 22px; background: var(--green); }
.slip-thumb { width: 120px; flex-shrink: 0; border-radius: 14px; border: 2px solid var(--line); background: #fff; object-fit: cover; max-height: 210px; }
.spinner { width: 46px; height: 46px; border-radius: 23px; border: 5px solid var(--mint); border-top-color: var(--green); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.swatch { width: 34px; height: 34px; border-radius: 17px; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); padding: 0; flex-shrink: 0; }
.swatch.on { border-color: var(--text); box-shadow: none; }

/* ไม่ให้การ์ดถูกบีบ เมื่อจอเตี้ย (เช่น iPhone SE) ให้เลื่อนในหน้าแทน */
.body > *, .sheet > * { flex-shrink: 0; }
.body > [style*="flex: 1"] { flex-shrink: 1; }

@media (max-height: 720px) {
  .keypad button { height: 40px; font-size: 19px; }
  .hgrid2 { grid-template-rows: repeat(2, 58px); }
  .tile { height: 58px; }
  .tile img { width: 28px; height: 28px; }
  .btn { height: 48px; }
  .hero { height: calc(130px + var(--safe-t)); }
  .big { font-size: 32px; }
}
