:root {
  --bg: #f6f7f5; --card: #ffffff; --ink: #17201d; --mute: #66736e; --line: #e2e6e3;
  --accent: #0f766e; --accent-ink: #ffffff; --gap: #fff7e6; --gap-line: #e9b949; --danger: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615; --card: #1a2120; --ink: #e9efec; --mute: #93a19b; --line: #2a3432;
    --accent: #2dd4bf; --accent-ink: #06201c; --gap: #2a2412; --gap-line: #a37b1a; --danger: #f97066;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Noto Sans Thai", "Sarabun", sans-serif;
  max-width: 480px; margin: 0 auto; min-height: 100vh;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.top { display: flex; align-items: baseline; justify-content: space-between; padding: 18px 0 8px; }
.top h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
.sync { font-size: 12px; color: var(--mute); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; }

section { margin: 14px 0; }
h2 { font-size: 13px; font-weight: 600; color: var(--mute); margin: 0 0 8px; }
.note { background: var(--gap); border: 1px solid var(--gap-line); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 8px 0 0; }
.empty { color: var(--mute); text-align: center; padding: 24px 0; margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 99px; padding: 8px 14px; min-height: 40px; }
.chip::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--mute)); margin-right: 7px; }
.chip.on { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); font-weight: 600; }
.chip.ghost::before { display: none; }
.chip.ghost { border-style: dashed; font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
label { display: block; font-size: 13px; color: var(--mute); margin-bottom: 12px; }
label:last-child { margin-bottom: 0; }
input[type=text], input[type=date], input[type=time] {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; min-height: 44px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--ink);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#f-amount { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; }
.row label { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.primary, .danger, .plain { display: block; width: 100%; border-radius: 12px; padding: 14px; margin-top: 10px; border: 0; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 17px; }
.danger { background: none; border: 1px solid var(--danger); color: var(--danger); }
.plain { background: none; color: var(--mute); text-decoration: underline; }

.datenav { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.datenav span { font-weight: 600; }
.datenav button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 22px; line-height: 1; }
.datenav button:disabled { opacity: .35; cursor: default; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.stats b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--mute); }

.ev, .gap { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; }
.ev { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--c); }
.gap { background: var(--gap); border: 1.5px dashed var(--gap-line); }
.time { font-size: 12px; color: var(--mute); font-variant-numeric: tabular-nums; line-height: 1.35; width: 40px; flex: none; }
.body { flex: 1; min-width: 0; }
.body b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.body small { display: block; color: var(--mute); font-size: 12px; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-top: 6px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px; min-height: 40px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.rangelabel { text-align: center; color: var(--mute); font-size: 14px; margin: 10px 0 0; }
.sum { margin-bottom: 14px; }
.sumhead { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 5px; }
.sumhead span { color: var(--mute); font-variant-numeric: tabular-nums; text-align: right; }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-bottom: 3px; }
.bar i { display: block; height: 100%; background: var(--c); border-radius: 99px; }
.bar.money { height: 4px; }
.bar.money i { background: var(--mute); }
.legend { font-size: 12px; color: var(--mute); margin: 0; }
.legend .k { display: inline-block; width: 16px; border-radius: 99px; vertical-align: middle; margin: 0 4px 0 8px; }
.legend .k.t { height: 8px; background: var(--accent); margin-left: 0; }
.legend .k.m { height: 4px; background: var(--mute); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; max-width: 160px; border: 0; background: none; padding: 8px 0 10px; font-size: 12px; color: var(--mute); }
.tabs .ico { display: block; font-size: 20px; line-height: 1.2; }
.tabs button.on { color: var(--accent); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 99px; font-size: 14px; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ตัวเลือกช่วงเวลาแบบตารางวัน */
.pickhint { font-size: 12px; color: var(--mute); margin: 12px 0 6px; }
.picker { height: 300px; margin-bottom: 12px; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.grid { position: relative; user-select: none; -webkit-user-select: none; }
.hr { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--line); }
.hr span { position: absolute; left: 8px; top: 2px; font-size: 11px; color: var(--mute); font-variant-numeric: tabular-nums; }
.pev { position: absolute; left: 52px; right: 8px; pointer-events: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  background: color-mix(in srgb, var(--c) 20%, var(--card)); border-left: 3px solid var(--c); border-radius: 6px; font-size: 11px; line-height: 14px; padding: 0 6px; }
.sel { position: absolute; left: 52px; right: 8px; z-index: 2; touch-action: none; cursor: grab;
  background: color-mix(in srgb, var(--accent) 26%, transparent); border: 2px solid var(--accent); border-radius: 8px;
  font-size: 12px; font-weight: 600; line-height: 14px; padding: 0 8px; white-space: nowrap; }
.sel .h { position: absolute; left: 0; right: 0; height: 24px; touch-action: none; cursor: ns-resize; }
.sel .h[data-h=top] { top: -13px; } .sel .h[data-h=bot] { bottom: -13px; }
.sel .h::after { content: ""; position: absolute; left: 50%; top: 50%; width: 30px; height: 6px; margin: -3px 0 0 -15px; border-radius: 99px; background: var(--accent); }

/* ป้ายสถานะเป็นปุ่มเชื่อม Google */
.sync { background: none; min-height: 28px; }
.sync.google { color: var(--accent); border-color: var(--accent); }
.sync.google-off { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; padding: 4px 12px; }
.sync.busy { opacity: .7; }
