/* ===== MODAL COMPONENT ===== */

/* --- Legacy modal (.modal > .modal-content) --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  z-index: 0;
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: sectionFadeIn 0.2s ease;
}

.modal-small .modal-content {
  max-width: 400px;
}

.modal-qr .modal-content {
  max-width: 360px;
  text-align: center;
}

/* .modal-header layout + .modal-close placement: shared-ui.css */

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-content form {
  padding: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 20px 24px;
  border-top: none;
}

.modal-content p {
  padding: 0 24px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.form-help-text {
  font-size: 13px;
  color: var(--text-muted);
  margin: -4px 0 12px;
}

/* --- Settings modal --- */
.modal-settings {
  max-width: 540px;
}

.settings-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: none;
}

/* --- QR modal --- */
.qr-content {
  padding: 24px;
}

#qr-container {
  background: white;
  padding: 16px;
  border-radius: var(--radius);
  display: inline-block;
  margin-bottom: 16px;
}

#qr-container img {
  width: 200px;
  height: 200px;
}

.qr-instructions {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 12px;
}

.qr-timer {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-status {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--primary-bg-dark);
}

/* --- Status badges --- */
.status-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  text-transform: capitalize;
}

.status-badge.connected {
  background: #0d2818;
  color: #4ade80;
}

.status-badge.connecting {
  background: #1c1708;
  color: #fbbf24;
}

.status-badge.disconnected {
  background: #2d1515;
  color: #f87171;
}

[data-theme="light"] .status-badge.connected {
  background: #dcfce7;
  color: #16a34a;
}

[data-theme="light"] .status-badge.connecting {
  background: #fef3c7;
  color: #d97706;
}

[data-theme="light"] .status-badge.disconnected {
  background: #fee2e2;
  color: #dc2626;
}

/* --- New modal structure (.modal-overlay > .modal-box) --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-box {
  overflow: hidden;
  position: relative;
  z-index: 0;
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: sectionFadeIn 0.2s ease;
  contain: layout style paint;
}

.modal-box[data-size="sm"] { max-width: 360px; }
.modal-box[data-size="md"] { max-width: 480px; }
.modal-box[data-size="lg"] { max-width: 640px; }
.modal-box[data-size="xl"] { max-width: 800px; }

.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: none;
}

.popup-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.popup-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.15s ease;
}

.popup-close:hover {
  color: var(--text-primary);
}

/* --- Glow effects (dark theme) --- */
.modal-content {
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent, rgba(var(--glow-rgb), 0.6), transparent) bottom / 100% 1px no-repeat,
    var(--bg-white);
  contain: layout style paint;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
}

.modal-content::before {
  content: '';
  position: absolute;
  inset: -1px;
  z-index: -2;
  opacity: 0;
  transition: opacity .35s;
  pointer-events: none;
  border-radius: calc(var(--radius-lg) + 1px);
  background: radial-gradient(500px circle at var(--gx, 50%) var(--gy, 50%), rgba(var(--glow-rgb), .35), transparent 40%);
}

.modal-content::after {
  content: '';
  position: absolute;
  inset: 1px;
  z-index: -1;
  pointer-events: none;
  border-radius: calc(var(--radius-lg) - 1px);
  background: var(--bg-white);
}

.modal-content:hover::before,
.modal-content:focus-within::before {
  opacity: 1;
}

[data-theme="light"] .modal-content {
  background: var(--bg-white);
  contain: unset;
  box-shadow: var(--shadow-lg);
}

[data-theme="light"] .modal-content::before,
[data-theme="light"] .modal-content::after {
  display: none;
}

.modal-box::before {
  content: '';
  position: absolute;
  inset: -1px;
  z-index: -2;
  opacity: 0;
  transition: opacity .35s;
  pointer-events: none;
  border-radius: calc(var(--radius-lg) + 1px);
  background: radial-gradient(500px circle at var(--gx, 50%) var(--gy, 50%), rgba(var(--glow-rgb), .35), transparent 40%);
}

.modal-box::after {
  content: '';
  position: absolute;
  inset: 1px;
  z-index: -1;
  pointer-events: none;
  border-radius: calc(var(--radius-lg) - 1px);
  background: var(--bg-white);
}

.modal-box:hover::before,
.modal-box:focus-within::before {
  opacity: 1;
}

[data-theme="light"] .modal-box {
  background: var(--bg-white);
  contain: unset;
  box-shadow: var(--shadow-lg);
}

[data-theme="light"] .modal-box::before,
[data-theme="light"] .modal-box::after {
  display: none;
}

/* Hide scrollbar for modals */
.modal-content::-webkit-scrollbar, .modal-box::-webkit-scrollbar { display: none; }
.modal-content, .modal-box { -ms-overflow-style: none; scrollbar-width: none; }

/* ui.html-aligned compact modals */
.modal-subscribe-compact,
.modal-tier-editor {
  position: relative;
  z-index: 0;
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  overflow: hidden;
  max-height: min(96vh, 560px);
  border-radius: 18px;
  background: var(--bg-white);
}

.modal-subscribe-compact {
  max-width: 428px;
}

.modal-tier-editor {
  max-width: 560px;
  max-height: min(94vh, 720px);
}

.modal-tier-editor form#tier-form {
  padding: 0 !important;
}

.modal-content.modal-subscribe-compact > .modal-header,
.modal-content.modal-tier-editor > .modal-header {
  padding: 12px 18px 4px;
  margin-bottom: 0;
}

.modal-content.modal-subscribe-compact > .modal-header .modal-title,
.modal-content.modal-tier-editor > .modal-header .modal-title {
  letter-spacing: -0.02em;
  margin: 0 0 2px;
}

.modal-content.modal-subscribe-compact > .modal-header .modal-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
}

.modal-content.modal-tier-editor > .modal-header .modal-title {
  text-transform: none;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}

.modal-subscribe-compact .sub-modal-form {
  padding: 0 18px 12px !important;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.modal-tier-editor .tier-modal-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 20px 10px;
  -webkit-overflow-scrolling: touch;
}

.modal-tier-editor #tier-form > div {
  margin-bottom: 10px;
}

.modal-tier-editor #tier-form .form-row {
  margin-bottom: 0;
}

.modal-tier-editor .tier-modal-footer.modal-actions {
  flex-shrink: 0;
  margin: 0;
  padding: 12px 20px;
  border-top: none;
  justify-content: flex-end;
  gap: 10px;
}

.modal-subscribe-compact .sub-modal-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Payment method on top, duration below */
#subscribe-payment-method-wrap {
  order: 1;
}
#subscribe-duration-wrap {
  order: 2;
}

@media (max-width: 440px) {
  .modal-subscribe-compact .sub-modal-grid {
    flex-direction: column;
  }
}

.modal-subscribe-compact .sub-modal-field {
  margin-bottom: 8px;
}

.modal-subscribe-compact .sub-modal-label {
  margin-bottom: 4px;
  font-size: 10px;
}

.modal-subscribe-compact .sub-modal-summary {
  margin-bottom: 10px;
  padding: 10px 12px;
}

.modal-subscribe-compact .sub-sum-row {
  padding: 3px 0;
  font-size: 12px;
}

.modal-subscribe-compact .sub-sum-total-val {
  font-size: 16px !important;
}

.modal-subscribe-compact .sub-modal-confirm-btn {
  padding: 11px;
  font-size: 14px;
}

.modal-subscribe-compact .glow-input {
  margin-bottom: 0 !important;
}

.modal-subscribe-compact .ri-dropdown {
  margin-bottom: 0;
}

[data-theme="light"] .modal-subscribe-compact,
[data-theme="light"] .modal-tier-editor {
  background: var(--bg-white);
}
