/* slipbook · โทนสมุดบัญชีธนาคาร: กระดาษเขียวเทา หมึกน้ำเงิน ตราประทับสถานะ */
:root {
  --bg: #e6ece7;
  --paper: #f7f9f6;
  --ink: #1b2a4a;
  --muted: #56667a;
  --rule: #c5d1c8;
  --rule-soft: #dbe3dd;
  --primary: #1f4e8c;
  --primary-ink: #ffffff;
  --ok: #2f6b4f;
  --warn: #8a5a00;
  --bad: #a12a22;
  --focus: #1f4e8c;
  --radius: 10px;
  --font: "Sukhumvit Set", "Noto Sans Thai", "Noto Sans Thai UI", "Leelawadee UI", "Thonburi", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121a17; --paper: #1a2420; --ink: #e3ebe6; --muted: #9aaba3; --rule: #34463f; --rule-soft: #26332e;
    --primary: #8db4ec; --primary-ink: #0d1a2c; --ok: #82c7a3; --warn: #e3b55c; --bad: #f08c82; --focus: #8db4ec;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121a17; --paper: #1a2420; --ink: #e3ebe6; --muted: #9aaba3; --rule: #34463f; --rule-soft: #26332e;
  --primary: #8db4ec; --primary-ink: #0d1a2c; --ok: #82c7a3; --warn: #e3b55c; --bad: #f08c82; --focus: #8db4ec;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0; }
a { color: var(--primary); }
.num, .amt { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* โครงหน้า */
.shell { min-height: 100vh; }
main { max-width: 760px; margin: 0 auto; padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); outline: none; }
.nav { position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; display: flex; background: var(--paper); border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom); }
.nav .brand { display: none; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; justify-content: center; font-size: 12px; color: var(--muted); text-decoration: none; position: relative; }
.nav a .ico { font-size: 20px; line-height: 1; }
.nav a[aria-current="page"] { color: var(--primary); font-weight: 700; }
.nav a[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; background: var(--primary); border-radius: 0 0 3px 3px; }
.count { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; line-height: 20px; text-align: center; font-weight: 700; }
@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 220px 1fr; }
  .nav { position: sticky; top: 0; height: 100vh; flex-direction: column; border-top: 0; border-right: 1px solid var(--rule); padding: 20px 12px; gap: 4px; }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 0 12px 16px; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 44px; padding: 0 12px; font-size: 16px; border-radius: 8px; }
  .nav a[aria-current="page"] { background: var(--rule-soft); }
  .nav a[aria-current="page"]::before { display: none; }
  .count { position: static; margin-left: auto; }
  main { padding: 32px 32px 64px; }
}

/* ส่วนประกอบ */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.sheet { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.sheet > h2 { margin-bottom: 10px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

button, .btn { font: inherit; min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
button:hover, .btn:hover { border-color: var(--muted); }
.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
.primary:hover { filter: brightness(1.08); border-color: var(--primary); }
.danger { color: var(--bad); border-color: currentColor; }
.ghost { border-color: transparent; background: transparent; color: var(--primary); }
button:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: 14px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--rule); border-radius: 8px; min-height: 44px; padding: 8px 10px; width: 100%; }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 4px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid .wide { grid-column: 1 / -1; }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-size: 16px; }
.check input { margin-top: 2px; flex: none; }
.field.low input, .field.low select { border-color: var(--warn); border-width: 2px; background: color-mix(in srgb, var(--warn) 8%, var(--bg)); }
.hint { font-size: 13px; color: var(--warn); }

/* ตัวเลขสรุป */
.figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.figure .label { font-size: 14px; color: var(--muted); }
.figure .amt { font-size: 22px; font-weight: 700; }
@media (max-width: 480px) { .figures { grid-template-columns: 1fr 1fr; } .figure:first-child { grid-column: 1 / -1; } .figure:first-child .amt { font-size: 30px; } }

.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-width: 56px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* บรรทัดสมุดบัญชี — จุดเด่นของหน้าตา */
.ledger { width: 100%; border-collapse: collapse; }
.ledger th { font-size: 13px; font-weight: 600; color: var(--muted); text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--ink); }
.ledger td { padding: 10px 8px; border-bottom: 1px dashed var(--rule); vertical-align: top; }
.ledger .amt { text-align: right; white-space: nowrap; }
.ledger th.amt { text-align: right; }
.ledger .out { color: var(--ink); }
.ledger .in { color: var(--ok); }
.ledger .xfer { color: var(--muted); }
.ledger .date { white-space: nowrap; color: var(--muted); font-size: 14px; }
.ledger .who { font-weight: 600; }
.ledger .meta { font-size: 13px; color: var(--muted); }
.ledger tr.total td { border-bottom: 0; border-top: 2px solid var(--ink); font-weight: 700; }

/* ตราประทับสถานะ */
.stamp { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px 1px; border: 2px solid currentColor; border-radius: 4px; transform: rotate(-3deg); white-space: nowrap; line-height: 1.9; }
.stamp.ok { color: var(--ok); }
.stamp.warn { color: var(--warn); }
.stamp.bad { color: var(--bad); }
.stamp.plain { color: var(--muted); transform: none; border-style: dashed; }

/* การ์ดใน Inbox */
.slip { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.slip header { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px dashed var(--rule); align-items: center; flex-wrap: wrap; }
.slip header .amt { font-size: 22px; font-weight: 700; }
.slip .body { display: grid; grid-template-columns: 120px 1fr; gap: 16px; padding: 16px; }
.slip .body.noimg { grid-template-columns: 1fr; }
.slip .thumb { width: 120px; border-radius: 6px; border: 1px solid var(--rule); background: var(--bg); min-height: 80px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; text-align: center; overflow: hidden; }
.slip .thumb img { width: 100%; display: block; }
.slip footer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px dashed var(--rule); flex-wrap: wrap; }
@media (max-width: 560px) { .slip .body { grid-template-columns: 1fr; } .slip .thumb { width: 100%; max-height: 160px; } .grid { grid-template-columns: 1fr; } }
.note { border-left: 4px solid var(--rule); padding: 8px 12px; background: var(--bg); border-radius: 0 8px 8px 0; }
.note.warn { border-color: var(--warn); }
.note.bad { border-color: var(--bad); }
.note.ok { border-color: var(--ok); }
.note ul { margin: 4px 0 0; padding-left: 20px; font-size: 14px; color: var(--muted); }

.drop { border: 2px dashed var(--rule); border-radius: var(--radius); padding: 24px 16px; text-align: center; background: var(--paper); }
.drop.over { border-color: var(--primary); }
.drop input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.progress { font-size: 14px; color: var(--muted); margin-top: 8px; min-height: 22px; }

/* รายการที่จะออก */
.due { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--rule); }
.due:last-child { border-bottom: 0; }
.due .day { text-align: center; line-height: 1.1; border: 1px solid var(--rule); border-radius: 8px; padding: 6px 0; background: var(--bg); }
.due .day b { display: block; font-size: 20px; }
.due .day span { font-size: 12px; color: var(--muted); }
.due .amt { font-weight: 700; text-align: right; }
.due.est .amt { color: var(--muted); }
.due.over .day { border-color: var(--bad); color: var(--bad); }

.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; font-size: 14px; }
.bar .track { grid-column: 1 / -1; height: 8px; background: var(--rule-soft); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--primary); border-radius: 4px; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 6px; }
.empty .row { justify-content: center; margin-top: 16px; }

#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
@media (min-width: 900px) { #toast { bottom: 24px; } }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.card-title { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
@media print { .nav, #toast, button { display: none !important; } body { background: #fff; } }
.ghost.danger { color: var(--bad); }
