/* PPK Medical - .shell / sidebar / topbar / content layout skeleton, shared by every page */

/* ---------- shell / drawer toggle (no JS: checkbox hack) ---------- */

.drawer-toggle { position: absolute; opacity: 0; pointer-events: none; }

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 24, 48, 0.5);
  z-index: 30;
}

.shell {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1fr;
  min-height: 100vh;
}
/* ---------- sidebar ---------- */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(84vw, var(--sidebar-w));
  z-index: 40;
  background: var(--card-bg);
  color: var(--ink-900);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 8px rgba(16, 24, 40, 0.04);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.drawer-toggle:checked ~ .drawer-backdrop { display: block; }
.drawer-toggle:checked ~ .shell .sidebar { transform: translateX(0); }

.sidebar-logo { display: flex; justify-content: center; padding: 4px 0 16px; }
.sidebar-logo img { width: 170px; max-width: 100%; height: auto; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.3;
  color: var(--ink-600);
  font-weight: 600;
}

/* บอกว่าอยู่แท็บไหนด้วยเส้นขอบสีเขียว ไม่ใช่พื้นหลังทึบ — พื้นหลังจางๆ ไว้แค่ช่วยให้เห็นขอบเขตปุ่ม */
.nav-item.active {
  background: rgba(20, 184, 166, 0.1);
  color: var(--teal-900);
  box-shadow: inset 0 0 0 1.5px var(--teal-700);
}

/* ไอคอนทุกตัวในเมนูซ้ายใช้กล่องขนาดเท่ากันเสมอ (28x28) ไม่ว่าจะเป็นไอคอนอะไร เพื่อให้แถวเรียงชิด
   แนวเดียวกัน ไม่ขึ้นอยู่กับว่า path ข้างในแต่ละรูปจะกินพื้นที่จริงเท่าไหร่ */
.nav-icon {
  flex: none;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.95;
}

.nav-icon svg { display: block; }

.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-subnav-toggle { position: absolute; opacity: 0; pointer-events: none; }

/* .nav-item-row ต้องมี padding/gap เท่ากับ .nav-item เป๊ะ (แถวนี้แยกไอคอนออกมาเป็น label ต่างหาก
   สำหรับ toggle เมนูย่อย) ไม่งั้นไอคอน/ตัวหนังสือของแถวนี้จะเยื้องซ้ายไม่ตรงกับแถวอื่นที่ไอคอนอยู่
   ในปุ่มเดียวกับข้อความ — เคยเจอปัญหานี้มาแล้ว ระวังอย่าทำให้กลับไปเป็นแบบเดิม */
.nav-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-radius: 10px;
}
.nav-item-row .nav-item { flex: 1; padding: 0; }

.nav-item-row.active {
  background: rgba(20, 184, 166, 0.1);
  box-shadow: inset 0 0 0 1.5px var(--teal-700);
}

.nav-item-row.active .nav-item { color: var(--teal-900); }

/* ไอคอนเดียวทำหน้าที่ทั้งแสดงหมวดหมู่และเป็นปุ่มย่อ/ขยายเมนูย่อย (label ของ checkbox hack เดิม)
   แทนลูกศร › แยกต่างหาก ที่ทำให้ดูเป็นสองปุ่มไม่เข้ากัน */
.nav-ekg-icon { cursor: pointer; color: var(--teal-700); }

/* ไอคอนเส้น SVG ของ home/เบาหวาน/หลอดเลือดหัวใจ/เก๊าท์ — สีเดียวกับ nav-ekg-icon ทั้งหมด (เขียวเข้ม
   โทนเดียวกับกราฟสัญญาณชีพ) ไม่มีพื้นหลัง ไม่ใช่ปุ่ม toggle (กลุ่มพวกนี้ไม่มีเมนูย่อย) */
.nav-svg-icon { color: var(--teal-700); }

.nav-subnav-toggle ~ .nav-subnav { display: none; }
.nav-subnav-toggle:checked ~ .nav-subnav { display: flex; }

.nav-subnav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0 8px 34px;
}

.nav-subitem {
  position: relative;
  padding: 7px 10px 7px 16px;
  border-radius: 8px;
  font-size: 0.78rem;
  line-height: 1.3;
  color: var(--ink-400);
}

.nav-subitem::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  transform: translateY(-50%);
}

.nav-subitem.active {
  color: var(--teal-900);
  font-weight: 600;
  background: var(--surface);
}

.nav-subitem.active::before { opacity: 1; }

.sidebar-status {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--ink-900);
}

.sidebar-status-title { font-weight: 600; margin-bottom: 8px; }
.sidebar-status-row { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.sidebar-status-row strong { margin-left: auto; }

/* แถวลิงก์ "เคสค้างรอปิด" — ใช้โครง .sidebar-status-row เดิม แต่เป็น <a> จึงต้อง reset สีตัวหนังสือ/
   ตัด underline เอง แล้วทำให้อ่านออกว่าเป็นลิงก์เตือนที่กดได้ (สีแดงเหมือน .dot-bad ข้างในบรรทัดเดียวกัน) */
.sidebar-status-row-warning {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  color: var(--status-critical);
  font-weight: 700;
  text-decoration: none;
}
.sidebar-status-row-warning:hover { text-decoration: underline; }

.sidebar-user {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.sidebar-user-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-role { color: var(--ink-600); font-size: 0.75rem; }

.sidebar-user-change-password {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--status-info);
  text-decoration: underline;
}

.sidebar-logout {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 7px 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--ink-600);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.sidebar-logout:hover { border-color: var(--status-critical); color: var(--status-critical); }

/* ---------- topbar ---------- */

.topbar {
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px 0 rgba(15, 23, 42, 0.04);
  min-width: 0;
  position: relative;
}
/* ไม่ตั้ง z-index บน .topbar เอง (ตั้งใจ) — ถ้ามี z-index ที่นี่ .topbar จะกลายเป็น stacking context
   ใหม่ ทำให้ z-index ของลูกหลานข้างใน (.open-cases-dropdown=45, .case-status-backdrop=46,
   .case-status-modal=47, .topbar-user-menu=100) ถูกตัดขาดจากลำดับชั้นจริงของหน้า เทียบได้แค่กันเองใน
   .topbar เท่านั้น ไม่ใช่เทียบกับ .open-cases-backdrop(35)/.sidebar(40) ที่อยู่นอก .topbar — บั๊กที่เจอ
   จริง: ตั้ง z-index:20 ไว้ก่อนหน้านี้ ทำให้ .open-cases-backdrop (35, อยู่นอก .topbar) วาดทับ
   .open-cases-dropdown ทั้งก้อน (ถูกตรึงไว้ที่ระดับ 20) สนิท ทำให้กดแถวในดรอปดาวน์ "งานที่ยังไม่จบ" ไม่ได้
   เลย (คลิกไปโดนแค่ backdrop โปร่งใสด้านบน) position: relative เฉยๆ (ไม่มี z-index) ไม่สร้าง stacking
   context ใหม่ จึงยังคงไว้เพื่อเผื่อโค้ดอื่นอ้างอิงอยู่ แต่ปลอดภัยกว่า */

.topbar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-brand h1 { 
  font-size: 1.05rem; 
  font-weight: 800; 
  color: #0f172a; 
  letter-spacing: -0.01em;
  overflow: hidden; 
  text-overflow: ellipsis; 
  white-space: nowrap; 
}

.topbar-actions { display: flex; align-items: center; gap: 12px; flex: none; }
.range-filter-form { margin: 0; }

/* ปุ่มย้อนกลับสไตล์เด่นชัด โต สวยงาม (Back Button) */
.btn-topbar-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 18px;
  border-radius: 999px;
  background: #ffffff;
  border: 1.5px solid #2563eb;
  color: #2563eb;
  font-weight: 700;
  font-size: 0.88rem;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.12);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  cursor: pointer;
}
.btn-topbar-back:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
  transform: translateY(-1px);
}
.btn-topbar-back:active {
  transform: translateY(0);
}
.btn-topbar-back svg {
  transition: transform 0.2s ease;
}
.btn-topbar-back:hover svg {
  transform: translateX(-3px);
}

/* User Profile Menu (ย้ายจาก Sidebar มาไว้ Header Topbar) */
.topbar-user-dropdown {
  position: relative;
  display: inline-block;
}
.user-menu-toggle {
  display: none;
}
.topbar-user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 5px;
  border-radius: 999px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
}
.topbar-user-pill:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}
.topbar-user-name {
  font-size: 0.84rem;
  font-weight: 700;
  color: #1e293b;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-user-chevron {
  color: #64748b;
  transition: transform 0.2s ease;
}
.user-menu-toggle:checked ~ .topbar-user-pill .topbar-user-chevron {
  transform: rotate(180deg);
}

/* Dropdown Menu Box */
.topbar-user-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 220px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 10px 30px -5px rgba(15, 23, 42, 0.18), 0 4px 12px -2px rgba(15, 23, 42, 0.08);
  padding: 10px;
  z-index: 100;
  animation: topbar-menu-slide 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
.user-menu-toggle:checked ~ .topbar-user-menu {
  display: block;
}

@keyframes topbar-menu-slide {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.topbar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 10px;
}
.topbar-user-avatar-lg {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e3a8a, #3b82f6);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  box-shadow: 0 2px 5px rgba(30, 58, 138, 0.25);
}
.topbar-user-details {
  min-width: 0;
}
.topbar-user-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: #0f172a;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-user-subtitle {
  font-size: 0.72rem;
  font-weight: 600;
  color: #64748b;
  margin: 1px 0 0;
}
.topbar-user-divider {
  height: 1px;
  background: #f1f5f9;
  margin: 4px 0 8px;
}

.topbar-user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  box-sizing: border-box;
  transition: all 0.15s ease;
  text-align: left;
}
.topbar-user-item:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.topbar-logout-form {
  margin: 2px 0 0;
}
.topbar-user-item-logout {
  color: #dc2626;
}
.topbar-user-item-logout:hover {
  background: #fef2f2;
  color: #b91c1c;
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: inherit;
  text-decoration: none;
  font-size: 1.2rem;
  cursor: pointer;
}

.icon-btn .badge {
  position: absolute;
  top: -4px;
  right: -8px;
  background: var(--status-critical);
  color: #fff;
  font-size: 0.6rem;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ปุ่มสลับโหมดเต็มจอ (เหมือนกด F11) — อยู่ในไฟล์ include core/_topbar_user.html จึงขึ้นทุกหน้าที่มี topbar
   ผู้ใช้ล็อกอินอัตโนมัติ ไม่ต้องแก้ทีละหน้า ไอคอนสลับเองระหว่างลูกศรกางออก/หุบเข้าด้วย :fullscreen ตาม
   สถานะจริงของเบราว์เซอร์ (ไม่ใช่แค่ตอนกดปุ่มนี้ เผื่อผู้ใช้กด Esc เอง) และไม่ต้องรอ JS จึงถูกต้องตั้งแต่เฟรมแรก
   ของหน้าที่โหลดใหม่ (ตัวสลับหน้าไม่หลุดเต็มจอ ดู core/static/core/js/fullscreen.js) */
.fullscreen-toggle-btn { font-size: 1.1rem; padding: 4px; border-radius: 8px; color: var(--ink-600); }
.fullscreen-toggle-btn:hover { background: rgba(37, 99, 235, 0.1); color: var(--status-info); }
.fullscreen-toggle-btn .fs-icon-collapse { display: none; }
:fullscreen .fullscreen-toggle-btn .fs-icon-expand { display: none; }
:fullscreen .fullscreen-toggle-btn .fs-icon-collapse { display: inline; }
:-webkit-full-screen .fullscreen-toggle-btn .fs-icon-expand { display: none; }
:-webkit-full-screen .fullscreen-toggle-btn .fs-icon-collapse { display: inline; }

/* แถบความคืบหน้าบางๆ ด้านบนจอตอนสลับหน้าในโหมดเต็มจอ (fullscreen.js ใส่ตัวเองเมื่อโหลดช้ากว่า 150ms) —
   ไม่มี spinner กลางจอ เพราะหน้าจอเฝ้าระวังไม่ควรมีอะไรมาบังข้อมูลผู้ป่วย */
#ppk-nav-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--status-info);
  opacity: 0;
  pointer-events: none;
  z-index: 3000;
  transition: opacity 0.2s ease;
}
#ppk-nav-progress.ppk-nav-progress-active {
  opacity: 1;
  width: 85%;
  transition: width 8s cubic-bezier(0.1, 0.6, 0.2, 1), opacity 0.2s ease;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  min-width: 0;
}

/* ---------- >=1024px: fixed sidebar + right panel ---------- */

@media (min-width: 1024px) {
  .drawer-backdrop { display: none !important; }
  .hamburger-btn { display: none; }
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    transform: none;
    grid-row: 1 / -1;
  }

  .shell {
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: auto 1fr;
  }
  /* modal SOS/ล้ม/สัญญาณชีพผิดปกติ (.sos-modal-backdrop) เป็น position:fixed ไม่กินพื้นที่ grid เลย
     (ต่างจาก .alert-banner เดิมที่เคยเป็นแถวบนสุดของ .shell และต้องกันแถวเปล่าไว้เผื่อไม่มีแบนเนอร์)
     จึงเหลือแค่ 2 แถว: topbar แล้วก็ content */
  .topbar {
    grid-column: 2;
    grid-row: 1;
  }

  .content { grid-column: 2; grid-row: 2; padding: 24px 28px; }
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  cursor: pointer;
}

.hamburger-btn span { width: 20px; height: 2px; background: var(--ink-900); border-radius: 2px; }
