/* The modal */
.ffmwp-modal {
  --wpfm-modal-bg: #fff;
  --wpfm-modal-text: #333;
  --wpfm-modal-text-secondary: #777;
  --wpfm-modal-border: #eee;
  --wpfm-modal-border-strong: #ddd;
  --wpfm-modal-close: #888;
  --wpfm-modal-close-hover: #fff;
  --wpfm-modal-section-bg: #f8f9fa;
  --wpfm-modal-accent: #007bff;

  color-scheme: light;
  font-family: sans-serif; /* the modal is a descendant of #ffmwp-wrapper, but headings (h1-h6) inside it can still be matched directly by theme CSS, which always beats an inherited value - see .ffmwp-modal-title / .ffmwp-modal-file-title */
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 9999; /* Sit on top */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgba(20,20,20,0.55); /* Dark scrim */
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  color: var(--wpfm-modal-text);
  animation: ffmwp-modal-fade-in 0.15s ease;
}

/* Lock background scroll while a modal is open */
body.ffmwp-modal-open {
  overflow: hidden;
}

@keyframes ffmwp-modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ffmwp-modal-pop-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.97); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Modal content */
.ffmwp-modal-content {
  background-color: var(--wpfm-modal-bg);
  margin: auto;
  padding: 24px;
  border: none;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  width: 70vw;
  max-width: 900px;
  max-height: 88vh; /* size to content; only scrolls if content genuinely can't fit the viewport */
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  overflow-y: auto;
  animation: ffmwp-modal-pop-in 0.18s ease;
}

/* Document viewer modal - its only content is an iframe showing the actual PDF/image,
   so it needs to be much larger than the file-detail modal (which is sized for a
   thumbnail + metadata layout). */
.ffmwp-modal-viewer .ffmwp-modal-content {
  width: 92vw;
  max-width: 1400px;
  height: 92vh;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.ffmwp-modal-viewer .ffmwp-modal-body {
  flex: 1;
  min-height: 0;
}

.ffmwp-modal-viewer #ffmwp-iframe-wrapper {
  width: 100%;
  height: 100%;
}

.ffmwp-modal-viewer #ffmwp-iframe-wrapper iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
}

/* Modal header (right padding clears the absolutely-positioned close button) */
.ffmwp-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--wpfm-modal-section-bg);
  border-bottom: 1px solid var(--wpfm-modal-border);
  border-radius: 12px 12px 0 0;
  margin: -24px -24px 16px;
  padding: 16px 56px 16px 20px;
}

/* Modal title */
.ffmwp-modal-title {
  margin: 0;
  font-family: sans-serif; /* it's an h3, so the theme's heading font (often serif) would otherwise override the inherited plugin font */
  font-size: 18px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Modal body */
.ffmwp-modal-body {
  display: flex;
  gap: 24px;
}

/* Modal columns */
.ffmwp-modal-col {
  padding: 0;
}

.ffmwp-modal-col-left {
  width: 30%;
  padding: 0 20px 0 0;
  border-right: 1px solid var(--wpfm-modal-border);
}

.ffmwp-modal-col-right {
  width: calc(70% - 24px);
  padding: 0;
}

.ffmwp-modal-col-right section + section {
  margin-top: 20px;
}

.ffmwp-modal-right-wrapper .ffmwp-form-group:last-of-type {
  margin-bottom: 12px;
}

.ffmwp-modal-right-wrapper .ffmwp-button {
  margin: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* The site-wide 150px textarea height is a lot of vertical space stacked twice
   (description + email message) - shrink it here so the modal fits without scrolling */
.ffmwp-modal-right-wrapper .ffmwp-textarea {
  height: 80px;
}

/* Modal column items - simple key/value rows */
.ffmwp-modal-col-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--wpfm-modal-border);
}

.ffmwp-modal-col-item:last-child {
  border-bottom: none;
}

.ffmwp-modal-thumb-wrapper {
  position: relative;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--wpfm-modal-section-bg);
  border: 1px solid var(--wpfm-modal-border);
  border-radius: 8px;
  box-sizing: border-box;
  cursor: pointer;
  overflow: hidden;
}

/* File thumbnail */
.ffmwp-modal-file-thumb {
  display: block;
  width: 100%;
  height: 180px;
  object-fit: contain;
  border-radius: 6px;
  box-sizing: border-box;
  transition: transform 0.2s ease;
}

.ffmwp-modal-thumb-wrapper:hover .ffmwp-modal-file-thumb {
  transform: scale(1.04);
}

/* Extension badge, e.g. "PDF" / "PNG" */
.ffmwp-modal-thumb-badge {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: rgba(20,20,20,0.72);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: 4px;
  line-height: 1.4;
  pointer-events: none;
}

/* "Preview" hint shown on hover, signals the whole card is clickable */
.ffmwp-modal-thumb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(20,20,20,0.45);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.ffmwp-modal-thumb-overlay .dashicons {
  font-size: 18px;
  width: 18px;
  height: 18px;
}

.ffmwp-modal-thumb-wrapper:hover .ffmwp-modal-thumb-overlay {
  opacity: 1;
}

/* Inline rename control */
.ffmwp-rename-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.ffmwp-rename-group .wpfm_filename {
  flex: 1;
  min-width: 0;
}

.ffmwp-rename-group .ffmwp-button {
  flex-shrink: 0;
  margin: 0;
}

/* Meta info card */
.ffmwp-modal-meta-wrapper {
  background: var(--wpfm-modal-section-bg);
  border-radius: 8px;
  padding: 4px 16px;
}

/* Modal column labels */
.ffmwp-modal-col-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
  color: var(--wpfm-modal-text-secondary);
  white-space: nowrap;
}

.ffmwp-modal-col-label .dashicons {
  font-size: 16px;
  width: 16px;
  height: 16px;
  color: var(--wpfm-modal-border-strong);
}

/* Modal column values */
.ffmwp-modal-col-value {
  flex: 1;
  text-align: right;
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* File title (readonly view) - explicit font-family since it's an h3 theme heading styles would otherwise win over the inherited plugin font */
.ffmwp-modal-file-title {
  margin: 0 0 8px;
  font-family: sans-serif;
  font-size: 16px;
  font-weight: 600;
}

/* File description */
.ffmwp-modal-file-desc {
  margin: 0;
  font-size: 14px;
  color: var(--wpfm-modal-text-secondary);
}

/* Section headers reused inside the modal (Edit Details, File Meta, Share File by Email) -
   more subdued than the full-width page header they're borrowed from */
.ffmwp-modal-right-wrapper .ffmwp-header {
  background: none;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--wpfm-modal-text-secondary);
  padding: 0 0 8px;
  margin: 0 0 12px;
  border-bottom: 1px solid var(--wpfm-modal-border-strong);
}

.ffmwp-edit-details-wrapper,
.ffmwp-file-meta-wrapper,
.ffmwp-email-msg-wrapper {
  background: var(--wpfm-modal-section-bg);
  border-radius: 8px;
  padding: 16px;
}

/* Close button - positioned absolutely since it's a sibling before .ffmwp-modal-header, not nested in it. Sits on the tinted header, so it needs its own contrast rather than reusing --wpfm-modal-section-bg. */
.ffmwp-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--wpfm-modal-bg);
  border: 1px solid var(--wpfm-modal-border-strong);
  color: var(--wpfm-modal-close);
  font-size: 20px;
  line-height: 1;
  font-weight: normal;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ffmwp-modal-close:hover,
.ffmwp-modal-close:focus {
  background: var(--wpfm-modal-accent);
  border-color: var(--wpfm-modal-accent);
  color: var(--wpfm-modal-close-hover);
  text-decoration: none;
  cursor: pointer;
}

/* Stack the columns and let the modal use more of a small screen */
@media (max-width: 782px) {
  .ffmwp-modal-content {
    width: 92vw;
    height: 88%;
    padding: 16px;
  }

  .ffmwp-modal-header {
    margin: -16px -16px 16px;
    padding: 14px 48px 14px 16px;
  }

  .ffmwp-modal-body {
    flex-direction: column;
    gap: 16px;
  }

  .ffmwp-modal-col-left,
  .ffmwp-modal-col-right {
    width: 100%;
    padding: 0;
    border-right: none;
  }

  .ffmwp-modal-col-left {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--wpfm-modal-border);
  }

  .ffmwp-modal-file-thumb {
    height: 200px;
  }
}
