/* Unified Modal Header (Green System Standard)
  Purpose: Standardize title and top-right controls across all modal headers
   Scope: Enhances existing markup in index.html modals without requiring rewrites
   Mobile: Always readable, safe-area aware, large touch targets
*/

:root {
  /* Lock header accent to neon green, independent of global --accent-color */
  --rmh-accent: #00ff88;
  --rmh-accent-soft: rgba(0, 255, 136, 0.35);
  --rmh-bg: var(--dark-color, #0f1016);
  --rmh-text: #dfffe8;
}

/* Normalize classic modal headers to left group (icon+title) and right controls */
.modal .modal-header {
  display: grid;
  grid-template-columns: 1fr auto; /* left group grows, right controls hug right */
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--rmh-bg);
  border-bottom: 2px solid var(--rmh-accent) !important; /* ensure no global magenta overrides */
}

/* Title: left-aligned, truncated, glowing green */
.modal .modal-header .rmh-title,
.modal .modal-header h2.rmh-title {
  margin: 0;
  text-align: left;
  font-size: 1.3rem;
  letter-spacing: 0.6px;
  color: var(--rmh-accent) !important; /* force neon green title */
  text-shadow: 0 0 10px rgba(0,255,136,.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Left group (icon + title) */
.rmh-left { 
  grid-column: 1;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0; /* allow truncation */
}
.rmh-left .rmh-icon { color: var(--rmh-accent); font-size: 20px; line-height: 1; text-shadow: 0 0 8px rgba(0,255,136,.35); }

/* Right actions group */
.rmh-actions-right { grid-column: 2; display: inline-flex; align-items: center; gap: 8px; justify-self: end; }

/* Standard control button */
.rmh-btn,
.modal .modal-header .btn-close, /* legacy close */
.nc-header .nc-icon-btn, /* NC */
.pc-header .pc-close-btn,
.uc-header .uc-close-btn,
.dc-header .dc-close,
#ac-header .ac-close,
.fa-header .fa-close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px; /* match header buttons */
  background: rgba(var(--dark-color-rgb), 0.6) !important; /* outline style: more negative space */
  border: 1px solid var(--secondary-color) !important;
  color: var(--primary-color) !important;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
  font-size: 18px;
  line-height: 1;
  opacity: 0.9;
}
.rmh-btn:hover,
.modal .modal-header .btn-close:hover,
.nc-header .nc-icon-btn:hover,
.pc-header .pc-close-btn:hover,
.uc-header .uc-close-btn:hover,
.dc-header .dc-close:hover,
#ac-header .ac-close:hover,
.fa-header .fa-close:hover {
  background: rgba(var(--dark-color-rgb), 0.8) !important;
  border-color: var(--primary-color) !important;
  opacity: 1;
  transform: translateY(-1px);
}
.rmh-btn:active,
.modal .modal-header .btn-close:active,
.nc-header .nc-icon-btn:active,
.pc-header .pc-close-btn:active,
.uc-header .uc-close-btn:active,
.dc-header .dc-close:active,
#ac-header .ac-close:active,
.fa-header .fa-close:active {
  transform: translateY(0) scale(1);
}
.rmh-btn:focus-visible,
.modal .modal-header .btn-close:focus-visible,
.nc-header .nc-icon-btn:focus-visible,
.pc-header .pc-close-btn:focus-visible,
.uc-header .uc-close-btn:focus-visible,
.dc-header .dc-close:focus-visible,
#ac-header .ac-close:focus-visible,
.fa-header .fa-close:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Icon glyph alignment for text-based symbols */
.rmh-close { font-size: 22px; }
.rmh-minimize { font-size: 16px; }
.rmh-refresh { font-size: 18px; }
.rmh-export  { font-size: 18px; }

/* Ensure the legacy close button appears on the right within actions group when we move it */
.modal .modal-header .rmh-actions-right > .btn-close { order: 0; }

/* On small screens: increase hit targets and keep layout tidy */
@media (max-width: 600px) {
  .modal .modal-header { padding: 10px 10px; }
  .modal .modal-header h2 { font-size: 1.1rem; }
  /* mirror header mobile sizing */
  .rmh-btn, .modal .modal-header .btn-close { width: 40px; height: 40px; border-radius: 10px; }
}

/* Respect safe area (iOS notches) for top-aligned bottom-sheet modals too */
@supports (padding: max(0px)) {
  .modal .modal-header { padding-top: max(10px, env(safe-area-inset-top)); }
}

/* Optional minimized state parity 
   Any modal can toggle class .minimized; header remains visible while body is hidden. */
.modal.minimized .modal-body, .modal.minimized .modal-footer { display: none !important; }
.modal.minimized .modal-content { width: auto; max-width: min(92vw, 520px); }

/* Toolbar directly under header for relocated controls (search, filters, etc.) */
.rmh-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px 10px;
  background: linear-gradient(180deg, rgba(0,0,0,0.25), rgba(0,0,0,0));
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.rmh-toolbar > * { margin: 0; }
.rmh-toolbar input[type="text"], .rmh-toolbar select { min-height: 34px; }
