/* ========================================
   UNIFIED MODAL SYSTEM
   Viewport-centered modal positioning for library and publications
   ======================================== */

:root {
  --jinan-teal: #316667;
  --jinan-gold: #cd9933;
  --jinan-teal-hover: #2a5a5b;
  --jinan-gold-hover: #ba8827;
  --jinan-teal-light: rgba(49, 102, 103, 0.1);
  --jinan-gold-light: rgba(205, 153, 51, 0.1);
  --border-radius: 8px;
  --border-radius-lg: 12px;
  --transition: all 0.3s ease;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Modal Overlay - Fixed to Viewport */
.unified-modal {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 99999 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.8) !important;
}

.unified-modal.active {
  opacity: 1;
  visibility: visible;
}

.unified-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  cursor: pointer;
}

/* Modal Container - Centered in Viewport */
.unified-modal-container {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideIn 0.3s ease;
  margin: auto;
}

/* Modal Content */
.unified-modal-content {
  background: white;
  border-radius: var(--border-radius-lg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

/* Modal Sizes */
.unified-modal.modal-sm .unified-modal-container {
  max-width: 400px;
}

.unified-modal.modal-md .unified-modal-container {
  max-width: 600px;
}

.unified-modal.modal-lg .unified-modal-container {
  max-width: 800px;
}

.unified-modal.modal-xl .unified-modal-container {
  max-width: 1200px;
}

/* Modal Header */
.unified-modal-header {
  background: linear-gradient(
    135deg,
    var(--jinan-teal) 0%,
    var(--jinan-gold) 100%
  );
  color: white;
  padding: 2rem;
  position: relative;
  border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
  flex-shrink: 0;
}

.unified-modal-title {
  margin: 0 3rem 0.5rem 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.3;
}

.unified-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.unified-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

/* Modal Body */
.unified-modal-body {
  padding: 2rem;
  flex: 1;
  overflow-y: auto;
}

/* Modal Footer */
.unified-modal-footer {
  padding: 1.5rem 2rem 2rem;
  border-top: 1px solid #e9ecef;
  flex-shrink: 0;
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
}

/* Modal Sections */
.unified-modal-section {
  margin-bottom: 2rem;
}

.unified-modal-section:last-child {
  margin-bottom: 0;
}

.unified-modal-section-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--jinan-teal);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Modal Meta Information */
.unified-modal-meta {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.unified-modal-meta-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #f8f9fa;
  border-radius: var(--border-radius);
  border-left: 4px solid var(--jinan-teal);
}

.unified-modal-meta-item i {
  color: var(--jinan-teal);
  width: 16px;
  flex-shrink: 0;
}

.unified-modal-meta-label {
  font-weight: 600;
  color: var(--jinan-teal);
  min-width: 100px;
  flex-shrink: 0;
}

.unified-modal-meta-value {
  color: #495057;
  flex-grow: 1;
}

/* Modal Abstract/Content */
.unified-modal-abstract {
  background: #f8f9fa;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  border-left: 4px solid var(--jinan-gold);
  color: #495057;
  line-height: 1.6;
  font-size: 0.95rem;
}

.unified-modal-abstract p {
  margin: 0.75rem 0;
  line-height: 1.6;
}

.unified-modal-abstract p:first-child {
  margin-top: 0;
}

.unified-modal-abstract p:last-child {
  margin-bottom: 0;
}

.unified-modal-abstract img {
  max-width: 100%;
  height: auto;
  margin: 15px 0;
  border-radius: 5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: block;
}

.unified-modal-abstract strong {
  color: var(--jinan-teal);
  font-weight: 600;
}

.unified-modal-abstract br {
  line-height: 2;
}

/* Modal Buttons */
.unified-modal-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--border-radius);
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.95rem;
}

.unified-modal-btn-primary {
  background: var(--jinan-teal);
  color: white;
}

.unified-modal-btn-primary:hover {
  background: var(--jinan-teal-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  color: white;
  text-decoration: none;
}

.unified-modal-btn-secondary {
  background: #6c757d;
  color: white;
}

.unified-modal-btn-secondary:hover {
  background: #545b62;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.unified-modal-btn-outline {
  background: transparent;
  color: var(--jinan-teal);
  border: 1px solid var(--jinan-teal);
}

.unified-modal-btn-outline:hover {
  background: var(--jinan-teal);
  color: white;
  text-decoration: none;
}

/* Prevent Body Scroll When Modal is Open */
body.modal-open {
  overflow: hidden;
}

/* Animation */
@keyframes modalSlideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Loading State */
.unified-modal .loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  color: var(--jinan-teal);
}

.unified-modal .loading-state i {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* RTL Support */
[dir="rtl"] .unified-modal-meta-item {
  border-left: none;
  border-right: 4px solid var(--jinan-teal);
}

[dir="rtl"] .unified-modal-abstract {
  border-left: none;
  border-right: 4px solid var(--jinan-gold);
  text-align: right;
}

[dir="rtl"] .unified-modal-close {
  right: auto;
  left: 1rem;
}

[dir="rtl"] .unified-modal-title {
  margin: 0 0 0.5rem 3rem;
}

[dir="rtl"] .unified-modal-abstract [dir="rtl"] {
  text-align: right;
  direction: rtl;
}

[dir="rtl"] .unified-modal-abstract p[dir="rtl"] {
  text-align: right;
  margin: 15px 0;
  line-height: 1.6;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
  .unified-modal {
    padding: 1rem;
  }

  .unified-modal-container {
    max-width: 95vw;
    max-height: 95vh;
  }

  .unified-modal-content {
    max-height: 95vh;
  }

  .unified-modal-header {
    padding: 1.5rem;
  }

  .unified-modal-title {
    font-size: 1.3rem;
    margin-right: 2rem;
  }

  .unified-modal-body {
    padding: 1.5rem;
  }

  .unified-modal-footer {
    padding: 1rem 1.5rem 1.5rem;
    flex-direction: column;
  }

  .unified-modal-btn {
    justify-content: center;
  }

  .unified-modal-meta-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .unified-modal-meta-label {
    min-width: auto;
  }

  /* Size adjustments for mobile */
  .unified-modal.modal-sm .unified-modal-container,
  .unified-modal.modal-md .unified-modal-container,
  .unified-modal.modal-lg .unified-modal-container,
  .unified-modal.modal-xl .unified-modal-container {
    max-width: 95vw;
  }
}

@media (max-width: 480px) {
  .unified-modal {
    padding: 0.5rem;
  }

  .unified-modal-header {
    padding: 1rem;
  }

  .unified-modal-title {
    font-size: 1.1rem;
    margin-right: 1.5rem;
  }

  .unified-modal-body {
    padding: 1rem;
  }

  .unified-modal-footer {
    padding: 0.75rem 1rem 1rem;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .unified-modal-overlay {
    background: rgba(0, 0, 0, 0.9);
  }

  .unified-modal-content {
    border: 2px solid var(--jinan-teal);
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .unified-modal,
  .unified-modal-container,
  .unified-modal-close,
  .unified-modal-btn {
    transition: none;
    animation: none;
  }

  .unified-modal .loading-state i {
    animation: none;
  }
}