/* ============================================================
   C-Cash-Maew — Design tokens
   ============================================================ */
:root {
  color-scheme: light;

  /* surfaces & ink — พื้นเทาอมฟ้า การ์ดขาว ตามโทนที่เลือก */
  --plane:          #eef1f4;
  --surface-1:      #ffffff;
  --surface-2:      #f3f6f8;
  --surface-3:      #e7ecef;
  --text-primary:   #0e1113;
  --text-secondary: #565e64;
  --text-muted:     #8a9198;
  --grid:           #e6eaee;
  --axis:           #c2c9cf;
  --border:         rgba(14,17,19,0.09);
  --border-strong:  rgba(14,17,19,0.16);
  --shadow-sm:      0 1px 2px rgba(14,17,19,.05), 0 1px 1px rgba(14,17,19,.03);
  --shadow-md:      0 6px 20px rgba(14,17,19,.08), 0 1px 3px rgba(14,17,19,.05);
  --shadow-lg:      0 24px 60px rgba(14,17,19,.20), 0 4px 12px rgba(14,17,19,.09);

  /* แถบเมนูเป็นสีดำทั้งธีมสว่างและธีมมืด เพราะเป็นเอกลักษณ์หลักของโทนนี้ */
  --rail:           #101311;
  --rail-ink:       #ffffff;
  --rail-dim:       #98a09c;
  --rail-hover:     rgba(255,255,255,.07);

  /* ชุดสีกราฟ — ใช้ชุดเดิมที่ผ่านการตรวจตาบอดสีมาแล้ว เพียงสลับลำดับให้เขียวมิ้นต์ขึ้นนำ
     ไม่ได้เพิ่มสีใหม่ เพื่อไม่ให้เสียคุณสมบัติที่ตรวจไว้แล้ว */
  --series-1: #1baf7a;  /* เขียวมิ้นต์ */
  --series-2: #2a78d6;  /* น้ำเงิน */
  --series-3: #eb6834;  /* ส้ม */
  --series-4: #4a3aa7;  /* ม่วง */
  --series-5: #eda100;  /* เหลือง */
  --series-6: #e87ba4;  /* ชมพู */
  --series-7: #008300;  /* เขียวเข้ม */
  --series-8: #e34948;  /* แดง */
  --series-other: #8a9198;

  /* ไล่เฉดเขียวมิ้นต์ ใช้กับปฏิทินความถี่ */
  --seq-100:#d7f0e6; --seq-200:#a9e0cb; --seq-300:#77cdae; --seq-400:#45b891;
  --seq-500:#2a9c76; --seq-600:#1c7b5c; --seq-700:#125742;

  /* status */
  --good:     #17a06a;
  --warning:  #f0b429;
  --serious:  #ec835a;
  --critical: #d64545;
  --good-text:#0f7d52;
  --crit-text:#b02b2b;

  /* เขียวมะนาวใช้เป็น "พื้น" เท่านั้น ตัวอักษรบนพื้นนี้ต้องเป็นสีดำ
     ส่วนตัวอักษรสีเน้นบนพื้นสว่างต้องใช้ --accent-text ไม่งั้นคอนทราสต์ไม่ผ่าน */
  --accent:      #d6f24b;
  --accent-ink:  #0e1113;
  --accent-text: #2f7d68;
  --accent-soft: #eef8c9;

  --r-sm: 9px; --r-md: 13px; --r-lg: 18px; --r-xl: 24px;
  --sidebar-w: 236px;
  --font: system-ui, -apple-system, "Leelawadee UI", "Noto Sans Thai", "Thonburi", "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0c0e0d;
  --surface-1:      #161a18;
  --surface-2:      #1f2422;
  --surface-3:      #2a302d;
  --text-primary:   #ffffff;
  --text-secondary: #b9c2be;
  --text-muted:     #8a9490;
  --grid:           #2a302d;
  --axis:           #39413d;
  --border:         rgba(255,255,255,0.10);
  --border-strong:  rgba(255,255,255,0.18);
  --shadow-sm:      0 1px 2px rgba(0,0,0,.5);
  --shadow-md:      0 4px 16px rgba(0,0,0,.5);
  --shadow-lg:      0 24px 60px rgba(0,0,0,.65);

  --rail:           #0a0c0b;
  --rail-ink:       #ffffff;
  --rail-dim:       #8a9490;
  --rail-hover:     rgba(255,255,255,.08);

  --series-1: #35c795;
  --series-2: #3987e5;
  --series-3: #d95926;
  --series-4: #9085e9;
  --series-5: #c98500;
  --series-6: #d55181;
  --series-7: #14a014;
  --series-8: #e66767;

  --seq-100:#0f3c2e; --seq-200:#145340; --seq-300:#1a6b53; --seq-400:#218567;
  --seq-500:#2a9c76; --seq-600:#45b891; --seq-700:#77cdae;

  --good-text:#35c795;
  --crit-text:#e66767;

  --accent:      #cbe94a;
  --accent-ink:  #0e1113;
  --accent-text: #7fd9b8;
  --accent-soft: #232a14;
}

/* ============================================================ Reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--plane);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
h1,h2,h3,h4,p,figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); text-decoration: none; }
svg { display: block; }
::selection { background: var(--accent-soft); }

/* ============================================================ Layout */
.app { display: flex; min-height: 100%; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--rail);
  color: var(--rail-ink);
  border-inline-end: 1px solid rgba(255,255,255,.07);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; }
/* มาสคอตแมว — ใช้ไฟล์ 192px ย่อลงมา 30px เพื่อให้คมบนจอ retina
   (ไฟล์นี้ sw precache ไว้อยู่แล้ว จึงไม่มีค่าโหลดเพิ่มหลังเปิดครั้งแรก)
   ปล่อยให้เบราว์เซอร์ย่อแบบ smooth ห้ามใส่ image-rendering: pixelated
   เพราะการย่อแบบ nearest จะทำให้พิกเซลหายเป็นแถบ */
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent);
  object-fit: cover;
  flex: 0 0 auto;
}
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
/* ต้องพ่วง .icon-btn ให้ specificity สูงกว่า ไม่งั้น .icon-btn{display:grid} ที่อยู่ล่างกว่าจะชนะ */
.icon-btn.sidebar-close { display: none; margin-inline-start: auto; color: var(--rail-ink); }
.icon-btn.sidebar-close:hover { background: var(--rail-hover); color: var(--rail-ink); }

.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 999px;
  color: var(--rail-dim); font-weight: 500;
}
.nav a:hover { background: var(--rail-hover); color: var(--rail-ink); }
.nav a.active { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.nav a svg { flex: 0 0 auto; opacity: .95; }
/* อยู่ในแถบเมนูสีดำ จึงต้องใช้สีของ rail ไม่ใช่สีตัวอักษรของหน้าเว็บ */
.sync-status { font-weight: 600; margin-bottom: 5px; color: var(--accent); }
.sync-status.warn { color: #f0b429; }
.sync-status.bad { color: #ff8f8f; }

.sidebar-foot {
  margin-top: auto; padding: 14px 16px;
  font-size: 11.5px; color: var(--rail-dim); line-height: 1.55;
  border-top: 1px solid rgba(255,255,255,.10);
}

.scrim { display: none; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title h1 { font-size: 19px; font-weight: 650; letter-spacing: -.015em; }
.topbar-title p { font-size: 12.5px; color: var(--text-muted); }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn.menu-btn { display: none; }

.view { flex: 1 1 auto; padding: 20px 22px 40px; max-width: 1500px; width: 100%; }
.app-foot {
  padding: 18px 22px 26px; font-size: 11.5px; color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.tabbar { display: none; }
.fab { display: none; }

/* การ์ดตัวเลขหลักเป็นพื้นดำตามโทนต้นแบบ
   ใช้วิธีประกาศตัวแปรทับที่ระดับการ์ด ลูกทุกตัวข้างในจึงเปลี่ยนสีตามเอง ไม่ต้องไล่แก้ทีละจุด
   (ยกเว้นกราฟ SVG ซึ่ง charts.js อ่านค่าตัวแปรจาก :root ไม่ใช่จากการ์ด จึงต้องคุมด้วย CSS แยก) */
.card.hero {
  background: var(--rail);
  border-color: transparent;
  color: #fff;
  --text-primary: #ffffff;
  --text-secondary: #c3ccc8;
  --text-muted: #949d99;
  --surface-1: #1b201e;
  --surface-2: rgba(255,255,255,.09);
  --surface-3: rgba(255,255,255,.14);
  --border: rgba(255,255,255,.13);
  --border-strong: rgba(255,255,255,.22);
  --good-text: #6fe0a8;
  --crit-text: #ff9b9b;
}
.card.hero .grid-line, .card.hero [stroke="#e6eaee"] { stroke: rgba(255,255,255,.10) !important; }
.card.hero text { fill: #949d99 !important; }
.card.hero .eyebrow { color: #949d99; }

/* ============================================================ Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-primary); font-weight: 550; font-size: 13.5px;
  box-shadow: var(--shadow-sm); white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 620; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 86%, #000); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); }
.btn-danger { background: var(--critical); border-color: transparent; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: var(--r-sm); border: 1px solid transparent;
  background: transparent; color: var(--text-secondary);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.icon-btn.on { background: var(--accent); color: var(--accent-ink); }

input[type=text], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface-1); color: var(--text-primary);
  font-size: 14px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
textarea { resize: vertical; min-height: 70px; }
select { appearance: none; padding-inline-end: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23898781' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 16px;
}
label.field { display: block; }
.field-label { font-size: 12.5px; font-weight: 560; color: var(--text-secondary); margin-bottom: 5px; display: block; }
.field-label .opt { font-weight: 400; color: var(--text-muted); font-size: 11.5px; }
.field-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; line-height: 1.5; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.money-input { position: relative; }
.money-input span.cur {
  position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-weight: 600; pointer-events: none;
}
.money-input input { padding-inline-start: 30px; }

.switch { position: relative; width: 40px; height: 23px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 2; }
.switch i {
  position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3);
  transition: background .15s;
}
.switch i::after {
  content: ""; position: absolute; top: 2.5px; inset-inline-start: 2.5px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-sm); transition: transform .15s;
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(17px); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r-sm); padding: 3px; gap: 3px; }
.seg button {
  border: 0; background: transparent; border-radius: 6px; padding: 6px 13px;
  font-size: 13.5px; font-weight: 550; color: var(--text-secondary);
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* ============================================================ Cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: flex-start; gap: 12px; padding: 15px 17px 0; }
.card-head .ttl { font-size: 14.5px; font-weight: 620; letter-spacing: -.01em; }
.card-head .sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.card-head .head-act { margin-inline-start: auto; display: flex; gap: 4px; align-items: center; }
.card-body { padding: 14px 17px 16px; }
.card-link { font-size: 12.5px; font-weight: 560; color: var(--accent-text); }

.grid { display: grid; gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { margin-inline-start: auto; }

/* stat tiles */
.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
/* grid item มี min-width:auto ตามค่าตั้งต้น ซึ่งถูกดันด้วย min-content ของ sparkline + ตัวเลขข้างใน
   ทำให้การ์ดกว้างเกิน track จนล้นจอ ต้องปลดที่ตัวการ์ดเองด้วย ไม่ใช่แค่ที่ track */
.tile { min-width: 0; }
.tile { padding: 14px 16px; }
.tile .lbl { font-size: 12.5px; color: var(--text-secondary); font-weight: 550; display: flex; align-items: center; gap: 6px; }
.tile .lbl .ico { margin-inline-start: auto; color: var(--text-muted); }
.tile .val { font-size: 25px; font-weight: 660; letter-spacing: -.02em; margin-top: 5px; }
.tile .val.sm { font-size: 21px; }
.tile .foot { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.tile-flex { display: flex; align-items: flex-end; gap: 10px; }
.tile-flex .spark { flex: 0 0 76px; }
.delta-note { white-space: nowrap; margin-top: 1px; }

.delta { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--crit-text); }
.delta.flat { color: var(--text-muted); }

.pos { color: var(--good-text); }
.neg { color: var(--crit-text); }

/* amounts + privacy mode */
.amt { font-variant-numeric: tabular-nums; }
body.privacy .amt { filter: blur(6px); transition: filter .12s; }
body.privacy .amt:hover { filter: none; }

/* pills / badges */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 570; line-height: 1.6;
  background: var(--surface-2); color: var(--text-secondary);
  border: 1px solid var(--border);
}
.pill.good { background: color-mix(in srgb, var(--good) 12%, var(--surface-1)); color: var(--good-text); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.pill.warn { background: color-mix(in srgb, var(--warning) 18%, var(--surface-1)); color: #7a5200; border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
:root[data-theme="dark"] .pill.warn { color: var(--warning); }
.pill.bad  { background: color-mix(in srgb, var(--critical) 12%, var(--surface-1)); color: var(--crit-text); border-color: color-mix(in srgb, var(--critical) 30%, transparent); }
.pill.info { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }

/* progress bars */
.bar { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
.bar > i.warn { background: var(--warning); }
.bar > i.bad  { background: var(--critical); }
.bar > i.good { background: var(--good); }

/* misc */
.emoji { font-size: 15px; line-height: 1; width: 20px; text-align: center; flex: 0 0 auto; }
.avatar {
  width: 32px; height: 32px; border-radius: 9px; flex: 0 0 auto;
  background: var(--surface-2); display: grid; place-items: center; font-size: 15px;
}
.muted { color: var(--text-muted); }
.sec { color: var(--text-secondary); }
.tiny { font-size: 11.5px; }
.small { font-size: 12.5px; }
.strong { font-weight: 620; }
.nowrap { white-space: nowrap; }
.eyebrow { font-size: 10.5px; font-weight: 640; letter-spacing: .07em; text-transform: uppercase; color: var(--text-muted); }
.hr { height: 1px; background: var(--border); margin: 12px 0; }

.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; }
.empty p { max-width: 380px; margin: 0 auto 14px; font-size: 13px; line-height: 1.6; }

/* ============================================================ Lists & tables */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 4px; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-item .grow { min-width: 0; flex: 1 1 auto; }
.list-item .t1 { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .t2 { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .end { text-align: end; flex: 0 0 auto; }

table.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.tbl th {
  text-align: start; font-size: 10.5px; font-weight: 640; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.tbl td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl td.num, table.tbl th.num { text-align: end; }
table.tbl tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* transactions table */
.tx-row td { padding: 9px 10px; }
.tx-desc { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tx-desc .grow { min-width: 0; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.tag { font-size: 10.5px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-muted); }
.tx-amt { font-weight: 600; white-space: nowrap; }
.rowbtn { opacity: 0; }
tr:hover .rowbtn, .rowbtn:focus { opacity: 1; }

/* ============================================================ Charts */
.chart { width: 100%; position: relative; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; }
.legend .li { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.legend .sw.line { height: 3px; border-radius: 2px; width: 14px; }

.tooltip {
  position: fixed; z-index: 200; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); box-shadow: var(--shadow-md);
  padding: 8px 10px; font-size: 12.5px; min-width: 120px;
  transition: opacity .08s;
}
.tooltip .tt-h { font-weight: 620; margin-bottom: 5px; font-size: 12.5px; }
.tooltip .tt-r { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-r .sw { width: 9px; height: 9px; border-radius: 3px; }
.tooltip .tt-r .v { margin-inline-start: auto; font-weight: 620; font-variant-numeric: tabular-nums; }

.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut-wrap .chart { flex: 0 0 190px; max-width: 190px; }
.donut-legend { flex: 1 1 230px; min-width: 200px; display: flex; flex-direction: column; }
.donut-legend .dl {
  display: flex; align-items: center; gap: 9px; padding: 4.5px 0; font-size: 12.5px;
}
.donut-legend .dl .nm { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend .dl .v { font-variant-numeric: tabular-nums; font-weight: 560; }
.donut-legend .dl .p { width: 44px; text-align: end; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.heat { display: grid; grid-auto-flow: column; gap: 3px; }
.heat-col { display: grid; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.heat-cell { width: 11px; height: 11px; border-radius: 2.5px; background: var(--surface-2); }
.heat-scale { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); }
.heat-scale .sw { width: 11px; height: 11px; border-radius: 2.5px; }

/* ============================================================ Modal */
/* จำเป็น: display:grid ด้านล่างชนะ display:none ที่ UA ให้มากับ [hidden] ทำให้ซ่อนไม่ลง */
.modal-root[hidden] { display: none; }
.modal-root {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(11,11,11,.45);
  display: grid; place-items: center;
  padding: 16px;
  overflow-y: auto;
  animation: fade .12s ease;
}
@keyframes fade { from { opacity: 0 } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985) } }
.modal {
  width: 100%; max-width: 480px;
  background: var(--surface-1); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  animation: pop .16s cubic-bezier(.2,.8,.3,1);
  max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
}
.modal.wide { max-width: 660px; }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 17px 19px 12px;
}
.modal-head h2 { font-size: 17px; font-weight: 640; letter-spacing: -.015em; }
.modal-body { padding: 0 19px 4px; overflow-y: auto; display: flex; flex-direction: column; gap: 13px; }
.modal-foot {
  display: flex; align-items: center; gap: 9px; justify-content: flex-end;
  padding: 16px 19px 18px;
}
.modal-foot .left { margin-inline-end: auto; }

.type-seg { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--r-md); }
.type-seg button {
  border: 0; background: transparent; border-radius: 8px; padding: 9px 4px;
  font-weight: 570; font-size: 13.5px; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.type-seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.type-seg button.on[data-type="expense"] { color: var(--crit-text); }
.type-seg button.on[data-type="income"] { color: var(--good-text); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.chip button { border: 0; background: none; color: var(--text-muted); padding: 0 0 0 2px; font-size: 14px; line-height: 1; }

/* toast */
.toast-root {
  position: fixed; inset-inline: 0; bottom: 20px; z-index: 300;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text-primary); color: var(--plane);
  padding: 9px 15px; border-radius: 999px; font-size: 13px; font-weight: 550;
  box-shadow: var(--shadow-md); pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  animation: pop .16s ease;
}
.toast button { background: none; border: 0; color: inherit; font-weight: 650; text-decoration: underline; padding: 0; }

/* filters bar */
.filters {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.filters .search { flex: 1 1 260px; min-width: 180px; position: relative; }
.filters .search svg { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.filters .search input { padding-inline-start: 33px; }
.filters select { width: auto; min-width: 130px; }

.kbd {
  display: inline-block; padding: 1px 6px; border-radius: 5px; min-width: 20px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; font-size: 11.5px; font-weight: 600; font-family: var(--font);
}

/* ============================================================ Responsive */
/* ต้องเป็น minmax(0,1fr) ไม่ใช่ 1fr เฉย ๆ — 1fr ยังมี auto minimum ตามสเปก CSS Grid
   ซึ่งถูกดันด้วย min-content ของ SVG กราฟข้างใน ทำให้คอลัมน์กว้างเกินกล่องแม่แล้วล้นจอ */
@media (max-width: 1100px) {
  .grid.dash-top { grid-template-columns: minmax(0, 1fr) !important; }
}
@media (max-width: 900px) {
  .grid.two { grid-template-columns: minmax(0, 1fr) !important; }
  .grid.dash-mid { grid-template-columns: minmax(0, 1fr) !important; }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0;
    transform: translateX(-102%); transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .icon-btn.sidebar-close { display: grid; }
  .icon-btn.menu-btn { display: grid; }
  .view { padding: 16px 14px 96px; }
  .topbar { padding: 10px 14px; }
  .topbar-title h1 { font-size: 17px; }
  .topbar-title p { display: none; }
  .topbar-actions .btn { display: none; }
  .app-foot { display: none; }

  .tabbar {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 45;
    background: color-mix(in srgb, var(--surface-1) 94%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 10.5px; color: var(--text-muted); font-weight: 550; padding: 4px 2px;
    border-radius: var(--r-sm); min-width: 0;
  }
  .tabbar a.active { color: var(--accent-text); }
  .fab {
    display: grid; place-items: center;
    position: fixed; inset-inline-end: 16px; bottom: calc(74px + env(safe-area-inset-bottom));
    width: 52px; height: 52px; border-radius: 50%; z-index: 46;
    background: var(--accent); color: var(--accent-ink); border: 0; font-size: 27px; font-weight: 300;
    box-shadow: var(--shadow-md);
    padding-bottom: 3px;
  }
  .card-head { padding: 13px 14px 0; }
  .card-body { padding: 12px 14px 14px; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .tile .val { font-size: 21px; }
  .donut-wrap { justify-content: center; }
  .donut-wrap .chart { flex: 0 0 160px; max-width: 160px; }
  .modal { max-width: none; border-radius: var(--r-xl) var(--r-xl) 0 0; align-self: flex-end; }
  .modal-root { place-items: end center; padding: 0; }
  .field-row { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .val { font-size: 18.5px; }
  .hide-sm { display: none !important; }
  .filters .search { flex: 1 1 100%; }
  .filters select, .filters .btn { flex: 1 1 auto; }
}

@media print {
  .sidebar, .topbar-actions, .tabbar, .fab, .filters { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
