:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --soft: #64748b;
  --line: #e2e8f0;
  --accent: #047857;
  --accent-bg: #ecfdf5;
  --warn: #92400e;
  --warn-bg: #fffbeb;
  --warn-line: #fcd34d;
  --tip-line: #a7f3d0;
  --in: #047857;
  --out: #be123c;
  --line-green: #06c755;
  --chat-bg: #8cabd9;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --card: #111a2b;
    --text: #e2e8f0;
    --muted: #a3b1c6;
    --soft: #8a9ab0;
    --line: #1e293b;
    --accent: #34d399;
    --accent-bg: #052e22;
    --warn: #fcd34d;
    --warn-bg: #2a2110;
    --warn-line: #78590f;
    --tip-line: #065f46;
    --in: #34d399;
    --out: #fb7185;
    --chat-bg: #3b4a63;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.75 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
}
a { color: var(--accent); }
img { max-width: 100%; height: auto; }

.top { max-width: 1120px; margin: 0 auto; padding: 20px 16px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 20px; color: var(--text); text-decoration: none; }
.top nav { display: flex; gap: 14px; font-size: 14px; flex-wrap: wrap; }

.layout { max-width: 1120px; margin: 16px auto 0; padding: 0 16px 48px; display: grid; grid-template-columns: 1fr; gap: 24px; }
@media (min-width: 960px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); align-items: start; }
  .toc { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
}

.toc { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; font-size: 14px; }
.toc summary { font-weight: 700; cursor: pointer; padding: 4px 0; }
.toc ol { list-style: none; margin: 6px 0 0; padding: 0; }
.toc li { margin: 0; }
.toc .part { margin-top: 10px; font-size: 12px; font-weight: 700; color: var(--soft); text-transform: none; }
.toc a { display: block; padding: 4px 8px; border-radius: 8px; color: var(--muted); text-decoration: none; line-height: 1.45; }
.toc a:hover { background: var(--bg); color: var(--text); }

main { min-width: 0; }
.hero, section.ch { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin-bottom: 16px; }
@media (min-width: 640px) { .hero, section.ch { padding: 28px; } }
.hero h1 { font-size: 28px; line-height: 1.3; margin: 0 0 6px; }
.hero p { margin: 0 0 10px; color: var(--muted); }
.who { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
@media (min-width: 640px) { .who { grid-template-columns: 1fr 1fr; } }
.who a { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-decoration: none; color: var(--text); }
.who a:hover { border-color: var(--accent); }
.who strong { display: block; }
.who span { font-size: 14px; color: var(--muted); }

.part-title { font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: .02em; margin: 28px 4px 8px; }
h2 { font-size: 22px; line-height: 1.35; margin: 0 0 6px; }
h2 .num { color: var(--accent); margin-right: 6px; }
h3 { font-size: 17px; margin: 22px 0 6px; }
.lead { color: var(--muted); margin: 0 0 12px; }
ol.steps { counter-reset: step; list-style: none; padding: 0; margin: 10px 0; }
ol.steps > li { counter-increment: step; position: relative; padding-left: 40px; margin: 10px 0; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 1px; width: 28px; height: 28px; border-radius: 999px;
  background: var(--accent-bg); color: var(--accent); font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center;
}
ul { padding-left: 22px; }
li { margin: 4px 0; }
.ui { font-weight: 600; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; white-space: nowrap; }
kbd { font: 600 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
.in { color: var(--in); font-weight: 700; }
.out { color: var(--out); font-weight: 700; }

.note, .tip { border-radius: 12px; padding: 12px 14px; margin: 14px 0; font-size: 15px; border: 1px solid; }
.note { background: var(--warn-bg); border-color: var(--warn-line); color: var(--text); }
.note strong:first-child { color: var(--warn); }
.tip { background: var(--accent-bg); border-color: var(--tip-line); }
.tip strong:first-child { color: var(--accent); }

figure { margin: 16px 0; }
figure img { display: block; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
figure.phone img { max-width: 300px; border-radius: 20px; }
figure.phones { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
figure.phones img { max-width: 260px; border-radius: 20px; }
figure.phones div { flex: 0 1 260px; }
figcaption { font-size: 13px; color: var(--soft); margin-top: 6px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 10px 0; display: block; overflow-x: auto; }
th, td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
th { background: var(--bg); white-space: nowrap; }

/* LINE chat illustration */
.chat { background: var(--chat-bg); border-radius: 16px; padding: 14px; max-width: 360px; font-size: 14px; line-height: 1.5; }
.chat .me { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.chat .me span { background: #a6e785; color: #111; padding: 8px 12px; border-radius: 16px 16px 4px 16px; }
.chat .photo { width: 120px; height: 150px; border-radius: 12px; background: repeating-linear-gradient(0deg, #f5f5f5 0 9px, #e5e7eb 9px 10px); border: 3px solid #fff; display: flex; align-items: center; justify-content: center; color: #64748b; font-size: 12px; }
.flex { background: #fff; color: #0f172a; border-radius: 16px; overflow: hidden; max-width: 270px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.flex .body { padding: 14px 16px 10px; }
.flex .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.flex .ok { color: #047857; font-weight: 700; font-size: 13px; }
.flex .tag-in { color: #047857; font-weight: 700; font-size: 12px; }
.flex .tag-out { color: #be123c; font-weight: 700; font-size: 12px; }
.flex .name { font-weight: 700; margin-top: 8px; }
.flex .amount { font-weight: 800; font-size: 22px; }
.flex .meta { color: #64748b; font-size: 12px; }
.flex .small { color: #94a3b8; font-size: 11px; margin-top: 10px; }
.flex .foot { border-top: 1px solid #f1f5f9; padding: 8px 12px 10px; display: grid; gap: 6px; }
.flex .btn2 { background: #f1f5f9; border-radius: 8px; text-align: center; padding: 6px; font-weight: 600; font-size: 13px; }
.flex .link { color: #2563eb; text-align: center; font-weight: 600; font-size: 13px; }

/* Google Sheets illustration */
.sheet { font: 13px/1.4 Arial, sans-serif; border: 1px solid #cbd5e1; border-radius: 8px; overflow-x: auto; background: #fff; color: #111; }
.sheet table { margin: 0; font-size: 13px; display: table; min-width: 640px; }
.sheet th, .sheet td { border: 1px solid #e2e8f0; padding: 4px 8px; white-space: nowrap; }
.sheet thead th { background: #04785a; color: #fff; font-weight: 700; }
.sheet .colhead th { background: #f1f5f9; color: #475569; font-weight: 400; text-align: center; }
.sheet .dup td { background: #fee2e2; }
.sheet .warn td { background: #fef3c7; }
.sheet .del td { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }
.sheet .num { text-align: right; }

footer { max-width: 1120px; margin: 0 auto; padding: 0 16px 32px; color: var(--soft); font-size: 13px; }
.back { display: inline-block; margin-top: 10px; font-size: 14px; }
figure img.narrow { max-width: min(420px, 100%); }
