/* rcwd · คณะราชาวดี — calm green ledger. Light theme only. */

:root {
  color-scheme: light;

  --bg: #f3f7f4;
  --surface: #ffffff;
  --surface-2: #f8fbf9;
  --ink: #10231a;
  --ink-2: #2b4237;
  --muted: #6b7f74;
  --line: #dde8e1;
  --line-strong: #c9d9cf;

  --g900: #0b3d27;
  --g700: #146c43;
  --g600: #1a8754;
  --g100: #e3f4ea;
  --g50: #f0faf4;

  --r700: #b42318;
  --r600: #d03a2f;
  --r100: #fde8e6;
  --r50: #fff5f4;

  --amber: #b54708;
  --amber-bg: #fef3e2;
  --amber-line: #f7d9ae;

  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 35, 26, .05);
  --shadow: 0 1px 2px rgba(16, 35, 26, .04), 0 6px 20px -10px rgba(16, 35, 26, .14);
  --shadow-lg: 0 18px 50px -18px rgba(11, 61, 39, .35);
  --focus: 0 0 0 3px rgba(26, 135, 84, .32);

  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Sukhumvit Set', 'Leelawadee UI', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --maxw: 1120px;
  --gutter: 24px;
  --ab-h: 0px;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  min-height: 100vh;
  padding-bottom: calc(var(--ab-h) + 48px);
}

h1, h2, h3 { line-height: 1.35; margin: 0; font-weight: 600; letter-spacing: -.005em; }
p { margin: 0; }
a { color: var(--g700); text-underline-offset: 3px; }
a:hover { color: var(--g900); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { flex: none; }
[hidden] { display: none !important; }

.num, .money, td.c-in, td.c-out, td.c-bal, .tile-value, .stat-value { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .88em; }

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

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--g700); color: #fff; padding: 8px 14px; border-radius: var(--radius-sm);
  text-decoration: none; transition: top .15s;
}
.skip-link:focus { top: 12px; color: #fff; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-xs); }
[tabindex="-1"]:focus { outline: none; box-shadow: none; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding-left: var(--gutter); padding-right: var(--gutter); }

/* ---------- top bar ---------- */

.topbar {
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 68px; }

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand:hover { color: var(--ink); }
.brand-mark { width: 40px; height: 40px; border-radius: 11px; box-shadow: 0 4px 12px -4px rgba(20, 108, 67, .5); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-word { font-weight: 700; font-size: 20px; letter-spacing: .02em; color: var(--g900); }
.brand-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #a9b8b0; }
.pill-on { background: var(--g50); border-color: #bfe3cd; color: var(--g700); }
.pill-on .dot { background: var(--g600); box-shadow: 0 0 0 3px rgba(26, 135, 84, .18); }
.pill-busy .dot { background: var(--g600); animation: pulse 1.2s ease-in-out infinite; }
.pill-err { background: var(--amber-bg); border-color: var(--amber-line); color: var(--amber); }
.pill-err .dot { background: var(--amber); }
.pill:hover { color: inherit; filter: brightness(.98); }

/* ---------- tabs ---------- */

.tabs-wrap { padding-top: 22px; }
.tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  background: #e6efe9; border-radius: 12px; border: 1px solid var(--line);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 7px 16px; border-radius: 9px; text-decoration: none; white-space: nowrap;
  color: var(--ink-2); font-weight: 500; font-size: 14.5px;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tab:hover { color: var(--g900); background: rgba(255, 255, 255, .55); }
.tab[aria-current="page"] { background: var(--surface); color: var(--g700); box-shadow: 0 1px 2px rgba(16, 35, 26, .08), 0 2px 8px -4px rgba(16, 35, 26, .12); }

/* ---------- layout ---------- */

main { padding-top: 20px; outline: none; }
.view { display: flex; flex-direction: column; gap: 18px; }
.view-head { display: flex; flex-direction: column; gap: 4px; padding-top: 4px; }
.view-head-row { flex-direction: row; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.view-title { font-size: 26px; font-weight: 700; color: var(--g900); }
.view-lead { color: var(--muted); max-width: 68ch; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px;
}
.card-title { font-size: 17px; font-weight: 600; margin-bottom: 14px; color: var(--ink); }

.section-title { font-size: 16px; font-weight: 600; color: var(--ink-2); margin: 10px 0 -6px; }
.toolbar .section-title { margin: 0; }

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none; cursor: pointer;
  font-weight: 500; font-size: 14.5px; line-height: 1.3; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: .5; }
.btn-primary { background: var(--g700); color: #fff; box-shadow: 0 1px 2px rgba(11, 61, 39, .25), inset 0 1px 0 rgba(255, 255, 255, .12); }
.btn-primary:hover:not(:disabled) { background: var(--g900); color: #fff; }
.btn-primary:focus-visible { box-shadow: var(--focus); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--g900); }
.btn-secondary:hover:not(:disabled) { border-color: var(--g600); color: var(--g700); background: var(--g50); }
.btn-ghost { color: var(--g700); }
.btn-ghost:hover:not(:disabled) { background: var(--g50); color: var(--g900); }
.btn-danger-ghost { color: var(--r700); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--r50); }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 13.5px; border-radius: 9px; }
.btn-lg { min-height: 46px; padding: 10px 22px; font-size: 15.5px; font-weight: 600; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn-row-end { justify-content: flex-end; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; }

.input, select.input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input::placeholder { color: #9aaba2; }
.input:hover:not(:disabled) { border-color: #b1c6b9; }
.input:focus { outline: none; border-color: var(--g600); box-shadow: var(--focus); }
.input:disabled { background: #f2f5f3; color: var(--muted); cursor: not-allowed; }
select.input {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%236b7f74' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
textarea.input { resize: vertical; min-height: 120px; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label { font-weight: 500; font-size: 14px; color: var(--ink-2); }
.field-help { font-size: 13px; color: var(--muted); }
.input-group { display: flex; gap: 6px; align-items: stretch; }
.input-group .input { flex: 1; min-width: 0; }
.input-addon { flex: none; }

.kbd {
  display: inline-block; padding: 0 7px; border-radius: 6px; font-size: .9em; line-height: 1.6;
  background: var(--g50); border: 1px solid #cfe7d8; color: var(--g900); white-space: nowrap;
}

/* ---------- notices ---------- */

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid; font-size: 14.5px;
}
.notice > svg { margin-top: 3px; }
.notice-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.notice-title { font-weight: 600; }
.notice ul { margin: 2px 0 0; padding-left: 1.1em; }
.notice-warn { background: var(--amber-bg); border-color: var(--amber-line); color: #7a3306; }
.notice-warn a { color: var(--amber); font-weight: 600; }
.notice-error { background: var(--r50); border-color: #f6c9c4; color: var(--r700); }
.notice-ok { background: var(--g50); border-color: #bfe3cd; color: var(--g900); }
.notice-info { background: var(--surface-2); border-color: var(--line); color: var(--ink-2); }

/* ---------- dropzone ---------- */

.dropzone {
  position: relative; display: flex; align-items: center; gap: 18px;
  padding: 34px 28px; border-radius: var(--radius);
  border: 1.5px dashed #a9cfb8; background: linear-gradient(180deg, #fbfefc 0%, var(--g50) 100%);
  cursor: pointer; user-select: none;
  transition: border-color .15s, background .15s, box-shadow .15s, padding .2s;
}
.dropzone:hover { border-color: var(--g600); background: var(--g50); }
.dropzone:focus-visible { border-color: var(--g600); box-shadow: var(--focus); border-radius: var(--radius); }
.dropzone.is-over { border-color: var(--g600); border-style: solid; background: var(--g100); box-shadow: 0 0 0 4px rgba(26, 135, 84, .12); }
.dropzone.is-busy { pointer-events: none; opacity: .7; }
.dz-icon {
  width: 60px; height: 60px; flex: none; border-radius: 16px; display: grid; place-items: center;
  background: var(--surface); color: var(--g700); border: 1px solid #cfe7d8; box-shadow: var(--shadow-sm);
}
.dz-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dz-title { font-size: 18px; font-weight: 600; color: var(--g900); }
.dz-sub { color: var(--ink-2); }
.dz-link { color: var(--g700); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.dz-hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.dropzone.is-compact { padding: 14px 18px; gap: 14px; }
.dropzone.is-compact .dz-icon { width: 42px; height: 42px; border-radius: 12px; }
.dropzone.is-compact .dz-icon svg { width: 22px; height: 22px; }
.dropzone.is-compact .dz-title { font-size: 15.5px; }
.dropzone.is-compact .dz-hint { display: none; }

/* ---------- spinner / parsing ---------- */

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--g100); border-top-color: var(--g600);
  animation: spin .8s linear infinite; flex: none;
}
.parsing { display: flex; align-items: center; gap: 14px; }
.parsing-title { font-weight: 600; }
.parsing-sub { color: var(--muted); font-size: 13.5px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- account card ---------- */

.result { display: flex; flex-direction: column; gap: 16px; animation: rise .25s ease-out; }

.acct { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px 24px; align-items: start; }
.acct-check { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--g700); font-size: 15.5px; }
.acct-check .ico-badge { background: var(--g600); }
.ico-badge {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none;
}
.acct-name { font-size: 18px; font-weight: 600; margin-top: 8px; overflow-wrap: anywhere; }
.acct-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.acct-meta b { color: var(--ink-2); font-weight: 500; }
.acct-file { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }

.acct-sums {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2);
}
.sum { padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sum + .sum { border-left: 1px solid var(--line); }
.sum-label { font-size: 12.5px; color: var(--muted); }
.sum-value { font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum-sub { font-size: 12px; color: var(--muted); }
.sum-in .sum-value { color: var(--g700); }
.sum-out .sum-value { color: var(--r700); }

.acct-bad { border-color: #f3b7b0; background: linear-gradient(180deg, #fff 0%, var(--r50) 100%); }
.acct-bad .acct-check { color: var(--r700); font-size: 18px; }
.acct-bad .ico-badge { background: var(--r600); }
.compare { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-top: 14px; font-size: 15px; }
.compare dt { color: var(--muted); }
.compare dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.compare .is-bad { color: var(--r700); }
.compare .is-good { color: var(--g700); }

/* ---------- stat tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tile-label .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.tile-value { font-size: 26px; font-weight: 600; line-height: 1.25; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { font-size: 12.5px; color: var(--muted); }
.tile-ok .dot { background: var(--g600); }
.tile-todo .dot { background: var(--amber); }
.tile-todo.is-active { background: var(--amber-bg); border-color: var(--amber-line); }
.tile-todo.is-active .tile-value { color: var(--amber); }
.tile-skip .dot { background: #9aaba2; }
.tile-in .tile-value { color: var(--g700); }
.tile-out .tile-value { color: var(--r700); }
.tile-money .tile-value { font-size: 22px; }

/* ---------- toolbar / chips ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px;
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-2); font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--g600); color: var(--g700); }
.chip[aria-pressed="true"] { background: var(--g700); border-color: var(--g700); color: #fff; }
.chip-count {
  min-width: 20px; padding: 0 6px; border-radius: 999px; font-size: 12px; line-height: 18px; text-align: center;
  background: var(--g50); color: var(--g700); font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] .chip-count { background: rgba(255, 255, 255, .2); color: #fff; }
.chip-todo .chip-count { background: var(--amber-bg); color: var(--amber); }

.search { position: relative; flex: 1 1 260px; max-width: 360px; }
.search .input { padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

/* ---------- ledger-style table ---------- */

.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.ltable { width: 100%; min-width: 700px; border-collapse: separate; border-spacing: 0; font-size: 14.5px; }
.ledger-table { min-width: 600px; }
.ltable th, .ltable td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.ltable thead th {
  background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 600;
  letter-spacing: .01em; white-space: nowrap; padding-top: 11px; padding-bottom: 11px;
}
.ltable .c-in, .ltable .c-out, .ltable .c-bal { text-align: right; white-space: nowrap; }
.ltable th.c-in, .ltable th.c-out, .ltable th.c-bal { text-align: right; }
.ltable .c-date { width: 104px; white-space: nowrap; }
.ltable .c-in, .ltable .c-out { width: 112px; }
.ltable .c-bal { width: 120px; }
.ltable .c-note { width: 17%; }
.ltable .c-status { width: 150px; }
.ltable tbody tr:last-child > td { border-bottom: 0; }

.month-band > th {
  background: #eaf2ed; color: var(--g900); font-weight: 600; font-size: 13.5px;
  padding: 7px 14px; border-bottom: 1px solid var(--line); letter-spacing: .01em;
}
.month-band .month-count { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12.5px; }

.date-main { font-weight: 500; font-variant-numeric: tabular-nums; }
.date-time { display: block; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* direction colouring — mirrors the sheet's green/red รายการ cells */
tr.dir-in > td { background: var(--g50); }
tr.dir-out > td { background: var(--r50); }
tr.dir-in > td:first-child { box-shadow: inset 4px 0 0 var(--g600); }
tr.dir-out > td:first-child { box-shadow: inset 4px 0 0 var(--r600); }
tr.tx.has-form > td { border-bottom-color: transparent; }
td.c-in .amt { color: var(--g700); font-weight: 600; }
td.c-out .amt { color: var(--r700); font-weight: 600; }
.c-bal { color: var(--ink-2); }

.desc { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; overflow-wrap: anywhere; }
.prefix {
  display: inline-flex; align-items: center; padding: 1px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; line-height: 1.6; white-space: nowrap; flex: none;
}
.prefix-in { background: #cdebd8; color: var(--g900); }
.prefix-out { background: #f8cfca; color: #7f1810; }
.desc-text { min-width: 0; }
.desc-empty { color: var(--amber); font-style: normal; font-weight: 500; }
.bankline { font-size: 12.5px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.desc + .bankline { margin-top: 2px; }
.note { color: var(--ink-2); font-size: 13.5px; overflow-wrap: anywhere; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap; line-height: 1.6; border: 1px solid transparent;
}
.badge svg { width: 13px; height: 13px; }
.badge-ok { background: var(--surface); color: var(--g700); border-color: #bfe3cd; }
.badge-add { background: var(--g700); color: #fff; }
.badge-skip { background: #eef2ef; color: #55675d; border-color: var(--line); }
.badge-todo { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-line); }
.badge-near { background: #fff8eb; color: var(--amber); border-color: var(--amber-line); border-style: dashed; }

/* skipped rows fade back */
tr.is-skipped > td { background: #f6f8f7; }
tr.is-skipped > td:first-child { box-shadow: inset 4px 0 0 #c3cfc8; }
tr.is-skipped .amt, tr.is-skipped .desc-text { color: var(--muted); }
tr.is-skipped .prefix { opacity: .55; }

/* inline form row */
tr.form-row > td { padding-top: 0; padding-bottom: 14px; }
.txform {
  display: flex; flex-direction: column; gap: 10px;
  background: rgba(255, 255, 255, .78); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px;
}
tr.dir-in .txform { border-color: #c9e7d4; }
tr.dir-out .txform { border-color: #f3d0cb; }
tr.needs-input .txform { border-color: var(--amber-line); box-shadow: 0 0 0 3px rgba(181, 71, 8, .06); }
.txform-grid { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.3fr) minmax(0, 1.1fr) auto; gap: 10px 12px; align-items: end; }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld-label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.fld-label .req { color: var(--amber); }
.fld .input { min-height: 38px; padding: 6px 10px; font-size: 14.5px; }
.desc-input { display: flex; align-items: stretch; min-width: 0; }
.desc-input .prefix {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); padding: 0 10px; font-size: 13px;
  border: 1px solid var(--line-strong); border-right: 0;
}
.desc-input .prefix-in { border-color: #a9d6ba; }
.desc-input .prefix-out { border-color: #efb3ab; }
.desc-input .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; flex: 1; min-width: 0; }
tr.needs-input .desc-input .input:not(:focus) { border-color: #e9b56e; background: #fffdf8; }
.txform .bankline { display: flex; flex-wrap: wrap; gap: 2px 6px; }
.bank-tag { font-weight: 500; color: var(--ink-2); }
.txform-foot { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: space-between; }
.suggest { font-size: 12.5px; color: var(--amber); display: inline-flex; gap: 6px; align-items: center; }
/* a skipped row collapses to the switch + bank line; un-skipping brings the fields back */
.txform.is-skipped { background: transparent; border-style: dashed; padding-top: 6px; padding-bottom: 8px; gap: 4px; }
.txform.is-skipped .fld { display: none; }
.txform.is-skipped .suggest { color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--ink-2); white-space: nowrap; min-height: 38px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; width: 36px; height: 21px; border-radius: 999px; background: #cfdad3; flex: none;
  transition: background .15s;
}
.switch-track::after {
  content: ''; position: absolute; top: 2.5px; left: 2.5px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .15s;
}
.switch input:checked + .switch-track { background: #6b7f74; }
.switch input:checked + .switch-track::after { transform: translateX(15px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }

.near-box { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; justify-content: space-between; }
.near-text { font-size: 14px; color: var(--ink-2); min-width: 0; overflow-wrap: anywhere; }
.near-text b { color: var(--amber); font-weight: 600; }
.undo { font-size: 12.5px; padding: 0; min-height: 0; border: 0; background: none; color: var(--g700); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty-title { color: var(--ink); font-weight: 600; font-size: 16px; margin-bottom: 4px; }

/* ---------- success ---------- */

.success {
  display: flex; gap: 16px; align-items: flex-start;
  border-color: #a9d6ba; background: linear-gradient(180deg, #fff 0%, var(--g50) 100%);
}
.success .ico-badge { width: 40px; height: 40px; background: var(--g600); }
.success-title { font-size: 18px; font-weight: 700; color: var(--g900); }
.success-sub { color: var(--ink-2); margin: 2px 0 10px; }

/* ---------- action bar ---------- */

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px -18px rgba(11, 61, 39, .35);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise .2s ease-out;
}
.actionbar-inner { display: flex; align-items: center; gap: 18px; padding-top: 12px; padding-bottom: 12px; }
.actionbar-progress { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.actionbar-text { display: flex; flex-wrap: wrap; gap: 2px 12px; align-items: baseline; }
.ab-text { font-weight: 600; }
.ab-text.is-todo { color: var(--amber); }
.ab-text.is-ready { color: var(--g700); }
.ab-sub { font-size: 13px; color: var(--muted); }
.progress { height: 6px; border-radius: 999px; background: #e3ebe6; overflow: hidden; }
.progress-bar { display: block; height: 100%; width: 0; background: var(--g600); border-radius: 999px; transition: width .3s ease; }
.progress.is-over .progress-bar, .progress-bar.is-over { background: var(--r600); }

/* ---------- ledger view ---------- */

.tiles-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.cat { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-sm); }
.cat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cat-name { font-weight: 600; overflow-wrap: anywhere; }
.cat-budget { font-size: 12.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cat-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; font-size: 13px; }
.cat-nums dt { color: var(--muted); }
.cat-nums dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.cat-left { color: var(--g700); }
.cat.is-over { border-color: #f3b7b0; background: var(--r50); }
.cat.is-over .cat-left { color: var(--r700); }
.cat-over-tag { font-size: 12px; color: var(--r700); font-weight: 600; }

/* ---------- settings ---------- */

.settings-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
.settings-card { position: sticky; top: 88px; }
.settings-result:empty { display: none; }
.settings-result { margin-top: 16px; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 16px; }
.steps > li { counter-increment: step; position: relative; padding-left: 44px; min-height: 30px; }
.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: -1px;
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--g100); color: var(--g700); font-weight: 700; font-size: 14px;
}
.substeps { margin: 6px 0 0; padding-left: 1.1em; color: var(--ink-2); }
.substeps li { margin: 2px 0; }
.step-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.code-fallback { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.guide-note { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; font-size: 13.5px; margin-top: 6px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- dialog ---------- */

.dialog {
  border: 0; padding: 0; border-radius: 18px; width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); overflow: auto; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(11, 30, 20, .42); backdrop-filter: blur(2px); }
.dialog[open] { animation: rise .18s ease-out; }
.dialog-body { padding: 22px 22px 18px; display: flex; flex-direction: column; gap: 14px; }
.dialog-title { font-size: 20px; font-weight: 700; color: var(--g900); }
.confirm-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.confirm-stat { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; background: var(--surface-2); }
.confirm-stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.confirm-stat span { font-size: 12.5px; color: var(--muted); }
.confirm-stat.is-add b { color: var(--g700); }
.confirm-list { margin: 0; padding: 0; list-style: none; max-height: 34vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.confirm-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; padding: 7px 12px; font-size: 13.5px; border-bottom: 1px solid var(--line); align-items: baseline; }
.confirm-list li:last-child { border-bottom: 0; }
.confirm-list li.dir-in { background: var(--g50); }
.confirm-list li.dir-out { background: var(--r50); }
.confirm-list .cl-date { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.confirm-list .cl-desc { overflow-wrap: anywhere; }
.confirm-list .cl-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.confirm-list .dir-in .cl-amt { color: var(--g700); }
.confirm-list .dir-out .cl-amt { color: var(--r700); }

/* ---------- toasts ---------- */

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--ab-h) + 16px); z-index: 60;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: min(480px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto; background: var(--g900); color: #fff; padding: 10px 16px; border-radius: 12px;
  box-shadow: var(--shadow-lg); font-size: 14.5px; animation: rise .2s ease-out; max-width: 100%;
}
.toast-error { background: var(--r700); }

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .ltable .c-in, .ltable .c-out { width: 96px; }
  .ltable .c-bal { width: 100px; }
  .ltable .c-status { width: 128px; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-card { position: static; }
  .txform-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .txform-grid .fld-desc { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  :root { --gutter: 16px; }
  body { font-size: 15px; }
  .topbar-inner { min-height: 60px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-word { font-size: 18px; }
  .sheet-link span { display: none; }
  .sheet-link { padding: 5px 9px; }
  .tabs-wrap { padding-top: 14px; }
  .tabs { display: flex; width: 100%; }
  .tab { flex: 1; text-align: center; padding: 7px 8px; font-size: 14px; }
  .view-title { font-size: 22px; }
  .card { padding: 16px; }
  .dropzone { padding: 22px 18px; gap: 14px; }
  .dz-icon { width: 48px; height: 48px; border-radius: 13px; }
  .dz-title { font-size: 16px; }

  .acct { grid-template-columns: minmax(0, 1fr); }
  .acct-sums { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sum:nth-child(3) { border-left: 0; }
  .sum:nth-child(n+3) { border-top: 1px solid var(--line); }
  .tiles, .tiles-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tiles-3 .tile:first-child { grid-column: 1 / -1; }
  .tile-value { font-size: 22px; }
  .tile-money .tile-value { font-size: 18px; }
  .search { max-width: none; flex-basis: 100%; }

  /* table → stacked cards */
  .table-card { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .table-scroll { overflow: visible; }
  .ltable, .ltable tbody { display: block; min-width: 0; }
  .ltable thead { display: none; }
  .ltable tr { display: block; }
  .month-band { margin: 18px 2px 8px; }
  .month-band:first-child { margin-top: 0; }
  .month-band > th { display: block; background: none; border: 0; padding: 0; font-size: 14.5px; }

  .ltable tr.tx {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "date status" "desc desc" "amt bal" "note note";
    gap: 4px 12px; padding: 12px 14px 12px 16px; margin-top: 10px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
  }
  .month-band + tr.tx { margin-top: 0; }
  .ltable tr.tx > td { display: block; padding: 0; border: 0; background: none !important; box-shadow: none !important; width: auto; text-align: left; }
  .ltable tr.tx.dir-in { background: var(--g50); border-color: #cfe7d8; box-shadow: inset 4px 0 0 var(--g600); }
  .ltable tr.tx.dir-out { background: var(--r50); border-color: #f4d3cf; box-shadow: inset 4px 0 0 var(--r600); }
  .ltable tr.tx.is-skipped { background: #f6f8f7; border-color: var(--line); box-shadow: inset 4px 0 0 #c3cfc8; }
  .ltable td.c-date { grid-area: date; display: flex !important; gap: 8px; align-items: baseline; }
  .ltable td.c-date .date-time { display: inline; }
  .ltable td.c-status { grid-area: status; justify-self: end; }
  .ltable td.c-desc { grid-area: desc; }
  .ltable td.c-in, .ltable td.c-out { grid-area: amt; }
  .ltable td.c-in .amt, .ltable td.c-out .amt { font-size: 18px; }
  .ltable td.c-in .amt::before { content: '+'; }
  .ltable td.c-out .amt::before { content: '−'; }
  .ltable td.is-empty { display: none !important; }
  .ltable td.c-bal { grid-area: bal; align-self: end; text-align: right; font-size: 12.5px; color: var(--muted); }
  .ltable td.c-bal:not(:empty)::before { content: 'คงเหลือ '; }
  .ltable td.c-note { grid-area: note; }
  .ltable td.c-note:empty { display: none !important; }

  .ltable tr.tx.has-form { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom-color: transparent; }
  .ltable tr.form-row {
    margin-top: -1px; padding: 0 12px 12px 16px;
    border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius);
  }
  .ltable tr.form-row.dir-in { background: var(--g50); border-color: #cfe7d8; box-shadow: inset 4px 0 0 var(--g600); }
  .ltable tr.form-row.dir-out { background: var(--r50); border-color: #f4d3cf; box-shadow: inset 4px 0 0 var(--r600); }
  .ltable tr.form-row.is-skipped { background: #f6f8f7; border-color: var(--line); box-shadow: inset 4px 0 0 #c3cfc8; }
  .ltable tr.form-row > td { display: block; padding: 0; border: 0; background: none !important; box-shadow: none !important; }
  .txform { padding: 10px 12px; }
  .txform-grid { gap: 8px 10px; }
  .txform-grid .switch { grid-column: 1 / -1; justify-self: start; min-height: 32px; }
  .input, select.input, .fld .input { font-size: 16px; }   /* ≥16px stops iOS zoom-on-focus */
  .ab-sub:not(.is-blocker) { display: none; }
  .actionbar-inner { padding-top: 10px; padding-bottom: 10px; gap: 8px; }

  .actionbar-inner { flex-direction: column; align-items: stretch; gap: 10px; }
  .actionbar .btn-lg { width: 100%; }
  .confirm-stats { gap: 6px; }
  .confirm-stat b { font-size: 19px; }
}

@media (max-width: 400px) {
  .brand-sub { font-size: 11.5px; }
  .pill { padding: 4px 10px 4px 8px; font-size: 12px; }
  .pill .pill-text { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
  .tab { font-size: 13px; padding: 7px 4px; }
  .dz-icon { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}

@media print {
  .topbar, .tabs-wrap, .dropzone, .actionbar, .toasts, .txform { display: none !important; }
  body { background: #fff; padding: 0; }
}

.balance-check { margin-top: 12px; font-size: 14px; }
.success .balance-check { margin: 4px 0 12px; }

/* ---------- login page ---------- */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card { display: flex; flex-direction: column; gap: 16px; padding: 28px 24px; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.login-title { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; color: var(--g900, #0b3d27); line-height: 1.1; }
.login-sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.login-card .field { margin: 0; }
.login-btn { width: 100%; justify-content: center; margin-top: 4px; }
.logout-link { white-space: nowrap; }
