/* ==========================================================================
   สไตล์ชีตเสริม (Custom Stylesheet)
   งานวิชาการและวิจัย โรงพยาบาลมหาสารคาม
   Academic & Research Affairs, Mahasarakham Hospital
   ========================================================================== */

/* 1. Base & Smooth Scrolling */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 115px; /* Offset for sticky header & nav */
}

body {
  font-family: 'Sarabun', sans-serif;
  transition: font-size 0.2s ease, background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4, h5, h6, .font-heading {
  font-family: 'Sarabun', sans-serif;
  font-weight: 700;
}

/* 2. Modern Dark Mode System */
html.dark,
body.dark-mode {
  background-color: #0b1329 !important;
  color: #f1f5f9 !important;
}

html.dark body {
  background-color: #0b1329 !important;
  color: #f1f5f9 !important;
}

/* Theme color mappings */
html.dark .bg-themeHeroBg,
body.dark-mode .bg-themeHeroBg,
html.dark .bg-themeContentBg,
body.dark-mode .bg-themeContentBg,
html.dark .bg-\[\#F7F9FC\],
body.dark-mode .bg-\[\#F7F9FC\] {
  background-color: #0b1329 !important;
}

html.dark .bg-themeCard,
body.dark-mode .bg-themeCard {
  background-color: #131d36 !important;
  color: #f1f5f9 !important;
}

html.dark .text-themeText,
body.dark-mode .text-themeText {
  color: #f1f5f9 !important;
}

/* Hero Title & Subtitle */
html.dark [data-editable="hero_title"],
body.dark-mode [data-editable="hero_title"],
html.dark #heroTitleWrapper div,
body.dark-mode #heroTitleWrapper div {
  color: #f8fafc !important;
}

html.dark [data-editable="hero_title"] .text-themeGreen,
body.dark-mode [data-editable="hero_title"] .text-themeGreen {
  color: #34d399 !important;
}

html.dark [data-editable="hero_subtitle"],
body.dark-mode [data-editable="hero_subtitle"] {
  color: #cbd5e1 !important;
}

html.dark .bg-emerald-50,
body.dark-mode .bg-emerald-50 {
  background-color: rgba(6, 78, 59, 0.4) !important;
  color: #a7f3d0 !important;
  border-color: rgba(5, 150, 105, 0.3) !important;
}

/* Scorecards in Dark Mode */
html.dark #scoreCardsGrid a,
body.dark-mode #scoreCardsGrid a {
  background-image: none !important;
  background-color: #131d36 !important;
  border-color: #243354 !important;
}

html.dark #scoreCardsGrid a:hover,
body.dark-mode #scoreCardsGrid a:hover {
  background-color: #18233e !important;
  border-color: #059669 !important;
}

html.dark #scoreCardsGrid .text-slate-900,
body.dark-mode #scoreCardsGrid .text-slate-900 {
  color: #f8fafc !important;
}

html.dark #scoreCardsGrid .text-slate-500,
body.dark-mode #scoreCardsGrid .text-slate-500 {
  color: #94a3b8 !important;
}

html.dark #scoreCardsGrid svg.text-slate-300,
body.dark-mode #scoreCardsGrid svg.text-slate-300 {
  color: #64748b !important;
}

/* Headings and primary text */
html.dark h1,
html.dark h2,
html.dark h3,
html.dark h4,
html.dark h5,
html.dark h6,
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
  color: #f8fafc !important;
}

/* Base text overrides */
html.dark .text-slate-900,
html.dark .text-slate-800,
html.dark .text-slate-700,
html.dark .text-navy-900,
html.dark .text-themeNavy,
html.dark .text-\[\#243247\],
html.dark .text-\[\#183153\],
body.dark-mode .text-slate-900,
body.dark-mode .text-slate-800,
body.dark-mode .text-slate-700,
body.dark-mode .text-navy-900,
body.dark-mode .text-themeNavy,
body.dark-mode .text-\[\#243247\],
body.dark-mode .text-\[\#183153\] {
  color: #f1f5f9 !important;
}

/* Secondary muted text */
html.dark .text-slate-600,
html.dark .text-slate-500,
body.dark-mode .text-slate-600,
body.dark-mode .text-slate-500 {
  color: #94a3b8 !important;
}

/* Headers & Navigation in Dark Mode */
html.dark header,
body.dark-mode header,
html.dark nav,
body.dark-mode nav {
  background-color: #0f172a !important;
  border-color: #1e293b !important;
  color: #f1f5f9 !important;
}

/* Cards & White Surfaces */
html.dark .bg-white,
body.dark-mode .bg-white {
  background-color: #131d36 !important;
  border-color: #243354 !important;
  color: #f1f5f9 !important;
}

/* Light gray backgrounds become sleek dark blue/slate */
html.dark .bg-slate-50,
html.dark .bg-slate-100,
body.dark-mode .bg-slate-50,
body.dark-mode .bg-slate-100 {
  background-color: #18233e !important;
}

html.dark .bg-slate-200,
body.dark-mode .bg-slate-200 {
  background-color: #1e293b !important;
}

/* Borders */
html.dark .border-slate-200,
html.dark .border-slate-100,
html.dark .border-slate-300,
html.dark .border-slate-200\/80,
body.dark-mode .border-slate-200,
body.dark-mode .border-slate-100,
body.dark-mode .border-slate-300,
body.dark-mode .border-slate-200\/80 {
  border-color: #243354 !important;
}

/* Hover states on cards / items */
html.dark .hover\:bg-slate-50:hover,
html.dark .hover\:bg-slate-100:hover,
body.dark-mode .hover\:bg-slate-50:hover,
body.dark-mode .hover\:bg-slate-100:hover {
  background-color: #1e2d4f !important;
}

/* News items hover */
html.dark article:hover,
body.dark-mode article:hover {
  background-color: #18233e !important;
}

/* Inputs & Form Controls */
html.dark input,
html.dark select,
html.dark textarea,
html.dark #heroSearchInput,
body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea,
body.dark-mode #heroSearchInput {
  background-color: #0f172a !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
}

html.dark input::placeholder,
body.dark-mode input::placeholder {
  color: #64748b !important;
}

/* Tables */
html.dark table thead th,
body.dark-mode table thead th {
  background-color: #0f172a !important;
  color: #94a3b8 !important;
  border-color: #243354 !important;
}

html.dark table tbody tr,
body.dark-mode table tbody tr {
  border-color: #1e293b !important;
}

html.dark table tbody tr:hover,
body.dark-mode table tbody tr:hover {
  background-color: #18233e !important;
}

/* Modals */
html.dark #loginModal > div,
html.dark #feedbackModal > div,
html.dark #pdfViewerModal > div,
body.dark-mode #loginModal > div,
body.dark-mode #feedbackModal > div,
body.dark-mode #pdfViewerModal > div {
  background-color: #131d36 !important;
  color: #f1f5f9 !important;
  border: 1px solid #243354 !important;
}

/* Footer */
html.dark footer,
body.dark-mode footer {
  background-color: #070d1e !important;
  border-color: #1e293b !important;
}

/* 4. Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #0b6e4f;
}

/* 5. Floating Back-to-Top Button */
#backToTopBtn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 45;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
}

#backToTopBtn.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* 6. Toast Notification Component */
#toastContainer {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast-message {
  pointer-events: auto;
  min-width: 280px;
  max-width: 380px;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  border-left: 4px solid #10b981;
  animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.3s ease;
}

.toast-message.toast-warn {
  border-left-color: #f59e0b;
}

.toast-message.toast-error {
  border-left-color: #ef4444;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}


/* 7. Admin Toolbar & In-Place Editing Styles */
#adminToolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.admin-only {
  display: none !important;
}

body.admin-mode .admin-only {
  display: flex !important;
}

body.admin-mode .admin-only-block {
  display: block !important;
}

body.admin-mode .admin-only-inline {
  display: inline-flex !important;
}

body.admin-mode [data-editable] {
  position: relative;
  outline: 2px dashed rgba(16, 185, 129, 0.5);
  outline-offset: 3px;
  border-radius: 4px;
  cursor: text;
  transition: all 0.2s ease;
}

body.admin-mode [data-editable]:hover {
  outline-color: #059669;
  background-color: rgba(16, 185, 129, 0.08);
}

body.admin-mode [data-editable]:focus {
  outline: 2px solid #059669;
  background-color: rgba(16, 185, 129, 0.14);
}

/* Modal Dialog Styles */
.admin-modal-backdrop {
  backdrop-filter: blur(5px);
  background-color: rgba(15, 23, 42, 0.75);
}

.admin-modal-box {
  animation: modalScaleIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalScaleIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* 8. Table Row Filter Animation */
.table-row-hidden {
  display: none !important;
}

/* 9. Active Navigation Link indicator */
.nav-link-active {
  background-color: #166534 !important; /* moph-800 */
  color: #ffffff !important;
  font-weight: 600 !important;
}

/* 10. Print Styles */
@media print {
  header,
  nav,
  #backToTopBtn,
  #toastContainer,
  .quick-search,
  button,
  footer {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 12pt !important;
  }

  section {
    page-break-inside: avoid;
    padding: 10px 0 !important;
  }
}

/* 11. Thai Typography & Heading Line-Height Spacing (ช่องไฟระหว่างบรรทัดภาษาไทย) */
.hero-title,
[data-editable="hero_title"],
h2[data-editable="hero_title"] {
  line-height: 1.65 !important;
  letter-spacing: 0.015em !important;
}

[data-editable="hero_title"] span {
  display: inline-block;
  margin-top: 0.35rem;
  line-height: 1.55;
}

[data-editable="hero_title"] br {
  margin-bottom: 0.25rem;
}


/* ==========================================================================
   12. 3D JOURNAL FLIPBOOK & BOOK CARDS (Option 2 Implementation)
   ========================================================================== */
.book-card-3d {
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.book-card-3d:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 30px -10px rgba(0,0,0,0.14);
}

.book-cover-mock {
  box-shadow: -4px 6px 16px rgba(0,0,0,0.22), inset -2px 0 5px rgba(0,0,0,0.18);
  position: relative;
  transition: transform 0.25s ease;
}
.book-card-3d:hover .book-cover-mock {
  transform: scale(1.02);
}

.book-spine-crease {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 28px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(0,0,0,0.22) 0%, rgba(0,0,0,0.04) 22%, rgba(255,255,255,0.35) 50%, rgba(0,0,0,0.04) 78%, rgba(0,0,0,0.22) 100%);
  pointer-events: none;
  z-index: 15;
}

.modal-spread {
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255,255,255,0.08);
  position: relative;
}

.flipbook-page {
  position: relative;
  background-color: #FFFFFF;
  background-image: linear-gradient(to right, rgba(0,0,0,0.02) 0%, rgba(255,255,255,0) 15%, rgba(0,0,0,0.01) 100%);
  overflow-y: auto;
  user-select: none;
}

/* Page curl animation effect */
.page-turning-left {
  animation: pageTurnLeft 0.4s ease-out forwards;
}
.page-turning-right {
  animation: pageTurnRight 0.4s ease-out forwards;
}

@keyframes pageTurnLeft {
  0% { transform: rotateY(0deg); opacity: 1; }
  50% { transform: rotateY(-35deg) skewY(-1deg); opacity: 0.85; }
  100% { transform: rotateY(0deg); opacity: 1; }
}

@keyframes pageTurnRight {
  0% { transform: rotateY(0deg); opacity: 1; }
  50% { transform: rotateY(35deg) skewY(1deg); opacity: 0.85; }
  100% { transform: rotateY(0deg); opacity: 1; }
}
