:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #17212b;
  --muted: #4f5b66;
  --border: #e1e5ea;
  --primary: #006633;
  --primary-strong: #004d26;
  --primary-ink: #ffffff;
  --primary-btn: #006633;
  --primary-soft: #e2f2e8;
  --brand-red: #e31b23;
  --brand-red-soft: #fde8e9;
  --brand-green: #00a54f;
  --ok: #17803d;
  --ok-soft: #e5f4e9;
  --warn: #a35c00;
  --warn-soft: #fff1dc;
  --danger: #c0262d;
  --danger-soft: #fdeaea;
  --info: #1e5bb8;
  --info-soft: #e7effb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --tabbar-h: 0px;
  --series-1: #2a78d6;
  --series-1-strong: #184f95;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #8a5cd6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1418;
    --surface: #182026;
    --surface-2: #1e272e;
    --text: #e8edf1;
    --muted: #b3bec8;
    --border: #2a353d;
    --primary: #2fbf71;
    --primary-strong: #0b3d22;
    /* ปุ่มสีเขียวตอนกลางคืน: พื้นเขียวเข้ม ตัวหนังสือขาว อ่านง่ายกว่าตัวหนังสือสีเข้ม */
    --primary-ink: #ffffff;
    --primary-btn: #157a4a;
    --primary-soft: #0f3322;
    --brand-red: #ff5c61;
    --brand-red-soft: #3b1618;
    --brand-green: #2fbf71;
    --ok: #4cc47a;
    --ok-soft: #14301f;
    --warn: #f0a646;
    --warn-soft: #36270f;
    --danger: #f06a6f;
    --danger-soft: #3a1a1c;
    --info: #6ea4f2;
    --info-soft: #172a45;
    --shadow: none;
    --series-1: #3987e5;
    --series-1-strong: #86b6ef;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #a17ce0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0f1418;
    --surface: #182026;
    --surface-2: #1e272e;
    --text: #e8edf1;
    --muted: #b3bec8;
    --border: #2a353d;
    --primary: #2fbf71;
    --primary-strong: #0b3d22;
    /* ปุ่มสีเขียวตอนกลางคืน: พื้นเขียวเข้ม ตัวหนังสือขาว อ่านง่ายกว่าตัวหนังสือสีเข้ม */
    --primary-ink: #ffffff;
    --primary-btn: #157a4a;
    --primary-soft: #0f3322;
    --brand-red: #ff5c61;
    --brand-red-soft: #3b1618;
    --brand-green: #2fbf71;
    --ok: #4cc47a;
    --ok-soft: #14301f;
    --warn: #f0a646;
    --warn-soft: #36270f;
    --danger: #f06a6f;
    --danger-soft: #3a1a1c;
    --info: #6ea4f2;
    --info-soft: #172a45;
    --shadow: none;
    --series-1: #3987e5;
    --series-1-strong: #86b6ef;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #a17ce0;
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* กันหน้าเลื่อนซ้าย-ขวาทั้งหน้า ถ้ามีอะไรกว้างเกินจอ (ตารางกว้างยังเลื่อนได้ในกรอบของตัวเอง) */
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Kanit", system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", Roboto, sans-serif;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.12rem; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- chrome ---------- */
#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--primary-strong); color: #fff;
  border-bottom: 4px solid var(--brand-red);
}
#brand { width: 36px; height: 36px; border-radius: 10px; flex: none; background: #fff; }
#title { font-size: 1.2rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#who { display: flex; flex-direction: column; align-items: flex-end; max-width: 46%; font-size: .78rem; line-height: 1.25; opacity: .92; text-align: right; }
#who span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#who span:first-child { font-weight: 700; font-size: .85rem; }
#title { min-width: 0; }
#main {
  max-width: 600px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; margin-left: -8px; border: 0; border-radius: 10px;
  background: transparent; color: inherit; cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }

/* ---------- building blocks ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card > h3, .card > .row > h3 { margin-bottom: 10px; }
.hero { border-top: 4px solid var(--brand-red); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.greet { margin: 0 0 12px; color: var(--muted); }
.section-title { margin: 22px 4px 8px; font-size: 1rem; color: var(--muted); font-weight: 600; }
.loading, .empty { text-align: center; padding: 32px 16px; color: var(--muted); }

/* หน้าจอตอนเปิดแอป (ก่อนข้อมูลจะมา) */
.app-splash { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18vh 16px 0; text-align: center; color: var(--muted); }
.app-splash img { width: 112px; height: 112px; border-radius: 24px; background: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.app-splash b { font-size: 1.6rem; font-weight: 800; letter-spacing: .5px; color: var(--primary); }
.spinner { display: inline-block; width: 26px; height: 26px; margin-top: 6px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.stack > * + * { margin-top: 10px; }
.link { color: var(--primary); font-weight: 600; font-size: .9rem; background: none; border: 0; padding: 0; cursor: pointer; font-family: inherit; }
.num { font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary-btn); border-color: var(--primary-btn); color: var(--primary-ink); }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.small { min-height: 42px; padding: 6px 12px; font-size: .95rem; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; white-space: nowrap; }
.badge.open { background: var(--info-soft); color: var(--info); }
.badge.closed { background: var(--warn-soft); color: var(--warn); }
.badge.verified { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.badge.owner { background: var(--primary-soft); color: var(--primary); }

.diff { font-weight: 700; font-size: .95rem; white-space: nowrap; }
.diff.ok { color: var(--ok); }
.diff.over { color: var(--info); }
.diff.short { color: var(--danger); }

.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: 1rem; display: block; overflow-wrap: anywhere; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat span { display: block; font-size: .88rem; color: var(--muted); }
.stat b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.wide { grid-column: 1 / -1; }

/* lists */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 14px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--border); }
.list-item:first-child { border-top: 0; }
a.list-item:active, button.list-item:active { background: var(--surface-2); }
button.list-item { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.list-item:first-child { border-top: 0; }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.li-sub { font-size: .92rem; color: var(--muted); overflow-wrap: anywhere; }
.li-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.li-amt { font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.del { border: 0; background: none; color: var(--danger); padding: 6px; cursor: pointer; border-radius: 8px; }
.del svg { width: 18px; height: 18px; }

/* key-value rows */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px dashed var(--border); }
.kv:first-of-type { border-top: 0; }
.kv > :last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* reconciliation */
.recon { font-variant-numeric: tabular-nums; }
.rline { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; }
.rline.sub { padding-left: 12px; color: var(--muted); }
.rline.strong { font-weight: 700; }
.rsep { border-top: 1px solid var(--border); margin: 6px 0; }
.rresult { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding: 12px 14px; border-radius: 12px; font-weight: 700; background: var(--surface-2); }
.rresult b { font-size: 1.4rem; }
.rresult.ok { background: var(--ok-soft); color: var(--ok); }
.rresult.over { background: var(--info-soft); color: var(--info); }
.rresult.short { background: var(--danger-soft); color: var(--danger); }

/* forms */
form { margin: 0; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.field small { display: block; color: var(--muted); font-size: .88rem; margin-top: 3px; }
.field small.calc { color: var(--primary); font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 1.05rem;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type=number] { font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-weight: 600; }
.check input { width: 22px; min-height: 22px; height: 22px; accent-color: var(--primary); }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 1rem; font-weight: 600; margin: 0 0 12px; }
.meter-line { padding: 12px 0; border-top: 1px solid var(--border); }
.meter-line:first-of-type { border-top: 0; padding-top: 0; }
.meter-line .field { margin-bottom: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 9px 16px; font: inherit; font-size: 1rem; cursor: pointer; }
.chip.active { background: var(--primary-btn); border-color: var(--primary-btn); color: var(--primary-ink); }
.filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.filters .field { margin-bottom: 0; min-width: 0; }
.filters input { min-width: 0; padding-left: 8px; padding-right: 6px; }

/* sheet dialog */
dialog.sheet {
  width: 100%; max-width: 600px; max-height: 92vh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
@media (min-width: 640px) { dialog.sheet { margin: auto; border-radius: 18px; } }
.sheet-form { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head .icon-btn { margin: 0 -8px 0 0; }

/* toasts */
#toasts { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 560px; padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 1rem; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); color: #fff; }

/* auth pages */
.auth { max-width: 380px; margin: 6vh auto 0; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 12px; }
.auth h2 { text-align: center; margin-bottom: 4px; }
.auth p.muted { text-align: center; margin-top: 0; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .95rem; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 7px 4px; border-top: 1px solid var(--border); text-align: right; white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th { color: var(--muted); font-weight: 600; border-top: 0; font-size: .78rem; }
.scroll-x { overflow-x: auto; overscroll-behavior-x: contain; }

/* ---------- home menu ---------- */
.status-strip {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 14px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); line-height: 1.4;
}
.status-strip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.status-strip.open { background: var(--info-soft); border-color: transparent; color: var(--info); }
.status-strip.open .dot { background: var(--info); box-shadow: 0 0 0 4px color-mix(in srgb, var(--info) 25%, transparent); }
.status-strip .small { color: var(--text); opacity: .8; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  min-height: 118px; padding: 16px; border-radius: 18px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); font: inherit; cursor: pointer;
}
.tile:active { transform: scale(.98); }
.tile.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; min-height: 92px; gap: 14px; }
.tile.primary { background: var(--primary-btn); border-color: var(--primary-btn); color: var(--primary-ink); }
.tile-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 46px; height: 46px; border-radius: 14px; background: var(--primary-soft); color: var(--primary);
}
.tile-icon svg { width: 26px; height: 26px; }
.tile.primary .tile-icon { background: rgba(255,255,255,.18); color: var(--primary-ink); }
.tile-text { display: flex; flex-direction: column; min-width: 0; }
.tile-label { font-weight: 800; font-size: 1.12rem; line-height: 1.3; }
.tile.wide .tile-label { font-size: 1.3rem; }
.tile-sub { font-size: .9rem; color: var(--muted); margin-top: 2px; }
.tile.primary .tile-sub { color: inherit; opacity: .85; }
.tile-count {
  position: absolute; top: 12px; right: 12px; min-width: 24px; height: 24px; padding: 0 7px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: .8rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- pager (month / day) ---------- */
.pager { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.pager .icon-btn { margin: 0; width: 44px; height: 44px; background: var(--surface); border: 1px solid var(--border); color: var(--text); flex: none; }
span.icon-btn { visibility: hidden; }
.pager-label { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; }
.pager-date { text-align: center; font-weight: 600; }

/* ---------- dashboard ---------- */
.hero-num { font-size: 2.1rem; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-num small { font-size: .95rem; font-weight: 600; color: var(--muted); }
.delta { display: block; font-size: .85rem; color: var(--muted); margin-top: 2px; }
.stat .diff { font-size: 1rem; }
.readout { display: flex; flex-direction: column; min-height: 46px; margin-bottom: 4px; }
.readout b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.readout span { font-size: .92rem; color: var(--muted); }
.chart-host { width: 100%; overflow: hidden; touch-action: pan-y; }
.chart { display: block; outline: none; width: 100%; height: auto; stroke: none; stroke-width: 0; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; font-family: inherit; }
.chart .bar { fill: var(--series-1); }
.chart .bar.sel { fill: var(--series-1-strong); }
.chart .avg { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .cursor { stroke: var(--muted); stroke-width: 1; }
.chart-note { margin: 6px 0 0; }
.table-view { margin-top: 10px; }
.table-view summary { cursor: pointer; color: var(--primary); font-weight: 700; font-size: 1rem; padding: 6px 0; }
.paybar { display: flex; gap: 2px; height: 22px; margin-bottom: 10px; }
.seg { min-width: 3px; }
.seg:first-child { border-radius: 4px 0 0 4px; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.seg:only-child { border-radius: 4px; }
.s1 { background: var(--series-1); }
.s2 { background: var(--series-2); }
.s3 { background: var(--series-3); }
.s4 { background: var(--series-4); }
.legend-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.pct { width: 52px; text-align: right; color: var(--muted); }
.hbar { padding: 6px 0; }
.hbar-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.hbar-track { height: 8px; }
.hbar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.list.flat { border: 0; box-shadow: none; margin: 0 -14px -14px; border-radius: 0; }
.list.flat .list-item:first-child { border-top: 1px solid var(--border); }
a.kv { color: inherit; }

/* ---------- tasks ---------- */
.big-btn { min-height: 56px; font-size: 1.1rem; }
.big-btn svg, .btn svg { width: 22px; height: 22px; }
.tabs { display: flex; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 4px; margin-bottom: 14px; overflow-x: auto; }
.tab { flex: 1; min-width: max-content; text-align: center; padding: 10px 12px; border-radius: 10px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab-count { display: inline-flex; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .8rem; align-items: center; justify-content: center; }
.badge.job-todo { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.badge.job-doing { background: var(--info-soft); color: var(--info); }
.badge.job-submitted { background: var(--warn-soft); color: var(--warn); }
.badge.job-redo { background: var(--danger-soft); color: var(--danger); }
.badge.job-approved { background: var(--ok-soft); color: var(--ok); }
.badge.job-cancelled { background: var(--surface-2); color: var(--muted); }
.badge svg { width: 14px; height: 14px; }
.inline-icon svg { width: 15px; height: 15px; vertical-align: -2px; margin-right: 4px; }
.li-note { margin-top: 4px; font-size: .92rem; color: var(--danger); font-weight: 600; }
.job-title { font-size: 1.45rem; margin: 10px 0 6px; overflow-wrap: anywhere; }
.job-desc { white-space: pre-wrap; margin: 12px 0 0; padding: 12px; border-radius: 12px; background: var(--surface-2); font-size: 1.05rem; }
.audio-box { margin-top: 12px; }
.audio-box .small svg { width: 16px; height: 16px; vertical-align: -3px; }
audio { width: 100%; margin-top: 6px; }
.actions { margin-bottom: 14px; }
.actions > .grid2:first-child { margin-top: 0; }
/* ป้ายชื่อยาวให้ขึ้นบรรทัดใหม่ได้ ส่วนตัวเลขด้านขวาไม่ตัดบรรทัด */
.kv > :first-child { min-width: 0; overflow-wrap: anywhere; }
.kv > :last-child { min-width: 0; overflow-wrap: anywhere; }
.event-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.event-head svg { width: 20px; height: 20px; }
.event-head .muted { flex-basis: 100%; }
.event-note { white-space: pre-wrap; margin: 8px 0 0; font-size: 1.05rem; }
.event.review-approved { border-left: 5px solid var(--ok); }
.event.review-approved .event-head { color: var(--ok); }
.event.review-redo { border-left: 5px solid var(--danger); }
.event.review-redo .event-head { color: var(--danger); }
.event.review-cancelled { border-left: 5px solid var(--muted); }
.warn-text { color: var(--warn); font-weight: 600; margin: 8px 0 0; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.photo-grid:empty { display: none; }
.photo { position: relative; padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: var(--surface-2); cursor: pointer; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-flag { position: absolute; left: 4px; bottom: 4px; right: 4px; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; border-radius: 6px; padding: 1px 4px; text-align: center; }
.photo-remove { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.photo-remove svg { width: 18px; height: 18px; }
dialog.photo-view { width: 100%; max-width: 900px; padding: 12px; border: 0; border-radius: 16px; background: var(--surface); color: var(--text); }
dialog.photo-view::backdrop { background: rgba(0,0,0,.8); }
dialog.photo-view img { width: 100%; border-radius: 10px; display: block; }
.photo-cap { margin-top: 8px; font-size: .95rem; color: var(--muted); }

/* segmented radio / checkbox */
.seg-group { display: flex; flex-wrap: wrap; gap: 8px; }
.seg-group label { flex: 1; min-width: max-content; }
/* ช่องเลือกที่ซ่อนไว้ ต้องไม่กินความกว้าง ไม่อย่างนั้นหน้าจะกว้างเกินจอมือถือ */
.seg-group input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.seg-group span { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface); font-weight: 700; cursor: pointer; }
.seg-group input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.seg-group input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.seg-group input:disabled + span { opacity: .6; cursor: default; }
.seg-group.days label { min-width: 0; }
.seg-group.days span { padding: 8px 0; }

/* recorder */
.rec-btn { width: 100%; border-style: dashed; border-width: 2px; }
.rec-live { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--danger-soft); }
.rec-live b { font-size: 1.3rem; }
.rec-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; flex: none; }
@keyframes blink { 50% { opacity: .25; } }
.rec-done .row { margin-top: 8px; }

/* in-app camera */


/* voice note under text fields */
.voice-slot { margin-top: 8px; }
.voice-slot .rec-btn { min-height: 44px; font-size: .98rem; }
.audio-inline { display: block; width: 100%; max-width: 360px; height: 40px; margin-top: 6px; }

/* date (พ.ศ.) & 24h time display over native pickers */
.dt-wrap { position: relative; display: block; }
.dt-display { display: flex; align-items: center; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.dt-display.placeholder { color: var(--muted); font-weight: 400; }
.dt-wrap.center .dt-display { justify-content: center; }
.dt-wrap input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.dt-wrap input:focus-visible + * , .dt-wrap:focus-within .dt-display { outline: 2px solid var(--primary); outline-offset: -1px; }


/* ---------- PT brand accents ---------- */
.tile-icon { background: var(--brand-red-soft); color: var(--brand-red); }
.tile.primary { background: var(--primary-btn); border-color: var(--primary-btn); }
.tile.primary .tile-icon { background: #fff; color: var(--brand-red); }
.tab.active { box-shadow: inset 0 -3px 0 var(--brand-red), var(--shadow); }
.status-strip.open { border-left: 5px solid var(--brand-green); }
.btn.primary { background: var(--primary-btn); border-color: var(--primary-btn); }
.greet { color: var(--primary); font-weight: 600; }
.auth .logo { border-radius: 0; width: 96px; height: 96px; }
.badge.role-owner { background: var(--primary-soft); color: var(--primary); }
.badge.role-manager { background: var(--info-soft); color: var(--info); }
.badge.role-attendant { background: var(--warn-soft); color: var(--warn); }
.badge.role-cleaner { background: var(--ok-soft); color: var(--ok); }
.approval .grid2 { margin-top: 12px; }
.approval .li-sub { margin-top: 2px; }
.pline { margin-bottom: 10px; }
.pline .del { margin-right: -6px; }

.task-photos { margin-top: 12px; }
.task-photos .small svg { width: 16px; height: 16px; vertical-align: -3px; }

/* ---------- in-app camera ----------
   จัดวางแบบแนวตั้งเสมอ เมื่อเลือกแนวนอน (.land) จะหมุนเฉพาะตัวหนังสือ/ไอคอน/นาฬิกา/รูปที่ถ่าย
   ตามทิศที่ตะแคงเครื่อง (--rot) โดยไม่ต้องพึ่งการหมุนจอของโทรศัพท์ */
dialog.camera { position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; color: #fff; overflow: hidden; }
dialog.camera:not([open]) { display: none; }
dialog.camera::backdrop { background: #000; }
dialog.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
dialog.camera video.mirror { transform: scaleX(-1); }
dialog.camera { --rot: 0deg; }
dialog.camera.land { --rot: 90deg; }
dialog.camera.land.cw { --rot: -90deg; }
.cam-ui { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.cam-ui > * { pointer-events: auto; }
.cam-shot { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.cam-top { position: relative; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 12px 12px; }
.cam-orient { display: flex; padding: 3px; border-radius: 999px; background: rgba(0,0,0,.55); border: 2px solid rgba(255,255,255,.7); }
.cam-orient button { display: inline-flex; align-items: center; gap: 4px; padding: 7px 11px; border: 0; border-radius: 999px; background: none; color: #fff; font: inherit; font-weight: 700; font-size: .95rem; cursor: pointer; }
.cam-orient button svg { width: 18px; height: 18px; }
.cam-orient button.active { background: #fff; color: #000; }
.cam-torch { display: inline-flex; align-items: center; gap: 4px; padding: 9px 12px; border-radius: 999px; border: 2px solid rgba(255,255,255,.7); background: rgba(0,0,0,.5); color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.cam-torch svg { width: 22px; height: 22px; }
.cam-torch.on { background: #ffd43b; border-color: #ffd43b; color: #000; }
.cam-torch.on svg { fill: #000; }
.cam-torch.unsupported { opacity: .55; }
.cam-msg { position: absolute; left: 50%; top: 45%; width: min(86vw, 70dvh); transform: translate(-50%, -50%) rotate(var(--rot)); margin: 0; text-align: center; background: rgba(0,0,0,.75); padding: 14px; border-radius: 12px; font-size: 1.05rem; }
.cam-bottom { margin-top: auto; } /* อยู่ขอบล่างเสมอ แม้ซ่อนแถบด้านบนตอนดูรูป */
.cam-clock { display: inline-block; margin: 0 0 8px 12px; padding: 6px 10px; border-radius: 8px; background: rgba(0,0,0,.6); font-weight: 700; font-size: 1.05rem; }
.cam-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px calc(14px + env(safe-area-inset-bottom)); background: rgba(0,0,0,.55); }
.cam-btn { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: #fff; font: inherit; font-size: 1.05rem; font-weight: 700; padding: 12px 6px; cursor: pointer; min-width: 88px; }
.cam-btn svg { width: 20px; height: 20px; }
.cam-bar[data-review] .cam-btn { min-width: 0; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: #fff; box-shadow: inset 0 0 0 4px #000; cursor: pointer; flex: none; }
.shutter:active { transform: scale(.94); }
.cam-bar .btn.primary { min-height: 52px; padding: 0 28px; font-size: 1.15rem; background: #157a4a; border: 2px solid #fff; color: #fff; }

.seg-group.stack-seg { flex-direction: column; }
.seg-group.stack-seg span { flex-direction: column; align-items: flex-start; text-align: left; padding: 10px 14px; }
.seg-group.stack-seg small { font-weight: 500; color: var(--muted); font-size: .85rem; margin-top: 2px; }

/* landscape: rotate only labels, icons, clock and the captured photo */
.cam-ui .rot { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transform: rotate(var(--rot)); transition: transform .25s ease; }
.cam-orient svg, .cam-torch svg { transform: rotate(var(--rot)); transition: transform .25s ease; }
dialog.camera.land .cam-orient span, dialog.camera.land .cam-torch span { display: none; }
dialog.camera.land .cam-bar .cam-btn, dialog.camera.land .cam-bar [data-use] { min-width: 72px; min-height: 92px; padding: 0 10px; justify-content: center; }
dialog.camera.land .cam-clock { position: absolute; top: 50%; left: 16px; margin: 0; transform-origin: left top; transform: rotate(90deg) translate(-50%, -100%); white-space: nowrap; }
dialog.camera.land.cw .cam-clock { left: auto; right: 16px; transform-origin: right top; transform: rotate(-90deg) translate(50%, -100%); }
dialog.camera.land .cam-shot { inset: auto; left: 50%; top: 50%; width: 100dvh; height: 100vw; transform: translate(-50%, -50%) rotate(var(--rot)); }

/* ---------- gallery photos ---------- */
.photo-flag.gallery { background: rgba(0,0,0,.6); }
.photo-btns { margin-top: 0; }
.photo-btns .btn.block { margin-top: 12px; }

/* ---------- attendance ---------- */
.badge.att-present { background: var(--ok-soft); color: var(--ok); }
.badge.att-late { background: var(--warn-soft); color: var(--warn); }
.badge.att-absent { background: var(--danger); color: #fff; }
.badge.att-leave { background: var(--info-soft); color: var(--info); }
.badge.att-sick { background: var(--brand-red-soft); color: var(--brand-red); }
.badge.att-off { background: var(--surface-2); color: var(--muted); }
.badge.att-waiting { background: var(--surface-2); color: var(--text); border: 1px dashed var(--border); }
.bad { color: var(--danger); }
.att-now { display: flex; align-items: center; gap: 12px; line-height: 1.4; }
.att-now b { display: block; font-size: 1.25rem; }
.att-now .small { color: var(--muted); }
.att-now .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; background: var(--muted); }
.att-now.in .dot { background: var(--ok); box-shadow: 0 0 0 5px var(--ok-soft); }
.att-now.in b { color: var(--ok); }
.att-now .photo-grid { display: block; width: 64px; margin: 0; flex: none; }
.att-face { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-2); }
.att-face.empty { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.att-counts { line-height: 1.5; }
.att-rec { background: var(--surface-2); box-shadow: none; }
.att-rec .kv { border-top-color: var(--border); }
.leave-item .grid2 { margin-top: 8px; }
.leave-item .li-right .link { margin-top: 6px; }
details.more { margin-top: 10px; }
details.more summary { cursor: pointer; color: var(--primary); font-weight: 600; padding: 8px 4px; text-align: center; }

/* ---------- portrait only ----------
   Android ที่ติดตั้งแอปจะล็อกแนวตั้งจาก manifest ส่วนเครื่องที่ล็อกไม่ได้ (เช่น iPhone) จะเห็นข้อความให้หมุนกลับ */
#rotate-lock { display: none; }
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) {
  #rotate-lock {
    position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 8px; padding: 24px; text-align: center; background: var(--primary-strong); color: #fff;
  }
  #rotate-lock svg { width: 56px; height: 56px; }
  #rotate-lock b { font-size: 1.3rem; }
  body { overflow: hidden; }
  dialog.sheet, dialog.photo-view { visibility: hidden; }
}
@media (max-width: 420px) {
  .tabs { gap: 2px; }
  .tab { padding: 10px 7px; font-size: .95rem; }
}

/* ---------- PAT44: ฟอนต์ Kanit ตัวหนา ---------- */
h1, h2, h3, .tile-label, .li-title, .hero-num, .job-title, .stat b, .btn, .tab, .badge, .field > span, .section-title { font-weight: 700; }
#title { font-weight: 800; letter-spacing: .02em; }
.tile-label, .hero-num, .job-title { font-weight: 800; }
.li-sub, .muted, small, .small, .tile-sub { font-weight: 400; }
input, select, textarea, .dt-display { font-weight: 500; }
.period-seg span { flex-direction: column; line-height: 1.2; }
.period-seg small { font-size: .8rem; color: var(--danger); margin: 2px 0 0; }
.ws-bar { display: grid; grid-template-columns: 92px 1fr 28px; align-items: center; gap: 8px; margin: 4px 0; font-size: .88rem; color: var(--muted); }
.ws-bar b { color: var(--text); text-align: right; }
.hbar-fill.ok { background: var(--ok); }
.hbar-fill.warn { background: var(--danger); }
.ws-item .li-main > .li-sub { margin-top: 2px; }
a.rline { color: inherit; }
.chips { scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.ws-bar .hbar-track { background: var(--surface-2); border-radius: 4px; overflow: hidden; }

/* ---------- เงินขาด: ไม่เกิน 60 = ปกติ, 60-100 เหลือง, 100-300 ส้ม, เกิน 300 แดง ---------- */
:root { --yellow: #9a7400; --yellow-soft: #fff4c2; --orange: #c2410c; --orange-soft: #ffe7d6; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --yellow: #f2c94c; --yellow-soft: #3a3110; --orange: #fb923c; --orange-soft: #3d2212; } }
:root[data-theme="dark"] { --yellow: #f2c94c; --yellow-soft: #3a3110; --orange: #fb923c; --orange-soft: #3d2212; }
.diff.short-ok { color: var(--text); }
.diff.short-yellow { color: var(--yellow); }
.diff.short-orange { color: var(--orange); }
.rresult.short-ok { background: var(--surface-2); color: var(--text); }
.rresult.short-yellow { background: var(--yellow-soft); color: var(--yellow); }
.rresult.short-orange { background: var(--orange-soft); color: var(--orange); }

/* ---------- สต๊อก ---------- */
.info-text { color: var(--info); }
.qty-pair { display: flex; gap: 6px; flex: none; }
.qty-pill { display: inline-flex; flex-direction: column; align-items: center; min-width: 58px; padding: 4px 6px; border-radius: 10px; background: var(--ok-soft); color: var(--ok); line-height: 1.15; }
.qty-pill small { font-size: .7rem; font-weight: 500; }
.qty-pill b { font-size: 1.1rem; }
.qty-pill em { font-style: normal; font-size: .7rem; font-weight: 700; }
.qty-pill.low { background: var(--warn-soft); color: var(--warn); }
.qty-pill.out { background: var(--danger-soft); color: var(--danger); }
.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 1.3rem; font-weight: 700; cursor: pointer; }
.stepper input { width: 52px; min-height: 40px; padding: 4px; text-align: center; font-weight: 700; }
.stepper.on input { border-color: var(--primary); background: var(--primary-soft); }
.search { margin-bottom: 4px; }
.sell-bar { position: sticky; bottom: calc(env(safe-area-inset-bottom) + 8px); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; margin: 12px 0; border-radius: 14px; background: var(--surface); border: 2px solid var(--primary); box-shadow: 0 4px 16px rgba(0,0,0,.15); z-index: 5; }
.sell-bar > div { display: flex; flex-direction: column; }
.sell-bar b.num { font-size: 1.4rem; }
.tabs.wrap-tabs { flex-wrap: wrap; overflow: visible; }
.tabs.wrap-tabs .tab { flex: 1 0 30%; min-width: 0; }
.tank-bar { height: 14px; border-radius: 7px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.tank-bar > div { height: 100%; background: var(--ok); border-radius: 7px; }
.tank-bar > .low { background: var(--warn); }
.tank-bar > .out { background: var(--danger); }
.margin-box { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.fuel-card h3 { margin: 0; }
.qty-pill.na { background: var(--surface-2); color: var(--muted); }
.alert .btn.block { margin-top: 10px; }

/* ---------- คลิปวิดีโอ ---------- */
.clip { margin-bottom: 10px; }
.clip video, .clip-view { width: 100%; max-height: 260px; border-radius: 12px; background: #000; display: block; }
.clips { display: grid; gap: 10px; margin-top: 8px; }
dialog.camera.vid video { object-fit: contain; }
dialog.camera.vid .shutter.rec { background: var(--danger); box-shadow: inset 0 0 0 4px #000; }
dialog.camera.vid.recording .shutter.rec { border-radius: 16px; animation: blink 1s infinite; }
.seg-group.stack-seg label { min-width: 0; }
.seg-group.stack-seg span { width: 100%; }
.seg-group.stack-seg small { white-space: normal; }
.list-item > .tile-icon { width: 40px; height: 40px; border-radius: 12px; }
.list-item > .tile-icon svg { width: 22px; height: 22px; }
.menu-order { display: grid; gap: 8px; margin-bottom: 12px; }
.menu-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); font-weight: 600; }
.menu-row .tile-icon { width: 34px; height: 34px; border-radius: 10px; }
.menu-row .tile-icon svg { width: 18px; height: 18px; }
.menu-row .icon-btn { width: 38px; height: 38px; margin: 0; background: var(--surface); border: 1px solid var(--border); font-size: 1rem; }
.menu-row .icon-btn:disabled { opacity: .35; }

/* ตารางกว้างให้เลื่อนเฉพาะในกรอบตัวเอง ไม่ทำให้ทั้งหน้าเลื่อนซ้ายขวา */
.card > table.tbl, section > table.tbl { display: block; overflow-x: auto; white-space: nowrap; }
.stat .diff, .stat b { white-space: normal; overflow-wrap: anywhere; }

/* ---------- โปรเจคในอนาคต ---------- */
.prog { height: 16px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; margin: 10px 0 6px; }
.prog > div { height: 100%; background: var(--primary-btn); border-radius: 8px; min-width: 2px; }
.prog > div.full { background: var(--ok); }
.prog-money { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .92rem; color: var(--muted); }
.prog-money b { color: var(--text); font-size: 1.05rem; }
.ok-text { color: var(--ok); }
.danger-text { color: var(--danger); }
.li-amt.minus { color: var(--danger); }
a.card.project { display: block; color: inherit; text-decoration: none; }
a.card.project:active { background: var(--surface-2); }
.badge.pj-saving { background: var(--info-soft); color: var(--info); }
.badge.pj-ready { background: var(--primary-soft); color: var(--primary); }
.badge.pj-doing { background: var(--warn-soft); color: var(--warn); }
.badge.pj-done { background: var(--ok-soft); color: var(--ok); }
.badge.pj-hold { background: var(--surface-2); color: var(--muted); }

/* ---------- งบกำไรขาดทุน ---------- */
.pnl-head { margin: 14px 0 4px; font-weight: 700; color: var(--muted); font-size: .92rem; border-bottom: 1px solid var(--border); padding-bottom: 3px; }
.pnl-head:first-child { margin-top: 0; }
.pnl-line { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; font-size: .98rem; }
.pnl-line.sub > span:first-child { padding-left: 12px; color: var(--muted); }
.pnl-line.strong { font-weight: 700; border-top: 1px solid var(--border); padding-top: 5px; margin-top: 2px; }
.pnl-line .num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.hero-num.bad { color: var(--danger); }
.print-view .pnl-line { font-size: .8rem; padding: 1px 0; }
.print-view .pnl-head { margin: 8px 0 2px; font-size: .84rem; }
@media print { .pnl { column-count: 2; column-gap: 16px; } .pnl-head { break-after: avoid; } .pnl-line { break-inside: avoid; } }

/* ---------- สต๊อกแก๊ส ---------- */
.gas-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 10px; }
.gas-num { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; border-radius: 12px;
  background: var(--surface-2); text-align: center; }
.gas-num b { font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.gas-num span { font-size: .78rem; color: var(--muted); }
.gas-num.full { background: var(--ok-soft); color: var(--ok); }
.gas-num.empty { background: var(--warn-soft); color: var(--warn); }
.gas-num.total { background: var(--info-soft); color: var(--info); }
.gas-num b { color: inherit; }

/* ---------- แจ้งเตือนทางไลน์ ---------- */
.line-steps { margin: 0 0 10px; padding-left: 20px; line-height: 1.6; }
.line-code { margin: 4px 0 8px; padding: 12px; border-radius: 12px; background: var(--primary-soft); color: var(--primary);
  text-align: center; font-size: 2.2rem; font-weight: 800; letter-spacing: 6px; }
.line-wait { color: var(--muted); margin: 6px 0 0; }
.line-switch { align-items: flex-start; }
.copy-box { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: .85rem; overflow-wrap: anywhere; margin-bottom: 8px; }

/* ---------- หน้าสำหรับพิมพ์ / บันทึก PDF ---------- */
.print-view { background: #fff; color: #111; padding: 16px; border-radius: 12px; overflow-x: auto; }
.print-head { display: flex; justify-content: space-between; gap: 12px; border-bottom: 2px solid #111; padding-bottom: 8px; }
.print-station { font-size: 1.3rem; }
.print-title { margin: 12px 0; font-size: 1.15rem; }
.print-view h3 { margin: 16px 0 6px; font-size: 1.02rem; border-bottom: 1px solid #bbb; padding-bottom: 3px; }
.print-tbl { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.print-tbl th, .print-tbl td { border: 1px solid #ccc; padding: 4px 6px; text-align: left; }
.print-tbl th { background: #f0f0f0; }
.print-tbl .num { text-align: right; white-space: nowrap; }
.print-tbl .b { font-weight: 700; }
.recon-cols td:first-child, .recon-cols th:first-child { width: 40%; }

/* ---------- ใบสรุปแบบกระดาษแผ่นเดียว (ไหลเป็น 2 คอลัมน์ ตัวเล็กลง) ---------- */
.print-view.compact { font-size: .84rem; }
.print-view.compact h3 { margin: 6px 0 3px; font-size: .9rem; }
.print-view.compact .print-title { margin: 4px 0 8px; font-size: 1.05rem; }
.print-view.compact .print-tbl { font-size: .72rem; margin-bottom: 2px; }
.print-view.compact .print-tbl th, .print-view.compact .print-tbl td { padding: 2px 4px; }
.print-view.compact .small { font-size: .68rem; }
.print-view.compact .print-flow { column-count: 2; column-gap: 12px; }
.print-view.compact .print-sec { break-inside: avoid; }
.print-view.compact .print-span { column-span: all; break-before: avoid; }
.print-duo { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; align-items: start; }
@media (max-width: 700px) { .print-duo { grid-template-columns: 1fr; } }
/* กำไรต่อลิตรแยกชนิด (หน้าจอ) */
.stat .per-liter { display: flex; justify-content: space-between; gap: 8px; font-size: 1.05rem; line-height: 1.5; }
.stat .per-liter span { font-variant-numeric: tabular-nums; }
@media (max-width: 700px) { .print-view.compact .print-flow { column-count: 1; } }
.recon-cols thead th { background: #f0f0f0; }
.print-view .small { font-size: .82rem; color: #444; }
.pay-tbl { font-size: .72rem; }
.pay-tbl th, .pay-tbl td { padding: 3px 4px; }
.pay-tbl th.grp { text-align: center; background: #e4e4e4; }
.pay-tbl td:first-child { min-width: 128px; }
.pay-tbl .total-row td { background: #f2f2f2; }
.pay-tbl .sign-cell { min-width: 90px; height: 36px; }
.print-view.wide { overflow-x: auto; }
.print-sign { display: flex; gap: 24px; margin-top: 28px; }
.print-sign > div { flex: 1; text-align: center; }
.sign-line { border-top: 1px dotted #555; margin-bottom: 4px; height: 36px; }
@media print {
  #topbar, #toasts, #back, .no-print, #rotate-lock { display: none !important; }
  html, body { background: #fff !important; color: #000 !important; }
  #main { padding: 0; max-width: none; }
  .print-view { padding: 0; overflow: visible; }
  /* ใบสรุปแผ่นเดียว: ไหล 2 คอลัมน์ และลดขนาดตัวอักษรของทั้งหน้า */
  html { font-size: 100% !important; }   /* ขนาดตัวอักษรที่ผู้ใช้เลือก ไม่ต้องมีผลตอนพิมพ์ */
  .print-view.compact .print-flow { column-count: 2; column-gap: 12px; }
  .print-view.compact .print-span { column-span: all; }
  .print-duo { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; align-items: start; }
  /* หัวข้อต้องอยู่หน้าเดียวกับข้อมูลของมัน */
  .print-sec, .print-tbl, .print-sign, .print-head { break-inside: avoid; page-break-inside: avoid; }
  .print-sec.tall { break-inside: auto; page-break-inside: auto; }
  .print-view h2, .print-view h3, .print-head { break-after: avoid; page-break-after: avoid; }
  .print-tbl tr { break-inside: avoid; page-break-inside: avoid; }
  .print-tbl thead { display: table-header-group; }
  .print-tbl thead th { border-bottom: 2px solid #999; }
  @page { margin: 12mm; }
}

/* ================================================================
   โหมดคอมพิวเตอร์ (html.desk) — จอกว้างตั้งแต่ 1024px เช่น คอมที่ปั๊ม โน้ตบุ๊ก แท็บเล็ตแนวนอน
   ไม่มีหน้าแรก เมนูทั้งหมดอยู่ด้านซ้าย (ซ่อนได้ด้วยปุ่ม ☰) และจัดหน้าให้ใช้พื้นที่เต็มจอ
   ทุกกฎขึ้นต้นด้วย .desk และส่วนที่เพิ่มในหน้าเว็บซ่อนด้วย hidden มือถือจึงเหมือนเดิมทุกอย่าง
   ================================================================ */
.desk { --nav-w: 15rem; --top-h: 64px; }
.desk body {
  display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); grid-template-rows: auto 1fr;
  min-height: 100vh;
}
.desk.nav-off body { grid-template-columns: minmax(0, 1fr); }

/* แถบบน: [☰ โลโก้ ชื่อปั๊ม] | ชื่อหน้า ........ ผู้ใช้ [เต็มจอ] */
.desk #topbar { grid-column: 1 / -1; height: var(--top-h); padding: 0 16px 0 0; gap: 12px; }
.desk #deskhead {
  display: flex; align-items: center; gap: 6px; flex: none; width: var(--nav-w); height: 100%;
  padding: 0 12px 0 10px; border-right: 1px solid rgba(255, 255, 255, .14);
}
.desk.nav-off #deskhead { width: auto; padding-right: 18px; }
.desk #navtoggle { margin: 0; flex: none; }
.desk #deskbrand { display: flex; align-items: center; gap: 10px; min-width: 0; color: #fff; font-size: 1.25rem; font-weight: 800; letter-spacing: .02em; }
.desk #deskbrand img { width: 36px; height: 36px; border-radius: 10px; background: #fff; flex: none; }
.desk #brand { display: none; }
.desk #back { margin-left: 4px; }
.desk #title { font-size: 1.3rem; margin-left: 6px; }
.desk #back:not([hidden]) + #brand + #title { margin-left: 0; }
.desk #who { max-width: 40%; padding: 6px 10px; border-radius: 10px; cursor: pointer; font-size: .85rem; }
.desk #fullscreen { margin: 0; flex: none; }
.desk #topbar .icon-btn:hover, .desk #who:hover { background: rgba(255, 255, 255, .12); }

/* เมนูด้านซ้าย */
.desk #sidenav {
  display: flex; flex-direction: column; gap: 2px; grid-column: 1; grid-row: 2;
  position: sticky; top: var(--top-h); align-self: start; height: calc(100vh - var(--top-h));
  overflow-y: auto; padding: 10px 10px 8px; background: var(--surface); border-right: 1px solid var(--border);
  scrollbar-width: thin;
}
.desk #sidenav[hidden], .desk.nav-off #sidenav { display: none; }
.nav-status {
  display: flex; align-items: flex-start; gap: 10px; flex: none; margin: 0 0 8px; padding: 9px 12px;
  border-radius: 12px; background: var(--surface-2); color: var(--text); font-size: .84rem; line-height: 1.4;
}
.nav-status b { display: block; font-size: .92rem; }
.nav-status .small { display: block; color: var(--text); opacity: .8; font-size: .8rem; }
.nav-status .dot { width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; flex: none; background: var(--muted); }
.nav-status.open { background: var(--info-soft); color: var(--info); border-left: 4px solid var(--brand-green); }
.nav-status.open .dot { background: var(--info); box-shadow: 0 0 0 3px color-mix(in srgb, var(--info) 25%, transparent); }
a.nav-status:hover { filter: brightness(.97); }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; flex: none; width: 100%; min-height: 40px;
  padding: 4px 10px; border: 0; border-radius: 12px; background: none; color: var(--text);
  font: inherit; font-size: .96rem; font-weight: 600; text-align: left; cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--brand-red);
}
.nav-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 30px; height: 30px; border-radius: 9px; background: var(--brand-red-soft); color: var(--brand-red);
}
.nav-icon svg { width: 18px; height: 18px; }
.nav-item.active .nav-icon { background: var(--surface); }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3; }
.nav-count {
  flex: none; display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px;
  padding: 0 7px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .78rem; font-weight: 700;
}
.nav-foot { margin-top: auto; padding-top: 6px; border-top: 1px solid var(--border); flex: none; }
.nav-mini {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; border-radius: 10px;
  background: none; color: var(--muted); font: inherit; font-size: .86rem; font-weight: 500; cursor: pointer; text-align: left;
}
.nav-mini:hover, .nav-mini.active { background: var(--surface-2); color: var(--text); }
.nav-mini svg { width: 18px; height: 18px; }

/* พื้นที่เนื้อหา: หน้าทั่วไปกว้างพอดีอ่าน ส่วนหน้าที่มีข้อมูลเยอะ (.wide) ใช้เต็มจอ */
.desk #main { grid-column: 2; grid-row: 2; width: 100%; max-width: 54rem; margin: 0 auto; padding: 24px 32px 48px; }
.desk #main.wide { max-width: 84rem; }
.desk #sidenav[hidden] + #main, .desk.nav-off #main { grid-column: 1 / -1; }
.desk.nav-off #main.wide { max-width: none; }
.desk #toasts { left: calc(var(--nav-w) + 16px); }
.desk.nav-off #toasts { left: 16px; }

/* ใช้เมาส์: ชี้แล้วมีปฏิกิริยา */
.desk .tile { transition: transform .12s ease, box-shadow .12s ease; }
.desk .tile:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(16, 24, 40, .12); }
.desk a.list-item:hover, .desk button.list-item:hover, .desk a.kv:hover { background: var(--surface-2); }
.desk .btn:hover:not(:disabled) { filter: brightness(.96); }
.desk .chip:hover { border-color: var(--primary); }

/* หน้าแรก (ใช้เฉพาะตอนโหลดเมนูไม่สำเร็จ): เมนูเป็นตาราง 3 ช่อง */
.desk #main[data-page="home"] .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.desk #main[data-page="home"] .tile.wide { grid-column: span 2; }

/* ---------- Dashboard: ทุกช่องอยู่ในจอเดียว (แต่ละช่องมีจำนวนแถวตายตัว) ---------- */
.desk #main[data-page="dashboard"] { padding: 12px 18px; container-type: inline-size; }
.dd { display: flex; flex-direction: column; gap: 10px; height: calc(100vh - var(--top-h) - 24px); min-height: 480px; }
.dd-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; flex: none; }
.dd-month { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dd-month .icon-btn { margin: 0; width: 36px; height: 36px; flex: none; background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.dd-month > div { display: flex; align-items: baseline; gap: 10px; min-width: 0; white-space: nowrap; }
.dd-month b { font-size: 1.15rem; }
.dd-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.dd-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: .84rem; font-weight: 600; white-space: nowrap;
}
.dd-pill svg { width: 16px; height: 16px; }
.dd-pill.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
a.dd-pill:hover { filter: brightness(.96); }
.dd-kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; flex: none; }
.kpi {
  display: flex; flex-direction: column; min-width: 0; padding: 7px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); line-height: 1.35;
}
.kpi.main { border-top: 4px solid var(--brand-red); padding-top: 4px; }
.kpi-label, .kpi-sub, .kpi .delta { font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-label { font-weight: 600; color: var(--muted); }
.kpi-sub { font-weight: 400; color: var(--muted); }
.kpi .delta { margin: 0; }
/* ตัวเลขใหญ่ขึ้นตามพื้นที่ (ซ่อนเมนูแล้วตัวเลขจะใหญ่ขึ้น) */
.kpi-value { font-size: clamp(1.02rem, 1.62cqi, 1.5rem); font-weight: 800; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value .diff { font-size: inherit; }
.kpi.good .kpi-value { color: var(--ok); }
.kpi.bad .kpi-value { color: var(--danger); }
.dd-grid {
  flex: 1; min-height: 0; display: grid; gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr));
}
.dd-card { min-height: 0; margin: 0; padding: 9px 13px; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; font-size: .86rem; }
.dd-card h3 { font-size: .98rem; margin: 0 0 5px; }
.dd-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex: none; margin-bottom: 5px; }
.dd-card-head h3 { margin: 0; }
.dd-chart { grid-column: span 2; display: flex; flex-direction: column; overflow: hidden; }
.dd-chart .readout { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: 0 8px; min-height: 0; margin: 0; }
.dd-chart .readout b { font-size: 1.02rem; }
.dd-chart .readout span { font-size: .78rem; }
.dd-chart .chart-host { position: relative; flex: 1; min-height: 0; }
.dd-chart .chart { position: absolute; inset: 0; width: 100%; height: 100%; }
.dd-chart .bar { cursor: pointer; }
.dd-card .rline { padding: 2px 0; font-size: .86rem; white-space: nowrap; }
.dd-card .rline > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.dd-card .rresult { margin-top: 6px; padding: 7px 10px; font-size: .9rem; }
.dd-card .rresult b { font-size: 1.1rem; }
.dd-card .paybar { height: 12px; margin: 2px 0 4px; }
.dd-card .legend-row { padding: 2px 0; gap: 6px; white-space: nowrap; }
.dd-card .legend-row .grow { overflow: hidden; text-overflow: ellipsis; }
.dd-card .pct { width: 34px; }
.dd-card .kv { padding: 3px 0; white-space: nowrap; }
.dd-card .kv > :first-child { overflow: hidden; text-overflow: ellipsis; }
.dd-card .diff { font-size: .84rem; }
.dd-card .empty { padding: 18px 8px; }
.dd-bar { padding: 2px 0 3px; }
.dd-bar-head { display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; line-height: 1.35; }
.dd-bar-head > :first-child { overflow: hidden; text-overflow: ellipsis; }
.dd-bar .hbar-track { height: 5px; margin-top: 2px; background: var(--surface-2); border-radius: 3px; }
.dd-bar .hbar-fill { border-radius: 3px; }
.dd-person { display: block; padding: 5px 13px; margin: 0 -13px; border-top: 1px solid var(--border); color: inherit; }
.dd-person:first-of-type { border-top: 0; }
.dd-person:hover { background: var(--surface-2); }
.dd-person-top, .dd-person-sub { display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; }
.dd-person-top b { overflow: hidden; text-overflow: ellipsis; }
.dd-person-sub { font-size: .78rem; color: var(--muted); }
/* หน้าต่างเตี้ย (เช่น เบราว์เซอร์ไม่เต็มจอบนจอ 768): บีบระยะห่าง ซ่อนบรรทัดรองของตัวเลขหลัก */
@media (max-height: 720px) {
  .dd { gap: 8px; }
  .dd-kpis, .dd-grid { gap: 8px; }
  .kpi .kpi-sub { display: none; }
  .dd-card { padding: 7px 12px; line-height: 1.4; }
  .dd-card .rline { padding: 1px 0; }
  .dd-card .rresult { margin-top: 4px; padding: 5px 10px; }
  .dd-card .legend-row, .dd-card .kv { padding: 1px 0; }
  .dd-bar { padding: 1px 0 2px; }
  .dd-person { padding: 3px 12px; margin: 0 -12px; }
  .nav-item { min-height: 37px; padding: 3px 10px; }
  .nav-icon { width: 28px; height: 28px; }
  .nav-status { padding: 7px 12px; margin-bottom: 6px; }
}
/* จอแคบ (เช่น 1024 พร้อมเมนู): เรียง 2 คอลัมน์ และเลื่อนดูทั้งหน้าตามปกติ */
@container (max-width: 940px) {
  .dd { height: auto; }
  .dd-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-value { font-size: 1.2rem; }
  .dd-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; grid-auto-rows: minmax(200px, auto); }
  .dd-chart { min-height: 260px; }
}

/* กะและยอดขาย: ปุ่มลัดแถวเดียว · รายการกะ 2 คอลัมน์ (กะเย็น|กะเช้า ของวันเดียวกัน) */
.desk #main[data-page="shifts"] .grid2 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.desk #main[data-page="shifts"] .filters { max-width: 36rem; }
.desk #main[data-page="shifts"] .list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.desk #main[data-page="shifts"] .list-item:nth-child(2) { border-top: 0; }
.desk #main[data-page="shifts"] .list-item:nth-child(odd) { border-right: 1px solid var(--border); }

/* สรุปรายวัน: ตัวเลขหลักซ้าย รายละเอียดขวา */
.desk .day-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 20px; align-items: start; }
.desk .day-right > .section-title:first-child { margin-top: 0; }
.desk .day-cols section > table.tbl { display: table; }

/* ฟอร์มเริ่มกะ/ปิดกะ: ช่องมิเตอร์และช่องเงินเรียง 2 คอลัมน์ ฟอร์มสั้นลงครึ่งหนึ่ง */
.desk .card:has(> .meter-line) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
.desk .card:has(> .meter-line) > .meter-line:nth-of-type(2) { border-top: 0; padding-top: 0; }
.desk #main[data-page="shift"] .card:has(> label.field + label.field) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; }

/* ปุ่มสลับกลับเป็นโหมดคอมพิวเตอร์ (เห็นเฉพาะจอกว้างที่เลือกมุมมองมือถือไว้) */
#deskpill {
  display: inline-flex; align-items: center; gap: 8px; position: fixed; right: 16px; bottom: 16px; z-index: 50;
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 700; box-shadow: 0 6px 20px rgba(0, 0, 0, .15); cursor: pointer;
}
#deskpill svg { width: 20px; height: 20px; }

/* สถานะข้อมูลอัปเดตอัตโนมัติ (ท้ายเมนูซ้าย) */
.nav-live { display: flex; align-items: center; gap: 9px; padding: 4px 10px 6px; color: var(--muted); font-size: .8rem; }
.nav-live .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.nav-live.off { color: var(--danger); font-weight: 600; }
.nav-live.off .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

@media print {
  #sidenav, #deskhead, #deskpill, #fullscreen { display: none !important; }
  .desk body { display: block; }
  .desk #main { max-width: none; margin: 0; padding: 0; }
}
