:root {
  color-scheme: light dark;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #5b6472;
  --line: #e5e7eb;
  --fill: #e5e7eb;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --income: #047857;
  --expense: #c2410c;
  --saving: #0369a1;
  --good: #047857;
  --bad: #b91c1c;
  --warn: #b45309;
  --hit: rgba(15, 118, 110, 0.1);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 16px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --max: 640px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e8eaed;
    --muted: #9aa3af;
    --line: #2a2f38;
    --fill: #2a2f38;
    --brand: #2dd4bf;
    --brand-ink: #04211e;
    --income: #34d399;
    --expense: #fb923c;
    --saving: #38bdf8;
    --good: #34d399;
    --bad: #f87171;
    --warn: #fbbf24;
    --hit: rgba(45, 212, 191, 0.12);
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.modal-open { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); font-size: 0.9rem; }
.noscript { padding: 24px; text-align: center; }

/* ---------- โครงหน้า ---------- */
#app {
  max-width: var(--max);
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 96px);
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.topbar-title { font-size: 1.25rem; font-weight: 700; }
.status {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 22px;
  background: transparent; font-size: 1.25rem;
}
.status.attention { background: color-mix(in srgb, var(--bad) 16%, transparent); }

.view { display: grid; gap: 12px; padding: 0 16px; }
.view.center { place-items: center; padding-top: 30vh; text-align: center; gap: 16px; }

.nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(100%, var(--max)); z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--nav-h); text-decoration: none; color: var(--muted); font-size: 0.75rem;
}
.nav-item.active { color: var(--brand); font-weight: 700; }
.nav-icon { font-size: 1.35rem; line-height: 1; }

.fab {
  position: fixed; z-index: 11;
  right: max(16px, calc(50vw - var(--max) / 2 + 16px));
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 58px; height: 58px; border: 0; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink);
  font-size: 2rem; line-height: 1; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}

/* ---------- การ์ดและตัวเลข ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); display: grid; gap: 12px;
}
.card-title { font-size: 1rem; font-weight: 700; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.group-title { font-size: 0.85rem; color: var(--muted); font-weight: 600; margin: 8px 0 4px; }

.hero { text-align: center; padding: 22px 16px; gap: 4px; }
.hero-label { color: var(--muted); }
.hero-amount { font-size: 2.6rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.hero-amount.good { color: var(--good); }
.hero-amount.bad { color: var(--bad); }
.hero-sub { color: var(--muted); font-size: 0.85rem; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tiles.two { grid-template-columns: repeat(2, 1fr); }
.tiles.two .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
.stat { background: var(--card); border-radius: 12px; padding: 12px 10px; display: grid; gap: 2px; box-shadow: var(--shadow); }
.card .stat { background: var(--bg); box-shadow: none; }
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-value { font-size: 1rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-value.income, .stat-value.good { color: var(--income); }
.stat-value.expense { color: var(--expense); }
.stat-value.saving { color: var(--saving); }
.stat-value.bad { color: var(--bad); }

.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.insight { display: grid; grid-template-columns: 1.6rem 1fr; gap: 6px; align-items: start; }
.insight-icon { font-size: 1.05rem; }

.amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* แท่งเทียบงบ */
.bar-row { display: grid; gap: 4px; width: 100%; padding: 6px 0; background: none; border: 0; text-align: left; }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.bar-name { display: inline-flex; align-items: center; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.bar { height: 10px; border-radius: 6px; background: var(--fill); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; min-width: 2px; }
.bar-fill.ok { background: var(--brand); }
.bar-fill.over { background: var(--bad); }
.bar-fill.neutral { background: var(--muted); opacity: 0.55; }
.bar-fill.saving { background: var(--saving); }
.bar-foot { font-size: 0.82rem; color: var(--muted); }
.cat-icon { display: inline-block; width: 1.5em; text-align: center; }

.link-card { display: flex; align-items: center; justify-content: space-between; text-decoration: none; }
.link-card-main { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.chevron { font-size: 1.8rem; color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.empty-card { text-align: center; }

/* ---------- ปุ่มและฟอร์ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; text-decoration: none;
  border: 1px solid var(--line); background: var(--card); font-weight: 600; text-align: center;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.btn.wide { width: 100%; }
.btn.danger-outline { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.btn.danger-outline.armed { background: var(--bad); color: #fff; border-color: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 160px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: 0; background: transparent;
  font-size: 1.6rem; line-height: 1; color: var(--text); display: inline-grid; place-items: center;
}
.icon-btn:disabled { opacity: 0.3; }
.link-btn { border: 0; background: none; color: var(--brand); padding: 0; font-size: 0.85rem; text-decoration: underline; }

.month-nav { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.month-title { display: grid; justify-items: center; }
.month-title strong { font-size: 1.1rem; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex: none; min-height: 40px; padding: 0 16px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--card);
}
.chip.active { background: var(--brand); color: var(--brand-ink); border-color: transparent; font-weight: 700; }

input[type="text"], input[type="search"], input[type="password"], input[type="date"], select {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.sheet input[type="text"], .sheet input[type="date"], .sheet select { background: var(--bg); }
.search { background: var(--card); }

/* ---------- รายการ ---------- */
.list-summary { padding: 0 4px; }
.tx-list { display: grid; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tx-list:has(.empty) { background: transparent; box-shadow: none; }
.tx-row {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px;
  width: 100%; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left;
}
.tx-row:last-child { border-bottom: 0; }
.tx-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; background: var(--bg); }
.tx-main { display: grid; min-width: 0; }
.tx-title { font-weight: 600; overflow-wrap: anywhere; }
.tx-sub { font-size: 0.82rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge { font-size: 0.7rem; padding: 0 6px; border-radius: 8px; background: var(--fill); color: var(--muted); }
.tx-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amount.kind-income { color: var(--income); }
.tx-amount.kind-expense { color: var(--text); }
.tx-amount.kind-saving { color: var(--saving); }

/* ---------- ผ่อน ---------- */
.inst-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.inst-row:first-of-type { border-top: 0; }
.inst-row.done { opacity: 0.65; }
.inst-main { display: grid; gap: 6px; border: 0; background: none; text-align: left; padding: 4px 0; min-width: 0; }
.inst-top { display: flex; justify-content: space-between; gap: 8px; }
.inst-name { font-weight: 600; overflow-wrap: anywhere; }
.stepper { display: flex; gap: 2px; }
.stepper .icon-btn { background: var(--bg); }
.timeline { margin: 0; padding-left: 20px; display: grid; gap: 12px; }
.finished summary { cursor: pointer; font-weight: 700; }

/* ---------- สรุปปี ---------- */
.chart-wrap { display: grid; gap: 8px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .axis.end { text-anchor: end; }
.chart .axis.middle { text-anchor: middle; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit.active { fill: var(--hit); }
.chart .bar-income { fill: var(--income); }
.chart .bar-expense { fill: var(--expense); }
.legend { display: flex; gap: 16px; font-size: 0.85rem; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.swatch.income { background: var(--income); }
.swatch.expense { background: var(--expense); }
.chart-detail { font-size: 0.9rem; min-height: 2.8em; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.table caption { text-align: left; color: var(--muted); padding-bottom: 6px; }
.table th, .table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.table thead th { color: var(--muted); font-weight: 600; }
.table tbody th, .table tfoot th { font-weight: 600; }
.table tfoot td, .table tfoot th { font-weight: 700; border-bottom: 0; }
.table .num { text-align: right; }
.table .bad { color: var(--bad); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }

/* ---------- ตั้งค่า ---------- */
.cat-group { display: grid; }
.cat-row { display: grid; grid-template-columns: 1.6rem 1fr auto auto; gap: 8px; align-items: center; padding: 4px 0; border-top: 1px solid var(--line); }
.cat-row-name { overflow-wrap: anywhere; }
.budget { display: inline-flex; align-items: center; gap: 4px; }
.budget-label { color: var(--muted); font-size: 0.85rem; }
.budget-input { width: 96px; min-height: 40px; text-align: right; }

/* ---------- หน้าต่างเลื่อนขึ้น ---------- */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: min(100%, 560px); max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 20px 20px 0 0; padding-bottom: var(--safe-b);
  animation: rise 0.18s ease-out;
}
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 20px; background: var(--card); }
.sheet-head h2 { font-size: 1.1rem; }
.sheet-body { padding: 8px 20px 20px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 720px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field-label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.field-hint { font-size: 0.8rem; color: var(--muted); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.form-error { color: var(--bad); font-weight: 600; }

.amount-wrap { position: relative; padding: 8px 0 0; }
.amount-prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-35%); font-size: 1.8rem; color: var(--muted); }
.amount-input {
  width: 100%; border: 0 !important; background: transparent !important;
  font-size: 2.6rem; font-weight: 800; text-align: center; padding: 0 44px; min-height: 64px;
  font-variant-numeric: tabular-nums;
}
.amount-input:focus-visible { outline-offset: 4px; border-radius: 12px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--bg); border-radius: 12px; }
.seg-btn { min-height: 40px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; color: var(--muted); }
.seg-btn.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg-btn.active.kind-income { color: var(--income); }
.seg-btn.active.kind-expense { color: var(--expense); }
.seg-btn.active.kind-saving { color: var(--saving); }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.cat-chip {
  display: grid; justify-items: center; gap: 2px; padding: 10px 6px; min-height: 76px;
  border-radius: 12px; border: 2px solid transparent; background: var(--bg); text-align: center;
}
.cat-chip .cat-icon { font-size: 1.5rem; }
.cat-chip .cat-name { font-size: 0.8rem; line-height: 1.25; overflow-wrap: anywhere; }
.cat-chip.active { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, var(--bg)); font-weight: 700; }

.cycle { display: flex; align-items: center; justify-content: space-between; background: var(--bg); border-radius: 12px; }
.cycle-label { font-weight: 700; }

/* ---------- แจ้งเตือน / ล็อกอิน ---------- */
#toasts { position: fixed; z-index: 100; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--safe-b) + 84px); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { max-width: 520px; padding: 12px 16px; border-radius: 12px; background: #1f2937; color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); font-size: 0.92rem; }
.toast.good { background: #065f46; }
.toast.bad { background: #991b1b; }
.toast.warn { background: #92400e; }

.login-screen { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: grid; place-items: center; padding: 20px; }
.login-card { width: min(100%, 360px); display: grid; gap: 14px; text-align: center; }
.logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 20px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 2.6rem; font-weight: 800; }
.login-card h1 { font-size: 1.6rem; }
.pin-input { text-align: center; font-size: 1.6rem; letter-spacing: 0.4em; }

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
}

/* ======================================================================
   โครงหน้าแบบ responsive
   มือถือ (ค่าเริ่มต้น) → แท็บเล็ต ≥ 640px → คอมพิวเตอร์ ≥ 960px
   ====================================================================== */

/* ---------- ชิ้นส่วนที่ใช้ทุกขนาดจอ ---------- */
.budget .budget-input[type="text"] { width: 110px; }
.budget-label { white-space: nowrap; }
.cols { display: grid; gap: 12px; }
.col { display: grid; gap: 12px; align-content: start; }
.toolbar { display: grid; gap: 12px; }
.spacer { flex: 1; }
.a-groups { display: grid; gap: 12px; }
.badge:empty { display: none; }
.tx-date::before { content: "·"; margin-right: 6px; }
.tx-head, .list-tiles { display: none; }
.add-btn, .brand, .nav-lock { display: none; }

/* ---------- แท็บเล็ต ---------- */
@media (min-width: 640px) {
  :root { --max: 820px; }
  .tiles { gap: 12px; }
}

/* ---------- คอมพิวเตอร์: เมนูด้านข้าง + หลายคอลัมน์ ---------- */
@media (min-width: 960px) {
  :root { --side-w: 236px; --content-max: 1280px; }

  #app { max-width: none; margin: 0; padding: 0 0 56px var(--side-w); }
  .topbar, #main { width: 100%; max-width: var(--content-max); margin-inline: auto; }
  .topbar { padding: 24px 32px 16px; background: var(--bg); backdrop-filter: none; gap: 12px; }
  .topbar-title { font-size: 1.7rem; }
  .add-btn { display: inline-flex; }
  .fab { display: none; }
  .view { padding: 0 32px; gap: 16px; }
  .card { padding: 20px; }
  .btn:hover:not(:disabled) { border-color: var(--muted); }
  .btn.primary:hover:not(:disabled) { filter: brightness(1.08); }

  /* เมนูด้านข้าง */
  .nav {
    top: 0; bottom: 0; left: 0; transform: none; width: var(--side-w);
    display: flex; flex-direction: column; gap: 4px; padding: 20px 12px 16px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 20px; font-weight: 800; font-size: 1.15rem; }
  .logo-sm {
    width: 40px; height: 40px; border-radius: 12px; background: var(--brand); color: var(--brand-ink);
    display: grid; place-items: center; font-size: 1.4rem; font-weight: 800;
  }
  .nav-item, .nav-lock {
    flex-direction: row; justify-content: flex-start; gap: 14px; min-height: 46px; padding: 0 14px;
    border-radius: 12px; font-size: 1rem; color: var(--muted);
  }
  .nav-item:hover, .nav-lock:hover { background: var(--fill); color: var(--text); }
  .nav-item.active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
  .nav-lock { display: flex; align-items: center; margin-top: auto; border: 0; background: none; text-align: left; }
  .nav-icon { width: 1.6rem; text-align: center; }

  .month-nav { justify-content: flex-start; gap: 4px; }
  .month-title { min-width: 200px; }
  .month-title strong { font-size: 1.25rem; }

  /* หน้าหลัก */
  .cols {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "hero breakdown" "tiles breakdown" "insights breakdown" "inst breakdown";
    grid-template-rows: auto auto auto 1fr; gap: 16px; align-items: start;
  }
  .col { display: contents; }
  .a-hero { grid-area: hero; }
  .a-tiles { grid-area: tiles; }
  .a-insights { grid-area: insights; }
  .a-breakdown { grid-area: breakdown; }
  .a-inst { grid-area: inst; }
  .hero-amount { font-size: 3rem; }

  /* รายการ: ตาราง */
  .list-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
  .list-tiles .stat { background: var(--card); padding: 16px; box-shadow: var(--shadow); }
  .list-tiles .stat-value { font-size: 1.3rem; }
  .toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
  .toolbar .search { max-width: 360px; }
  .tx-head, .tx-row { grid-template-columns: 44px minmax(0, 2.2fr) minmax(0, 1.3fr) 90px 72px 150px; gap: 12px; }
  .tx-head { display: grid; padding: 12px 20px; color: var(--muted); font-size: 0.8rem; font-weight: 600; border-bottom: 1px solid var(--line); }
  .tx-head span:last-child { text-align: right; }
  .tx-row { padding: 12px 20px; }
  .tx-row:hover { background: var(--bg); }
  .tx-sub .badge { justify-self: start; align-self: center; padding: 1px 10px; font-size: 0.75rem; }
  .tx-sub .badge:empty { display: block; background: transparent; padding: 0; }
  .tx-main, .tx-sub { display: contents; }
  .tx-cat, .tx-date { color: var(--muted); font-size: 0.92rem; }
  .tx-date::before { content: none; }
  .tx-amount { text-align: right; font-size: 1.05rem; }

  /* ผ่อน: รายการตามบัตรอยู่ซ้าย, สรุป/ไทม์ไลน์อยู่ขวา */
  .inst-layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-areas: "groups summary" "groups timeline" "groups finished";
    grid-template-rows: auto auto 1fr; gap: 16px; align-items: start;
  }
  .a-groups { grid-area: groups; gap: 16px; }
  .a-summary { grid-area: summary; }
  .a-timeline { grid-area: timeline; }
  .a-finished { grid-area: finished; }

  /* สรุปปี: สรุปคู่กับหมวด, กราฟและตารางเต็มความกว้าง */
  .year-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "nav nav" "summary top" "chart chart"; align-items: start; gap: 16px;
  }
  .year-layout > .month-nav { grid-area: nav; }
  .a-top { grid-area: top; }
  .a-chart { grid-area: chart; }
  .chart .axis { font-size: 11px; }
  .table { font-size: 0.92rem; }
  .table th, .table td { padding: 8px 10px; }

  /* ตั้งค่า */
  .settings-layout {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-areas: "cats backup" "cats security" "cats info";
    grid-template-rows: auto auto 1fr; gap: 16px; align-items: start;
  }
  .a-cats { grid-area: cats; }
  .a-backup { grid-area: backup; }
  .a-security { grid-area: security; }
  .a-info { grid-area: info; }

  /* หน้าต่างกรอกข้อมูล และแจ้งเตือน */
  .sheet { width: min(100%, 600px); }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  #toasts { left: var(--side-w); bottom: 24px; }
}

/* จอใหญ่มาก: ขยายพื้นที่เนื้อหาอีกหน่อย ไม่ปล่อยว่างสองข้าง */
@media (min-width: 1600px) {
  :root { --content-max: 1480px; }
}
