/* ===========================================================
   HazeFree Monitoring Dashboard 2026
   Modern dark UI · Sidebar (collapsible) + Grafana iframe
   =========================================================== */

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

:root {
  /* Light grey two-tone — sidebar เทาเข้มเล็กน้อย + content ขาวนวล */

  /* sidebar (light grey, slightly darker than content) */
  --bg-sidebar:    #e6ebf1;
  --bg-sidebar-2:  #dde3eb;
  --side-text:     #0f172a;
  --side-muted:    #475569;
  --side-dim:      #94a3b8;
  --side-border:   rgba(15, 23, 42, 0.09);
  --side-border-2: rgba(15, 23, 42, 0.05);
  --side-hover:    rgba(15, 23, 42, 0.05);
  --side-active:   rgba(8, 145, 178, 0.16);

  /* content (very light, almost white) */
  --bg-app:        #fafbfc;
  --bg-content:    #fafbfc;
  --bg-card:       #ffffff;
  --bg-card-hover: #f5f7fa;
  --bg-topbar:     rgba(255, 255, 255, 0.82);

  --border:        rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);

  --text:          #0f172a;
  --text-muted:    #475569;
  --text-dim:      #94a3b8;

  /* accent (เน้นจุด active / ปุ่มหลัก) */
  --accent:        #0891b2;
  --accent-2:      #0e7490;
  --accent-soft:   #67e8f9;
  --accent-glow:   rgba(8, 145, 178, 0.22);

  /* status colors */
  --good:          #16a34a;
  --moderate:      #ca8a04;
  --warn:          #ea580c;
  --bad:           #dc2626;
  --hazardous:     #9333ea;

  --shadow-card:   0 1px 3px rgba(15,23,42,0.06), 0 4px 14px rgba(15,23,42,0.05);
  --shadow-pop:    0 12px 40px rgba(15,23,42,0.18);

  --sidebar-w:        272px;
  --sidebar-w-mini:   72px;
  --topbar-h:         64px;
  --radius:           14px;
  --radius-sm:        10px;
}

html, body {
  /* รองรับ mobile browsers ทุกรุ่น: fallback → svh → dvh */
  height: 100%;
  min-height: 100vh;
  min-height: 100svh;
  width: 100%;
  max-width: 100vw;
  background: var(--bg-app);
  color: var(--text);
  font-family: 'Inter', 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
ul { list-style: none; }

/* subtle radial backdrop */
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(900px 600px at -10% -10%, rgba(8,145,178,0.04), transparent 60%),
    radial-gradient(800px 600px at 110% 10%, rgba(99,102,241,0.035), transparent 60%);
  pointer-events: none; z-index: 0;
}

/* =============== Layout =============== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  /* รองรับ mobile browser ทุกรุ่น — ฟังก์ชัน svh/dvh จะ override ตัวที่ใหม่กว่า */
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);   /* fallback ที่ JS เซ็ต ให้ Safari เก่าทำงานได้ */
  height: 100svh;                       /* small viewport (iOS 15.4+, Chrome 108+) */
  height: 100dvh;                       /* dynamic viewport (URL bar ปรับได้) */
  width: 100%;
  max-width: 100vw;
  position: relative;
  z-index: 1;
  overflow: hidden;
}
.app.collapsed { grid-template-columns: var(--sidebar-w-mini) 1fr; }

/* =============== Sidebar =============== */
.sidebar {
  background: linear-gradient(180deg, var(--bg-sidebar) 0%, var(--bg-sidebar-2) 100%);
  border-right: 1px solid var(--side-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease;
  color: var(--side-text);
}

.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--side-border);
  height: var(--topbar-h);
  flex-shrink: 0;
}
.brand-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent) 0%, #22d3ee 100%);
  color: #ffffff;
  font-weight: 800; font-size: 14px;
  box-shadow: 0 6px 18px var(--accent-glow);
  flex-shrink: 0;
  overflow: hidden;
}
/* รูปแบบเมื่อใช้รูปภาพแทนตัวอักษร — ไม่ต้องมี gradient ครอบ */
.brand-logo--image {
  background: #ffffff;
  padding: 4px;
  box-shadow: 0 4px 14px rgba(15,23,42,0.08), 0 0 0 1px rgba(255,255,255,0.04);
}
.brand-logo-img {
  display: block;
  width: 100%; height: 100%;
  object-fit: contain;
  object-position: center;
}
.brand-text { overflow: hidden; }
.brand-name { font-weight: 700; font-size: 15px; color: var(--side-text); white-space: nowrap; }
.brand-tag  { font-size: 11px; color: var(--side-muted); white-space: nowrap; }

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(15,23,42,0.18) transparent;
}
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(15,23,42,0.16); border-radius: 3px; }

/* ---- Section header divider ---- */
.menu-header {
  font-size: 10.5px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--side-dim);
  padding: 14px 12px 6px;
  font-weight: 700;
  border-top: 1px solid var(--side-border-2);
  margin: 8px 0 4px;
}
.menu-header:first-child { border-top: 0; padding-top: 4px; }

/* ---- Solo link (no submenu) ---- */
.menu-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--side-muted);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  position: relative;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  cursor: pointer;
  white-space: nowrap;
}
.menu-item:hover { background: var(--side-hover); color: var(--side-text); }
.menu-item.active {
  background: linear-gradient(90deg, var(--side-active) 0%, rgba(8,145,178,0.04) 100%);
  color: var(--accent-2);
  font-weight: 600;
}
.menu-item.active::before {
  content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px;
  background: var(--accent); border-radius: 0 3px 3px 0;
  box-shadow: 0 0 10px var(--accent-glow);
}
.menu-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.menu-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* ---- Collapsible group ---- */
.menu-group { margin: 2px 0; }
.menu-group-toggle {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--side-muted);
  font-size: 13.5px; font-weight: 600;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.menu-group-toggle:hover { background: var(--side-hover); color: var(--side-text); }
.menu-group-toggle .icon { width: 18px; height: 18px; flex-shrink: 0; }
.menu-group-toggle .label { flex: 1; }
.menu-group-toggle .caret {
  width: 16px; height: 16px; opacity: 0.6;
  transition: transform 0.2s;
}
.menu-group.has-active > .menu-group-toggle { color: var(--side-text); }
.menu-group.has-active > .menu-group-toggle .icon { color: var(--accent); }
.menu-group.open > .menu-group-toggle .caret { transform: rotate(180deg); }

/* sub-items container */
.menu-sub {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.28s ease;
  padding-left: 14px;
  margin-left: 14px;
  border-left: 1px dashed rgba(15,23,42,0.12);
  margin-top: 2px;
}
.menu-group.open > .menu-sub { max-height: 1500px; }

.menu-sub-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--side-muted);
  font-size: 12.7px;
  font-weight: 500;
  position: relative;
  transition: background 0.15s, color 0.15s;
  white-space: normal;
}
.menu-sub-item:hover { background: var(--side-hover); color: var(--side-text); }
.menu-sub-item .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--side-dim);
  flex-shrink: 0;
  transition: background 0.15s, box-shadow 0.15s;
}
.menu-sub-item:hover .dot { background: var(--accent); }
.menu-sub-item .label { flex: 1; line-height: 1.35; }
.menu-sub-item.active {
  background: linear-gradient(90deg, var(--side-active) 0%, rgba(8,145,178,0.04) 100%);
  color: var(--accent-2);
  font-weight: 600;
}
.menu-sub-item.active .dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* War room daily items: red blinking icon */
.menu-sub-item.is-warroom .dot {
  width: 8px;
  height: 8px;
  background: #ef4444;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.75);
  animation: warroom-red-blink 3.4s ease-in-out infinite;
}

.menu-sub-item.is-warroom:hover .dot,
.menu-sub-item.is-warroom.active .dot {
  background: #dc2626;
}

@keyframes warroom-red-blink {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.75), 0 0 10px rgba(239, 68, 68, 0.35);
  }
  50% {
    opacity: 0.45;
    box-shadow: 0 0 0 7px rgba(239, 68, 68, 0), 0 0 2px rgba(239, 68, 68, 0.15);
  }
}
.menu-sub-item.active .dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* badges */
.menu-item .badge,
.menu-sub-item .badge {
  font-size: 9px; font-weight: 700;
  background: var(--bad); color: #fff;
  padding: 2px 6px; border-radius: 99px;
  letter-spacing: 0.5px;
  animation: pulse-live 1.6s infinite;
}
@keyframes pulse-live {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.6); }
  70%     { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* ---- Sidebar footer (user) ---- */
.sidebar-footer {
  border-top: 1px solid var(--side-border);
  padding: 12px;
  flex-shrink: 0;
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: rgba(15,23,42,0.04);
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #0891b2);
  display: grid; place-items: center; font-weight: 700; color: #fff;
  flex-shrink: 0; font-size: 13px;
}
.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; color: var(--side-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--side-muted); }
.user-status { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 8px rgba(34,197,94,0.6); }

/* Collapsed sidebar — labels hidden */
.app.collapsed .brand-text,
.app.collapsed .menu-item .label,
.app.collapsed .menu-item .badge,
.app.collapsed .menu-header,
.app.collapsed .menu-sub,
.app.collapsed .menu-group-toggle .label,
.app.collapsed .menu-group-toggle .caret,
.app.collapsed .user-info { display: none; }
.app.collapsed .menu-item,
.app.collapsed .menu-group-toggle { justify-content: center; padding: 10px; }
.app.collapsed .brand { justify-content: center; padding: 18px 8px; }
.app.collapsed .user-card { justify-content: center; }

/* =============== Top bar =============== */
.main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  overflow: hidden;
  width: 100%;
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg-topbar);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 18px;
  gap: 14px;
  flex-shrink: 0;
  min-width: 0;
  width: 100%;
}
.btn-icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: rgba(15,23,42,0.06); color: var(--text); }
.btn-icon .icon { width: 20px; height: 20px; }

/* Hamburger — ซ่อนบนเดสก์ท็อป โผล่เมื่อ ≤1024px */
.hamburger { display: none; }
@media (max-width: 1024px) {
  .hamburger { display: grid; }
}

.page-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 15.5px; font-weight: 600; color: var(--text);
  flex: 1 1 0; min-width: 0;
  overflow: hidden;
}
.page-title #pageLabel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.page-title .icon { width: 20px; height: 20px; color: var(--accent); flex-shrink: 0; }
.page-title .crumbs-mini {
  color: var(--text-muted); font-weight: 400; font-size: 12.5px;
  margin-left: 4px;
}
.page-title .crumbs-mini::before { content: '· '; margin: 0 4px; opacity: 0.5; }

.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.live-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600;
  color: var(--good);
  padding: 5px 10px;
  border-radius: 99px;
  border: 1px solid rgba(22,163,74,0.28);
  background: rgba(22,163,74,0.10);
}
.live-dot::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--good); box-shadow: 0 0 8px var(--good);
  animation: blink 1.4s infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 99px;
  background: rgba(15,23,42,0.04);
  border: 1px solid var(--border);
}

/* =============== Content area =============== */
.content {
  flex: 1 1 0;
  min-height: 0; min-width: 0;
  overflow: hidden;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Crumbs (inside content) */
.crumbs {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
}
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: 0.4; }
.crumbs .current { color: var(--text); font-weight: 500; }

/* Frame card holding the Grafana iframe */
.frame-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column;
  flex: 1;
  min-height: 0;
}
.frame-head {
  display: flex; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(15,23,42,0.015), transparent);
}
.frame-title { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 8px; color: var(--text);}
.frame-title .icon { width: 16px; height: 16px; color: var(--accent); }
.frame-title .sub { color: var(--text-muted); font-weight: 400; font-size: 11.5px; }
.frame-actions { margin-left: auto; display: flex; gap: 6px; }
.frame-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; font-size: 12px; font-weight: 500;
  border-radius: 8px; color: var(--text-muted);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.frame-btn:hover { background: rgba(15,23,42,0.05); color: var(--text); border-color: var(--border); }
.frame-btn.primary {
  background: var(--accent); color: #ffffff; font-weight: 600;
  border-color: var(--accent);
}
.frame-btn.primary:hover { background: var(--accent-2); color: #ffffff; border-color: var(--accent-2); }
.frame-btn .icon { width: 14px; height: 14px; }

.frame-body { flex: 1; position: relative; background: var(--bg-content); min-height: 0; }
.frame-body iframe {
  width: 100%; height: 100%;
  border: 0; display: block;
  background: #ffffff;
}
.frame-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-card);
  color: var(--text-muted);
  z-index: 1;
  flex-direction: column; gap: 12px;
  font-size: 12.5px;
}
.frame-loading.hidden { display: none; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(15,23,42,0.10);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state for invalid Grafana URL */
.empty-state {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 20px;
  font-size: 13px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* พื้นหลังลายจุดอ่อน ๆ ให้ไม่ดูเป็นหน้าขาวล้วน */
  background:
    radial-gradient(circle at 1px 1px, rgba(15,23,42,0.06) 1px, transparent 0) 0 0/20px 20px,
    var(--bg-app);
}
.empty-state .icon {
  width: 48px; height: 48px;
  color: var(--moderate); margin-bottom: 6px;
  flex-shrink: 0;
  padding: 10px;
  background: rgba(234,138,4,0.10);
  border-radius: 14px;
  box-sizing: content-box;
}
.empty-state code {
  background: rgba(15,23,42,0.06);
  padding: 3px 10px; border-radius: 6px;
  color: var(--accent-2); font-size: 12px;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Toast */
.toast {
  position: fixed; right: 18px; bottom: 18px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow-pop);
  display: flex; align-items: center; gap: 10px;
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }

/* =============== Responsive =============== */
/* Tablet & laptop เล็ก ๆ — บีบ sidebar + ลด padding */
@media (max-width: 1280px) {
  :root {
    --sidebar-w: 248px;
  }
  .topbar { padding: 0 14px; gap: 10px; }
  .content { padding: 12px; gap: 10px; }
  .page-title { font-size: 14.5px; }
  .page-title .crumbs-mini { display: none; }   /* ช่วยให้พื้นที่หัวข้อไม่ตีกัน */
  .frame-head { padding: 9px 12px; }
  .frame-title .sub { display: none; }
  .brand-logo { width: 38px; height: 38px; }
}

/* Tablet — sidebar กลายเป็น drawer (เลื่อนเข้า/ออก) */
@media (max-width: 1024px) {
  /* คอลัมน์เดียว: main ใช้พื้นที่เต็มเสมอ
     (sidebar เป็น position: fixed ออกจาก grid flow แล้ว
      ถ้าประกาศ 0 1fr จะดัน main ไปอยู่ในคอลัมน์ 0px ทำให้หน้าขาว) */
  .app,
  .app.mobile-open { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w); z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .app.mobile-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-pop);
  }
  .clock { display: none; }
}

/* Mobile แนวตั้ง (≤ 768px) */
@media (max-width: 768px) {
  :root {
    --topbar-h: 56px;
    --sidebar-w: min(280px, 86vw);
  }

  .topbar { padding: 0 10px; gap: 6px; }
  .topbar .btn-icon { width: 36px; height: 36px; }
  .topbar .btn-icon .icon { width: 18px; height: 18px; }

  .brand { padding: 14px 16px; }
  .brand-logo { width: 36px; height: 36px; border-radius: 9px; }
  .brand-logo--image { padding: 3px; }

  .live-dot { padding: 4px 8px; font-size: 10.5px; }
  .live-dot .live-text { display: none; }

  .page-title { font-size: 14px; gap: 8px; }
  .page-title .icon { width: 18px; height: 18px; }

  .content { padding: 8px; gap: 8px; }
  .crumbs { font-size: 11px; flex-wrap: wrap; gap: 4px; }

  .frame-head {
    padding: 8px 10px; gap: 6px;
    flex-wrap: nowrap;            /* บังคับแถวเดียว */
    overflow-x: hidden;
  }
  .frame-title {
    font-size: 12.5px;
    min-width: 0; flex: 1 1 0;
    overflow: hidden;
  }
  .frame-title span:first-of-type {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .frame-actions { gap: 4px; flex-shrink: 0; }
  .frame-btn { padding: 6px 8px; font-size: 11.5px; }

  /* ซ่อนปุ่ม "เปิดใน Grafana" + ปุ่มกลับเวอร์ชั่นเก่า */
  #btnOpenNew { display: none; }
  .topbar-right .btn-icon[title*="กลับ"] { display: none; }
}

/* Tablet/Phone แนวตั้ง — กันอาการหน้าไม่แสดงหรือคอนเทนต์โดนตัด */
@media (max-width: 1024px) {
  html, body {
    overflow-y: hidden;
    overflow-x: hidden;
  }

  .app.is-portrait {
    min-height: calc(var(--vh, 1vh) * 100);
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
  }

  .app.is-portrait .main {
    min-height: 0;
    height: 100%;
  }

  .app.is-portrait .content {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }

  .app.is-portrait .frame-card {
    flex: 1 1 auto;
    min-height: 360px;
  }

  .app.is-portrait .frame-body {
    min-height: 300px;
  }

  .app.is-portrait .empty-state {
    justify-content: flex-start;
    padding: 24px 16px;
  }

}

/* Mobile เล็ก (≤ 480px) — เน้นให้ iframe เห็นชัดสุด */
@media (max-width: 480px) {
  :root {
    --topbar-h: 52px;
    --sidebar-w: min(280px, 88vw);
  }

  .topbar { padding: 0 6px; gap: 4px; }
  .topbar .btn-icon { width: 34px; height: 34px; }
  .topbar .btn-icon .icon { width: 17px; height: 17px; }

  .page-title { font-size: 13.5px; gap: 6px; }

  .content { padding: 6px; gap: 6px; }
  .crumbs { display: none; }                /* แสดงผ่าน topbar อยู่แล้ว */

  /* frame buttons เป็นไอคอนล้วน */
  .frame-btn { padding: 7px 8px; }
  .frame-btn span:not(.icon) { display: none; }
  .frame-btn .icon { width: 16px; height: 16px; }

  /* ลดการลื่นข้อความใน topbar */
  #pageGroup { display: none !important; }

  .empty-state {
    gap: 8px;
    padding: 20px 12px;
    font-size: 12px;
  }
  .empty-state .icon {
    width: 34px;
    height: 34px;
  }
  .empty-state code {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
}

/* Mobile จิ๋ว (≤ 360px) — iPhone SE 1st gen / Galaxy รุ่นเก่า */
@media (max-width: 360px) {
  .topbar { gap: 2px; }
  .topbar .btn-icon { width: 32px; height: 32px; }
  .live-dot { padding: 3px 6px; }
  .frame-card { border-radius: 10px; }
  .brand-logo { width: 34px; height: 34px; border-radius: 8px; }
  .brand-logo--image { padding: 2px; }
}

/* แนวนอนบนมือถือ (landscape สั้น) */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --topbar-h: 46px; }
  .content { padding: 6px; }
  .frame-head { padding: 6px 10px; }
  .crumbs { display: none; }
}

/* Backdrop ใต้ sidebar (drawer mode) */
.backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  z-index: 40;
  animation: fadeIn 0.2s ease;
}
.app.mobile-open .backdrop { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* fullscreen mode for iframe (hide chrome) */
.app.fullscreen .sidebar,
.app.fullscreen .topbar,
.app.fullscreen .frame-head { display: none !important; }
.app.fullscreen { grid-template-columns: 1fr; }
.app.fullscreen .content { padding: 0; gap: 0; }
.app.fullscreen .frame-card { border-radius: 0; border: 0; }
.app.fullscreen .crumbs { display: none; }

@media (max-width: 1024px) {
  .app.is-portrait.fullscreen .topbar,
  .app.is-portrait.fullscreen .frame-head {
    display: flex !important;
  }
  .app.is-portrait.fullscreen .content {
    padding: 8px;
    gap: 8px;
  }
  .app.is-portrait.fullscreen .frame-card {
    border-radius: var(--radius);
    border: 1px solid var(--border);
  }
  .app.is-portrait.fullscreen .crumbs {
    display: flex;
  }
}
