@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;700;800&display=swap');

/* โทเคนสีเดียวกับ PIN Wallet / PIN Studio (ชมพู→ม่วง) มี 2 โหมด: มืด (ค่าเริ่มต้น) และสว่าง */
:root, :root[data-theme='dark'] {
  color-scheme: dark;
  --canvas: #08080b; --surface: #14141c; --surface-2: #101016; --ink: #f5f3f7; --muted: #a39bab;
  --line: rgba(255, 255, 255, 0.11); --field: #101016;
  --brand: #ff2d95; --brand-soft: #ff7ac0; --violet: #8b3dff; --brand-gradient: linear-gradient(120deg, #ff2d95, #8b3dff);
  --green: #4fd1a5; --green-soft: rgba(79, 209, 165, 0.14); --coral: #ff7a93; --coral-soft: rgba(255, 122, 147, 0.14);
  --blue: #6fb0d4; --band: #1b1324; --nav: rgba(13, 9, 17, 0.92); --nav-line: rgba(255, 255, 255, 0.1);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45); --scrim: rgba(0, 0, 0, 0.62); --chip-soft: rgba(255, 255, 255, 0.06);
  --glow-1: rgba(255, 45, 149, 0.16); --glow-2: rgba(139, 61, 255, 0.14);
}
:root[data-theme='light'] {
  color-scheme: light;
  --canvas: #f7f3fa; --surface: #ffffff; --surface-2: #f1ecf5; --ink: #1c1624; --muted: #6b6275;
  --line: rgba(28, 22, 36, 0.12); --field: #ffffff;
  --brand: #ff2d95; --brand-soft: #c2187a; --violet: #8b3dff; --brand-gradient: linear-gradient(120deg, #ff2d95, #8b3dff);
  --green: #178a68; --green-soft: rgba(23, 138, 104, 0.12); --coral: #cf3556; --coral-soft: rgba(207, 53, 86, 0.1);
  --blue: #2f7fa8; --band: #f1e8fb; --nav: rgba(255, 255, 255, 0.94); --nav-line: rgba(28, 22, 36, 0.1);
  --shadow: 0 14px 40px rgba(60, 30, 90, 0.14); --scrim: rgba(20, 10, 30, 0.45); --chip-soft: rgba(28, 22, 36, 0.05);
  --glow-1: rgba(255, 45, 149, 0.1); --glow-2: rgba(139, 61, 255, 0.09);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { overflow-x: clip; }
body { margin: 0; min-width: 320px; min-height: 100dvh; background: var(--canvas); color: var(--ink); font: 400 14px/1.5 'Noto Sans Thai', sans-serif; letter-spacing: 0; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible { outline: 3px solid rgba(255, 122, 192, 0.75); outline-offset: 3px; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.shell { min-height: 100dvh; background: radial-gradient(circle at 92% 6%, var(--glow-1), transparent 32%), radial-gradient(circle at 4% 96%, var(--glow-2), transparent 34%), var(--canvas); }
.main { width: min(760px, 100%); margin: 0 auto; padding: 0 18px 118px; }

/* แถบบน */
.topbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 12px; min-height: 58px; margin: 0 -18px; padding: max(10px, env(safe-area-inset-top)) 18px 10px; background: var(--canvas); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand img { width: 36px; height: 36px; border-radius: 22%; flex: none; }
.brand b { display: block; font-size: 18px; font-weight: 800; line-height: 1.2; }
.brand small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--chip-soft); border: 1px solid var(--line); color: var(--ink); }
.icon-btn:hover { border-color: var(--brand-soft); }

h1 { font-size: 24px; line-height: 1.25; margin: 22px 0 4px; font-weight: 800; }
h2 { font-size: 18px; margin: 22px 0 8px; font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; min-width: 0; }

/* การ์ด */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 16px; margin: 12px 0; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08); }
:root[data-theme='dark'] .card { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); }
.hero { position: relative; overflow: hidden; margin: 14px 0; padding: 20px; border-radius: 24px; color: #fff; background: var(--brand-gradient); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 14px 36px rgba(255, 45, 149, 0.28); }
.hero small { display: block; font-size: 13px; opacity: 0.9; }
.hero .big { font-size: 28px; font-weight: 800; line-height: 1.2; }
.hero .progress { background: rgba(255, 255, 255, 0.28); }
.hero .progress > i { background: #fff; }
.hero .mini { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; }

/* ฟอร์ม */
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
input, select, textarea { width: 100%; min-height: 58px; padding: 0 16px; background: var(--field); border: 1px solid var(--line); border-radius: 16px; outline: none; font-size: 16px; }
textarea { padding: 14px 16px; min-height: 120px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-soft); box-shadow: 0 0 0 3px rgba(255, 45, 149, 0.22); }
::placeholder { color: var(--muted); opacity: 0.8; }
.err { color: var(--coral); font-size: 13px; margin-top: 6px; }

/* ปุ่ม */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 58px; padding: 0 22px; border-radius: 17px; border: 1px solid var(--line); background: transparent; font-weight: 700; font-size: 16px; }
.btn.primary { background: var(--brand-gradient); border: 0; color: #fff; box-shadow: 0 10px 26px rgba(255, 45, 149, 0.28); }
.btn.danger { border-color: rgba(255, 122, 147, 0.5); background: var(--coral-soft); color: var(--coral); }
.btn.small { min-height: 44px; padding: 0 16px; font-size: 14px; border-radius: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand-soft); font-size: 12px; font-weight: 800; min-height: 44px; padding: 0 4px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 500; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.ok { color: var(--green); background: var(--green-soft); border-color: transparent; }
.chip.warn { color: var(--brand-soft); background: rgba(255, 45, 149, 0.12); border-color: transparent; }
.chip.bad { color: var(--coral); background: var(--coral-soft); border-color: transparent; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--brand-gradient); border-radius: 99px; transition: width .3s; }

.notice { display: flex; align-items: center; gap: 10px; margin: 12px 0; padding: 12px 14px; border-radius: 16px; background: var(--band); border: 1px solid rgba(139, 61, 255, 0.35); font-size: 13px; }
.notice::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 99px; background: var(--green); }

/* รายการหน่วย */
.unit { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 12px 14px; margin: 10px 0; min-height: 68px; }
.unit:hover { border-color: var(--brand-soft); }
.unit .badge { display: grid; place-items: center; flex: none; width: 46px; height: 46px; border-radius: 15px; background: rgba(255, 45, 149, 0.12); color: var(--brand-soft); font-weight: 800; font-size: 15px; }
.unit .badge.done { background: var(--green-soft); color: var(--green); }
.unit .t { font-weight: 700; font-size: 16px; line-height: 1.3; }
.unit .chev { color: var(--muted); }

.tabs { display: flex; gap: 8px; }
.tabs button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; border-radius: 99px; border: 1px solid var(--line); background: none; font-weight: 700; }
.tabs button.on { border-color: transparent; background: var(--brand-gradient); color: #fff; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 9px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.r, th.r { text-align: right; }
tr:last-child td { border-bottom: 0; }

/* แผ่นล่าง */
.sheet-bg { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; background: var(--scrim); backdrop-filter: blur(3px); }
.sheet { position: relative; width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 26px 26px 0 0; padding: 26px 18px calc(24px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
.sheet::before { content: ''; position: absolute; top: 10px; left: 50%; width: 45px; height: 5px; border-radius: 5px; background: var(--line); transform: translateX(-50%); }
.sheet-close { position: absolute; right: 14px; top: 14px; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--chip-soft); }
.sheet h2:first-child { margin-top: 0; padding-right: 48px; }
.kv { padding: 14px 16px; border-radius: 20px; background: var(--surface-2); }
.kv .v { font-size: 28px; font-weight: 800; line-height: 1.2; }

/* เมนู: แถบล่างบนมือถือ */
nav.menu { position: fixed; z-index: 30; left: 14px; right: 14px; bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 4px; max-width: 560px; margin: 0 auto; padding: 7px; border-radius: 24px; background: var(--nav); border: 1px solid var(--nav-line); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
nav.menu button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; border: 0; border-radius: 18px; background: none; color: var(--muted); font-size: 11px; font-weight: 700; }
nav.menu button.on { color: var(--brand-soft); background: rgba(255, 45, 149, 0.12); }

.desktop-note { display: none; }
.hide-wide { display: initial; }

/* จอใหญ่ (เจ้าของ/ผู้จัดการ): เมนูซ้าย เนื้อหากลาง */
@media (min-width: 900px) {
  .shell.manager { display: grid; grid-template-columns: 250px minmax(0, 1fr); }
  .shell.manager nav.menu { position: sticky; top: 0; left: auto; right: auto; bottom: auto; flex-direction: column; justify-content: flex-start; gap: 6px; height: 100dvh; max-width: none; margin: 0; padding: 88px 14px 14px; border-radius: 0; border: 0; border-right: 1px solid var(--line); box-shadow: none; backdrop-filter: none; background: var(--surface-2); order: -1; }
  .shell.manager nav.menu button { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 52px; padding: 0 16px; font-size: 14px; }
  .shell.manager .main { width: min(820px, 100%); padding-bottom: 48px; }
  .shell.manager .topbar { margin-inline: -18px; }
  .shell.reader .app-body, .shell.reader nav.menu { display: none; }
  .shell.reader .desktop-note { display: block; margin-top: 24px; }
}
@media (max-width: 380px) { .main { padding-inline: 14px; } .topbar { margin-inline: -14px; padding-inline: 14px; } h1 { font-size: 22px; } }

/* รูปมิเตอร์ + อ่านเลขจากรูป */
.photo-actions { display: grid; gap: 10px; }
.photo-actions .btn { min-height: 48px; font-size: 14px; }
.meter-photo { width: 100%; max-height: 220px; object-fit: contain; border-radius: 16px; border: 1px solid var(--line); background: #000; }
