/* styles.css — mobile-first · โทนเดียวกับแบบหน้าจอใน showcase/ (ขาว-slate ไอคอนเส้น ไม่ใช้ emoji) */
:root {
  --ink: 30 41 59;
  --muted: 92 100 120;
  --faint: 150 156 172;
  --line: 26 32 50;
  --surface: 249 250 252;
  --card: 255 255 255;
  --accent: 0 166 126;          /* เขียวมิ้นต์ = สีหลักของแบรนด์ */
  --accent2: 0 194 168;         /* ปลายไล่สี */
  --brand-grad: linear-gradient(135deg, #00c2a8, #009e86);
  --late: #dc2626;
  --late-ink: #b3261e;
  --soon: #f59e0b;
  --soon-ink: #92660b;
  --ok: #0f766e;
  --sh-sm: 0 1px 2px rgb(26 32 50/.05), 0 1px 1px rgb(26 32 50/.03);
  --sh-md: 0 4px 14px -4px rgb(26 32 50/.10), 0 2px 6px -2px rgb(26 32 50/.06);
  --radius: 18px;
  --tabbar-h: 62px;
  --tap: 44px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: rgb(var(--surface));
  color: rgb(var(--ink));
  font-family: "Anuphan", -apple-system, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
.disp, h1, h2, h3 { font-family: "Bai Jamjuree", "Anuphan", sans-serif; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- แถบหัว ---------- */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 13px 16px;
  background: rgb(var(--card));
  border-bottom: 1px solid rgb(var(--line)/.09);
}
.appbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.appbar-date { font-size: 12.5px; color: rgb(var(--muted)); white-space: nowrap; }

.view { padding: 15px 15px calc(var(--tabbar-h) + 28px); max-width: 720px; margin: 0 auto; }

/* ---------- การ์ดทั่วไป ---------- */
.card {
  background: rgb(var(--card)); border: 1px solid rgb(var(--line)/.11);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--sh-md);
}
.card h2 { margin: 0 0 8px; font-size: 15.5px; font-weight: 600; }
.card p { margin: 0; color: rgb(var(--muted)); font-size: 13.5px; }
.muted { color: rgb(var(--muted)); font-size: 13px; }
.empty { text-align: center; color: rgb(var(--muted)); padding: 26px 14px; }
.empty .big { font-size: 30px; display: block; margin-bottom: 8px; }

.sec-h { font-size: 12.5px; font-weight: 600; color: rgb(var(--muted)); margin: 18px 0 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px;
  border-top: 1px solid rgb(var(--line)/.07); }
.kv:first-of-type { border-top: none; }
.kv b { font-family: "Bai Jamjuree", sans-serif; font-weight: 600; font-variant-numeric: tabular-nums; }

.note-box { font-size: 12.5px; color: rgb(var(--muted)); background: rgb(var(--line)/.04);
  border: 1px solid rgb(var(--line)/.08); border-radius: 10px; padding: 10px 12px; margin: 10px 0 0; }
.note-warn { font-size: 12.5px; line-height: 1.55; color: var(--soon-ink);
  background: rgb(234 179 8/.07); border: 1px solid rgb(234 179 8/.3);
  border-radius: 10px; padding: 9px 11px; margin: 10px 0; }

/* ---------- แถบเตือนใหญ่ ---------- */
.alert {
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(135deg, #dc2626, #b3261e); color: #fff;
  border-radius: 14px; padding: 14px 16px; margin-bottom: 12px;
  box-shadow: 0 8px 20px -8px rgb(220 38 38/.5);
}
.alert.ok { background: var(--brand-grad); box-shadow: 0 8px 20px -8px rgb(0 166 126/.5); }
.alert.warn { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 8px 20px -8px rgb(245 158 11/.45); }
.alert .n { font-family: "Bai Jamjuree", sans-serif; font-size: 28px; font-weight: 700; line-height: 1; }
.alert .txt { flex: 1; font-size: 13px; line-height: 1.45; }
.alert .txt b { display: block; font-size: 15px; font-weight: 600; }

/* ---------- แถวรายการ ---------- */
.row {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: rgb(var(--card)); border: 1px solid rgb(var(--line)/.11);
  border-radius: 15px; padding: 12px 14px; margin-bottom: 9px;
  cursor: pointer; box-shadow: var(--sh-sm); font: inherit; color: inherit;
  min-height: var(--tap);
}
.row:hover { border-color: rgb(var(--ink)/.26); }
.row .bar { width: 4px; align-self: stretch; border-radius: 4px; background: rgb(var(--line)/.18); flex: none; }
.row .mid { flex: 1; min-width: 0; }
.row .t { display: block; font-size: 14.5px; line-height: 1.35; }
.row .s { display: block; font-size: 12px; color: rgb(var(--muted)); margin-top: 2px; }
.row .amt { font-family: "Bai Jamjuree", sans-serif; font-variant-numeric: tabular-nums;
  font-size: 15px; font-weight: 600; text-align: right; white-space: nowrap; }
.row .chev { color: rgb(var(--faint)); font-size: 20px; line-height: 1; }

.row.late { background: #fff5f4; border-color: rgb(220 38 38/.26); }
.row.late .bar { background: var(--late); }
.row.late .t { font-weight: 600; }
.row.late .amt { color: var(--late-ink); }
.row.soon { background: #fffbf2; border-color: rgb(245 158 11/.28); }
.row.soon .bar { background: var(--soon); }
.row.done { opacity: .72; }
.row.done .bar { background: #16985f; opacity: .55; }
.row .amt.in { color: var(--ok); }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; border: 1px solid; white-space: nowrap; }
.pill.gray { color: rgb(var(--muted)); border-color: rgb(var(--line)/.18); background: rgb(var(--line)/.04); }
.pill.late { color: var(--late-ink); border-color: rgb(220 38 38/.34); background: rgb(220 38 38/.06); }
.pill.soon { color: var(--soon-ink); border-color: rgb(245 158 11/.36); background: rgb(245 158 11/.08); }
.pill.done { color: var(--ok); border-color: rgb(16 185 129/.34); background: rgb(16 185 129/.06); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 14px; }
.kpi-c { background: rgb(var(--card)); border: 1px solid rgb(var(--line)/.11);
  border-radius: 12px; padding: 12px 13px; box-shadow: var(--sh-sm); }
.kpi-c .l { font-size: 11.5px; color: rgb(var(--muted)); }
.kpi-c .v { font-family: "Bai Jamjuree", sans-serif; font-size: 20px; font-weight: 600;
  font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi-c .v.neg { color: var(--late-ink); }
.kpi-c .v.pos { color: var(--ok); }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid rgb(var(--line)/.16); border-radius: 11px;
  background: rgb(var(--card)); color: rgb(var(--ink));
  font: inherit; font-size: 14.5px; font-weight: 600; cursor: pointer; box-shadow: var(--sh-sm);
}
.btn:hover { border-color: rgb(var(--ink)/.3); }
.btn-primary { background: var(--brand-grad); border-color: transparent; color: #fff;
  box-shadow: 0 6px 16px -6px rgb(0 166 126/.55); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-danger { color: var(--late-ink); border-color: rgb(220 38 38/.3); }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.row-btns .btn { flex: 1 1 auto; }
.file-btn { cursor: pointer; }
.back { display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; color: rgb(var(--muted));
  background: none; border: none; cursor: pointer; padding: 0 0 10px; font-family: inherit; }
.titlebar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- ฟอร์ม ---------- */
.fl { display: block; font-size: 12.5px; color: rgb(var(--muted)); margin: 14px 0 4px; }
.fi, textarea.io, input[type="date"] {
  width: 100%; border: 1px solid rgb(var(--line)/.16); border-radius: 10px;
  padding: 11px 12px; font-family: inherit; font-size: 15px; background: #fff; color: rgb(var(--ink));
  min-height: var(--tap);
}
.fi:focus, textarea.io:focus { outline: none; border-color: rgb(var(--accent));
  box-shadow: 0 0 0 3px rgb(37 99 235/.12); }
textarea.fi { min-height: 64px; resize: vertical; }
textarea.io { min-height: 110px; margin-top: 12px; font-family: ui-monospace, monospace; font-size: 12.5px; resize: vertical; }

.seg { display: flex; gap: 6px; background: rgb(var(--line)/.05); padding: 4px; border-radius: 11px; }
.seg label { flex: 1; text-align: center; padding: 9px; border-radius: 8px; font-size: 14px;
  color: rgb(var(--muted)); cursor: pointer; }
.seg label.on { background: rgb(var(--card)); color: rgb(var(--ink)); font-weight: 600; box-shadow: var(--sh-sm); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }

.cat-head { display: grid; grid-template-columns: 1fr 96px 62px; gap: 8px;
  font-size: 11.5px; color: rgb(var(--faint)); margin: 12px 0 6px; }
.cat-row { display: grid; grid-template-columns: 1fr 96px 62px; gap: 8px; align-items: center; margin-bottom: 8px; }
.cat-name { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: var(--tap); }
.cat-name input { width: 20px; height: 20px; accent-color: rgb(var(--accent)); }
.cat-amt, .cat-day { width: 100%; border: 1px solid rgb(var(--line)/.16); border-radius: 9px;
  padding: 9px 10px; font-family: inherit; font-size: 14px; text-align: right; min-height: var(--tap); }

/* ---------- แผ่นเลื่อนขึ้น ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgb(26 32 50/.4); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88vh; overflow-y: auto;
  background: rgb(var(--card)); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgb(26 32 50/.2);
}
.sheet h3 { margin: 0 0 3px; font-size: 16px; font-weight: 600; }

/* ---------- แถบล่าง ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgb(var(--card)); border-top: 1px solid rgb(var(--line)/.09);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: rgb(var(--muted)); font-size: 11px; font-weight: 500;
}
.tabbar a.active { color: rgb(var(--accent)); font-weight: 600; }
.tabbar svg { width: 20px; height: 20px; }

/* ---------- ข้อความแจ้งผล ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px);
  transform: translateX(-50%) translateY(10px);
  max-width: min(92vw, 420px);
  background: rgb(var(--ink)); color: #fff; font-size: 14px; line-height: 1.5;
  padding: 11px 16px; border-radius: 12px; z-index: 60;
  opacity: 0; pointer-events: none; transition: .22s;
  box-shadow: 0 10px 28px rgb(26 32 50/.24);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: #0f766e; }
.toast.bad { background: #b3261e; }

.linkish { border:none; background:none; padding:0; font:inherit; font-weight:600; color:rgb(var(--accent)); cursor:pointer; text-decoration:underline; text-underline-offset:3px; }
select.fi { appearance:none; background-image:url("data:image/svg+xml;utf8,<svg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27 fill=%27none%27 stroke=%27%23888%27 stroke-width=%272%27><path d=%27M6 9l6 6 6-6%27/></svg>"); background-repeat:no-repeat; background-position:right 12px center; padding-right:38px; }

/* ---------- หัวหน้าแรกแบบไล่สี + ปุ่มลัดสีสด (ตามแบบที่เจ้าของเลือก) ---------- */
.hero {
  background: var(--brand-grad); color: #fff;
  border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: 0 10px 24px -10px rgb(0 166 126/.55);
}
.hero .hi { font-size: 13px; opacity: .9; }
.hero .big { font-family: "Bai Jamjuree", sans-serif; font-size: 19px; font-weight: 600; margin-top: 2px; }
.hero-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 13px; }
.hero-kpis div { background: rgb(255 255 255/.16); border-radius: 13px; padding: 10px 12px; }
.hero-kpis .l { font-size: 11.5px; opacity: .9; }
.hero-kpis .v { font-family: "Bai Jamjuree", sans-serif; font-size: 19px; font-weight: 600;
  font-variant-numeric: tabular-nums; margin-top: 1px; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-bottom: 16px; }
.quick button {
  background: rgb(var(--card)); border: 1px solid rgb(var(--line)/.09); border-radius: 15px;
  padding: 12px 6px 10px; cursor: pointer; box-shadow: var(--sh-sm);
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  font: inherit; font-size: 11.5px; color: rgb(var(--muted));
}
.quick button:hover { border-color: rgb(var(--ink)/.2); }
.quick .ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: #fff; }
.quick .ic svg { width: 19px; height: 19px; }
.quick .c1 { background: linear-gradient(135deg, #00c2a8, #009e86); }
.quick .c2 { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.quick .c3 { background: linear-gradient(135deg, #f59e0b, #ea8a00); }
.quick .c4 { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }

/* การ์ดบ้านแบบมีแถบรูปนำ (รูปจริงจะมาตอน T5b) */
.row .thumb {
  width: 46px; height: 46px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, rgb(var(--accent2)/.22), rgb(var(--accent)/.3));
  display: grid; place-items: center; color: rgb(var(--accent));
}
.row .thumb svg { width: 21px; height: 21px; }
