/* =========================================================
   mobile.css — Web App มือถือ/แท็บเล็ตเป็นหลัก (รายงาน 06_ · D-16)
   ขนาดจอ: < 600 มือถือ (เมนูล่าง) · 600–979 แท็บเล็ต (แถบเมนูข้างแบบไอคอน) · ≥ 980 คอมพิวเตอร์ (เมนูข้างเต็ม เดิม)
   ใช้ token จาก ptru-ds.css เท่านั้น
   ========================================================= */

/* ---------- โครงหน้าระหว่างโหลดครั้งแรก ---------- */
.boot{min-height:100vh;min-height:100dvh;background:var(--bg)}
.boot-bar{height:var(--ctx-h);display:flex;align-items:center;gap:14px;padding:0 var(--cpad);background:var(--surface);border-bottom:1px solid var(--line)}
.boot-logo{width:36px;height:36px;border-radius:var(--r2);background:var(--primary)}
.boot-bar .boot-t{width:160px;margin:0}
.boot-body{padding:20px var(--cpad);display:flex;flex-direction:column;gap:14px;max-width:var(--page-max)}
.boot-body .skel{margin:0}
.boot-hero{height:150px;border-radius:var(--r4)}
.boot-row{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.boot-row .skel{height:76px;border-radius:var(--r3)}
.boot-list{height:260px;border-radius:var(--r3)}

/* ---------- แถบบน: ปุ่มย้อนกลับ + ชื่อหน้า (มือถือ) ---------- */
.ctx .back-btn,.ctx .ctx-title{display:none}
.ctx-title{min-width:0;line-height:1.25}
.ctx-title small{display:block;font-size:var(--fs-1);color:var(--ink-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ctx-title b{display:block;font-size:var(--fs-4);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ctx .crumb a{display:inline-flex;align-items:center;min-height:44px}
.net-pill{display:inline-flex;align-items:center;gap:6px;padding:4px 10px;border-radius:var(--rpill);background:var(--warn-soft);color:var(--warn-ink);font-size:var(--fs-1);font-weight:600;white-space:nowrap}
.net-pill[hidden]{display:none}
.net-pill .ph{font-size:16px}

/* ---------- แถบแจ้งสัญญาณหลุด (อยู่ในหน้า ไม่ขวางงาน) ---------- */
.net-banner{position:sticky;top:var(--ctx-h);z-index:25;display:flex;gap:10px;align-items:flex-start;margin:calc(-1 * clamp(18px,2.4vw,30px)) calc(-1 * var(--cpad)) 16px;padding:10px var(--cpad);background:var(--warn-soft);color:var(--warn-ink);font-size:var(--fs-2);line-height:1.5;border-bottom:1px solid var(--line)}
.net-banner .ph{font-size:20px;flex:0 0 auto;margin-top:1px}
body.public .net-banner{top:0;margin:0}

/* ---------- แถบเมนูข้างแบบไอคอน (แท็บเล็ต) ---------- */
.nav-rail{display:none}
.nav-rail a{position:relative;display:flex;flex-direction:column;align-items:center;gap:3px;width:76px;padding:6px 0;border-radius:var(--r3);color:var(--rail-ink);text-decoration:none;font-size:var(--fs-1);font-weight:500;line-height:1.3;text-align:center;min-height:56px;justify-content:center}
.nav-rail a .ph{font-size:24px;padding:4px 18px;border-radius:var(--r3)}
.nav-rail a.on{color:var(--on-dark)}
.nav-rail a.on .ph{background:var(--glass-2);color:var(--gold)}
.nav-rail a:hover .ph{background:var(--rail-hover)}
.nav-rail .nr-logo{min-height:0;margin-bottom:10px}
.nav-rail .nr-logo .logo{width:44px;height:44px}
.nav-rail .nr-more{margin-top:auto}
.nav-rail .cnt{position:absolute;top:2px;right:12px;background:var(--gold);color:var(--primary-700);font-size:11px;border-radius:var(--rpill);padding:0 6px;line-height:1.6}

@media (min-width:600px) and (max-width:979.98px){
  .shell{grid-template-columns:92px minmax(0,1fr)}
  .nav-rail{display:flex;flex-direction:column;align-items:center;gap:4px;position:sticky;top:0;height:100vh;height:100dvh;padding:max(14px,env(safe-area-inset-top)) 0 max(14px,env(safe-area-inset-bottom));padding-left:env(safe-area-inset-left);background:var(--rail-bg);z-index:40}
  .bottom-nav{display:none!important}
  .content{padding-bottom:60px}
  .ctx .menu-btn{display:none}
  .toasts{bottom:16px}
  .grid.g4{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media (min-width:700px) and (max-width:979.98px){
  .grid.g4{grid-template-columns:repeat(4,minmax(0,1fr));gap:12px}
  .kpi{gap:10px;padding:14px}
  .kpi .ic{width:40px;height:40px;flex-basis:40px;font-size:20px}
  .kpi .v{font-size:var(--fs-5)}
  .kpi .l{font-size:var(--fs-1);line-height:1.35}
}

/* ---------- มือถือ ---------- */
@media (max-width:599.98px){
  .ctx{gap:8px;padding-left:max(12px,env(safe-area-inset-left));padding-right:max(12px,env(safe-area-inset-right))}
  .ctx .crumb{display:none}
  .ctx .ctx-title{display:block;flex:1 1 auto}
  .ctx .back-btn{display:inline-flex}
  .ctx .menu-btn.has-back{display:none}
  .ctx .meta .btn.icon{display:none}
  .content{padding-left:max(16px,env(safe-area-inset-left));padding-right:max(16px,env(safe-area-inset-right))}
  .toasts{left:12px;right:12px;max-width:none;bottom:calc(84px + env(safe-area-inset-bottom))}
  /* หน้าหลักครู: การ์ดต้อนรับกระชับ เห็นสถิติและรายการหน่วยในจอแรก (D-15: คงสี/ลำดับเดิม) */
  .greet{padding:16px}
  .greet>.row.between.top{flex-wrap:nowrap;align-items:center;gap:12px}
  .greet h1{font-size:var(--fs-6)}
  .greet>.row p:last-child{font-size:var(--fs-2);margin-bottom:0}
  .greet-meter{width:84px;flex:0 0 84px;padding:4px}
  .greet .continue{margin-top:12px;padding:12px}
  .greet .continue .btn{width:100%;justify-content:flex-start;text-align:left}
  .grid.g4{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
  .kpi{gap:10px;padding:12px}
  .kpi .ic{width:40px;height:40px;flex-basis:40px;font-size:20px}
  .kpi .v{font-size:var(--fs-5)}
  .kpi .l{font-size:var(--fs-1);line-height:1.35}
  /* หน้าเริ่มแบบทดสอบ: ตัวเลข 3 ช่องในแถวเดียว */
  .test-facts{grid-template-columns:repeat(3,minmax(0,1fr))!important;gap:8px}
  .test-facts div{padding:10px 4px}
  .test-facts b{font-size:var(--fs-6)}
  .test-facts span{font-size:var(--fs-1);display:block;line-height:1.3}
}

/* ---------- พื้นที่กดสำหรับนิ้ว (จอสัมผัส) ---------- */
.btn.icon{width:44px;min-height:44px}
.rail a.nav{min-height:44px}
.bottom-nav a{min-height:52px}
.auth .box a.small,.auth .box p.small a,.auth .box p.center a{display:inline-flex;align-items:center;gap:6px;min-height:44px}
@media (pointer:coarse){
  .btn{min-height:44px}
  .btn.sm{min-height:40px}
  .check{min-height:44px;align-items:center}
  .check input{margin-top:0}
}

/* ---------- โหมดโฟกัส (ทำแบบทดสอบ) ---------- */
body.focus .bottom-nav,body.focus .nav-rail{display:none!important}
@media (min-width:600px) and (max-width:979.98px){body.focus .shell{grid-template-columns:minmax(0,1fr)}}
.player .autosave{display:flex;gap:4px;align-items:center;margin-top:2px}
@media (max-width:599.98px){
  body.focus .content{padding-bottom:110px}
  body.focus .q-actions{position:fixed;left:0;right:0;bottom:0;z-index:45;margin:0;padding:12px max(16px,env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));background:var(--surface);border-top:1px solid var(--line);box-shadow:var(--sh-2);flex-wrap:nowrap}
  body.focus .q-actions .btn{flex:1 1 0;white-space:nowrap}
  body.focus .q-actions .btn.ghost{flex:0 0 auto}
  body.focus .toasts{bottom:calc(84px + env(safe-area-inset-bottom))}
  .q-nav .q-grid{grid-template-columns:repeat(auto-fill,minmax(40px,1fr))}
  .q-nav [data-submit]{display:none}
}

/* ---------- แผ่นจากด้านล่าง (bottom sheet) ---------- */
.sheet-bg{position:fixed;inset:0;z-index:95;background:var(--overlay);display:flex;align-items:flex-end;justify-content:center;animation:fin .15s}
.sheet{background:var(--surface);width:100%;max-width:520px;max-height:calc(100dvh - 40px);overflow:auto;border-radius:var(--r4) var(--r4) 0 0;box-shadow:var(--sh-3);padding:10px 20px calc(24px + env(safe-area-inset-bottom));animation:shup .22s ease}
.sheet .grab{width:40px;height:5px;border-radius:3px;background:var(--line-2);margin:0 auto 14px}
.sheet h3{font-family:var(--sans);font-size:var(--fs-5);margin:0 0 6px}
.sheet .sh-ic{width:64px;height:64px;border-radius:50%;display:grid;place-items:center;font-size:32px;margin-bottom:10px;background:var(--primary-soft);color:var(--primary)}
.sheet .sh-ic.warn{background:var(--warn-soft);color:var(--warn-ink)}
.sheet .err{color:var(--bad-ink);font-size:var(--fs-2);margin:0 0 10px}
.sheet .app-ic{border-radius:var(--r3);flex:0 0 56px}
.sh-points{list-style:none;margin:0 0 18px;padding:0;display:flex;flex-direction:column;gap:8px}
.sh-points li{display:flex;gap:10px;align-items:center}
.sh-points .ph{font-size:20px;color:var(--primary)}
.sh-steps{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:12px}
.sh-steps li{display:flex;gap:12px;align-items:center}
.sh-steps li>span{width:40px;height:40px;border-radius:50%;background:var(--primary-soft);color:var(--primary);display:grid;place-items:center;font-weight:700;flex:0 0 40px}
.sh-steps .ph{font-size:22px;color:var(--info-deep)}
.sh-acts{gap:10px;flex-wrap:nowrap}
.sh-acts .btn{flex:1 1 0}
@media (min-width:600px){.sheet-bg{align-items:center;padding:16px}.sheet{border-radius:var(--r4);padding-bottom:24px}.sheet .grab{display:none}}
@keyframes shup{from{transform:translateY(40px);opacity:.4}to{transform:none;opacity:1}}

/* ---------- แจ้งผลสั้น (toast) ---------- */
.toasts{pointer-events:none} /* แตะทะลุแถบแจ้งผลได้ ไม่บังตัวเลือก/ปุ่มด้านหลัง */
.toast .t-act,.toast .t-x{pointer-events:auto}
.toast .grow{flex:1 1 auto;min-width:0}
.toast.info{background:var(--info-ink)}
.toast .t-act{background:none;border:0;color:var(--gold);font-weight:700;font-size:var(--fs-3);padding:6px 8px;min-height:40px;cursor:pointer;white-space:nowrap}
.toast .t-x{background:none;border:0;color:inherit;opacity:.8;min-width:40px;min-height:40px;display:grid;place-items:center;cursor:pointer;font-size:18px;padding:0}

/* ---------- ดึงลงเพื่อรีเฟรช ---------- */
.ptr{position:fixed;left:50%;top:calc(env(safe-area-inset-top) + 8px);z-index:60;transform:translate(-50%,-56px);display:flex;gap:8px;align-items:center;background:var(--surface);color:var(--ink-2);border:1px solid var(--line);box-shadow:var(--sh-2);border-radius:var(--rpill);padding:8px 14px;font-size:var(--fs-2);pointer-events:none}
.ptr .ph{font-size:20px;color:var(--primary);transition:transform .2s}
.ptr.ready .ph{transform:rotate(180deg)}
.ptr.spin .ph{animation:ptrspin .8s linear infinite}
@keyframes ptrspin{to{transform:rotate(360deg)}}

/* ---------- หน้าสถานะ (ว่าง/ล็อก/ข้อผิดพลาด/ไม่มีสิทธิ์/ไม่พบหน้า) ---------- */
.empty.tone>.ph,.empty.state>.ph{width:88px;height:88px;border-radius:50%;display:grid;place-items:center;margin:0 auto 12px;font-size:44px;background:var(--primary-soft);color:var(--primary)}
.empty.state.bad>.ph{background:var(--bad-soft);color:var(--bad-ink)}
.empty.state.warn>.ph{background:var(--warn-soft);color:var(--warn-ink)}
.empty.state:not(.bad):not(.warn)>.ph{background:var(--bg-2);color:var(--ink-3)}
/* ไอคอนในปุ่ม/ป้ายภายในหน้าว่าง ใช้ขนาดปกติ (กฎ .empty .ph เดิมทำให้ใหญ่ผิด) */
.empty .btn .ph,.empty .badge .ph,.empty .step-pills>.ph{display:inline;width:auto;height:auto;margin:0;font-size:1.15em;background:none;color:inherit;border-radius:0}
.empty .ref{display:inline-block;font-size:var(--fs-1);background:var(--bg-2);border-radius:var(--r1);padding:3px 10px;color:var(--ink-3)}
.empty .row.center{justify-content:center}
.step-pills{display:flex;gap:6px;align-items:center;justify-content:center;flex-wrap:wrap;margin:6px 0 16px;color:var(--ink-3)}

/* ---------- การ์ดแอปบนเครื่องนี้ (ข้อมูลส่วนตัว) ---------- */
.kv-line{display:flex;justify-content:space-between;gap:12px;padding:8px 0;border-bottom:1px solid var(--line);font-size:var(--fs-2)}
.kv-line span{color:var(--ink-3)}
/* D-44: ปุ่ม/คำอธิบายใต้เส้นคั่นห่างอย่างน้อย 12px */
.kv-line+.btn,.kv-line+p,.kv-line+.row{margin-top:12px}
#device-card h3 .ph{color:var(--primary)}
#device-card .row{gap:8px}

/* ---------- เปิดแบบแอป (standalone): เว้นขอบรอยบากแนวนอน ---------- */
@media (display-mode:standalone){
  .rail{padding-top:max(18px,env(safe-area-inset-top))}
  .site-nav{padding-top:env(safe-area-inset-top)}
}

@media print{.nav-rail,.net-banner,.net-pill,.ptr,.sheet-bg{display:none!important}}
