/* ── Base ──────────────────────────────────────────────────────────────────── */
:root {
  --bg:        #eef2f7;
  --card:      #ffffff;
  --card2:     #f4f7fb;
  --card3:     #eef2f7;
  --border:    #d1dae8;
  --text:      #0f172a;
  --secondary: #5a6e87;
  --sec:       #5a6e87;
  --accent:    #0284c7;
  --green:     #059669;
  --red:       #dc2626;
  --yellow:    #d97706;
  --amber:     #d97706;
  --shadow:    0 1px 3px rgba(15,23,42,.07), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  height: 100vh;
  overflow: hidden;
}

/* ── Global: Chips ─────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; padding: 2px 7px;
  border-radius: 3px; font-size: .62rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; vertical-align: middle;
  white-space: nowrap;
}
.ch-doc  { background: #5b21b6; color: #fff; }
.ch-cam  { background: #d1fae5; color: #065f46; }
.ch-adm  { background: #dbeafe; color: #1e40af; }
.ch-gen  { background: #f1f5f9; color: #475569; }
.ch-scr  { background: #fff7ed; color: #9a3412; }
.ch-info { background: #f0fdfa; color: #0f766e; }
.ch-prt  { background: #f1f5f9; color: #475569; }
.ch-msu  { background: #dbeafe; color: #1e40af; }
.ch-bedside { background: #d1fae5; color: #065f46; }
.ch-eng  { background: #f5f3ff; color: #6d28d9; }

/* ── Global: Small action button ── */
.btn-sm {
  padding: 4px 10px; font-size: .72rem; border-radius: 5px;
  cursor: pointer; font-weight: 500; text-decoration: none;
  display: inline-block; white-space: nowrap; border: 1px solid var(--border);
  background: var(--card3); color: var(--text); transition: background .12s;
}
.btn-sm:hover { background: var(--border); }
.btn-sm.links  { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.btn-sm.links:hover { background: #dbeafe; }
.btn-sm.danger { background: #fff5f5; color: var(--red); border-color: #fecaca; }
.btn-sm.danger:hover { background: #fee2e2; border-color: #fca5a5; }

/* ── Entry Page ────────────────────────────────────────────────────────────── */
.entry-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
.entry-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 48px;
  width: 400px;
  text-align: center;
}
.entry-card h1 { font-size: 1.4rem; margin-bottom: 8px; }
.entry-card .room-id { color: var(--secondary); font-size: 0.85rem; margin-bottom: 28px; }

.input-wrap { position: relative; margin-bottom: 8px; }
.input-wrap input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
.input-wrap input:focus { border-color: var(--accent); }
.input-wrap input.error { border-color: var(--red); }
.input-error { color: var(--red); font-size: 0.8rem; min-height: 18px; text-align: left; margin-bottom: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: opacity 0.15s, background 0.15s;
  min-height: 48px;
  min-width: 48px;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: #0369a1; }
.btn-danger   { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost    { background: var(--card); border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--card2); }
.btn-active   { background: var(--accent); color: #fff; }

.connecting-msg { color: var(--secondary); margin-top: 16px; font-size: 0.9rem; }

/* ── Room Page ─────────────────────────────────────────────────────────────── */
.room-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

/* HD grid — 2 big slots */
.hd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
}
.hd-grid.hd-grid-single {
  grid-template-columns: 1fr;
}

.hd-slot {
  position: relative;
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}
/* Zoom wrapper — fills slot, handles overflow + cursor */
.slot-zoom-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: default;
  z-index: 1;
}
.slot-zoom-inner {
  /* absolute + layout-size zoom (JS sets width/height/left/top when zoomed) —
     adaptiveStream requests a sharper simulcast layer as the element grows;
     transform:scale would keep the low-res layer = blurry zoom */
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}
.slot-zoom-inner video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
/* Fullscreen: zoom wrap becomes grabbable */
:fullscreen .slot-zoom-wrap { cursor: grab; }
:fullscreen .slot-zoom-wrap:active { cursor: grabbing; }
/* Hide non-video elements while fullscreen for cleaner view */
:fullscreen .slot-label,
:fullscreen .cam-switcher { display: none !important; }
:fullscreen .slot-participant-name { z-index: 10; }
:fullscreen .fullscreen-btn { z-index: 10; }
.hd-slot .slot-label {
  position: absolute;
  top: 8px;
  left: 10px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  z-index: 2;
}
.hd-slot .slot-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--secondary);
}
.hd-slot .slot-placeholder .icon { font-size: 3rem; }
.hd-slot .slot-placeholder .ph-ic {
  width: 3rem; height: 3rem; opacity: .7;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.sf-picker-label .sf-ic {
  width: 16px; height: 16px; display: block;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* MSU cam switcher — top-right of left slot */
.cam-switcher {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  background: rgba(0,0,0,0.6);
  border-radius: 20px;
  padding: 4px;
  z-index: 5;
}
.cam-switcher button {
  padding: 4px 14px;
  border-radius: 16px;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
}
.cam-switcher button.active { background: var(--accent); color: #000; }
.obs-scene-btn { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.obs-not-ready { font-size: 0.75rem; color: #888; padding: 2px 4px; }

/* ปุ่มปรับ "การแสดงผลของสลอตนี้" — ติดอยู่บนภาพ ไม่ใช่แถบล่าง (owner 2026-09-24)
   ใช้กับ "ตามหน้า" (face tracking) บนสลอตซ้าย · อยู่แถวตั้งฝั่งขวาล่างชุดเดียวกับ
   .sf-zoom-ctrl ของสลอตขวา เพื่อให้ภาษาการใช้งานเป็นชุดเดียวกัน
   (ปุ่มบนภาพ = ปรับภาพนี้เท่านั้น ไม่กระทบคนอื่น)
   🔴 ต่างจากปุ่มในแถบล่างตรงที่ **ไม่กระทบคนอื่นในห้อง** — อย่าเอาไปปนกัน */
.slot-view-ctrl {
  position: absolute;
  /* owner 2026-09-24: "วางปุ่มเรียงทางขวาล่างเป็นแนวตั้งขึ้นไป ปุ่มซูมเดิมก็ด้วย"
     ⇒ ปุ่มบนภาพทุกชนิดไปรวมกันเป็นแถวตั้งที่ขอบขวาล่าง เหนือปุ่มเต็มจอ
     🔴 ห้ามย้ายกลับมุมล่างซ้าย — ที่นั่นเป็นของ .slot-participant-name (ชื่อคน)
        เคยวางทับกันจนอ่านไม่ออกทั้งคู่ (owner เจอ 2026-09-24) */
  bottom: 46px;
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  z-index: 5;
}
/* 🔴 ปุ่มบนภาพต้องเห็นบน "ภาพอะไรก็ได้" — owner 2026-09-24: "มันกลืนหายไปกับภาพ"
   เดิมพื้นดำโปร่ง 60% ⇒ จมหายบนภาพในรถที่มืด
   ⇒ ใช้ภาษา **ขอบเรืองสี = ปิด · ทึบสี = เปิด** (outlined/filled) ซึ่งอ่านออกทันที
      + พื้นเกือบทึบ + เงา เพื่อให้ตัดกับทั้งภาพสว่างและภาพมืด */
/* 🔴 owner 2026-09-24 (รอบ 2 · ดูจากรถจริง): *"ปุ่มกด face tracking เวลาไม่ได้กด
   ขอพื้นหลังสว่างกว่านี้หรือเป็นสีขาวเลยก็ได้ มันมองไม่เห็น"*
   รอบแรกเราแก้จากดำโปร่ง 60% → กรมท่าทึบ 88% + ขอบเรืองสี ซึ่ง **ยังไม่พอ**
   บนภาพในรถที่สว่าง (ผนังขาว/แสงจากหน้าต่าง) ⇒ เปลี่ยนเป็น **ขาวทึบ** ไปเลย
   🪤 บทเรียน: ปุ่มลอยบนวิดีโอต้องเด่นกับ **ทั้งฉากมืดและฉากสว่าง** — การเลือก
      "เข้มขึ้น" แก้ได้แค่ฉากสว่าง ส่วนขาวทึบ + ขอบเข้ม + เงา เด่นได้ทั้งสองแบบ */
.slot-view-ctrl button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 30px; padding: 6px 11px;
  border: 1.5px solid rgba(15, 23, 42, .35); border-radius: 15px;
  background: #fff; color: #0f172a;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .45);
  font-family: inherit; font-size: .72rem; font-weight: 600;
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.slot-view-ctrl button .ci { color: #0f172a; }
/* 🔴 :hover ต้องไม่ทับ .active — เดิมชี้เมาส์ตอนเปิดอยู่แล้วสีจางลง (alpha .35)
   คอนทราสต์ตกจาก 19:1 เหลือ 4.1:1 = สถานะ "เปิด" ดูอ่อนกว่า "ปิด" ซึ่งกลับหัวกัน */
.slot-view-ctrl button:hover:not(:disabled):not(.active) { background: #e2e8f0; }
.slot-view-ctrl button:disabled { opacity: .55; cursor: default; }
/* เปิดอยู่ = ทึบสี ตัดกับตอนปิดชัดเจน ไม่ต้องอ่านตัวหนังสือก็รู้ */
.slot-view-ctrl button.active {
  background: var(--accent); color: #fff; border-color: #7dd3fc;
  box-shadow: 0 0 0 2px rgba(125, 211, 252, .45), 0 2px 8px rgba(0, 0, 0, .55);
}
.slot-view-ctrl button.active:hover { background: var(--accent); }
.slot-view-ctrl button.active .ci { color: #fff; }
.slot-view-ctrl .ci { width: 15px; height: 15px; }
/* แนวตั้งบนมือถือ: ภาพเล็ก พื้นที่น้อย → เหลือไอคอน (เหมือนแถบล่าง)
   ยังกดโดนเพราะปุ่มสูง 30px + อยู่มุมภาพที่นิ้วเอื้อมง่าย */
@media (max-width: 639px) and (orientation: portrait) {
  .slot-view-ctrl button { padding: 7px 8px; gap: 0; }
  .slot-view-ctrl .cl { display: none; }
}
:fullscreen .slot-view-ctrl { z-index: 10; }

/* REQ-SF-06: Screen Feed pan/zoom control — สไตล์ปุ่ม +/- ของ map widget ทั่วไป
   วางมุมล่างซ้าย (ตรงข้าม .fullscreen-btn ที่อยู่ล่างขวา กันซ้อนทับ)
   🔴 bottom ต้องเลย .slot-participant-name ขึ้นไป — เดิมตั้ง 8px เท่ากับป้ายชื่อ
      ทำให้ชื่อคนบนจอทับปุ่ม +/− (บั๊กเดิมตั้งแต่ REQ-SF-06 owner เพิ่งเห็น 2026-09-24) */
.sf-zoom-ctrl {
  position: absolute;
  /* owner 2026-09-24: ย้ายมาอยู่แถวตั้งฝั่งขวาล่างชุดเดียวกับปุ่มอื่นบนภาพ
     เดิมอยู่ซ้ายล่างซึ่งทับ .slot-participant-name (เห็นชัดบนมือถือ) */
  bottom: 46px;
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  z-index: 5;
}
.sf-zoom-ctrl button {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  /* ให้เห็นบนภาพมืดเหมือน .slot-view-ctrl (owner 2026-09-24) */
  border: 1.5px solid var(--accent);
  background: rgba(8,15,30,0.88);
  box-shadow: 0 2px 8px rgba(0,0,0,.55);
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sf-zoom-ctrl button:hover { background: rgba(0,0,0,0.8); }
/* REQ-SF-09a "เอาจอคืน" — ปุ่มเดียวในแถวนี้ที่เป็นไอคอน ไม่ใช่ตัวอักษร +/−
   🪤 svg ที่ไม่ถูกกำหนดขนาดจะกาง 300×150 ตาม default ของเบราว์เซอร์ = ล้นปุ่มทั้งแถว */
.sf-zoom-ctrl .ci {
  width: 16px; height: 16px; display: block;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  color: var(--accent);
}
/* กดแล้วดึงคนลง = การกระทำที่ย้อนไม่ได้ทันที → ใช้สีเตือนแยกจากปุ่มซูมที่กดเล่นได้ */
#pulldown-btn { border-color: var(--amber, #f59e0b); }
#pulldown-btn .ci { color: var(--amber, #f59e0b); }
#pulldown-btn:hover { background: rgba(245, 158, 11, .28); }
:fullscreen .sf-zoom-ctrl { display: flex !important; } /* ใช้ซูมได้ตอนเต็มจอด้วย ต่างจาก cam-switcher */

/* Fullscreen button — z-index above slot-zoom-wrap (z:1) */
.fullscreen-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.5);
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 4px;
  z-index: 3;
}

/* Active speaker border */
.hd-slot.speaking { outline: 3px solid var(--accent); }
.thumb-item.speaking { outline: 2px solid var(--accent); }

/* Thumbnail bar */
.thumb-bar {
  height: 76px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
}
.thumb-item {
  position: relative;
  width: 96px;
  height: 60px;
  flex-shrink: 0;
  background: var(--card);
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
}
.thumb-item video, .thumb-item .thumb-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumb-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: var(--card);
  color: var(--secondary);
}
.thumb-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 4px;
  display: flex;
  align-items: center;
  gap: 3px;
}
.thumb-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.thumb-mic-icon {
  flex-shrink: 0;
  line-height: 0;
}
.thumb-muted {
  position: absolute;
  top: 3px;
  right: 3px;
  font-size: 0.7rem;
  background: rgba(248,113,113,0.85);
  border-radius: 50%;
  padding: 1px 3px;
}

/* Controls bar */
.controls {
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  flex-shrink: 0;
}
.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
}
/* Cam + Info Screen selectors share one row */
/* MSU-127: device selectors (มิค/ลำโพง/กล้อง/info screen) ย้ายเข้า ⚙️ bottom-sheet
   แทน scroll band-aid MSU-124/126 (46vh ที่ browser bar มือถือยังบัง) — ใช้ทั้ง mobile+desktop.
   แถบ controls เหลือปุ่มหลัก → ไม่ล้นจอ */
.ctrl-gear.btn-active { background: rgba(124,92,255,.18); color: var(--accent); }
.dsheet-backdrop {
  position: fixed; inset: 0; background: rgba(5,6,11,.5);
  opacity: 0; visibility: hidden; transition: opacity .2s; z-index: 40;
}
.dsheet-backdrop.open { opacity: 1; visibility: visible; }
.dsheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 560px; margin: 0 auto;             /* desktop: กลางจอ ไม่เต็มกว้าง */
  background: var(--card); border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -18px 40px -12px rgba(0,0,0,.5);
  transform: translateY(110%); transition: transform .25s cubic-bezier(.4,0,.2,1);
  max-height: 85vh; overflow-y: auto;           /* sheet = modal → scroll ได้ (ต่างจาก control bar); 4 แถวไม่ถึงอยู่แล้ว */
}
.dsheet.open { transform: translateY(0); }
.dsheet-grab { width: 38px; height: 4px; border-radius: 99px; background: var(--border); margin: 2px auto 12px; cursor: grab; }
.dsheet-title { font-size: .95rem; font-weight: 700; color: var(--text); }
.dsheet-sub { font-size: .72rem; color: var(--secondary); margin: 2px 0 12px; }
.devrow { display: flex; align-items: center; gap: 11px; padding: 11px 0; border-top: 1px solid var(--border); }
.devrow:first-of-type { border-top: none; }
.devrow-ic { width: 20px; height: 20px; color: var(--accent); flex: none; display: inline-flex; align-items: center; }
.devrow-ic .sf-ic { width: 20px; height: 20px; }
.devrow-lab { font-size: .72rem; color: var(--secondary); width: 56px; flex: none; }
.devrow-sel {
  flex: 1; min-width: 0; background: rgba(255,255,255,.05);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px;
  font-size: .82rem; font-weight: 600; color: var(--text); font-family: inherit; cursor: pointer; outline: none;
}
.devrow-sel:focus { border-color: var(--accent); }
.devrow-sel option { background: var(--card); }
/* MSU-129: แถวลำโพง disabled (เปลี่ยนใน browser ไม่ได้) — โชว์-disabled แทนซ่อน */
.devrow-sel:disabled { opacity: .5; cursor: not-allowed; color: var(--secondary); background: rgba(255,255,255,.03); }
.devrow-hint { font-size: .66rem; color: var(--secondary); line-height: 1.4; padding: 0 2px 10px 31px; margin-top: -6px; }
/* Icon-first control pills (Lucide icons + label) */
.controls .ctrl,
.controls .ctrl-leave {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-size: 0.8rem; font-weight: 500;
  border: 1px solid transparent; border-radius: 22px;
  padding: 9px 15px; min-height: 40px; cursor: pointer;
  transition: background .15s, color .15s;
}
.controls .ctrl { background: rgba(255,255,255,.06); color: var(--text); }
.controls .ctrl:hover:not(:disabled) { background: rgba(255,255,255,.13); }
.controls .ctrl:disabled { opacity: .55; cursor: default; }
/* owner 2026-09-24: *"การ shared screen ถ้าบนมือถือ...เราทำเป็นสีเทากดไม่ได้เลยดีป่ะ"*
   ต่างจาก :disabled ทั่วไปตรงที่ต้องอ่านออกว่า "ทำไม่ได้บนเครื่องนี้" ไม่ใช่ "รออยู่" */
.controls .ctrl.ctrl-unsupported,
.controls .ctrl[aria-disabled="true"] {
  opacity: 1;
  background: rgba(148, 163, 184, .16);
  color: #94a3b8;
  cursor: not-allowed;
}
.controls .ctrl.ctrl-unsupported .ci { color: #94a3b8; }
.controls .ctrl.btn-muted { background: var(--red); color: #fff; }
.controls .ctrl.btn-muted:hover { background: #ef4444; }
.controls .ctrl.btn-active { background: var(--accent); color: #fff; }
.controls .ctrl-leave { background: rgba(242,86,91,.14); color: var(--red); }
.controls .ctrl-leave:hover { background: var(--red); color: #fff; }
.controls .ctrl .ci,
.controls .ctrl-leave .ci {
  width: 18px; height: 18px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.controls .cl { line-height: 1; }

/* Network quality dot (admin panel net stats) */
.netq { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; flex-shrink: 0; }
.net-row { display: flex; align-items: center; gap: 8px; font-size: .75rem; padding: 4px 0; }
.net-row .net-uid { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.net-row .net-rtt { font-variant-numeric: tabular-nums; color: var(--secondary); flex-shrink: 0; }
/* small inline icon for sidebar buttons (admin mute toggle) */
.ic-sm { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

/* Room SVG glyphs (fullscreen btn, thumbnail avatar, warning overlay) */
.fullscreen-btn .fs-ic { width: 16px; height: 16px; display: block;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.thumb-avatar .avatar-ic { width: 1.7rem; height: 1.7rem;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.warn-ic { width: 2.2rem; height: 2.2rem; color: var(--amber);
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Notification toast */
.toast-container {
  position: fixed;
  bottom: 80px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 240px;
  font-size: 0.85rem;
  animation: slide-in 0.2s ease;
}
.toast.warning { border-left-color: var(--yellow); }
.toast.error   { border-left-color: var(--red); }
.toast.info    { border-left-color: var(--green); }
@keyframes slide-in {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* HD Request popup */
.popup-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.popup-overlay.show { display: flex; }
.popup-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  width: 340px;
  text-align: center;
}
.popup-card h3 { margin-bottom: 10px; }
.popup-card p  { color: var(--secondary); margin-bottom: 20px; }
.popup-card .btns { display: flex; gap: 10px; }
.popup-card .btns .btn { flex: 1; }

/* Admin panel (right sidebar on desktop) */
.admin-layout {
  display: flex;
  height: 100vh;
  background: var(--bg);
}
.admin-video { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-panel {
  width: 280px;
  background: var(--card);
  border-left: 1px solid var(--border);
  overflow-y: hidden;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

/* ── Admin sidebar sections ── */
.sb-scroll { flex: 1; overflow-y: auto; }
.sb-scroll::-webkit-scrollbar { width: 4px; }
.sb-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.sb-sec { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.sb-lbl {
  font-size: .62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--secondary); margin-bottom: 7px;
}
.sb-rname { font-size: .9rem; font-weight: 700; color: var(--text); }
.sb-rcase { font-size: .72rem; color: var(--secondary); }
.case-state-active  { font-size: .72rem; font-weight: 600; color: var(--green); }
.case-state-waiting { font-size: .72rem; font-weight: 600; color: var(--accent); }

.sb-usr { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.sb-usr:last-child { border-bottom: none; }
.sb-usr-dev { flex-basis: 100%; font-size: .68rem; color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-usrn { flex: 1; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.sb-usra { display: flex; gap: 3px; flex-shrink: 0; }

.sb-lnk { display: flex; align-items: center; gap: 6px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.sb-lnk:last-child { border-bottom: none; }
.sb-lnkr { flex: 1; display: flex; align-items: center; gap: 5px; }
.sb-lnka { display: flex; gap: 3px; flex-shrink: 0; }

.sb-qrow { display: flex; align-items: center; gap: 6px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.sb-qrow:last-child { border-bottom: none; }
.sb-qnm { flex: 1; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-qa { display: flex; gap: 4px; flex-shrink: 0; }

.sb-net { display: flex; align-items: center; justify-content: space-between; padding: 3px 0; }
.sb-nn { font-size: .72rem; color: var(--text); }
.sb-nr { font-size: .72rem; font-variant-numeric: tabular-nums; }

.sb-foot {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  flex-shrink: 0;
  background: var(--card);
}
.btn-close-case {
  width: 100%; padding: 8px; border-radius: 8px;
  background: #fef2f2; color: var(--red);
  border: 1px solid #fecaca; font-size: .82rem; font-weight: 600;
  cursor: pointer; transition: background .12s;
}
.btn-close-case:hover { background: #fee2e2; border-color: #fca5a5; }

/* Open case (idle permanent room) — pressing it also commands the vehicle kiosk to join */
.btn-open-case {
  width: 100%; padding: 8px; border-radius: 8px;
  background: #f0fdf4; color: #15803d;
  border: 1px solid #bbf7d0; font-size: .82rem; font-weight: 600;
  cursor: pointer; transition: background .12s;
}
.btn-open-case:hover { background: #dcfce7; border-color: #86efac; }
.case-idle-note {
  font-size: .7rem; color: var(--secondary); text-align: center; margin-bottom: 6px;
}

/* legacy — kept for backward compat */
.admin-section { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.admin-section h3 { font-size: 0.75rem; color: var(--secondary); margin-bottom: 8px; text-transform: uppercase; }

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-role-badge {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--border);
  color: var(--secondary);
  white-space: nowrap;
}
.user-role-badge.doctor      { background: #1e3a5f; color: var(--accent); }
.user-role-badge.msucam      { background: #1a3329; color: var(--green); }
.user-role-badge.participant { background: #2d2a1a; color: var(--yellow); }
.user-name { flex: 1; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-actions { display: flex; gap: 4px; }
.user-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--secondary);
  border-radius: 4px;
  font-size: 0.7rem;
  padding: 2px 6px;
  cursor: pointer;
}
.user-actions button:hover { border-color: var(--red); color: var(--red); }

.hd-queue-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.hd-queue-item:last-child { border-bottom: none; }
.hd-queue-item .q-name { flex: 1; }
.hd-queue-item .btn { font-size: 0.7rem; padding: 3px 8px; min-height: 28px; }

/* HD slot participant name overlay */
.slot-participant-name {
  position: absolute;
  bottom: 10px;
  left: 10px;
  text-align: left;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  pointer-events: none;
  z-index: 4;
  background: rgba(0,0,0,0.45);
  padding: 2px 8px;
  border-radius: 4px;
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Screenfeed picker — in controls area, same row style as cam-device-select */
#screenfeed-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sf-picker-label {
  color: var(--accent);
  font-size: 0.78rem;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Webcam device selector — full row, centred */
.cam-device-select {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  width: 100%;
  max-width: 360px;
  outline: none;
}
.cam-device-select:focus { border-color: var(--accent); }
.cam-device-select option { background: var(--card); }

/* Room header bar */
.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  background: linear-gradient(90deg, rgba(139,92,246,.16), rgba(34,211,238,.04) 55%, transparent), var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.room-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}
.room-title .ci {
  width: 17px; height: 17px; flex-shrink: 0;
  fill: none; stroke: var(--accent); stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.room-my-name {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--secondary);
}
/* เวอร์ชันที่ "แท็บนี้" โหลดไว้ — จางไว้ ไม่ให้แย่งสายตาจากชื่อ/สถานะ LIVE
   REQ-ROOM-15: header ห้ามล้นบนจอแคบ → ซ่อนบนมือถือ (ดูจากหน้า dashboard แทนได้) */
.room-ver {
  font-size: 0.6rem;
  opacity: 0.4;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 639px) { .room-ver { display: none; } }
.room-live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.62rem; font-weight: 700; letter-spacing: .04em;
  color: var(--green);
  background: rgba(52,211,153,.12); border: 1px solid rgba(52,211,153,.25);
  border-radius: 20px; padding: 2px 9px;
}
.room-live i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--green);
  animation: room-live-blink 1.7s ease infinite;
}
@keyframes room-live-blink { 0%,100%{opacity:1} 50%{opacity:.25} }

/* ── v0.17.0 header meta: นาฬิกาเคส + แท่งสัญญาณ + สถานะ LIVE ────────────────── */
/* แนวคิดเทียบเคียง MSU-SOS (EGMU): tPA clock / 5G QoS meter / ON AIR */
.room-hdr-meta {
  display: inline-flex; align-items: center; gap: 8px;
  min-width: 0; flex-shrink: 1;
}
.room-clock {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .68rem; font-weight: 700; letter-spacing: .02em;
  color: var(--text);
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px 3px 8px;
  font-variant-numeric: tabular-nums;
}
.room-clock .ci {
  width: 13px; height: 13px; flex-shrink: 0;
  fill: none; stroke: var(--secondary); stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.room-clock.warn { color: var(--amber); border-color: rgba(217,119,6,.45); }
.room-clock.warn .ci { stroke: var(--amber); }

.qos-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .66rem; font-weight: 600; color: var(--secondary);
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px 3px 8px;
  white-space: nowrap;
}
.qos-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.qos-bars i { width: 3px; border-radius: 1px; background: var(--border); display: block; }
.qos-bars i:nth-child(1) { height: 5px; }
.qos-bars i:nth-child(2) { height: 8px; }
.qos-bars i:nth-child(3) { height: 12px; }
.qos-chip.q-good { color: var(--green); border-color: rgba(52,211,153,.35); }
.qos-chip.q-ok   { color: var(--amber); border-color: rgba(217,119,6,.35); }
.qos-chip.q-bad  { color: var(--red);   border-color: rgba(220,38,38,.4); }
.qos-chip.q-good .qos-bars i.on { background: var(--green); }
.qos-chip.q-ok   .qos-bars i.on { background: var(--amber); }
.qos-chip.q-bad  .qos-bars i.on { background: var(--red); }

/* REQ-ROOM-14: ป้าย LIVE บอกสถานะจริง */
.room-live.live-voice { color: var(--amber); background: rgba(217,119,6,.12); border-color: rgba(217,119,6,.3); }
.room-live.live-voice i { background: var(--amber); animation: none; }
.room-live.live-warn  { color: var(--amber); background: rgba(217,119,6,.12); border-color: rgba(217,119,6,.3); }
.room-live.live-warn i { background: var(--amber); }
.room-live.live-off   { color: var(--red);   background: rgba(220,38,38,.12); border-color: rgba(220,38,38,.35); }
.room-live.live-off i { background: var(--red); animation: none; }

/* REQ-ROOM-10: มิเตอร์ระดับเสียงไมค์ (ข้างปุ่มไมค์) */
.mic-meter {
  width: 6px; height: 26px; border-radius: 3px; flex: none;
  background: rgba(255,255,255,.07); border: 1px solid var(--border);
  display: none; align-items: flex-end; overflow: hidden;
  margin: 0 2px 0 -4px;
}
.mic-meter.on { display: inline-flex; }
.mic-meter i {
  display: block; width: 100%; height: 0%;
  background: var(--accent); border-radius: 3px;
  transition: height .06s linear;
}
.mic-meter.speaking i { background: var(--green); box-shadow: 0 0 8px rgba(52,211,153,.7); }

/* REQ-ROOM-13: ปุ่มสลับในแถว ⚙️ sheet */
.devrow-toggle {
  flex: none; min-width: 62px; cursor: pointer; font-family: inherit;
  font-size: .78rem; font-weight: 700; color: var(--secondary);
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: 20px; padding: 8px 14px; outline: none;
}
.devrow-toggle:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
/* label ของแถวนี้ยาวกว่า "กล้อง/ไมค์/ลำโพง" — ปล่อยกว้างได้ ไม่ต้องตัดบรรทัด */
#voice-only-row .devrow-lab { width: auto; flex: 1; min-width: 0; }
.devrow-toggle:disabled { opacity: .5; cursor: not-allowed; }
.devrow-toggle.on { color: var(--amber); border-color: rgba(217,119,6,.5); background: rgba(217,119,6,.14); }

/* จอแคบ: เก็บ header ไม่ให้ล้น (บทเรียน MSU-126/127) — เหลือแท่งสัญญาณ + นาฬิกา */
@media (max-width: 639px) {
  .room-hdr-meta { gap: 5px; }
  .qos-lab { display: none; }
  .qos-chip { padding: 3px 7px; gap: 0; }
  .room-clock { font-size: .62rem; padding: 3px 7px 3px 6px; }
  .room-clock .ci { width: 11px; height: 11px; }

  .controls-row { gap: 5px; }
  .controls .ctrl,
  .controls .ctrl-leave { padding: 9px 10px; font-size: .74rem; gap: 5px; }
  .controls .ctrl .ci,
  .controls .ctrl-leave .ci { width: 16px; height: 16px; }
}

/* 🔴 มือถือ "แนวตั้ง" — ตัดคำกำกับบนปุ่มออก เหลือไอคอน (owner สั่ง 2026-09-23)
   เหตุผลจากการวัดจริงที่ 375px (ไม่ใช่ความรู้สึก):
     ปุ่มเต็ม 7 อัน + คำกำกับ  = 3 บรรทัด · แถบสูง 153px
     บีบ padding อย่างเดียว    = 2 บรรทัด · แถบสูง 106px
     ตัดคำ + บีบให้พอดี        = **1 บรรทัด · แถบสูง 61px**  ← คืนพื้นที่ภาพให้หมอ 92px
   ⚠️ เฉพาะ "แนวตั้ง" — แนวนอน/จอคอมยังมีคำกำกับครบ (จอกว้างพอ ไม่ต้องแลก)
   ⚠️ สิ่งที่ต้องระวังเมื่อไม่มีคำกำกับ: **ไอคอนต้องแยกออกจากกันได้ด้วยตาเปล่า**
      IC.track จึงห้ามเป็นรูปคน ไม่งั้นซ้ำกับ IC.faceUp (ดูคอมเมนต์ใน room.js)
   ⚠️ ห้ามลด min-height ต่ำกว่า 40px — นิ้วต้องยังกดโดนตอนรถวิ่ง */
@media (max-width: 639px) and (orientation: portrait) {
  .controls-row { gap: 4px; }
  .controls .ctrl,
  .controls .ctrl-leave { padding: 10px 9px; gap: 0; }
  .controls .ctrl .cl,
  .controls .ctrl-leave .cl { display: none; }
  .controls .ctrl .ci,
  .controls .ctrl-leave .ci { width: 18px; height: 18px; }
}

/* Room Links */
.link-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.link-row:last-child { border-bottom: none; }
.link-label { flex: 1; color: var(--text); font-size: 0.8rem; }
.btn-copy {
  background: var(--border); border: none; border-radius: 4px;
  color: var(--secondary); font-size: 0.7rem; padding: 3px 8px;
  cursor: pointer; white-space: nowrap;
}
.btn-copy:hover { background: var(--accent); color: #fff; }
.btn-open {
  color: var(--accent); font-size: 0.8rem; text-decoration: none;
  padding: 3px 5px; border-radius: 4px; flex-shrink: 0;
}
.btn-open:hover { background: var(--border); }

/* Mobile portrait — scrollable, full-width slots */
@media (max-width: 640px) {
  .room-layout {
    height: auto;
    min-height: 100svh; /* svh = small viewport (excludes mobile browser chrome) */
  }
  .hd-grid {
    flex: none;          /* stop filling viewport height */
    grid-template-columns: 1fr; /* stack slots vertically */
    overflow: visible;
  }
  .hd-slot {
    aspect-ratio: 16 / 9;
    width: 100%;
    min-height: 0;
  }
  /* controls always reachable by scrolling — not sticky */
  .controls { padding: 10px 12px; }
  .controls .btn { font-size: 0.85rem; }

  /* Admin layout on mobile: video on top, panel takes 45% height and scrolls */
  .admin-layout { flex-direction: column; height: 100vh; }
  /* MSU-671: overflow:hidden ตัด .controls (ปุ่ม "ออก") หายไปหลัง hd-grid สูงเกิน
     พื้นที่ที่เหลือ (stacked 16:9 x2) — เปลี่ยนเป็น scroll แทน ตาม comment เดิม
     "controls always reachable by scrolling" ที่ room-layout ปกติทำได้อยู่แล้ว */
  .admin-video  { flex: 1; min-height: 0; overflow-y: auto; }
  .admin-video .room-layout { height: auto; min-height: 100%; }
  .admin-panel  {
    width: 100%;
    height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow-y: auto;
  }
}

/* ── Bedside self-preview PiP ───────────────────────────────────────────────── */
/* position: absolute inside #slot-right (.hd-slot has position:relative) */
.self-pip {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 22%;          /* ~22% of slot width — responsive without media query */
  min-width: 80px;
  max-width: 140px;
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.25);
  background: #000;
  z-index: 5;          /* above slot-zoom-wrap (z:1) and slot-label (z:2) */
}
.self-pip video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.self-pip.mirror video { transform: scaleX(-1); }
.self-pip { cursor: pointer; }
.self-pip-label {
  position: absolute;
  bottom: 4px;
  left: 6px;
  font-size: 0.65rem;
  color: var(--text);
  background: rgba(0,0,0,0.55);
  padding: 1px 5px;
  border-radius: 4px;
  pointer-events: none;
}
.self-pip-hint {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.5);
  pointer-events: none;
}
/* Bedside single-slot view: fill portrait frame — no letterbox black bars */
.hd-grid-single .slot-zoom-inner video { object-fit: cover; }

/* ── Room / video-conference pages — override back to dark palette ──────── */
/* room.html uses .room-layout; admin.html uses .admin-layout               */
/* CSS custom properties cascade, so all children automatically use dark    */
.room-layout,
.admin-layout {
  --bg:        #101018;
  --card:      #1a1a28;
  --card2:     #222232;
  --card3:     #14141f;
  --border:    #2b2b40;
  --text:      #ececf5;
  --secondary: #8888a2;
  --sec:       #8888a2;
  --accent:    #8b5cf6;
  --accent2:   #22d3ee;
  --green:     #34d399;
  --red:       #f87171;
  --yellow:    #fbbf24;
  --amber:     #fbbf24;
  /* re-declare color here so text re-evaluates to the dark-zone --text;
     otherwise children inherit body's already-computed light-theme color (dark) → invisible on dark bg */
  color: var(--text);
}
