/* Reusable Modal Component */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  /* Must clear studio.php's rulers (z-index: 99999 !important) or they
     render on top of every modal opened over the studio canvas. */
  z-index: 100000;
  animation: modalFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

/* Position Classes - 9 positions on screen */
/* Top Left */
.modal-position-tl {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 20px;
}

/* Top Center (legacy 'top') */
.modal-position-tc,
.modal-position-top {
  align-items: flex-start;
  justify-content: center;
  padding-top: 60px;
}

/* Top Right */
.modal-position-tr {
  align-items: flex-start;
  justify-content: flex-end;
  padding: 20px;
}

/* Left Center */
.modal-position-lc {
  align-items: center;
  justify-content: flex-start;
  padding: 20px;
}

/* Page Center (default) */
.modal-position-pc,
.modal-position-center {
  align-items: center;
  justify-content: center;
}

/* Right Center */
.modal-position-rc {
  align-items: center;
  justify-content: flex-end;
  padding: 20px;
}

/* Bottom Left */
.modal-position-bl {
  align-items: flex-end;
  justify-content: flex-start;
  padding: 20px;
}

/* Bottom Center */
.modal-position-bc {
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
}

/* Bottom Right */
.modal-position-br {
  align-items: flex-end;
  justify-content: flex-end;
  padding: 20px;
}

.modal {
  background: var(--panel, #ffffff);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(24, 27, 32, 0.2), 0 0 1px rgba(24, 27, 32, 0.1);
  width: 90%;
  max-height: 90vh;
  height: auto;
  overflow: hidden;
  animation: modalSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Size variants */
.modal-sm {
  max-width: 400px;
}

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

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

.modal-xl {
  max-width: 1000px;
  max-height: 92vh;
}

/* Loading spinner animation */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 10;
  width: 100%;
  padding: 24px 28px;
  border-bottom: 1px solid var(--line, #dfe4ea);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--panel, #ffffff);
  border-radius: 16px 16px 0 0;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink, #181b20);
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--muted, #5b6572);
  cursor: pointer;
  padding: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border-radius: 8px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
  margin-left: 16px;
}

.modal-close:hover {
  background: var(--paper, #f7f7f5);
  color: var(--ink, #181b20);
  transform: scale(1.05);
}

.modal-close:active {
  transform: scale(0.95);
}

.modal-body {
  width: 100%; /* pages with a legacy .modal { align-items: center } rule would otherwise shrink the body to its content */
  padding: 20px 24px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(90vh - 140px);
  box-sizing: border-box;
}

.modal-footer {
  position: sticky;
  bottom: 0;
  z-index: 10;
  width: 100%;
  padding: 20px 28px;
  border-top: 1px solid var(--line, #dfe4ea);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-shrink: 0;
  background: var(--paper, #f7f7f5);
  border-radius: 0 0 16px 16px;
}

.modal-btn {
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  border: none;
  letter-spacing: -0.01em;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modal-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.modal-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modal-btn-secondary {
  background: var(--panel, #ffffff);
  border: 1.5px solid var(--line, #dfe4ea);
  color: var(--ink, #181b20);
}

.modal-btn-secondary:hover {
  background: var(--paper, #f7f7f5);
  border-color: var(--steel, #8a929b);
}

.modal-btn-primary {
  background: var(--primary, #6750a4);
  color: white;
}

.modal-btn-primary:hover {
  background: var(--primary-dark, #4f378b);
}

.modal-btn-success {
  background: var(--teal, #1f7a76);
  color: white;
}

.modal-btn-success:hover {
  background: #196662;
}

.modal-btn-danger {
  background: var(--accent, #d83f31);
  color: white;
}

.modal-btn-danger:hover {
  background: var(--accent-dark, #a92f25);
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-30px) scale(0.96);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Address Comparison Styles */
.address-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0 8px 0;
  width: 100%;
  max-width: 100%;
}

.address-box {
  padding: 18px;
  border-radius: 12px;
  border: 2px solid var(--line, #dfe4ea);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 0; /* Allow flex items to shrink */
  max-width: 100%;
  background: var(--panel, #ffffff);
  overflow: hidden;
}

.address-box.selected {
  border-color: var(--teal, #1f7a76);
  background: #f0fdf9;
  box-shadow: 0 0 0 4px rgba(31, 122, 118, 0.08);
  transform: translateY(-2px);
}

.address-box-header {
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted, #5b6572);
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1.5px solid var(--line, #dfe4ea);
}

.address-box-title {
  font-size: 0.875rem;
  color: var(--ink, #181b20);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.address-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.6875rem;
  font-weight: 700;
  width: fit-content;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.address-badge-original {
  background: #fff8e6;
  color: var(--gold, #b28b45);
  border: 1px solid #ffe9a6;
}

.address-badge-validated {
  background: #e6f7f6;
  color: var(--teal, #1f7a76);
  border: 1px solid #b3e5e2;
}

.address-line {
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--ink, #181b20);
  margin: 6px 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
  padding: 4px 0;
  font-weight: 500;
}

.address-line.changed {
  background: #fff8e6;
  padding: 6px 10px;
  margin: 6px -10px;
  border-radius: 6px;
  font-weight: 600;
  border-left: 3px solid var(--gold, #b28b45);
}

@media (max-width: 768px) {
  .address-comparison {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .modal {
    width: 95%;
    max-height: 95vh;
  }

  .modal-body {
    max-height: calc(95vh - 180px);
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-btn {
    width: 100%;
  }

  .address-box {
    padding: 20px;
  }
}

@media (min-width: 769px) {
  /* Ensure side-by-side layout on desktop */
  .address-comparison {
    min-height: 150px;
  }
}
