/* ============================================================
   MEDCORE MODAL SYSTEM — Unified, Responsive & Accessible
   ============================================================ */

/* Utility classes */
.d-none {
  display: none !important;
}

.mt-20 {
  margin-top: 20px;
}

/* Button Variants */
.btn-danger {
  background-color: var(--red, #ef4444);
  color: #ffffff;
  padding: 12px 20px;
  min-height: 46px;
  font-size: 14.5px;
  font-weight: 700;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
  transition: all 0.15s ease;
}

.btn-danger:hover {
  background-color: #dc2626;
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.3);
}

/* 1. Backdrop Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

/* 2. Base Modal Sheet */
.modal-sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  width: 100%;
  max-width: 520px;
  padding: 28px;
  box-shadow: 0 20px 45px -10px rgba(15, 23, 42, 0.18), 0 0 1px 1px var(--border);
  position: relative;
  color: var(--text-primary);
  transform: scale(0.96) translateY(8px);
  transition: transform 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-overlay.open .modal-sheet {
  transform: scale(1) translateY(0);
}

[data-theme="dark"] .modal-sheet {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--border);
}

/* 3. Sheet Variants */
.modal-sheet-scroll {
  max-height: 85vh;
  overflow-y: auto;
}

.modal-sheet-center {
  text-align: center;
}

.modal-sheet-sm {
  max-width: 440px;
}

.modal-sheet-center-sm {
  max-width: 400px;
  text-align: center;
}

.modal-sheet-clear {
  max-width: 420px;
  text-align: center;
}

.modal-sheet-history {
  max-width: 480px;
  width: 100%;
  border-radius: 24px;
  padding: 24px;
}

/* 4. Headers & Controls */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header-bordered {
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header-flex {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-header-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--indigo-dim);
  color: var(--indigo);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-header-icon-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-header .modal-header-icon-title {
  margin-bottom: 0;
}

.modal-header h3 {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--text-primary);
  font-family: 'Be Vietnam Pro', sans-serif;
}

.modal-title-bold {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 0;
  font-family: 'Be Vietnam Pro', sans-serif;
}

.modal-title-mb {
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
  color: var(--text-primary);
  font-family: 'Be Vietnam Pro', sans-serif;
}

.modal-title-custom {
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
  color: var(--text-primary);
  font-family: 'Be Vietnam Pro', sans-serif;
}

.modal-close-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  transition: all 0.18s ease;
  flex-shrink: 0;
}

.modal-close-btn:hover {
  background: var(--border);
  color: var(--text-primary);
  transform: scale(1.05);
}

/* 5. Typography & Subtitles */
.modal-subtitle {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 18px;
  line-height: 1.5;
}

.modal-desc {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.modal-desc-mb {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 22px;
  line-height: 1.55;
}

.modal-desc-custom {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 22px;
  line-height: 1.6;
}

.modal-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* 6. Form Grids & Inputs */
.modal-form-grid {
  display: grid;
  gap: 16px;
}

.modal-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background-color: var(--surface-2);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.modal-input:focus {
  border-color: var(--indigo);
  background-color: var(--surface);
}

.modal-textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
}

/* 7. Action Button Layouts */
.modal-actions-row {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.modal-actions-row .btn-secondary { flex: 1; min-height: 46px; }
.modal-actions-row .btn-primary { flex: 1.5; min-height: 46px; }

.modal-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 12px;
  align-items: stretch;
}

.modal-actions-grid .btn {
  min-height: 46px;
  width: 100%;
}

.modal-actions-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: stretch;
}

.modal-actions-grid-2 .btn {
  min-height: 46px;
  width: 100%;
}

/* 8. Modal Icons (Red & Indigo circles) */
.modal-icon-wrap {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  transition: transform 0.2s ease;
}

.modal-icon-red {
  background: rgba(239, 68, 68, 0.12);
  color: var(--red);
}

.modal-icon-indigo {
  background: var(--indigo-dim);
  color: var(--indigo);
}

.modal-icon-amber {
  background: var(--amber-dim);
  color: var(--amber);
}

/* 9. Confirmation Stats Grid */
.confirm-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-pill-indigo {
  background: var(--indigo-dim);
  border: 1px solid rgba(37, 99, 235, 0.15);
  padding: 12px 8px;
  border-radius: 14px;
  text-align: center;
}

.stat-pill-val-indigo {
  font-size: 20px;
  font-weight: 800;
  color: var(--indigo);
  font-family: 'DM Mono', monospace;
  line-height: 1.1;
}

.stat-pill-label-indigo {
  font-size: 8.5px;
  font-weight: 800;
  color: var(--indigo);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.stat-pill-red {
  background: var(--red-dim);
  border: 1px solid rgba(239, 68, 68, 0.15);
  padding: 12px 8px;
  border-radius: 14px;
  text-align: center;
}

.stat-pill-val-red {
  font-size: 20px;
  font-weight: 800;
  color: var(--red);
  font-family: 'DM Mono', monospace;
  line-height: 1.1;
}

.stat-pill-label-red {
  font-size: 8.5px;
  font-weight: 800;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* 10. Guide Modal */
.guide-grid {
  display: grid;
  gap: 16px;
}

.guide-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.guide-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-primary);
}

.guide-text b {
  color: var(--indigo);
}

.modal-step-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--indigo-dim);
  color: var(--indigo);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  flex-shrink: 0;
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.guide-tip-box {
  margin-top: 20px;
  background: var(--indigo-dim);
  border: 1px solid rgba(37, 99, 235, 0.15);
  padding: 14px 16px;
  border-radius: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.guide-tip-icon {
  color: var(--indigo);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.guide-tip-text {
  font-size: 13px;
  color: var(--indigo);
  font-weight: 600;
  line-height: 1.45;
}

/* 11. Library Info Modal */
.lib-info-box {
  background: var(--surface-2);
  padding: 16px;
  border-radius: 16px;
  font-size: 13.5px;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.lib-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.lib-row:last-child {
  margin-bottom: 0;
}

.lib-label {
  color: var(--text-secondary);
}

.lib-version {
  font-family: 'DM Mono', monospace;
  color: var(--indigo);
}

.lib-note {
  text-align: right;
  max-width: 200px;
  font-size: 12px;
}

/* 12. About Modal */
.about-logo-wrap {
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
}

.about-logo-img {
  width: 84px;
  height: 84px;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.22);
}

.about-title {
  font-weight: 800;
  font-size: 22px;
  margin-bottom: 12px;
  color: var(--text-primary);
  font-family: 'Be Vietnam Pro', sans-serif;
  text-align: center;
}

.about-desc {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 18px;
  font-weight: 400;
  text-align: center;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

.about-desc b {
  color: var(--indigo);
  font-weight: 700;
}

.about-share-section {
  margin: 16px auto 14px;
  text-align: center;
  max-width: 340px;
}

.about-share-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-family: 'Be Vietnam Pro', sans-serif;
}

.about-share-subtitle {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  font-weight: 500;
}

.about-qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 14px auto 18px;
}

.about-qr-card {
  background: #ffffff;
  padding: 10px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease;
}

.about-qr-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.14);
}

.about-qr-img {
  width: 140px;
  height: 140px;
  display: block;
  border-radius: 6px;
  object-fit: contain;
}

.about-qr-caption {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 10px;
  letter-spacing: 0.01em;
}

.about-copyright {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  margin-bottom: 14px;
}

/* 13. History List Modal */
.modal-history-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-family: 'Be Vietnam Pro', sans-serif;
  margin: 0;
  color: var(--text-primary);
}

.modal-history-sub {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 3px;
}

.history-list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
  padding-right: 4px;
}

.history-list-container::-webkit-scrollbar {
  width: 5px;
}
.history-list-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

.history-actions-center {
  margin-top: 20px;
  text-align: center;
}

.btn-history-close {
  border-radius: 99px;
  padding: 12px;
  font-weight: 700;
}

.badge-success-pill {
  display: inline-block;
  background: var(--green-dim);
  color: var(--green);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 700;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

/* 14. Lightbox Image Preview Modal */
.modal-sheet-lightbox {
  max-width: 94vw;
  max-height: 94vh;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
}

.lightbox-header-wrap {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
}

.lightbox-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lightbox-icon {
  font-size: 16px;
  line-height: 1;
}

.lightbox-title-text {
  color: #f8fafc;
  font-size: 14px;
  font-weight: 700;
}

.modal-close-btn-light {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.modal-close-btn-light:hover {
  background: rgba(255, 255, 255, 0.3);
  color: #ffffff;
}

.lightbox-body-wrap {
  overflow: auto;
  max-height: calc(88vh - 60px);
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 16px;
  background: #000000;
  padding: 8px;
}

.lightbox-image-target {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  cursor: zoom-out;
  border-radius: 8px;
}

/* 15. Mobile Dialog Positioning (Strictly Centered) */
@media (max-width: 640px) {
  .modal-overlay {
    padding: 16px !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .modal-sheet {
    border-radius: 24px !important;
    max-height: calc(100vh - 36px) !important;
    max-height: calc(100dvh - 36px) !important;
    padding: 22px 18px !important;
    transform: scale(0.95) translateY(0) !important;
    border: 1px solid var(--border) !important;
    margin: auto !important;
    width: 100% !important;
    max-width: min(440px, calc(100vw - 32px)) !important;
    align-self: center !important;
  }

  .modal-overlay.open .modal-sheet {
    transform: scale(1) translateY(0) !important;
  }

  .modal-sheet-lightbox {
    border-radius: 20px;
    margin-bottom: auto;
    margin-top: auto;
    padding: 12px;
    max-width: calc(100vw - 24px);
  }

  .modal-actions-grid {
    grid-template-columns: 1fr 1.25fr;
    gap: 10px;
  }

  .modal-actions-grid-2 {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
}
