@import url('https://fonts.googleapis.com/css2?family=Prompt:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  --primary-green: #1d7b38;
  --primary-green-dark: #16642d;
  --primary-green-light: #2da14f;
  --accent-orange: #f06418;
  --accent-orange-hover: #d8540e;
  --accent-orange-light: #fff3ec;
  --accent-orange-border: #f8c8a7;
  --nav-bar-bg: #4a5568;
  --nav-bar-hover: #3b4554;
  --btn-view-bg: #e5f7ed;
  --btn-view-color: #1a8754;
  --btn-view-hover: #d2f0df;
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --border-card: #e2e8f0;
  --border-subframe: #cbd5e1;
  --text-main: #1f2937;
  --text-muted: #64748b;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 18px rgba(0, 0, 0, 0.07);
  --shadow-modal: 0 20px 40px rgba(0, 0, 0, 0.25);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --font-main: 'Prompt', sans-serif;
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
}

/* ==========================================================================
   Hospital Sticky Header Stacking Fix
   ป้องกันเนื้อหาหน้าเพจลอยทับแถบ Header/Navbar ของเว็บไซต์โรงพยาบาลเวลาเลื่อนจอ
   ========================================================================== */
body > header,
header:not(.header-banner),
.site-header:not(.header-banner),
.main-header,
.top-header,
.navbar,
.main-navbar,
.site-navbar,
.header-navbar,
.sticky-top,
.fixed-top,
#mainHeader,
#mainNavbar,
#navbar,
#header {
  position: sticky !important;
  top: 0 !important;
  z-index: 1000 !important;
}

/* ป้องกันแถบเมนูล่างมือถือ (Bottom Navigation Capsule) ไม่ให้โดนทับหรือเพี้ยน */
.mobile-bottom-nav {
  position: fixed !important;
  bottom: 12px !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  z-index: 1050 !important;
}

/* ==========================================================================
   Outer Page Wrapper Frame
   ========================================================================== */
.page-wrapper {
  position: relative;
  z-index: 1;
  max-width: 1140px;
  margin: 20px auto 40px auto;
  background-color: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid #e2e8f0;
  overflow: hidden;
}

/* ==========================================================================
   Header Banner Matching 1.jpg
   ========================================================================== */
.header-banner {
  background: linear-gradient(135deg, #1c7c38 0%, #17652e 100%);
  position: relative;
  overflow: hidden;
  padding: 38px 24px 34px 24px;
  text-align: center;
  color: #ffffff;
}

.header-banner::before {
  content: '';
  position: absolute;
  top: -40px;
  right: 12%;
  width: 260px;
  height: 260px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  pointer-events: none;
}

.header-banner::after {
  content: '';
  position: absolute;
  bottom: -60px;
  right: 4%;
  width: 180px;
  height: 180px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 50%;
  pointer-events: none;
}

.header-banner .decor-circle-left {
  position: absolute;
  top: -80px;
  left: -50px;
  width: 220px;
  height: 220px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 50%;
}

.header-content-inner {
  position: relative;
  z-index: 2;
}

.header-banner h1 {
  font-size: 2.1rem;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.3px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.header-banner p.subtitle {
  font-size: 1.35rem;
  font-weight: 600;
  color: #ffffff;
  margin-top: 4px;
  letter-spacing: 0.5px;
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* ==========================================================================
   Top Navigation Bar Matching 3.jpg (Dark Slate Tabs)
   ========================================================================== */
.portal-nav-bar {
  background-color: var(--nav-bar-bg);
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 2px solid #3b4554;
  overflow: visible;
}

.nav-tabs-container {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0 0 0;
  overflow: visible;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

.nav-tabs-container::-webkit-scrollbar,
.portal-nav-bar::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

.nav-tab-btn {
  background-color: transparent;
  color: #e2e8f0;
  border: none;
  padding: 10px 22px;
  font-size: 0.98rem;
  font-family: var(--font-main);
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.nav-tab-btn:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.nav-tab-btn.active {
  background-color: #ffffff;
  color: var(--primary-green-dark);
  font-weight: 700;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
  position: relative;
}

.nav-tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background-color: #ffffff;
}

.nav-staff-action {
  padding: 6px 0;
}

.btn-staff-login {
  background-color: var(--primary-green);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 7px 18px;
  font-size: 0.9rem;
  font-family: var(--font-main);
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-staff-login:hover {
  background-color: var(--primary-green-light);
  transform: translateY(-1px);
}

/* ==========================================================================
   Staff Logged-in Control Dashboard Bar
   ========================================================================== */
.staff-logged-in-bar {
  background: #f0fdf4;
  border-bottom: 1px solid #bbf7d0;
  padding: 12px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.staff-info-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: #166534;
}

.staff-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-add-doc {
  background-color: var(--accent-orange);
  color: #ffffff;
  border: none;
  padding: 7px 16px;
  font-size: 0.88rem;
  font-family: var(--font-main);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-add-doc:hover {
  background-color: var(--accent-orange-hover);
}

.btn-staff-action-tool {
  background-color: #ffffff;
  color: #1e293b;
  border: 1px solid #cbd5e1;
  padding: 7px 14px;
  font-size: 0.88rem;
  font-family: var(--font-main);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-staff-action-tool:hover {
  background-color: #f8fafc;
  border-color: #94a3b8;
  color: var(--primary-green);
}

.btn-staff-logout {
  background-color: #ef4444;
  color: #ffffff;
  border: none;
  padding: 7px 14px;
  font-size: 0.88rem;
  font-family: var(--font-main);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-staff-logout:hover {
  background-color: #dc2626;
}

/* ==========================================================================
   Main Content Area & Framed Boxes (Matching 3.jpg)
   ========================================================================== */
.content-body.portal-main-frame {
  padding: 30px 32px 50px 32px;
  min-height: 520px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: tabFadeIn 0.25s ease;
}

@keyframes tabFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Sub-framed Box (กรอบย่อยใส่กรอบอีกทีตามแบบ 3.jpg) */
.sub-framed-box {
  background-color: #ffffff;
  border: 1.5px solid var(--border-card);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 28px;
  overflow: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sub-framed-box::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.sub-frame-header {
  background-color: #ffffff;
  border-bottom: 1.5px solid #f1f5f9;
  padding: 18px 24px;
  border-radius: 20px 20px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.sub-frame-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  color: #1e293b;
}

.sub-frame-title svg {
  color: var(--primary-green);
}

.sub-frame-actions {
  display: none;
  gap: 8px;
}

.staff-active .admin-only-inline {
  display: inline-flex !important;
}

.btn-quick-admin-tool {
  background-color: #f0fdf4;
  color: #166534;
  border: 1px solid #86efac;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-family: var(--font-main);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-quick-admin-tool:hover {
  background-color: #dcfce7;
}

.sub-frame-body {
  padding: 22px;
  background-color: #ffffff;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sub-frame-body::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

/* ==========================================================================
   TAB 1: Certificate Page Styles (Matching 4.jpg & 5.jpg)
   ========================================================================== */
.cert-page-header {
  background: linear-gradient(135deg, rgba(29, 123, 56, 0.95) 0%, rgba(45, 161, 79, 0.9) 100%);
  border-radius: 20px;
  padding: 26px 30px;
  margin-bottom: 24px;
  color: #ffffff;
  box-shadow: var(--shadow-sm);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.cert-header-text {
  text-align: center;
  width: 100%;
}

.cert-header-text h2 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.cert-header-text p {
  font-size: 1.02rem;
  color: rgba(255, 255, 255, 0.95);
  margin-top: 4px;
}

/* Carousel / Slider - Clean, White & Smooth Curved */
.certificate-carousel {
  position: relative;
  width: 100%;
  height: 480px;
  background-color: #ffffff;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.certificate-carousel::-webkit-scrollbar,
.carousel-track::-webkit-scrollbar,
.carousel-slide::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.carousel-track {
  width: 100%;
  height: 100%;
  position: relative;
}

.carousel-slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.carousel-slide.active {
  opacity: 1;
  visibility: visible;
}

.carousel-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  cursor: zoom-in;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.carousel-img:hover {
  transform: scale(1.015);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

/* Slider Controls */
.slider-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: rgba(30, 41, 59, 0.55);
  color: #ffffff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 5;
  user-select: none;
}

.slider-btn:hover {
  background-color: rgba(30, 41, 59, 0.85);
  transform: translateY(-50%) scale(1.08);
}

.slider-btn.prev {
  left: 16px;
}

.slider-btn.next {
  right: 16px;
}

.slider-dots-container {
  position: absolute;
  bottom: 14px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  z-index: 5;
}

.slider-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: all 0.2s ease;
}

.slider-dot.active {
  background-color: var(--primary-green);
  width: 26px;
  border-radius: 10px;
}

/* ==========================================================================
   Timeline Section Styles (Matching 4.jpg)
   ========================================================================== */
.timeline-stage-group {
  margin-bottom: 30px;
}

.timeline-stage-title-box {
  background: linear-gradient(90deg, #f0fdf4 0%, #ffffff 100%);
  border-left: 4px solid var(--primary-green);
  padding: 11px 20px;
  border-radius: 12px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.timeline-stage-title {
  font-size: 1.12rem;
  font-weight: 700;
  color: #166534;
}

.timeline-items-wrapper {
  position: relative;
  margin-left: 18px;
  padding-left: 26px;
  border-left: 2px dashed #94a3b8;
}

.timeline-node {
  position: relative;
  margin-bottom: 14px;
}

/* Blinking Green Dot with Pulse Animation */
.timeline-dot {
  position: absolute;
  top: 20px;
  left: -35px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--primary-green);
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 2px var(--primary-green-light);
  animation: pulseGreenBlink 1.8s infinite ease-in-out;
}

@keyframes pulseGreenBlink {
  0% {
    box-shadow: 0 0 0 0 rgba(29, 123, 56, 0.85);
    background-color: #1d7b38;
    transform: scale(0.95);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    background-color: #22c55e;
    transform: scale(1.2);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(29, 123, 56, 0);
    background-color: #1d7b38;
    transform: scale(0.95);
  }
}

/* Structured Grid Alignment for Timeline Columns */
.timeline-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 14px 22px;
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(180px, 1.1fr) minmax(180px, 1.1fr) auto;
  align-items: center;
  gap: 16px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.timeline-card:hover {
  border-color: #86efac;
  transform: translateX(4px);
  box-shadow: 0 4px 14px rgba(22, 101, 52, 0.08);
}

.timeline-round-badge {
  font-weight: 600;
  font-size: 1rem;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
}

.timeline-date-col {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.timeline-date-col .timeline-label {
  color: #64748b;
  white-space: nowrap;
}

.timeline-date-col .timeline-val {
  font-weight: 600;
  white-space: nowrap;
}

.timeline-date-col.cert .timeline-val {
  color: #15803d;
}

.timeline-admin-actions {
  display: none;
  gap: 6px;
  justify-content: flex-end;
}

.staff-active .timeline-admin-actions {
  display: inline-flex;
}

.btn-timeline-del {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: var(--font-main);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-timeline-del:hover {
  background-color: #ef4444;
  color: #ffffff;
}

/* ==========================================================================
   TAB 2: Search Box & Download List (Matching 1.jpg & 2.jpg)
   ========================================================================== */
.search-box-wrapper {
  background-color: #ffffff;
  border: 2px solid var(--primary-green);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  padding: 4px 6px 4px 20px;
  box-shadow: 0 4px 12px rgba(29, 123, 56, 0.08);
  margin-bottom: 30px;
  transition: all 0.2s ease;
}

.search-box-wrapper:focus-within {
  box-shadow: 0 6px 16px rgba(29, 123, 56, 0.16);
  border-color: var(--primary-green-dark);
}

.search-input-group {
  flex: 1;
  display: flex;
  align-items: center;
}

.search-input-group input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 1rem;
  font-family: var(--font-main);
  color: var(--text-main);
  background: transparent;
  padding: 8px 4px;
}

.search-input-group input::placeholder {
  color: #9ca3af;
}

.btn-search-submit {
  background-color: var(--primary-green);
  color: #ffffff;
  border: none;
  padding: 9px 28px;
  font-size: 1rem;
  font-family: var(--font-main);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.2s ease;
}

.btn-search-submit:hover {
  background-color: var(--primary-green-dark);
}

.category-section-block {
  margin-top: 10px;
}

.category-header-badge-wrapper {
  margin-bottom: 16px;
}

.category-header-badge {
  background-color: #17642d;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px 10px 20px;
  border-radius: var(--radius-full);
  font-size: 1.05rem;
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(23, 100, 45, 0.22);
}

.badge-count {
  background-color: #ffffff;
  color: #17642d;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  margin-left: 4px;
}

.documents-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doc-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.doc-card:hover {
  border-color: #86efac;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(29, 123, 56, 0.08);
}

.doc-card-title {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text-main);
  flex: 1;
  padding-right: 20px;
}

.doc-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-view-file {
  background-color: var(--btn-view-bg);
  color: var(--btn-view-color);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 7px 18px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(26, 135, 84, 0.2);
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-view-file:hover {
  background-color: var(--btn-view-hover);
  border-color: rgba(26, 135, 84, 0.35);
  transform: translateY(-1px);
}

.btn-download-file {
  background-color: #fff7ed;
  color: #ea580c;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 7px 18px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(234, 88, 12, 0.25);
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-download-file:hover {
  background-color: #ffedd5;
  border-color: rgba(234, 88, 12, 0.45);
  transform: translateY(-1px);
}

/* Pagination Bar */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 26px;
  padding: 10px 0;
}

.pagination-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-card);
  box-shadow: var(--shadow-sm);
}

.btn-page-nav {
  background: transparent;
  border: 1px solid transparent;
  padding: 6px 14px;
  font-size: 0.88rem;
  font-family: var(--font-main);
  font-weight: 500;
  color: #334155;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-page-nav:hover:not(:disabled) {
  background: #f1f5f9;
  color: var(--primary-green);
}

.btn-page-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.page-numbers {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  font-family: var(--font-main);
  font-size: 0.92rem;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.page-btn:hover:not(.active) {
  background: #f1f5f9;
  color: var(--primary-green);
}

.page-btn.active {
  background: var(--primary-green);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(29, 123, 56, 0.3);
}

.doc-admin-actions {
  display: none;
  margin-left: 4px;
}

.staff-active .doc-admin-actions {
  display: block;
}

.btn-action-delete {
  background-color: #fee2e2;
  color: #dc2626;
  border: 1px solid #fca5a5;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-main);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-action-delete:hover {
  background-color: #dc2626;
  color: #ffffff;
}

.no-results {
  display: none;
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
  background: #f8fafc;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-card);
  margin-top: 20px;
}

/* ==========================================================================
   Modals & Lightbox
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.6);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 99999 !important;
  padding: 20px;
  backdrop-filter: blur(3px);
}

.modal-overlay.active {
  display: flex;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.modal-box {
  background-color: #ffffff;
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-box.modal-lg {
  max-width: 680px;
}

.modal-header {
  background: linear-gradient(135deg, #1d7b38 0%, #16642d 100%);
  color: #ffffff;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.modal-close:hover {
  opacity: 1;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: #374151;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: var(--font-main);
  border: 1px solid #d1d5db;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background-color: #ffffff;
}

.form-control:focus {
  border-color: var(--primary-green);
  box-shadow: 0 0 0 3px rgba(29, 123, 56, 0.15);
}

.btn-modal-submit {
  width: 100%;
  padding: 11px;
  font-size: 1rem;
  font-family: var(--font-main);
  font-weight: 600;
  color: #ffffff;
  background-color: var(--primary-green);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.2s, transform 0.2s;
}

.btn-modal-submit:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.demo-account-hint {
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 18px;
  font-size: 0.88rem;
  color: #166534;
}

/* Admin Subforms & Item Lists in Modals */
.admin-subform-box {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 20px;
}

.admin-items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 250px;
  overflow-y: auto;
}

.admin-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 8px 14px;
  border-radius: 6px;
  gap: 12px;
}

.admin-item-preview {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-item-thumb {
  width: 50px;
  height: 38px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
}

/* Lightbox Modal */
.lightbox-box {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lightbox-img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.lightbox-caption {
  color: #ffffff;
  margin-top: 10px;
  font-size: 1rem;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.lightbox-close {
  position: absolute;
  top: -40px;
  right: -10px;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 2.2rem;
  cursor: pointer;
}

/* Portal Footer */
.portal-footer {
  text-align: center;
  padding: 24px;
  background-color: #f8fafc;
  border-top: 1px solid #e2e8f0;
  font-size: 0.9rem;
  color: #64748b;
}

/* ==========================================================================
   Responsive Adaptations: Tablet (769px - 1024px)
   ========================================================================== */
@media (min-width: 769px) and (max-width: 1024px) {
  .page-wrapper {
    margin: 12px 16px 30px 16px;
    border-radius: var(--radius-md);
  }

  .header-banner {
    padding: 30px 20px 26px 20px;
  }

  .header-banner h1 {
    font-size: 1.85rem;
  }

  .header-banner p.subtitle {
    font-size: 1.2rem;
  }

  .content-body.portal-main-frame {
    padding: 24px 20px 36px 20px;
  }

  .certificate-carousel {
    height: 380px;
  }

  .timeline-card {
    grid-template-columns: 140px 1.2fr 1.6fr auto;
    padding: 14px 18px;
    gap: 12px;
  }

  .doc-card {
    padding: 16px 20px;
  }
}

/* ==========================================================================
   Responsive Adaptations: Mobile (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
  /* ลบช่องว่างส่วนเกินด้านบนและด้านข้างของ main ที่มาจาก CSS กลางของ รพ. */
  main {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Safe Area for Mobile Page Wrapper to prevent overlap with template's bottom nav */
  .page-wrapper {
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    /* เว้นระยะปลอดภัยด้านล่างบนมือถือ สำหรับ Floating Nav + แถบ Home Bar ของ iPhone */
    padding-bottom: calc(115px + env(safe-area-inset-bottom, 24px)) !important;
  }

  /* Header Banner */
  .header-banner {
    padding: 24px 16px 20px 16px;
  }

  .header-banner h1 {
    font-size: 1.5rem;
    line-height: 1.3;
  }

  .header-banner p.subtitle {
    font-size: 1.1rem;
    margin-top: 2px;
  }

  .header-banner::before {
    width: 180px;
    height: 180px;
    right: -20px;
  }

  .header-banner::after {
    display: none;
  }

  /* Top Navigation Bar: Touch-Friendly Scrollable Tabs */
  .portal-nav-bar {
    padding: 0 8px;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 2px solid #334155;
    scrollbar-width: none;
  }

  .portal-nav-bar::-webkit-scrollbar {
    display: none;
  }

  .nav-tabs-container {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    width: auto;
    flex: 1 0 auto;
  }

  .nav-tab-btn {
    padding: 10px 14px;
    font-size: 0.88rem;
    min-height: 44px;
    border-radius: 6px 6px 0 0;
    white-space: nowrap;
  }

  .nav-staff-action {
    flex-shrink: 0;
  }

  .btn-staff-login {
    padding: 8px 12px;
    font-size: 0.82rem;
    min-height: 40px;
  }

  /* Staff Admin Bar */
  .staff-logged-in-bar {
    padding: 12px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .staff-info-tag {
    font-size: 0.88rem;
  }

  .staff-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .btn-add-doc,
  .btn-staff-action-tool {
    padding: 8px 10px;
    font-size: 0.82rem;
    justify-content: center;
    min-height: 40px;
  }

  .btn-staff-logout {
    grid-column: span 2;
    width: 100%;
    justify-content: center;
    min-height: 40px;
    margin-left: 0;
  }

  /* Main Body Frame */
  .content-body.portal-main-frame {
    padding: 16px 12px 28px 12px;
  }

  /* Certificate Page Header */
  .cert-page-header {
    padding: 18px 14px;
    border-radius: 14px;
    margin-bottom: 16px;
  }

  .cert-header-text h2 {
    font-size: 1.35rem;
  }

  .cert-header-text p {
    font-size: 0.9rem;
  }

  /* Sub-Framed Boxes */
  .sub-framed-box {
    border-radius: 16px;
    margin-bottom: 18px;
    border-width: 1px;
  }

  .sub-frame-header {
    padding: 14px 16px;
    border-radius: 16px 16px 0 0;
  }

  .sub-frame-title {
    font-size: 0.95rem;
    gap: 8px;
  }

  .sub-frame-body {
    padding: 14px 10px;
  }

  /* Certificate Carousel */
  .certificate-carousel {
    height: 260px;
    border-radius: 12px;
  }

  .slider-btn {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .slider-btn.prev {
    left: 8px;
  }

  .slider-btn.next {
    right: 8px;
  }

  /* Timeline Section on Mobile (ป้องกันข้อความตกบรรทัดใน iPhone ตาม problem.jpg) */
  .timeline-stage-title-box {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 6px !important;
    padding: 12px 14px !important;
    margin-bottom: 14px !important;
  }

  .timeline-stage-title {
    font-size: 1.05rem !important;
    line-height: 1.38 !important;
    word-break: break-word !important;
  }

  .timeline-stage-title-box > span:last-child {
    font-size: 0.8rem !important;
    color: #166534 !important;
    background: rgba(22, 101, 52, 0.09) !important;
    padding: 3px 10px !important;
    border-radius: 9999px !important;
    display: inline-block !important;
    white-space: nowrap !important;
  }

  .timeline-items-wrapper {
    margin-left: 12px !important;
    padding-left: 20px !important;
  }

  .timeline-dot {
    left: -29px !important;
    top: 18px !important;
  }

  .timeline-card {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    padding: 14px !important;
    border-radius: 12px !important;
    grid-template-columns: none !important;
  }

  .timeline-round-badge {
    font-size: 0.95rem !important;
  }

  .timeline-date-col {
    font-size: 0.86rem !important;
    flex-wrap: wrap !important;
  }

  .timeline-stage-col {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .timeline-title-col h4 {
    font-size: 0.98rem;
    margin-bottom: 2px;
  }

  .timeline-period-col {
    font-size: 0.82rem;
    color: var(--text-muted);
    border-top: 1px dashed #f1f5f9;
    padding-top: 6px;
  }

  .timeline-status-col {
    display: flex;
    justify-content: flex-start;
  }

  /* Search Box */
  .search-box-wrapper {
    flex-direction: column;
    padding: 6px;
    gap: 8px;
    border-radius: var(--radius-md);
  }

  .search-input-group input {
    font-size: 16px !important; /* Prevents auto-zoom in iOS Safari */
    padding: 12px 14px;
    border-radius: var(--radius-sm);
  }

  .btn-search-submit {
    width: 100%;
    min-height: 44px;
    border-radius: var(--radius-sm);
    justify-content: center;
    font-size: 0.96rem;
  }

  /* Category Header Badge */
  .category-header-badge {
    padding: 8px 14px;
    font-size: 0.92rem;
    width: 100%;
    justify-content: space-between;
  }

  /* Document Cards */
  .doc-card {
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
    gap: 12px;
    border-radius: 12px;
  }

  .doc-card-title {
    font-size: 0.95rem;
    line-height: 1.45;
  }

  .doc-card-meta {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: center;
  }

  .btn-view-file,
  .btn-download-file {
    min-height: 42px;
    padding: 8px 12px;
    font-size: 0.88rem;
    justify-content: center;
    width: 100%;
  }

  .doc-admin-actions {
    grid-column: span 2;
    margin-left: 0;
    margin-top: 4px;
  }

  .btn-action-delete {
    width: 100%;
    min-height: 38px;
    justify-content: center;
    display: inline-flex;
    align-items: center;
  }

  /* Pagination Bar */
  .pagination-bar {
    gap: 4px;
    flex-wrap: wrap;
  }

  .page-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    font-size: 0.88rem;
  }

  /* Modals on Mobile */
  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }

  .modal-box {
    max-width: 100%;
    width: 100%;
    border-radius: 20px 20px 10px 10px;
    max-height: 86vh;
  }

  .modal-header {
    padding: 14px 18px;
  }

  .modal-body {
    padding: 16px 18px 24px 18px;
    overflow-y: auto;
  }

  .form-control {
    font-size: 16px !important; /* iOS Zoom Prevention */
    min-height: 44px;
  }

  .btn-modal-submit {
    min-height: 46px;
    font-size: 1rem;
  }

  /* Lightbox */
  .lightbox-box {
    max-width: 95%;
  }

  .lightbox-close {
    top: -46px;
    right: 0;
    font-size: 2.4rem;
  }
}

/* ==========================================================================
   Responsive Adaptations: Small Phones (< 480px)
   ========================================================================== */
@media (max-width: 480px) {
  .header-banner h1 {
    font-size: 1.35rem;
  }

  .header-banner p.subtitle {
    font-size: 1rem;
  }

  .certificate-carousel {
    height: 230px;
  }

  .doc-card-meta {
    grid-template-columns: 1fr;
  }
}
