/* Shared modal base: overlay + card shell */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--color-text-primary) 35%, transparent);
  z-index: 5000;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 20px 20px;
  overscroll-behavior: contain;
}

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

.modal-card {
  width: 100%;
  max-width: 340px;
  background: var(--color-bg-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}

#confirm-reopen-modal .modal-card,
#confirm-reopen-modal .modal-card-body {
  overflow: visible;
}

.modal-card-wide {
  max-width: 420px;
}

.modal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--color-bg-muted);
}

.modal-card-title {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--color-bg-muted);
  border-radius: var(--radius-md);
  font-size: 20px;
  line-height: 1;
  color: var(--color-text-secondary);
  cursor: pointer;
}

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

.modal-card-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.theme-material .modal-overlay {
  background: rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

body.theme-material.dark-theme .modal-overlay {
  background: rgba(71, 85, 105, 0.65);
}

body.theme-material .modal-card {
  background: var(--color-bg-surface);
  border-radius: 8px;
  box-shadow: var(--shadow-3), var(--shadow-2);
}

body.theme-material .modal-card-header {
  border-bottom-color: var(--color-border-default);
}

body.theme-material .modal-card-title {
  color: var(--color-text-primary);
}

body.theme-material .modal-close {
  background: transparent;
  border-radius: 50%;
  color: var(--color-text-secondary);
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

body.theme-material .modal-close:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
  transform: scale(1.08);
}

body.theme-material .modal-close:focus-visible {
  outline: 2px solid var(--color-focus-border);
  outline-offset: 2px;
}

body.theme-material .app-confirm-modal {
  background: color-mix(in srgb, var(--color-text-primary) 32%, transparent);
  z-index: 6200;
  align-items: center;
  padding: 20px;
}

body.theme-material .app-confirm-card {
  max-width: 520px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
}

body.theme-material .app-confirm-card .modal-card-header,
body.theme-material .app-confirm-header {
  padding: 16px 24px;
}

body.theme-material .app-confirm-card .modal-card-title,
body.theme-material .app-confirm-header .app-modal-title {
  font-size: 20px;
  line-height: 28px;
  font-weight: 700;
}

body.theme-material .app-confirm-card .modal-card-body,
body.theme-material .app-confirm-body {
  padding: 0;
  gap: 0;
}

body.theme-material .app-confirm-card .modal-confirm-text,
body.theme-material .app-confirm-message {
  min-height: 78px;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 18px 24px;
  font-size: 14px;
  line-height: 1.6;
  font-weight: 400;
  color: #475569;
}

body.theme-material .app-confirm-card .modal-form-actions,
body.theme-material .app-confirm-footer .app-modal-footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

body.theme-material .app-confirm-header .app-modal-title-wrap {
  gap: 12px;
}

body.theme-material .app-confirm-header .app-modal-title-icon {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
}

body.theme-material .app-confirm-header .app-modal-title-icon svg {
  width: 19px;
  height: 19px;
}

body.theme-material .app-confirm-footer {
  justify-content: flex-end;
}

body.theme-material .app-confirm-card .modal-form-actions .modal-btn,
body.theme-material .app-confirm-footer .modal-btn {
  min-width: 0;
  height: 37.6px;
  border-radius: 6px;
  padding: 0 14px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
  font-family: var(--font-family-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  box-shadow: none;
  transform: none !important;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease !important;
}

body.theme-material .app-confirm-card .modal-form-actions #app-confirm-cancel,
body.theme-material .app-confirm-footer #app-confirm-cancel {
  width: 95.825px;
  border: 0.8px solid #e2e8f0 !important;
  color: #0f172a !important;
  background: #ffffff !important;
}

body.theme-material .app-confirm-card .modal-form-actions #app-confirm-cancel:hover,
body.theme-material .app-confirm-footer #app-confirm-cancel:hover {
  border-color: #d6e0ef !important;
  color: #0f172a !important;
  background: #f8fafc !important;
}

body.theme-material .app-confirm-card .modal-form-actions #app-confirm-ok,
body.theme-material .app-confirm-card .modal-form-actions #app-confirm-ok.modal-btn-danger,
body.theme-material .app-confirm-footer #app-confirm-ok,
body.theme-material .app-confirm-footer #app-confirm-ok.modal-btn-danger {
  width: 182px;
  border: none !important;
  background: #ef4444 !important;
  color: #ffffff !important;
}

body.theme-material .app-confirm-card .modal-form-actions #app-confirm-ok:hover,
body.theme-material .app-confirm-card .modal-form-actions #app-confirm-ok.modal-btn-danger:hover,
body.theme-material .app-confirm-footer #app-confirm-ok:hover,
body.theme-material .app-confirm-footer #app-confirm-ok.modal-btn-danger:hover {
  background: #dc2626 !important;
  border: none !important;
  color: #ffffff !important;
}

body.theme-material .app-confirm-card .modal-form-actions #app-confirm-ok.modal-btn-primary,
body.theme-material .app-confirm-footer #app-confirm-ok.modal-btn-primary {
  background: #3b82f6 !important;
}

body.theme-material .app-confirm-card .modal-form-actions #app-confirm-ok.modal-btn-primary:hover,
body.theme-material .app-confirm-footer #app-confirm-ok.modal-btn-primary:hover {
  background: #2563eb !important;
}

body.theme-material .app-confirm-card .modal-form-actions .modal-btn:hover,
body.theme-material .app-confirm-card .modal-form-actions .modal-btn:active,
body.theme-material .app-confirm-footer .modal-btn:hover,
body.theme-material .app-confirm-footer .modal-btn:active {
  transform: none !important;
}

body.theme-material.dark-theme .app-confirm-modal {
  background: rgba(15, 23, 42, 0.58);
}

body.theme-material.dark-theme .app-confirm-header .app-modal-title-icon {
  background: rgba(251, 191, 36, 0.12);
  color: #fcd34d;
}

body.theme-material.dark-theme .app-confirm-card .modal-confirm-text,
body.theme-material.dark-theme .app-confirm-message {
  color: var(--color-text-secondary);
}

body.theme-material.dark-theme .app-confirm-card .modal-form-actions #app-confirm-cancel,
body.theme-material.dark-theme .app-confirm-footer #app-confirm-cancel {
  border-color: var(--color-border-strong) !important;
  color: var(--color-text-primary) !important;
  background: var(--color-bg-surface) !important;
}

@media (max-width: 640px) {
  body.theme-material .app-confirm-modal {
    padding: 16px;
  }

  body.theme-material .app-confirm-card {
    width: min(100%, 520px);
  }

  body.theme-material .app-confirm-card .modal-form-actions,
  body.theme-material .app-confirm-footer .app-modal-footer-actions {
    width: 100%;
  }

  body.theme-material .app-confirm-card .modal-form-actions .modal-btn,
  body.theme-material .app-confirm-footer .modal-btn {
    flex: 1 1 0;
    width: auto !important;
  }
}

body.theme-material.dark-theme .modal-card {
  background: var(--color-bg-surface);
  color: var(--color-text-primary);
  font-family: var(--font-family-body);
  box-shadow: var(--shadow-3);
}

/* App modal contract: full-width header/body/footer sections. */
body.theme-material {
  --app-modal-header-bg: #f8fafc;
  --app-modal-body-bg: #ffffff;
  --app-modal-border: #e2e8f0;
  --app-modal-title-color: #0f172a;
  --app-modal-header-min-height: 64px;
  --app-modal-header-padding: 16px 24px;
  --app-modal-body-padding: 22px 32px 24px;
  --app-modal-footer-padding: 16px 32px 18px;
  --app-modal-title-size: 20px;
  --app-modal-title-line-height: 28px;
  --app-modal-title-weight: 700;
  --app-modal-card-radius: 8px;
  --app-modal-title-icon-size: 44px;
  --app-modal-title-icon-svg-size: 19px;
  --app-modal-close-size: 36px;
  --app-modal-close-svg-size: 20px;
  --app-modal-footer-button-height: 37.6px;
  --app-modal-footer-button-radius: 6px;
  --app-modal-footer-button-font-size: 14px;
  --app-modal-footer-button-line-height: 20px;
  --app-modal-footer-button-weight: 400;
  --app-modal-footer-button-padding-x: 14px;
  --app-modal-footer-button-secondary-min-width: 116px;
  --app-modal-footer-button-primary-min-width: 136px;
}

body.theme-material.dark-theme {
  --app-modal-header-bg: #101f30;
  --app-modal-body-bg: #0f172a;
  --app-modal-border: #334155;
  --app-modal-title-color: #e2e8f0;
}

body.theme-material .app-modal-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--app-modal-card-radius);
  background: var(--app-modal-body-bg);
}

body.theme-material .app-modal-header,
body.theme-material .app-modal-footer {
  flex: 0 0 auto;
  background: var(--app-modal-header-bg);
}

body.theme-material .app-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--app-modal-header-min-height);
  padding: var(--app-modal-header-padding);
  border-bottom: 1px solid var(--app-modal-border);
}

body.theme-material .app-modal-title-wrap {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

body.theme-material .app-modal-title-icon {
  width: var(--app-modal-title-icon-size);
  height: var(--app-modal-title-icon-size);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 var(--app-modal-title-icon-size);
  background: #e8f0ff;
  color: #3b82f6;
}

body.theme-material .app-modal-title-icon svg {
  width: var(--app-modal-title-icon-svg-size);
  height: var(--app-modal-title-icon-svg-size);
}

body.theme-material .app-modal-warning-header .app-modal-title-icon {
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
}

body.theme-material .app-modal-title {
  margin: 0;
  min-width: 0;
  color: var(--app-modal-title-color);
  font-size: var(--app-modal-title-size);
  line-height: var(--app-modal-title-line-height);
  font-weight: var(--app-modal-title-weight);
  letter-spacing: 0;
}

body.theme-material .app-modal-close {
  width: var(--app-modal-close-size);
  height: var(--app-modal-close-size);
  min-width: var(--app-modal-close-size);
  min-height: var(--app-modal-close-size);
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 var(--app-modal-close-size);
  cursor: pointer;
}

body.theme-material .app-modal-close svg {
  display: block;
  width: var(--app-modal-close-svg-size);
  height: var(--app-modal-close-svg-size);
  flex: 0 0 var(--app-modal-close-svg-size);
}

body.theme-material .app-modal-close:hover {
  background: #eef2f7;
  color: #0f172a;
}

body.theme-material .app-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--app-modal-body-padding);
  background: var(--app-modal-body-bg);
}

body.theme-material .app-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
  padding: var(--app-modal-footer-padding);
  border-top: 1px solid var(--app-modal-border);
}

body.theme-material .app-modal-footer .modal-btn {
  min-width: var(--app-modal-footer-button-secondary-min-width);
  height: var(--app-modal-footer-button-height);
  border-radius: var(--app-modal-footer-button-radius);
  padding: 0 var(--app-modal-footer-button-padding-x);
  font-size: var(--app-modal-footer-button-font-size);
  line-height: var(--app-modal-footer-button-line-height);
  font-weight: var(--app-modal-footer-button-weight);
  font-family: var(--font-family-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  box-shadow: none;
  transform: none !important;
}

body.theme-material .app-modal-footer .modal-btn-primary {
  min-width: var(--app-modal-footer-button-primary-min-width);
}

body.theme-material .app-modal-footer .app-modal-secondary-btn {
  border: 0.8px solid #d9e2f1;
  background: #ffffff;
  color: #64748b;
}

body.theme-material .app-modal-footer .app-modal-secondary-btn:hover {
  border-color: #d6e0ef;
  background: #f8fafc;
  color: #0f172a;
}

body.theme-material .app-modal-footer .app-modal-primary-btn {
  border: 0.8px solid #3b82f6;
  background: #3b82f6;
  color: #ffffff;
}

body.theme-material .app-modal-footer .app-modal-primary-btn:hover {
  border-color: #2563eb;
  background: #2563eb;
  color: #ffffff;
}

body.theme-material .app-modal-footer .app-modal-danger-btn {
  min-width: var(--app-modal-footer-button-primary-min-width);
  border: 0.8px solid #ef4444;
  background: #ef4444;
  color: #ffffff;
}

body.theme-material .app-modal-footer .app-modal-danger-btn:hover {
  border-color: #dc2626;
  background: #dc2626;
  color: #ffffff;
}

body.theme-material .app-modal-footer .app-modal-primary-btn:disabled,
body.theme-material .app-modal-footer .app-modal-primary-btn:disabled:hover {
  border-color: #cbd5e1;
  background: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
}

/* Shared modal field-section pattern for repeated address/network/contact forms. */
body.theme-material .modal-field-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

body.theme-material .modal-field-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
  letter-spacing: 0;
  text-transform: uppercase;
}

body.theme-material .modal-field-title-icon {
  width: 18px;
  height: 18px;
  color: #3b82f6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 18px;
}

body.theme-material .modal-field-title-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

body.theme-material .modal-field-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

body.theme-material .modal-field-label {
  color: var(--color-text-secondary);
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
}

body.theme-material .modal-field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

body.theme-material .modal-field-grid-network {
  grid-template-columns: minmax(0, 3fr) minmax(0, 1.1fr);
}

body.theme-material .modal-field-section .modal-input {
  width: 100%;
  min-height: 38.6px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--color-border-default);
  border-radius: 6px;
  background: var(--color-bg-surface-alt);
  color: var(--color-text-primary);
  font-size: 14px;
  line-height: 21px;
  font-weight: 400;
  font-family: var(--font-family-body);
  letter-spacing: normal;
  box-shadow: none;
  outline: none;
}

body.theme-material .modal-field-section .modal-input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.65;
  font-weight: 400;
}

body.theme-material .modal-field-section .modal-input:focus {
  border-color: var(--color-focus-border);
  box-shadow: 0 0 0 2px var(--color-focus-ring);
  outline: none;
}

body.theme-material.dark-theme .app-modal-card {
  background: var(--app-modal-body-bg);
}

body.theme-material.dark-theme .app-modal-header,
body.theme-material.dark-theme .app-modal-footer {
  background: var(--app-modal-header-bg);
}

body.theme-material.dark-theme .app-modal-header,
body.theme-material.dark-theme .app-modal-footer {
  border-color: var(--app-modal-border);
}

body.theme-material.dark-theme .app-modal-body {
  background: var(--app-modal-body-bg);
}

body.theme-material.dark-theme .app-modal-title-icon {
  background: rgba(59, 130, 246, 0.14);
  color: #60a5fa;
}

body.theme-material.dark-theme .app-modal-warning-header .app-modal-title-icon {
  background: rgba(251, 191, 36, 0.12);
  color: #fcd34d;
}

body.theme-material.dark-theme .app-modal-title {
  color: var(--app-modal-title-color);
}

body.theme-material.dark-theme .app-modal-close {
  color: #94a3b8;
}

body.theme-material.dark-theme .modal-field-title {
  color: #7c8aa5;
}

body.theme-material.dark-theme .modal-field-title-icon {
  color: #3b82f6;
}

body.theme-material.dark-theme .modal-field-label {
  color: #f1f5f9;
}

body.theme-material.dark-theme .modal-field-section .modal-input {
  border-color: var(--color-border-strong);
  background: var(--color-bg-muted);
  color: var(--color-text-primary);
}

body.theme-material.dark-theme .modal-field-section .modal-input::placeholder {
  color: #7c8aa5;
  opacity: 0.72;
}

body.theme-material.dark-theme .app-modal-close:hover {
  background: rgba(148, 163, 184, 0.12);
  color: #e2e8f0;
}

body.theme-material.dark-theme .app-modal-footer .app-modal-secondary-btn {
  border-color: #334155;
  background: #0f172a;
  color: #f1f5f9;
}

body.theme-material.dark-theme .app-modal-footer .app-modal-secondary-btn:hover {
  border-color: #475569;
  background: #1e293b;
  color: #ffffff;
}

body.theme-material.dark-theme .app-modal-footer .app-modal-primary-btn {
  border-color: #3b82f6;
  background: #3b82f6;
  color: #ffffff;
}

body.theme-material.dark-theme .app-modal-footer .app-modal-primary-btn:hover {
  border-color: #2563eb;
  background: #2563eb;
  color: #ffffff;
}

body.theme-material.dark-theme .app-modal-footer .app-modal-primary-btn:disabled,
body.theme-material.dark-theme .app-modal-footer .app-modal-primary-btn:disabled:hover {
  border-color: #334155;
  background: #334155;
  color: #64748b;
}

.admin-modal-overlay,
.stats-modal-overlay {
  overscroll-behavior: contain;
}

.admin-modal-body,
.stats-modal-body {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
  body.theme-material .notifications-modal-footer.app-modal-footer {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 12px 16px 14px;
    overflow: hidden;
  }

  body.theme-material .notifications-modal-footer.app-modal-footer .modal-btn {
    width: 100%;
    min-width: 0;
    height: 40px;
    min-height: 40px;
    padding: 0 10px;
    font-size: 13px;
    line-height: 18px;
  }

  body.theme-material .notifications-modal-footer.app-modal-footer .notifications-push-btn {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 8px;
    justify-self: start;
  }

  body.theme-material .notifications-modal-footer.app-modal-footer .notifications-push-btn .notifications-btn-label {
    display: none;
  }

  body.theme-material .notifications-modal-footer.app-modal-footer .notifications-push-btn .notifications-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  body.theme-material .notifications-modal-footer.app-modal-footer .notifications-push-btn .notifications-btn-icon svg {
    width: 17px;
    height: 17px;
  }
}
