/* PANN Biz — mobile-first · ฟอนต์ไทย Sarabun / Noto Sans Thai (โหลดจาก Google Fonts ในแต่ละหน้า) */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #667085;
  --line: #dfe3ea;
  --brand: #0f6b5c;
  --brand-ink: #ffffff;
  --danger: #b42318;
  --ok: #067647;
  --radius: 12px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.55;
}

h1 { font-size: 1.4rem; margin: 0 0 .25rem; line-height: 1.3; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
.muted { color: var(--muted); font-size: .95rem; }
[hidden] { display: none !important; }

/* ---------- เมนู ---------- */
#menu {
  position: sticky; top: 0; z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  min-height: 98px;            /* จองที่ไว้ก่อน เมนูวาดเสร็จแล้วหน้าไม่กระตุก */
}
.menu-top { display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem .35rem; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--brand); text-decoration: none; white-space: nowrap; }
.menu-business { flex: 1; min-width: 0; }
.menu-business select { width: 100%; font-weight: 600; }
.menu-nav { display: flex; align-items: center; gap: 1rem; padding: 0 1rem .5rem; overflow-x: auto; white-space: nowrap; }
.menu-nav a { color: var(--ink); text-decoration: none; padding: .3rem 0; border-bottom: 3px solid transparent; }
.menu-nav a.active { border-bottom-color: var(--brand); font-weight: 600; }
.menu-user { margin-left: auto; color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; max-width: 9rem; }

/* ---------- โครงหน้า ---------- */
main { max-width: 640px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.banner { background: #fff4e5; color: #7a4100; padding: .6rem 1rem; font-size: .95rem; border-bottom: 1px solid #f3d6a8; }

/* ---------- ฟอร์ม ---------- */
label { display: block; font-weight: 600; margin: .85rem 0 .3rem; }
label .hint { font-weight: 400; color: var(--muted); font-size: .9rem; }
input[type="text"], input[type="email"], input[type="tel"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus, button:focus-visible { outline: 3px solid rgba(15, 107, 92, .3); outline-offset: 1px; border-color: var(--brand); }
input:disabled, select:disabled { background: #f0f2f5; color: var(--muted); }
.field-note { font-size: .9rem; min-height: 1.4em; margin-top: .25rem; color: var(--muted); }
.field-note.bad { color: var(--danger); }
.field-note.good { color: var(--ok); }

.choice { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.choice label {
  margin: 0; font-weight: 500; text-align: center;
  border: 1px solid var(--line); border-radius: 10px; padding: .65rem .5rem; background: #fff; cursor: pointer;
  min-height: 48px; display: flex; align-items: center; justify-content: center;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label:has(input:checked) { border-color: var(--brand); background: #e7f3f0; color: var(--brand); font-weight: 700; }
.choice label:has(input:focus-visible) { outline: 3px solid rgba(15, 107, 92, .3); }
.choice label:has(input:disabled) { opacity: .6; cursor: default; }

button { font: inherit; cursor: pointer; }
button:disabled { opacity: .6; cursor: default; }
.primary {
  display: block; width: 100%; min-height: 54px; margin-top: 1.25rem;
  background: var(--brand); color: var(--brand-ink);
  border: 0; border-radius: 12px; font-size: 1.1rem; font-weight: 700;
}
.secondary {
  min-height: 48px; padding: .5rem 1rem;
  background: #fff; color: var(--brand); border: 1px solid var(--brand); border-radius: 10px; font-weight: 600;
}
.link { background: none; border: 0; padding: .3rem 0; color: var(--muted); text-decoration: underline; }
.danger { color: var(--danger); }

/* ---------- หน้าเข้าใช้ ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1.25rem; }
.login .card { width: 100%; max-width: 420px; text-align: center; padding: 2rem 1.25rem; }
.login h1 { font-size: 1.8rem; color: var(--brand); }
.google {
  display: flex; align-items: center; justify-content: center; gap: .6rem;
  width: 100%; min-height: 56px; margin-top: 1.5rem;
  background: #fff; color: var(--ink); border: 1px solid #c8ced8; border-radius: 12px; font-size: 1.1rem; font-weight: 600;
}

/* ---------- รายการ ---------- */
.badges { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 0; }
.badge { background: #eef1f5; border-radius: 999px; padding: .15rem .7rem; font-size: .9rem; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { padding: .75rem 0; border-top: 1px solid var(--line); display: grid; gap: .4rem; }
.rows li:first-child { border-top: 0; }
.row-actions { display: flex; gap: .5rem; align-items: center; }
.row-actions select { flex: 1; }
.inline { display: grid; gap: .5rem; }

/* ---------- แจ้งผล ---------- */
#toast {
  position: fixed; left: 1rem; right: 1rem; bottom: 1rem; z-index: 50;
  max-width: 600px; margin: 0 auto; padding: .8rem 1rem; border-radius: 12px;
  color: #fff; background: var(--danger); box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
  transform: translateY(150%); transition: transform .18s ease;
}
#toast.show { transform: none; }
#toast.ok { background: var(--ok); }

.skeleton { color: transparent; background: #e9ecf1; border-radius: 6px; user-select: none; }

/* ---------- งาน 004: เอกสาร ---------- */
main.wide { max-width: 860px; }
.as-link { text-align: center; line-height: 54px; text-decoration: none; }
a.row-main { text-decoration: none; }
.row-top { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.row-top h1 { margin: 0; }
.amount { font-weight: 700; white-space: nowrap; }
.sumline { margin: .75rem 0 0; font-weight: 600; }
.badge.green { background: #dcfae6; color: #085d3a; }
.badge.red { background: #fee4e2; color: #912018; }
.badge.amber { background: #fef0c7; color: #93370d; }
.badge.gray { background: #eef1f5; color: #475467; }
.tabs { display: flex; gap: .4rem; overflow-x: auto; margin-top: 1rem; padding-bottom: .25rem; }
.tabs button {
  flex: 0 0 auto; min-height: 44px; padding: .3rem .9rem; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--ink);
}
.tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.pick {
  display: block; padding: .9rem 1rem; margin-top: .6rem; border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 1.05rem;
}
.chosen {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  border: 1px solid var(--brand); background: #e7f3f0; border-radius: 10px; padding: .6rem .75rem;
}
.suggest { display: grid; }
.suggest button {
  text-align: left; background: #fff; border: 1px solid var(--line); border-top: 0; padding: .55rem .75rem; min-height: 48px; color: var(--ink);
}
.suggest button:first-child { border-top: 1px solid var(--line); margin-top: .35rem; border-radius: 10px 10px 0 0; }
.suggest button:last-child { border-radius: 0 0 10px 10px; }
.suggest button:only-child { border-radius: 10px; }
.suggest button.add { color: var(--brand); font-weight: 600; }
.line { border: 1px solid var(--line); border-radius: 12px; padding: .25rem .75rem .75rem; margin-bottom: .75rem; background: #fcfcfd; }
.line .check { margin-top: .5rem; }
.line .row-top { margin-top: .5rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 0 .5rem; }
.readonly { min-height: 48px; display: flex; align-items: center; padding: 0 .75rem; background: #f0f2f5; border-radius: 10px; }

/* แถบยอดรวมล่างจอ */
body.has-bar main { padding-bottom: 9.5rem; }
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line);
  padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(16, 24, 40, .08);
}
.bar > * { max-width: 608px; margin-left: auto; margin-right: auto; }
.bar .primary { margin-top: .5rem; }
.bar-totals { font-size: .98rem; }
.bar-totals b { font-size: 1.15rem; }
body.has-bar #toast { bottom: 9.5rem; }

/* ---------- งาน 006: รับชำระ · บิลประจำ · รายได้ ---------- */
.pay-line { display: grid; grid-template-columns: 1.2fr 1fr auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.sumline.danger { color: var(--danger); }
.voided { opacity: .6; text-decoration: line-through; }
.voided .field-note { text-decoration: none; }
.report { width: 100%; border-collapse: collapse; font-size: .95rem; }
.report th { text-align: left; font-weight: 600; color: var(--muted); padding: .4rem .5rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
.report td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
.report .r { text-align: right; white-space: nowrap; }
.report tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.scroll-x { overflow-x: auto; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .75rem 0; }
.stat { background: #f7f8fa; border-radius: 10px; padding: .6rem .75rem; }
.stat b { display: block; font-size: 1.15rem; }

/* ---------- งาน 005: ออกแบบ · ส่งให้ลูกค้า (หน้าตาของตัวเอกสารอยู่ใน doc.css) ---------- */
.slip { display: block; max-width: 220px; max-height: 260px; margin-top: .4rem; border: 1px solid var(--line); border-radius: 8px; }
.notice { margin-top: 1rem; padding: .7rem .85rem; background: #fef0c7; color: #7a4100; border-radius: 10px; display: grid; gap: .3rem; }
.notice a { color: #7a4100; font-weight: 600; }
.swatches { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.swatch.active { box-shadow: 0 0 0 3px var(--ink); }
input[type="color"] { width: 64px; height: 48px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
main.design { max-width: 1180px; }
body:not(.show-preview) #preview-pane { display: none; }
body.show-preview #form-pane { display: none; }
body.public { background: var(--bg); }
body.public main { padding-top: 1rem; }

/* ---------- งาน 003: ฟอร์มยาว รายการ หน้าต่างฟอร์ม ---------- */
textarea { min-height: 5.5rem; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.thai-date { display: grid; grid-template-columns: 5rem 1fr 6.5rem; gap: .5rem; }
.choice.one { grid-template-columns: 1fr; }
.choice.one label { justify-content: flex-start; text-align: left; padding: .65rem .9rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; color: var(--muted); margin-top: 1rem; }
.check input { width: 22px; height: 22px; }
.menu-logo { height: 26px; max-width: 70px; object-fit: contain; vertical-align: middle; margin-right: .4rem; }

.row-main {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: .1rem 0; color: var(--ink);
  min-height: 48px;
}
.row-main .badge { margin-left: .4rem; font-size: .8rem; }
.rows .row-actions { justify-content: flex-end; flex-wrap: wrap; }

.checklist { list-style: none; margin: 0; padding: 0; color: var(--muted); }
.checklist li { padding: .15rem 0; }
.checklist li.done { color: var(--ok); }

.files { display: grid; gap: 1rem; }
.file-title { font-weight: 600; margin-bottom: .35rem; }
.file-preview {
  min-height: 96px; border: 1px dashed var(--line); border-radius: 10px; background: #fafbfc;
  display: flex; align-items: center; justify-content: center; padding: .5rem;
}
.file-preview img { max-width: 100%; max-height: 120px; object-fit: contain; }
.file-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .5rem; }
.file-actions select { flex: 1 1 100%; }
.sign-pad {
  display: block; width: 100%; height: 220px; margin-bottom: .75rem;
  border: 2px dashed var(--line); border-radius: 12px; background: #fff; touch-action: none;
}

.more { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .5rem; }
.more summary { cursor: pointer; color: var(--brand); font-weight: 600; padding: .5rem 0; min-height: 44px; }
.import-result ul { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.import-result { margin-top: .75rem; }

dialog.sheet {
  width: 100%; max-width: 640px; height: 100%; max-height: 100%; margin: 0 auto; padding: 0;
  border: 0; background: var(--card); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(16, 24, 40, .45); }
.sheet-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; background: var(--card); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; }
.sheet-body { padding: 0 1rem 1.5rem; }

@media (min-width: 720px) {
  dialog.sheet { height: auto; max-height: 92vh; margin: 4vh auto; border-radius: 14px; }

  .files { grid-template-columns: repeat(3, 1fr); }
  .inline { grid-template-columns: 1fr 14rem auto; align-items: end; }
  .rows li { grid-template-columns: 1fr 22rem; align-items: center; }
  #menu { min-height: 0; display: flex; align-items: center; justify-content: space-between; }
  .menu-top { padding: .6rem 1rem; flex: 0 1 26rem; }
  .menu-nav { padding: .6rem 1rem; }
}

/* หน้าออกแบบ: จอกว้างเห็นตั้งค่ากับตัวอย่างข้างกัน */
@media (min-width: 980px) {
  main.design { display: grid; grid-template-columns: 380px 1fr; gap: 1rem; align-items: start; }
  main.design .design-switch { display: none; }
  body:not(.show-preview) #preview-pane, body.show-preview #form-pane { display: block; }
  #preview-pane { position: sticky; top: 4.5rem; }
}
