/* =====================================================================
   BAY2FIN · ธีม v2 "Friendly Pastel"
   โหลดต่อจาก style.css (ทับค่าเดิม) — ใช้ใน index.html
   ที่มา: Design canvas BAY2FIN (Desktop — ภาพรวม)
   ===================================================================== */

:root {
  --bg: #EAF3F6;          /* พื้นฟ้าอ่อน */
  --surface: #FFFFFF;
  --surface-2: #F5F9FB;   /* ช่องกรอก / พื้นรอง */
  --track: #F1F5F7;       /* ราง progress bar */
  --text: #14212B;
  --ink: #14212B;
  --muted: #5B6B75;
  --border: #E3EBEF;

  --brand: #D4EC7E;       /* lime — highlight, ปุ่มรอง, pill */
  --brand-deep: #B4D63F;  /* lime เข้ม — แท่งกราฟ */
  --brand-ink: #14212B;
  --brand-soft: #EEF6D2;
  --sky: #BFE1F0;         /* การ์ด hero */
  --sky-deep: #7FC0DC;
  --lilac: #CFC6F2;
  --lilac-soft: #ECE8FB;
  --peach: #F2A48A;
  --peach-soft: #FCE6DC;

  --accent: #14212B;      /* ปุ่มหลัก = ดำแคปซูล */
  --income: #2F7A4B;
  --expense: #B4461F;
  --danger: #B42318;
  --ok-soft: #EEF6D2;
  --warn-soft: #FFF1CC;
  --bad-soft: #FCE6DC;

  --radius: 24px;
  --line: 0 solid transparent;
  --shadow: 0 2px 12px rgb(20 33 43 / 0.04);
}

body { font-family: 'Outfit', 'Anuphan', system-ui, sans-serif; background: var(--bg); }
h2 { color: var(--text); font-weight: 500; font-size: 1.1rem; }
.card .value, .bd-amt, .tx-amt, .env-side b, .budget-total b, .ytable, .mbar small { font-variant-numeric: tabular-nums; }

/* ---------- แถบบน ---------- */
.topbar { background: var(--bg); border-bottom: none; padding: 16px 16px 8px; }
.brand { font-weight: 600; font-size: 1.35rem; }
.brand span { color: var(--ink); background: var(--brand); padding: 0 10px; border-radius: 999px; margin-left: 2px; }
.banner { background: var(--brand-soft); border: none; border-radius: 16px; }

/* ---------- ปุ่มสลับ ---------- */
.segmented { background: var(--surface); border: none; padding: 4px; box-shadow: var(--shadow); }
.segmented button { color: var(--muted); padding: 8px 16px; }
.segmented button.active { background: var(--ink); color: #fff; font-weight: 500; }
.period-tabs { border-radius: 999px; }
.period-tabs button { border-radius: 999px; }
.period-tabs button.active { background: var(--ink); color: #fff; }
.hello { margin: 0; font-size: 1.25rem; font-weight: 400; color: var(--ink); line-height: 1.3; }
.hello b { font-weight: 600; }
.scope-bar .segmented[hidden] { display: none; }
.tabbar .side-brand { display: none; }

.period-nav { background: var(--surface); border: none; box-shadow: var(--shadow); border-radius: 999px; padding: 6px; }
.period-nav #monthLabel { font-weight: 500; }
.nav-btn { width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--bg); color: var(--ink); font-size: 1.4rem; }
.nav-btn:hover { background: var(--brand); filter: none; }

/* ---------- การ์ดสรุป ---------- */
.card, .breakdown, .mchart, .table-wrap, .person-card, .account-card, .login-card {
  border: none; box-shadow: var(--shadow); border-radius: var(--radius); background: var(--surface);
}
.summary { gap: 14px; }
.card { padding: 18px 20px; }
.card .label { font-size: 0.85rem; opacity: 1; color: var(--muted); }
.card .value { font-weight: 400; font-size: 1.6rem; }
.card.balance { background: var(--sky); color: var(--ink); border: none; padding: 24px; }
.card.balance .label { color: #2E4552; font-weight: 500; }
.card.balance .value { font-size: 3rem; font-weight: 300; letter-spacing: -0.02em; line-height: 1.1; }
.card.income { background: var(--brand-soft); }
.card.expense { background: var(--peach-soft); }
.card.income .label, .card.expense .label { color: #2E4552; }
/* จอแคบ: ไม่ให้ตัวเลขยาวดัน grid จนล้นจอ */
.summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.summary > .card { min-width: 0; }
.card.income .value, .card.expense .value { font-size: clamp(1.15rem, 5.2vw, 1.6rem); overflow-wrap: anywhere; }

/* ---------- รายจ่ายตามหมวด ---------- */
.breakdown { padding: 8px 20px; }
.bd-group + .bd-group { border-top: 1px solid var(--track); }
.bd-bar { height: 10px; border: none; border-radius: 999px; background: var(--track); }
.bd-bar div { border-radius: 999px; background: var(--fill, var(--brand-deep)); }
.grp-emo, .env-emo { border: none; border-radius: 50%; background: var(--tile, var(--brand-soft)); }

/* ---------- เป้ารายจ่าย ---------- */
.env { border: none; box-shadow: var(--shadow); border-radius: var(--radius); padding: 18px; }
.env.bg-total { background: var(--brand); }
.tag { border: none; padding: 3px 10px; }
.bg-bar { border: none; border-radius: 999px; background: var(--track); }
.env.bg-total .bg-bar { background: rgb(255 255 255 / 0.6); }
.bg-bar > div:first-child { border-radius: 999px 0 0 999px; }
.bg-bar.ahead .bg-used, .bg-bar.ahead .bg-later { background: #F2C66D; }
.bg-bar.over .bg-used, .bg-bar.over .bg-later { background: var(--peach); }
.bg-total .bg-used { background: var(--ink); }
.bg-pace { width: 3px; border-radius: 2px; }

/* ---------- กราฟรายเดือน / ตาราง ---------- */
.mchart { padding: 16px 12px 10px; }
.mbar-track div { background: var(--brand-deep); border: none; border-radius: 6px 6px 3px 3px; }
.mbar:hover .mbar-track div { background: var(--ink); }
.ytable th, .ytable td { border-bottom: 1px solid var(--track); }
.yc-tag { border: none; background: var(--track); color: var(--text); }

/* ---------- รายการ ---------- */
.tx-item { border: none; border-radius: 20px; box-shadow: var(--shadow); margin-bottom: 8px; padding: 12px 16px; }
.tx-item:hover { transform: none; box-shadow: 0 4px 16px rgb(20 33 43 / 0.08); border: none; }
.tx-icon { border: none; border-radius: 50%; width: 44px; height: 44px; background: var(--bg); }
.tx-date { color: var(--muted); font-weight: 500; }
.tx-amt { font-weight: 500; }
.chip { border: none; background: var(--surface); box-shadow: var(--shadow); padding: 8px 18px; }
.chip.active { background: var(--ink); color: #fff; }
.owner-tag { background: var(--lilac-soft); color: var(--text); border: none; border-radius: 999px; padding: 0 8px; }

/* ---------- ปุ่ม ---------- */
.btn { border: 1px solid transparent; border-radius: 999px; font-weight: 500; padding: 10px 20px; }
.btn.primary { background: var(--ink); color: #fff; box-shadow: none; }
.btn.ghost { background: var(--surface); border-color: #D5E0E6; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { background: var(--brand); box-shadow: none; border: none; }
.btn.primary:active, .btn:active { transform: scale(0.98); box-shadow: none; }

.fab {
  border-radius: 50%; border: none; background: var(--ink); color: var(--brand);
  box-shadow: 0 8px 24px rgb(20 33 43 / 0.25);
}
.fab:active { transform: scale(0.95); box-shadow: 0 4px 12px rgb(20 33 43 / 0.2); }

.tabbar {
  border-top: none; border-radius: 24px 24px 0 0;
  box-shadow: 0 -4px 20px rgb(20 33 43 / 0.06);
}
.tabbar button.active { color: var(--ink); font-weight: 500; }
.tabbar button.active span { background: var(--brand); border: none; border-radius: 999px; padding: 2px 16px; }

/* ---------- ฟอร์ม & dialog ---------- */
dialog { border: none; border-radius: 28px; background: var(--surface); box-shadow: 0 20px 60px rgb(20 33 43 / 0.18); }
dialog::backdrop { background: rgb(20 33 43 / 0.35); }
.form label { color: var(--text); font-weight: 500; }
.form input[type='text'], .form input[type='url'], .form input[type='number'], .form input[type='date'],
.form .budget-fields input { border: 1px solid #DCE6EB; background: var(--surface-2); border-radius: 14px; }
.form input:focus { outline: 3px solid var(--brand); outline-offset: 0; }
.type-toggle { background: var(--track); border: none; border-radius: 999px; }
.type-toggle span { border-radius: 999px; }
.type-toggle input:checked + span { border: none; box-shadow: none; }
.type-toggle input[value='expense']:checked + span { background: var(--peach-soft); color: var(--expense); }
.type-toggle input[value='income']:checked + span { background: var(--brand); color: var(--ink); }
.cat-opt { background: var(--surface-2); border: 1px solid transparent; border-radius: 14px; }
.cat-opt.selected { background: var(--brand); border-color: transparent; box-shadow: none; }
#txDialog .cat-opt { border-radius: 12px; }
.bf-group { border: 1px solid var(--border); background: var(--surface); border-radius: 16px; }
.bf-toggle small { color: var(--expense); }
.budget-total { border-top: 1px solid var(--border); }
.calc-keys button { background: var(--track); border: none; box-shadow: none; border-radius: 12px; }
.calc-keys .eq { background: var(--brand); }
.calc-keys button:active { transform: scale(0.96); }

/* ---------- อื่นๆ ---------- */
.toast { background: var(--ink); color: #fff; border-radius: 999px; }
.toast.error { background: var(--danger); }
.login-screen { background: var(--bg); }
.login-card { border-radius: 28px; padding: 40px 28px; }

/* ---------- การ์ด Savings rate ---------- */
.card.savings { grid-column: 1 / -1; background: var(--brand); color: var(--ink); }
.card.savings .label { color: #2E4552; font-weight: 500; }
.card.savings .value { font-size: 2.6rem; font-weight: 300; letter-spacing: -0.02em; line-height: 1.1; }
.card.savings .value.negative { color: var(--expense); }
.save-cells { display: grid; grid-template-columns: repeat(12, 1fr); gap: 5px; margin: 14px 0 10px; }
.save-cells i { aspect-ratio: 1; border-radius: 6px; background: rgb(255 255 255 / 0.55); }
.save-cells i.on { background: var(--ink); }
.save-note { font-size: 0.82rem; color: #2E4552; }

/* ---------- กราฟคงเหลือรายเดือน (ในการ์ด hero) ---------- */
.trend { margin-top: 16px; }
.trend-head { font-size: 0.78rem; color: #2E4552; margin-bottom: 6px; }
.trend-plot { position: relative; height: 64px; }
.trend-plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.trend-line { fill: none; stroke: #fff; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.trend-area { fill: rgb(255 255 255 / 0.28); stroke: none; }
.trend-zero { stroke: rgb(20 33 43 / 0.25); stroke-width: 1; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.trend-dot {
  position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%;
  background: var(--ink); border: 2.5px solid #fff; box-sizing: border-box;
}
.trend-months { display: grid; grid-template-columns: repeat(12, 1fr); margin-top: 6px; font-size: 0.62rem; color: #2E4552; text-align: center; }
.trend-months span:first-child { text-align: left; }
.trend-months span:last-child { text-align: right; }
.trend-months span.on { color: var(--ink); font-weight: 600; }

/* ---------- ไอคอน SVG (tab bar / FAB) ---------- */
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button span { display: flex; align-items: center; justify-content: center; height: 28px; font-size: 0; }
.tabbar button.active span { padding: 3px 16px; }
.fab { display: grid; place-items: center; }
.fab .ico { width: 26px; height: 26px; stroke-width: 2.25; }

/* ---------- ผู้ใช้ใน sidebar (ซ่อนบนมือถือ) ---------- */
.tabbar .nav-me { display: none; }
.avatar {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; overflow: hidden;
  background: var(--lilac); color: var(--ink); font-size: 1.1rem; font-weight: 500;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- โมดูลอื่น (ความมั่งคั่ง / พอร์ต) ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.soon-pill { background: var(--brand); color: var(--ink); border-radius: 999px; padding: 4px 12px; font-size: 0.78rem; font-weight: 500; }
.module-grid { display: grid; gap: 14px; }
.module-card { padding: 22px; }
.module-card .value { font-size: 2.2rem; font-weight: 300; margin: 4px 0 8px; color: var(--ink); }
.module-card p { margin: 6px 0 0; font-size: 0.88rem; color: #2E4552; }
.module-card.networth { background: var(--sky); }
.module-card.portfolio { background: var(--lilac-soft); }
.module-card.accounts { background: var(--surface); }

/* ---------- Desktop (≥1024px): tab bar → sidebar ไอคอนวงกลมด้านซ้าย 96px ---------- */
@media (min-width: 1024px) {
  body { padding-bottom: 0; padding-left: 96px; }
  .tabbar {
    top: 0; right: auto; bottom: 0; width: 96px;
    flex-direction: column; align-items: center; gap: 14px;
    padding: 96px 0 24px; border-radius: 0 28px 28px 0;
    box-shadow: 4px 0 24px rgb(20 33 43 / 0.06);
  }
  .tabbar button { flex: none; width: 88px; padding: 4px 0; gap: 6px; font-size: 0.72rem; }
  .tabbar button span, .tabbar button.active span {
    width: 52px; height: 52px; padding: 0; border-radius: 50%; background: var(--bg);
  }
  .tabbar button.active span { background: var(--brand); }
  .tabbar button:hover:not(.active) span { background: var(--track); }
  /* โลโก้บนสุด · ตั้งค่า + ผู้ใช้ชิดล่าง */
  .topbar { display: none; }
  .banner { margin-top: 16px; }
  .tabbar { padding-top: 24px; }
  .tabbar .side-brand {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    font-size: 1.05rem; line-height: 1.2; margin-bottom: 26px;
  }
  .tabbar .side-brand span { margin-left: 0; }
  .tabbar button[data-view='settings']:not(.nav-me) { margin-top: auto; }
  .tabbar .nav-me { display: flex; }
  .hello { font-size: 1.75rem; font-weight: 300; }
  .tabbar .nav-me[hidden] { display: none; }
  .tabbar .nav-me span.avatar { width: 44px; height: 44px; background: var(--lilac); font-size: 1.1rem; }
  .tabbar .nav-me.active span.avatar { background: var(--lilac); outline: 3px solid var(--brand); outline-offset: 2px; }
  .tabbar .nav-me b { font-weight: 500; max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .fab { bottom: 32px; right: 32px; }
}

/* ---------- จอกว้าง (tablet / desktop) ---------- */
@media (min-width: 900px) {
  main { max-width: 880px; padding: 24px 32px; }
  /* แถวแรก hero 3 : savings 2 · แถวสอง รายรับ/รายจ่าย ครึ่งๆ */
  .summary { grid-template-columns: repeat(30, minmax(0, 1fr)); }
  .card.balance { grid-column: span 18; grid-row: span 1; }
  .card.savings { grid-column: span 12; }
  .card.income, .card.expense, .card.invest { grid-column: span 10; }
  .module-grid { grid-template-columns: 3fr 2fr; }
  .module-card.accounts { grid-column: 1 / -1; }
}

/* ---------- หาร 2 คน / ทำซ้ำรายเดือน (ฟอร์มเพิ่มรายการ) ---------- */
.form label.split-toggle {
  flex-direction: row; align-items: center; gap: 10px; cursor: pointer;
  background: var(--surface-2, var(--bg)); border-radius: 14px; padding: 10px 12px;
  font-size: 0.9rem; color: var(--text);
}
.split-toggle[hidden] { display: none !important; }
.split-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.split-box {
  flex: none; width: 20px; height: 20px; border-radius: 6px;
  border: 2px solid var(--muted); display: grid; place-items: center;
}
.split-toggle input:checked + .split-box { background: var(--ink, var(--brand)); border-color: var(--ink, var(--brand)); }
.split-toggle input:checked + .split-box::after { content: ''; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }
.split-toggle input:focus-visible + .split-box { outline: 3px solid var(--brand); outline-offset: 1px; }
.split-text { flex: 1; min-width: 0; }
.split-each { font-weight: 600; white-space: nowrap; }

.repeat-box { display: flex; flex-direction: column; gap: 8px; }
.repeat-box[hidden] { display: none; }
.segmented.repeat-seg { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
.segmented.repeat-seg button { padding: 7px 4px; font-size: 0.85rem; white-space: nowrap; }
.form label.repeat-months { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.repeat-months[hidden] { display: none !important; }
.form .repeat-months input { width: 90px; text-align: center; padding: 8px 10px; }
.tx-preview { margin: 0; font-size: 0.85rem; line-height: 1.6; color: var(--muted); }
.tx-preview b { color: var(--text); }

/* ---------- Investment (type invest = เงินออกที่ไม่นับเป็นรายจ่าย) ---------- */
:root { --invest: #2C6E8F; --invest-soft: #E0F2EA; --invest-fill: #5FB58A; }
.card.invest { grid-column: 1 / -1; background: var(--invest-soft); }
.card.invest .label { color: #2E4552; }
.card.invest .value { color: var(--invest); font-size: clamp(1.15rem, 5.2vw, 1.6rem); overflow-wrap: anywhere; }
.tx-amt.invest { color: var(--invest); }
.type-toggle { grid-template-columns: repeat(3, 1fr); }
.type-toggle input[value='invest']:checked + span { background: var(--invest-soft); color: var(--invest); }
.bg-bar.invest .bg-used, .bg-bar.invest .bg-later { background: var(--invest-fill); }
.tag-behind { background: var(--warn-soft); }
.tag-reached { background: var(--invest-soft); color: var(--invest); }
.bf-section { margin-top: 10px; font-weight: 600; }
.bf-section small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.bf-group.invest { background: var(--invest-soft); border-color: transparent; }
.budget-total.invest { border-top: none; padding-top: 0; }
.budget-total.invest b { color: var(--invest); }
.wealth-list { margin-top: 12px; display: grid; gap: 4px; font-size: 0.9rem; }
.wealth-list:empty { display: none; }
.wealth-list .line { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.wealth-list small { color: var(--muted); }
@media (min-width: 900px) {
  .card.invest { grid-column: span 10; }
}

/* =====================================================================
   v9 · ตัวเลือกช่วงเวลา · Wealth รายไตรมาส · Overview
   ===================================================================== */

/* ---------- ปุ่มชื่อเดือน/ปี/ไตรมาส → เปิดตัวเลือก ---------- */
.period-pick {
  flex: 1; min-width: 0; border: none; background: transparent; color: var(--ink);
  font: inherit; font-weight: 500; font-size: 1.05rem; text-align: center;
  padding: 8px 12px; border-radius: 999px; cursor: pointer;
}
.period-pick:hover { background: var(--bg); }
.period-pick:focus-visible { outline: 3px solid var(--brand); outline-offset: 1px; }
.period-pick small { color: var(--muted); font-size: 0.78rem; font-weight: 400; margin-left: 4px; }
.period-pick span { color: var(--muted); font-size: 0.75rem; margin-left: 2px; }
.period-nav.quarter-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }

.picker { width: min(360px, calc(100vw - 32px)); padding: 18px; }
.picker-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.picker-head h3 { margin: 0; font-size: 1.05rem; font-weight: 500; }
.picker-year { border: none; background: var(--bg); color: var(--ink); font: inherit; font-weight: 500; padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.picker-year:hover { background: var(--brand); }
.picker-year span { font-size: 0.75rem; color: var(--muted); }
.picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.picker-grid.quarter { grid-template-columns: repeat(2, 1fr); }
.picker-grid button {
  position: relative; border: none; background: var(--surface-2); color: var(--ink); font: inherit;
  padding: 14px 6px; border-radius: 14px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.picker-grid button small { font-size: 0.72rem; color: var(--muted); }
.picker-grid button:hover { background: var(--brand-soft); }
.picker-grid button.now { box-shadow: inset 0 0 0 2px var(--sky-deep); }
.picker-grid button.selected { background: var(--ink); color: #fff; font-weight: 500; }
.picker-grid button.selected small { color: #C9D6DD; }
.picker-grid button.has::after {
  content: ''; position: absolute; top: 7px; right: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--brand-deep);
}
.picker-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; }

/* ---------- tooltip ของกราฟ ---------- */
.chart-tip {
  position: fixed; z-index: 1000; pointer-events: none; max-width: 240px;
  background: var(--ink); color: #fff; font-size: 0.8rem; line-height: 1.5;
  padding: 8px 10px; border-radius: 10px; box-shadow: 0 8px 24px rgb(20 33 43 / 0.2);
  font-variant-numeric: tabular-nums;
}
.chart-tip[hidden] { display: none; }
.chart-tip b { font-weight: 600; }
.chart-tip .dot, .alloc-legend i, .ov-legend i, .sw {
  display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px;
}

/* ---------- ▲▼ ส่วนต่าง (ข้อความสีหมึก ลูกศรบอกทิศ) ---------- */
.delta { font-size: 0.8rem; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up::first-letter { color: var(--income); }
.delta.down::first-letter { color: var(--expense); }
.delta.flat { color: var(--muted); }
.muted { color: var(--muted); font-size: 0.8rem; }

/* ---------- แถบสัดส่วน 100% (ช่องว่าง 2px) ---------- */
.alloc-bar { display: flex; gap: 2px; height: 14px; margin-top: 14px; }
.alloc-bar i { min-width: 3px; border-radius: 3px; cursor: default; }
.alloc-bar i:first-child { border-radius: 7px 3px 3px 7px; }
.alloc-bar i:last-child { border-radius: 3px 7px 7px 3px; }
.alloc-bar i:only-child { border-radius: 7px; }
.alloc-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 0.82rem; color: var(--text); }
.alloc-legend b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Wealth ---------- */
.networth-card { background: var(--sky); padding: 24px; margin-bottom: 14px; }
.networth-card .label { color: #2E4552; font-weight: 500; }
.networth-card .value { font-size: clamp(2rem, 9vw, 3rem); font-weight: 300; letter-spacing: -0.02em; line-height: 1.15; }
.nw-delta { min-height: 1.2em; margin-top: 2px; }
.nw-delta .muted { color: #2E4552; }
.nw-people { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 14px; }
.nw-people[hidden] { display: none; }
.nw-people div, .ov-people div {
  background: rgb(255 255 255 / 0.6); border-radius: 14px; padding: 8px 12px;
  display: flex; justify-content: space-between; gap: 8px; font-size: 0.88rem;
}
.nw-people b, .ov-people b { font-weight: 600; font-variant-numeric: tabular-nums; }

.copy-card { display: flex; align-items: center; gap: 14px; justify-content: space-between; background: var(--brand-soft); margin-bottom: 14px; }
.copy-card[hidden] { display: none; }
.copy-card .hint { margin: 2px 0 0; font-size: 0.85rem; }
.copy-card .btn { flex: none; }

.wealth-sections { display: grid; gap: 14px; }
.wealth-sec { padding: 16px 18px 12px; border-top: 5px solid var(--sec); }
.ws-head { display: flex; align-items: center; gap: 12px; }
.ws-icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 1.2rem; flex: none; }
.ws-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ws-title b { font-weight: 500; }
.ws-title small, .ws-total small { color: var(--muted); font-size: 0.78rem; }
.ws-total { text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.ws-total b { font-size: 1.2rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.ws-items { margin-top: 10px; display: flex; flex-direction: column; }
.ws-items .empty { padding: 12px 0; font-size: 0.88rem; }
.wi-owner {
  display: flex; justify-content: space-between; margin-top: 8px; padding: 4px 2px;
  font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.wi-owner b { font-weight: 600; font-variant-numeric: tabular-nums; }
.wi-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  border: none; background: transparent; color: var(--text); font: inherit; text-align: left;
  padding: 10px 2px; border-top: 1px solid var(--track); cursor: pointer;
}
.wi-row:hover { background: var(--surface-2); }
.wi-name { min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.wi-name small { color: var(--muted); font-size: 0.78rem; }
.wi-amt { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ws-add {
  margin-top: 8px; width: 100%; border: 1.5px dashed #CBD8DF; background: transparent; color: var(--ink);
  font: inherit; font-size: 0.88rem; padding: 9px; border-radius: 14px; cursor: pointer;
}
.ws-add:hover { background: var(--brand-soft); border-color: var(--brand-deep); }

#wealthTrendSection { margin-top: 18px; }
#wealthTrendSection[hidden] { display: none; }
.wq-chart { padding: 16px 16px 12px; }
.wq-bars { display: flex; align-items: stretch; gap: 8px; height: 190px; }
.wq-col {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  border: none; background: transparent; font: inherit; color: var(--text); cursor: pointer; padding: 0; border-radius: 10px;
}
.wq-col:hover { background: var(--surface-2); }
.wq-val { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.wq-stack { width: min(36px, 70%); display: flex; flex-direction: column; gap: 2px; }
.wq-stack i { display: block; min-height: 2px; border-radius: 2px; }
.wq-stack i:first-child { border-radius: 4px 4px 2px 2px; }
.wq-lbl { font-size: 0.78rem; margin-top: 6px; display: flex; gap: 1px; align-items: baseline; }
.wq-lbl small { color: var(--muted); font-size: 0.68rem; }
.wq-col.current .wq-lbl { background: var(--ink); color: #fff; padding: 1px 8px; border-radius: 999px; }
.wq-col.current .wq-lbl small { color: #C9D6DD; }
.wq-col.current .wq-val { color: var(--ink); font-weight: 600; }

/* ฟอร์ม Wealth */
.segmented.wealth-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; background: var(--surface-2); box-shadow: none; }
.segmented.wealth-seg button { padding: 8px 4px; font-size: 0.88rem; white-space: nowrap; }
.name-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.name-suggest:empty { display: none; }
.name-suggest button {
  border: none; background: var(--surface-2); color: var(--ink); font: inherit; font-size: 0.82rem;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.name-suggest button:hover { background: var(--brand); }
#wealthPrevHint { margin: -4px 0 0; font-size: 0.82rem; }
#wealthPrevHint[hidden] { display: none; }

/* ---------- Overview ---------- */
.ov-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.ov-card { display: block; text-align: left; color: var(--text); cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.ov-card:hover { box-shadow: 0 6px 20px rgb(20 33 43 / 0.08); }
.ov-card:focus-visible { outline: 3px solid var(--brand-deep); outline-offset: 2px; }
.ov-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.ov-head h3 { margin: 0; font-size: 0.9rem; font-weight: 500; color: #2E4552; }
.ov-go { flex: none; font-size: 0.75rem; color: var(--ink); background: rgb(255 255 255 / 0.65); padding: 3px 10px; border-radius: 999px; }
.ov-big { font-size: clamp(1.8rem, 8vw, 2.6rem); font-weight: 300; letter-spacing: -0.02em; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ov-big.negative { color: var(--expense); }
.ov-sub { font-size: 0.85rem; color: #2E4552; min-height: 1.2em; }
.ov-sub b { font-weight: 600; }
.ov-card .empty { text-align: left; padding: 10px 0 0; font-size: 0.88rem; }
.ov-card .hint { margin: 10px 0 0; font-size: 0.78rem; }

.ov-networth { background: var(--sky); }
.ov-month { background: var(--brand-soft); }
.ov-month .ov-go { background: var(--surface); }
.ov-card:not(.ov-networth):not(.ov-month) .ov-go { background: var(--bg); }

.ov-spark { display: flex; align-items: flex-end; gap: 4px; height: 64px; margin-top: 14px; }
.ov-spark i { flex: 1; background: rgb(20 33 43 / 0.22); border-radius: 4px 4px 2px 2px; min-height: 2px; }
.ov-spark i.on { background: var(--ink); }
.ov-spark-lbl { display: flex; justify-content: space-between; font-size: 0.72rem; color: #2E4552; margin-top: 4px; }

.ov-hbars { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.ov-hbar { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: 0.85rem; }
.ov-hbar.wide { grid-template-columns: minmax(0, 150px) minmax(0, 1fr) auto; }
.ov-hbar > span { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-hbar .grp-emo { width: 24px; height: 24px; font-size: 0.8rem; display: inline-grid; place-items: center; flex: none; font-style: normal; }
.ov-hbar > b { font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.ov-hbar > b small { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 0.75rem; }
.ov-track { position: relative; height: 12px; background: rgb(255 255 255 / 0.7); border-radius: 999px; }
.ov-card:not(.ov-month) .ov-track { background: var(--track); }
.ov-track i { display: block; height: 100%; border-radius: 999px; min-width: 3px; }
.ov-track em { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); border-radius: 1px; }

.ov-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.82rem; margin: 4px 0 10px; }
.ov-legend b { font-weight: 600; font-variant-numeric: tabular-nums; }
.ov-cols { display: flex; align-items: stretch; gap: 4px; height: 150px; }
.ov-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; border-radius: 8px; padding-top: 4px; }
.ov-col:hover { background: var(--surface-2); }
.ov-pair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.ov-pair i { width: min(10px, 40%); border-radius: 4px 4px 1px 1px; min-height: 2px; }
.ov-col span { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }
.ov-col.now span { color: var(--ink); font-weight: 600; }

.ov-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-size: 0.88rem; }
.ov-rows div { display: flex; justify-content: space-between; gap: 8px; }
.ov-rows b { font-weight: 500; font-variant-numeric: tabular-nums; }
.ov-people { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 12px; }
.ov-people div { background: var(--surface-2); }

.ov-goal + .ov-goal { margin-top: 14px; }
.ov-goal-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.88rem; margin-bottom: 8px; }
.ov-goal-num { font-size: 0.82rem; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.ov-goal-num b { color: var(--text); font-weight: 600; }

@media (min-width: 900px) {
  .wealth-sections { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
  .ov-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .ov-networth { grid-column: span 4; }
  .ov-month { grid-column: span 2; }
  .ov-year { grid-column: span 4; }
  .ov-alloc { grid-column: span 2; }
  .ov-groups { grid-column: span 3; }
  .ov-goals { grid-column: span 3; }
  .ov-grid > .ov-groups:last-child { grid-column: 1 / -1; }
}
@media (min-width: 1024px) {
  main:has(#view-overview:not([hidden])), main:has(#view-wealth:not([hidden])) { max-width: 1080px; }
}
#monthLabel.period-pick::after { content: ' ▾'; font-size: 0.75rem; color: var(--muted); }

/* ---------- Wealth mix: โดนัท 2 มุมมอง (ก้อนใหญ่ / ประเภทสินทรัพย์) ---------- */
.mix-pies {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
  margin-top: 16px; background: var(--surface); border-radius: 20px; padding: 14px 12px;
}
.ov-alloc .mix-pies { padding: 0; margin-top: 8px; }
.donut { margin: 0; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.donut figcaption {
  align-self: flex-start; margin: 0 0 10px 4px; font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.donut-chart { position: relative; width: min(100%, 136px); aspect-ratio: 1; }
.donut-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.donut-seg {
  fill: none; stroke-width: 13; cursor: default;
  transition: stroke-width 0.2s ease, opacity 0.2s ease;
  animation: donut-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes donut-in { from { stroke-dasharray: 0 400; } }
.donut.focus .donut-seg { opacity: 0.25; }
.donut.focus .donut-seg.on { opacity: 1; stroke-width: 17; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; text-align: center; line-height: 1.2; font-variant-numeric: tabular-nums;
}
.donut-center small {
  max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.66rem; color: var(--muted); letter-spacing: 0.04em;
}
.donut-center b { font-size: 1.1rem; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.donut-center span { font-size: 0.68rem; color: var(--muted); }
.donut-center span:empty { display: none; }
.donut-legend {
  list-style: none; margin: 12px 0 0; padding: 0; width: 100%;
  display: flex; flex-direction: column; gap: 2px; font-size: 0.8rem;
}
.donut-legend li {
  display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; column-gap: 8px; align-items: center;
  padding: 5px 8px; border-radius: 10px; color: var(--ink); transition: background 0.15s, opacity 0.15s;
}
.donut-legend li.on { background: var(--surface-2); }
.donut.focus .donut-legend li:not(.on) { opacity: 0.5; }
.donut-legend li.zero { opacity: 0.4; }
.donut-legend i { width: 8px; height: 8px; border-radius: 50%; }
.donut-legend span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend b { grid-column: 3; grid-row: 1; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.donut-legend small { grid-column: 2 / -1; grid-row: 2; color: var(--muted); font-size: 0.72rem; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) {
  .donut-seg { animation: none; transition: none; }
}
@media (min-width: 900px) {
  .networth-card .donut-legend li { grid-template-columns: 8px minmax(0, 1fr) auto 3.4em; }
  .networth-card .donut-legend small { grid-column: 3; grid-row: 1; }
  .networth-card .donut-legend b { grid-column: 4; }
  .networth-card .donut-chart { width: 148px; }
  .networth-card .donut { display: grid; grid-template-columns: 148px minmax(0, 1fr); column-gap: 20px; align-items: center; padding: 0 8px; }
  .networth-card .donut figcaption { grid-column: 1 / -1; justify-self: start; }
  .networth-card .donut-legend { margin: 0; }
}
.wi-cat {
  align-self: flex-start; margin: 2px 0; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink); font-style: normal; font-size: 0.7rem; font-weight: 500;
}
