.iotpv-modal-open {
  overscroll-behavior: none;
}

.iotpv-modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(17, 24, 39, 0.55);
  opacity: 0;
  transition: opacity 120ms ease;
}

.iotpv-modal-backdrop.iotpv-modal-visible {
  opacity: 1;
}

.iotpv-modal-backdrop.iotpv-modal-leaving {
  opacity: 0;
  pointer-events: none;
}

.iotpv-modal {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: min(100%, 640px);
  max-height: calc(100vh - 2.5rem);
  overflow: hidden;
  background: #fff;
  border: 0;
  border-radius: 0.85rem;
  box-shadow: 0 1.5rem 4rem rgba(15, 23, 42, 0.28);
  color: #344767;
  outline: 0;
  transform: translateY(8px) scale(0.99);
  transition: transform 120ms ease;
}

.iotpv-modal *,
.iotpv-modal *::before,
.iotpv-modal *::after {
  box-sizing: border-box;
}

.iotpv-modal-visible .iotpv-modal {
  transform: translateY(0) scale(1);
}

.iotpv-modal-sm { width: min(100%, 460px); }
.iotpv-modal-md { width: min(100%, 640px); }
.iotpv-modal-lg { width: min(100%, 860px); }
.iotpv-modal-xl { width: min(96vw, 1120px); }
.iotpv-modal-full { width: min(97vw, 1440px); height: min(94vh, 980px); }

.iotpv-modal-header,
.iotpv-modal-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: #fff;
}

.iotpv-modal-header {
  justify-content: space-between;
  border-bottom: 1px solid #e9ecef;
}

.iotpv-modal-title {
  margin: 0;
  color: #344767;
  font-size: 1.05rem;
  font-weight: 700;
}

.iotpv-modal-close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: #67748e;
  font-size: 1.65rem;
  line-height: 1;
}

.iotpv-modal-close:hover,
.iotpv-modal-close:focus {
  background: #f6f9fc;
  color: #344767;
}

.iotpv-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 1.25rem;
  overflow: auto;
  overscroll-behavior: contain;
}

.iotpv-modal-feedback {
  flex: 0 0 auto;
  margin: 0 1.25rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
}

.iotpv-modal-feedback-error {
  background: #fee2e2;
  color: #991b1b;
}

.iotpv-modal-footer {
  justify-content: flex-end;
  border-top: 1px solid #e9ecef;
}

body.wp-admin .iotpv-modal .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 7px 14px;
  border: 1px solid #8c8f94;
  border-radius: 4px;
  background: #f6f7f7;
  color: #2c3338;
  font-weight: 600;
  cursor: pointer;
}

body.wp-admin .iotpv-modal .btn-primary {
  border-color: #135e96;
  background: #2271b1;
  color: #fff;
}

body.wp-admin .iotpv-modal .btn-danger {
  border-color: #b32d2e;
  background: #b32d2e;
  color: #fff;
}

body.wp-admin .iotpv-modal .btn:focus-visible {
  outline: 2px solid #2271b1;
  outline-offset: 2px;
}

.iotpv-modal-busy {
  cursor: wait;
}

.iotpv-modal-danger .iotpv-modal-header {
  background: #fff5f5;
}

.iotpv-modal-danger .iotpv-modal-title {
  color: #b91c1c;
}

.iotpv-modal .choices,
.iotpv-modal .table-responsive,
.iotpv-modal .nav {
  max-width: 100%;
}

.iotpv-modal-prompt .form-control {
  min-height: 44px;
}

.iotpv-modal-prompt textarea.form-control {
  min-height: 112px;
  resize: vertical;
}

.iotpv-toast-region {
  position: fixed;
  z-index: 11020;
  top: max(1rem, env(safe-area-inset-top));
  right: 1rem;
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem - env(safe-area-inset-top));
  gap: 0.65rem;
  overflow: hidden;
  pointer-events: none;
}

.iotpv-toast {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) 2rem;
  align-items: start;
  gap: 0.7rem;
  min-height: 72px;
  padding: 0.9rem;
  border: 1px solid #e9ecef;
  border-left: 4px solid #5e72e4;
  border-radius: 0.5rem;
  background: #fff;
  box-shadow: 0 0.75rem 2rem rgba(23, 43, 77, 0.2);
  color: #344767;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: auto;
}

.iotpv-toast-visible {
  opacity: 1;
  transform: translateY(0);
}

.iotpv-toast-leaving {
  opacity: 0;
  transform: translateX(12px);
}

.iotpv-toast-success { border-left-color: #2dce89; }
.iotpv-toast-error { border-left-color: #f5365c; }
.iotpv-toast-warning { border-left-color: #fb6340; }
.iotpv-toast-info { border-left-color: #11cdef; }

.iotpv-toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: #eef1ff;
  color: #5e72e4;
  font-size: 0.95rem;
}

.iotpv-toast-success .iotpv-toast-icon { background: #e7f9f1; color: #198754; }
.iotpv-toast-error .iotpv-toast-icon { background: #fff0f3; color: #dc3545; }
.iotpv-toast-warning .iotpv-toast-icon { background: #fff4e8; color: #b45309; }
.iotpv-toast-info .iotpv-toast-icon { background: #e7f8fc; color: #087990; }

.iotpv-toast-content {
  min-width: 0;
}

.iotpv-toast-title,
.iotpv-toast-message {
  display: block;
  overflow-wrap: anywhere;
}

.iotpv-toast-title {
  margin-bottom: 0.2rem;
  color: #172b4d;
  font-size: 0.92rem;
  line-height: 1.3;
}

.iotpv-toast-message {
  color: #525f7f;
  font-size: 0.86rem;
  line-height: 1.45;
}

.iotpv-toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: #67748e;
}

.iotpv-toast-close:hover,
.iotpv-toast-close:focus-visible {
  background: #f6f9fc;
  color: #172b4d;
  outline: 2px solid #5e72e4;
  outline-offset: 1px;
}

.iotpv-toast-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

@media (max-width: 767.98px) {
  .iotpv-toast-region {
    top: auto;
    right: 0.65rem;
    bottom: max(0.65rem, env(safe-area-inset-bottom));
    width: calc(100vw - 1.3rem);
    max-height: min(42vh, 360px);
  }

  .iotpv-toast {
    min-height: 68px;
    padding: 0.8rem;
    transform: translateY(10px);
  }

  .iotpv-toast-visible {
    transform: translateY(0);
  }

  .iotpv-modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .iotpv-modal,
  .iotpv-modal-sm,
  .iotpv-modal-md,
  .iotpv-modal-lg,
  .iotpv-modal-xl,
  .iotpv-modal-full {
    width: 100%;
    height: auto;
    max-height: 96vh;
    border-radius: 0.85rem 0.85rem 0 0;
  }

  .iotpv-modal-full {
    height: 96vh;
  }

  .iotpv-modal-header,
  .iotpv-modal-body,
  .iotpv-modal-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .iotpv-modal-footer .btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    margin: 0 !important;
  }

  .iotpv-modal-footer {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .iotpv-toast,
  .iotpv-modal-backdrop,
  .iotpv-modal {
    transition: none;
  }
}
