/* ==========================================================================
   PPCH Facility Check — Khun Nick's Healthcare Light Design System
   - Zero Double Scrollbars (Single Page Scrollbar, overflow-x:auto for tables)
   - Collapsible Left Sticky Sidebar (Deep Midnight Royal Navy, Zero Layout Shift)
   - Symbol-Based Status Buttons & Floating Action Speed Dial
   ========================================================================== */

:root {
  --bg-page: #f4f7fb;
  --bg-card: #ffffff;
  --navy-deep: #001f44;
  --navy-darker: #001733;
  --navy-primary: #1e3a8a;
  --teal-accent: #0284c7;
  --teal-med: #0d9488;
  --emerald: #10b981;
  --amber: #f59e0b;
  --orange: #f97316;
  --red: #ef4444;
  --slate-900: #0f172a;
  --slate-700: #334155;
  --slate-500: #64748b;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 18px 40px rgba(0, 31, 68, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Prompt', 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-page);
  color: var(--slate-900);
  -webkit-font-smoothing: antialiased;
}

/* Phitsanuvej Medical Cross Preloader */
#ppch-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
#ppch-loader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.css-logo-loader {
  position: relative;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.css-logo-loader::before,
.css-logo-loader::after {
  content: "";
  position: absolute;
  background: linear-gradient(135deg, #1e3a8a, #0284c7);
  border-radius: 6px;
  animation: pulseCross 1.3s ease-in-out infinite;
}
.css-logo-loader::before { width: 18px; height: 54px; }
.css-logo-loader::after { width: 54px; height: 18px; }
@keyframes pulseCross {
  0%, 100% { transform: scale(0.92); opacity: 0.82; }
  50% { transform: scale(1.06); opacity: 1; }
}

/* App Shell with Collapsible Left Sticky Sidebar */
.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 68px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-deep) 0%, var(--navy-darker) 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  z-index: 120;
  transition: width 0.24s cubic-bezier(0.22, 1, 0.36, 1), margin-right 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
  box-shadow: 4px 0 24px rgba(0, 23, 51, 0.18);
}

.sidebar:hover,
.sidebar.expanded {
  width: 240px;
  margin-right: -172px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 4px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 12px;
  white-space: nowrap;
}
.sidebar-brand img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #ffffff;
  padding: 3px;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-brand-text {
  opacity: 0;
  transition: opacity 0.2s ease;
  line-height: 1.25;
}
.sidebar:hover .sidebar-brand-text,
.sidebar.expanded .sidebar-brand-text {
  opacity: 1;
}
.sidebar-brand-title {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
}
.sidebar-brand-sub {
  font-size: 11px;
  color: #93c5fd;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 12px;
  border-radius: 10px;
  color: #cbd5e1;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.18s ease, color 0.18s ease;
  margin-bottom: 4px;
}
.nav-item .material-symbols-rounded {
  font-size: 22px;
  flex-shrink: 0;
}
.nav-item span.nav-label {
  opacity: 0;
  transition: opacity 0.18s ease;
}
.sidebar:hover .nav-item span.nav-label,
.sidebar.expanded .nav-item span.nav-label {
  opacity: 1;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}
.nav-item.active {
  background: linear-gradient(90deg, #0284c7, #0d9488);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Main Workspace */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 20px 28px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.topbar-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--navy-deep);
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #e0f2fe;
  color: #0369a1;
}
.status-pill.live {
  background: #dcfce7;
  color: #15803d;
}
.status-pill.offline {
  background: #fef3c7;
  color: #b45309;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px 20px;
  border: 1px solid var(--slate-200);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.kpi-label {
  font-size: 13px;
  color: var(--slate-500);
  font-weight: 500;
  margin-bottom: 4px;
}
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--slate-900);
  line-height: 1.1;
}
.kpi-sub {
  font-size: 12px;
  color: var(--slate-500);
  margin-top: 4px;
}
.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

/* Panel & Single-Row Streamlined Header + Collapsible Filter Drawer */
.panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--slate-200);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.panel-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--slate-200);
  flex-wrap: nowrap;
  overflow-x: auto;
}
.panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--navy-deep);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.input-search {
  height: 38px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--slate-300);
  border-radius: 10px;
  font-family: inherit;
  font-size: 13px;
  min-width: 220px;
  background: #f8fafc;
  color: var(--slate-900);
}
.input-search:focus {
  outline: 2px solid var(--teal-accent);
  background: #ffffff;
}
.search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search-wrap .material-symbols-rounded {
  position: absolute;
  left: 10px;
  font-size: 18px;
  color: var(--slate-500);
  pointer-events: none;
}

/* Collapsible Filter Drawer (Option 3 — 0px default) */
.filter-drawer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
  background: #f8fafc;
  border-bottom: 0 solid var(--slate-200);
  padding: 0 18px;
}
.filter-drawer.open {
  max-height: 220px;
  padding: 14px 18px;
  border-bottom-width: 1px;
}
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.filter-select, .filter-input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--slate-300);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  background: #ffffff;
  color: var(--slate-900);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: all 0.16s ease;
}
.btn-primary {
  background: linear-gradient(135deg, var(--navy-primary), var(--teal-accent));
  color: #ffffff;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-success {
  background: var(--emerald);
  color: #ffffff;
}
.btn-outline {
  background: #ffffff;
  border-color: var(--slate-300);
  color: var(--slate-700);
}
.btn-outline:hover { background: var(--slate-100); }
.btn-danger {
  background: var(--red);
  color: #ffffff;
}
.btn-icon-badge {
  position: relative;
}
.badge-count {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Floating Speed Dial (Auto-collapse 1s) */
.speed-dial {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.speed-dial-tray {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #ffffff;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  flex-direction: row;
  gap: 6px;
  z-index: 80;
  white-space: nowrap;
}
.speed-dial.open .speed-dial-tray {
  display: inline-flex;
}

/* Responsive Data Table (Horizontal scroll only, NO vertical double scroll) */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-wrap:focus {
  outline: 2px solid var(--teal-accent);
  outline-offset: -2px;
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table thead th {
  background: #f8fafc;
  color: var(--slate-700);
  font-weight: 600;
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--slate-200);
  white-space: nowrap;
}
table.data-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--slate-100);
  vertical-align: middle;
}
table.data-table tbody tr:hover {
  background: #f8fafc;
}

/* Symbol-Based Status Buttons */
.status-dot-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.status-dot-btn:hover { transform: scale(1.1); }
.status-dot-btn.pass { background: #dcfce7; color: #16a34a; }
.status-dot-btn.issue { background: #fee2e2; color: #dc2626; }
.status-dot-btn.repair { background: #fef3c7; color: #d97706; }
.status-dot-btn.pending { background: #f1f5f9; color: #64748b; }

/* Single-Row Horizontal Strip Cards */
.strip-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.strip-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: #ffffff;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  padding: 12px 16px;
}
.strip-card-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.strip-card-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.code-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 7px;
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 12px;
  font-weight: 600;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

/* Native Modal Dialog */
dialog.ppch-dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(720px, 94vw);
  max-height: 90vh;
  box-shadow: var(--shadow-lg);
  background: #ffffff;
  color: var(--slate-900);
}
dialog.ppch-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}
.dialog-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
}
.dialog-head h3 {
  margin: 0;
  font-size: 16px;
  color: var(--navy-deep);
}
.dialog-body {
  padding: 20px;
}
.dialog-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--slate-200);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: #f8fafc;
}

/* Toast Notification */
#ppch-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9500;
  background: var(--navy-deep);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: none;
  align-items: center;
  gap: 8px;
}
#ppch-toast.show { display: inline-flex; }

/* Action Loader Overlay */
#action-loader {
  position: fixed;
  inset: 0;
  z-index: 9800;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #ffffff;
  font-weight: 600;
}
#action-loader.show { display: flex; }

/* Mobile Responsive */
@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main-content { padding: 14px 14px 80px; }
}
@media (max-width: 640px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed;
    bottom: 0;
    top: auto;
    left: 0;
    right: 0;
    width: 100% !important;
    height: 62px;
    margin-right: 0 !important;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    padding: 4px 8px;
  }
  .sidebar-brand, .sidebar-footer, .nav-item span.nav-label { display: none; }
  .nav-item { width: auto; padding: 10px; justify-content: center; margin: 0; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}
