/**
 * Bootstrap shell-модалки + настройки (стиль WespDialog).
 * Без Bootstrap .fade — анимация через .wesp-shell-visible / .wesp-shell-closing (JS).
 */

:root {
  --wesp-modal-duration: 0.22s;
  --wesp-modal-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Backdrop (Bootstrap создаёт .modal-backdrop без fade, если у modal нет .fade) */
body.modal-open .modal-backdrop.show {
  opacity: 0.55;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal.wesp-shell-modal {
  --bs-modal-bg: transparent;
}

.modal.wesp-shell-modal.show {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--bs-modal-margin, 0.5rem);
}

.modal.wesp-shell-modal .modal-dialog.modal-dialog--shell {
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
  min-height: 0 !important;
  height: auto;
  flex: 0 0 auto;
  display: block;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.97) translateY(8px);
  transition:
    transform var(--wesp-modal-duration) var(--wesp-modal-ease),
    opacity var(--wesp-modal-duration) var(--wesp-modal-ease);
}

.modal.wesp-shell-modal .modal-dialog.modal-dialog--shell-wide {
  max-width: min(520px, calc(100vw - 1rem));
}

.modal.wesp-shell-modal.wesp-shell-visible .modal-dialog.modal-dialog--shell {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

.modal.wesp-shell-modal.wesp-shell-closing .modal-dialog.modal-dialog--shell {
  opacity: 0;
  transform: scale(0.97) translateY(8px);
  pointer-events: none;
}

.modal.wesp-shell-modal .modal-content.wesp-shell-bsmodal {
  pointer-events: auto;
}

.modal.wesp-shell-modal .modal-content.wesp-shell-bsmodal {
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: min(90vh, 560px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 20px 22px;
  font-family: var(--zootech-font, Inter, system-ui, sans-serif);
  font-size: var(--zt-font-body, 0.9375rem);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-align: left;
  background: #fff;
  color: #111827;
  border-radius: 8px;
  border: 1px solid #e5e7eb !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18) !important;
}

.modal.wesp-shell-modal .modal-content.wesp-shell-bsmodal--settings {
  max-height: min(92vh, 720px);
}

.wesp-shell-bsmodal-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 12px;
}

.wesp-shell-bsmodal-title-row .wesp-shell-bsmodal-title {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.wesp-shell-bsmodal-close {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
}

.wesp-shell-bsmodal-close:hover {
  background: rgba(15, 23, 42, 0.06);
  color: #111827;
}

.modal.wesp-shell-modal .wesp-shell-bsmodal-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
  line-height: 1.3;
}

.modal.wesp-shell-modal .wesp-shell-bsmodal-body {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #374151;
}

.modal.wesp-shell-modal .wesp-shell-bsmodal-body .form-label {
  color: #374151;
  font-weight: 500;
}

.modal.wesp-shell-modal .wesp-shell-bsmodal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.modal.wesp-shell-modal .wesp-shell-bsmodal-btn {
  min-width: 120px;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #374151;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, filter 0.2s;
}

.modal.wesp-shell-modal .wesp-shell-bsmodal-btn:hover {
  filter: brightness(0.97);
}

.modal.wesp-shell-modal .wesp-shell-bsmodal-btn-primary {
  background: var(--primary-color, #2196f3);
  border-color: var(--primary-color, #2196f3);
  color: #fff;
}

.modal.wesp-shell-modal .wesp-shell-bsmodal-btn-primary:hover {
  filter: none;
  box-shadow: 0 4px 12px rgba(var(--primary-rgb, 33, 150, 243), 0.25);
}

/* Внутренние блоки модалки настроек */
.wesp-shell-bsmodal-body--settings .settings-user-card,
.wesp-shell-bsmodal-body--settings .settings-credentials-form,
.wesp-shell-bsmodal-body--settings .settings-sync-card,
.wesp-shell-bsmodal-body--settings .settings-sync-form,
.wesp-shell-bsmodal-body--settings .settings-theme-card {
  background: var(--surface-muted, #f8fafc);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border-light, #e5e7eb);
}

.wesp-shell-bsmodal-body--settings .settings-theme-card {
  min-width: 0;
}

.wesp-shell-bsmodal-body--settings .settings-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0;
  color: var(--text, #1e293b);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.wesp-shell-bsmodal-body--settings .settings-user-card--clickable,
.wesp-shell-bsmodal-body--settings .settings-sync-card--clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.wesp-shell-bsmodal-body--settings .settings-user-card--clickable:hover,
.wesp-shell-bsmodal-body--settings .settings-sync-card--clickable:hover {
  border-color: var(--primary-color, #2196f3);
  background: rgba(var(--primary-rgb, 33, 150, 243), 0.04);
}

.wesp-shell-bsmodal-body--settings .settings-credentials-form,
.wesp-shell-bsmodal-body--settings .settings-sync-form {
  animation: wesp-settings-panel-in 0.22s var(--wesp-modal-ease) both;
}

@keyframes wesp-settings-panel-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 576px) {
  .modal.wesp-shell-modal .wesp-shell-bsmodal-actions {
    flex-direction: column;
  }

  .modal.wesp-shell-modal .wesp-shell-bsmodal-actions .wesp-shell-bsmodal-btn {
    width: 100%;
  }
}

html[data-theme="dark"] .modal.wesp-shell-modal .modal-content.wesp-shell-bsmodal {
  background: var(--dm-surface, #2c3338) !important;
  color: var(--dm-text, #f5f5f5) !important;
  border-color: var(--dm-border, rgba(255, 255, 255, 0.12)) !important;
}

html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-title,
html[data-theme="dark"] .wesp-shell-bsmodal-close:hover {
  color: var(--dm-text, #f5f5f5);
}

html[data-theme="dark"] .wesp-shell-bsmodal-close {
  color: var(--dm-muted, #a8b0b8);
}

html[data-theme="dark"] .wesp-shell-bsmodal-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--dm-text, #f5f5f5);
}

html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-body,
html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-body p,
html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-body strong {
  color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-body .form-label {
  color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-body .text-muted {
  color: var(--dm-muted, #a8b0b8) !important;
}

html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-body .form-control {
  background-color: var(--dm-field, #3e444a) !important;
  color: var(--dm-text, #f5f5f5) !important;
  border-color: var(--dm-border, rgba(255, 255, 255, 0.12)) !important;
}

html[data-theme="dark"] .wesp-shell-bsmodal-body--settings .settings-user-card,
html[data-theme="dark"] .wesp-shell-bsmodal-body--settings .settings-credentials-form,
html[data-theme="dark"] .wesp-shell-bsmodal-body--settings .settings-sync-card,
html[data-theme="dark"] .wesp-shell-bsmodal-body--settings .settings-sync-form,
html[data-theme="dark"] .wesp-shell-bsmodal-body--settings .settings-theme-card {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--dm-border, rgba(255, 255, 255, 0.12));
}

html[data-theme="dark"] .wesp-shell-bsmodal-body--settings .settings-card-title {
  color: var(--dm-text, #f5f5f5);
}

html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-btn {
  background: var(--dm-field, #3e444a) !important;
  border-color: var(--dm-border, rgba(255, 255, 255, 0.12)) !important;
  color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .modal.wesp-shell-modal .wesp-shell-bsmodal-btn-primary {
  background: var(--primary-color) !important;
  border-color: var(--primary-color) !important;
  color: #fff !important;
}

/* Появление карточек сетки */
@keyframes wesp-grid-item-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.feed-dispensers-page .dispenser-card.wesp-grid-enter-item,
.components-page .component-card.wesp-grid-enter-item,
.reports-page .report-card.wesp-grid-enter-item {
  animation: wesp-grid-item-enter var(--wesp-enter-duration, 350ms) var(--wesp-enter-ease, cubic-bezier(0.22, 1, 0.36, 1)) both;
  animation-delay: calc(var(--wesp-grid-i, 0) * 45ms);
}

html.wesp-page-enter-pending .feed-dispensers-page .dispenser-card.wesp-grid-enter-item,
html.wesp-page-enter-ready .feed-dispensers-page .dispenser-card.wesp-grid-enter-item,
html.wesp-page-enter-pending .components-page .component-card.wesp-grid-enter-item,
html.wesp-page-enter-ready .components-page .component-card.wesp-grid-enter-item,
html.wesp-page-enter-pending .reports-page .report-card.wesp-grid-enter-item,
html.wesp-page-enter-ready .reports-page .report-card.wesp-grid-enter-item {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
}

.feed-dispensers-page .empty-state.wesp-content-reveal,
.feed-dispensers-page .loading-state.wesp-content-reveal,
.components-page .empty-state.wesp-content-reveal,
.components-page .loading-state.wesp-content-reveal,
.reports-page .empty-state.wesp-content-reveal,
.reports-page .loading-state.wesp-content-reveal {
  animation: wesp-enter-fade var(--wesp-enter-duration-fast, 350ms) var(--wesp-enter-ease, cubic-bezier(0.22, 1, 0.36, 1)) both;
}

@media (prefers-reduced-motion: reduce) {
  .modal.wesp-shell-modal .modal-dialog.modal-dialog--shell {
    transition: opacity 0.12s ease !important;
    transform: none !important;
  }

  body.modal-open .modal-backdrop.show {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .feed-dispensers-page .dispenser-card.wesp-grid-enter-item,
  .components-page .component-card.wesp-grid-enter-item,
  .feed-dispensers-page .empty-state.wesp-content-reveal,
  .feed-dispensers-page .loading-state.wesp-content-reveal,
  .components-page .empty-state.wesp-content-reveal,
  .components-page .loading-state.wesp-content-reveal,
  .reports-page .report-card.wesp-grid-enter-item,
  .reports-page .empty-state.wesp-content-reveal,
  .reports-page .loading-state.wesp-content-reveal,
  .wesp-shell-bsmodal-body--settings .settings-credentials-form,
  .wesp-shell-bsmodal-body--settings .settings-sync-form {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

/* —— Notification center modal —— */
.zt-notify-center__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.zt-notify-center__title {
  margin: 0;
}

.zt-notify-center__read-all {
  border: none;
  background: transparent;
  color: var(--primary-color, #2196f3);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.25rem 0.35rem;
  cursor: pointer;
}

.zt-notify-center__body {
  min-height: 200px;
  max-height: min(52vh, 380px);
  overflow: auto;
}

.zt-notify-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.zt-notify-toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.zt-notify-toolbar__filters {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
}

.zt-notify-toolbar__filters .zt-tab {
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
  min-height: auto;
}

.zt-notify-toolbar__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  flex-wrap: wrap;
}

.zt-notify-toolbar__unread {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
  margin: 0;
  cursor: pointer;
  user-select: none;
}

.zt-notify-toolbar__unread input {
  margin: 0;
}

.zt-notify-load-more {
  padding: 0.5rem 0 0.25rem;
  text-align: center;
}

.zt-notify-load-more__hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
}

.zt-notify-load-more__spinner {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted, #64748b);
}

.zt-notify-empty--loading .zt-spinner {
  margin-bottom: 0.5rem;
}

.zt-notify-toolbar__sort {
  flex-shrink: 0;
  margin: 0;
}

.zt-notify-toolbar__sort select {
  border: 1px solid var(--border-light, #e2e8f0);
  border-radius: 8px;
  background: var(--bg-light, #f8fafc);
  color: var(--text-dark, #1e293b);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.35rem 1.75rem 0.35rem 0.55rem;
  cursor: pointer;
  max-width: 11rem;
}

.zt-notify-group {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #64748b);
  padding: 0.35rem 0.15rem 0.15rem;
}

.zt-notify-group:not(:first-child) {
  margin-top: 0.35rem;
}

.zt-notify-item__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
}

.zt-notify-item__category {
  font-size: 0.6875rem;
  color: var(--text-muted, #64748b);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zt-notify-empty {
  text-align: center;
  color: var(--text-muted, #64748b);
  padding: 2.5rem 1rem;
}

.zt-notify-empty i {
  font-size: 2rem;
  margin-bottom: 0.75rem;
  opacity: 0.45;
}

.zt-notify-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border-light, #e2e8f0);
  border-radius: 10px;
  background: var(--bg-light, #f8fafc);
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.zt-notify-item:hover {
  background: #fff;
  border-color: rgba(var(--primary-rgb), 0.25);
}

.zt-notify-item--unread {
  background: #fff;
  border-color: rgba(var(--primary-rgb), 0.35);
}

.zt-notify-item__dot {
  flex-shrink: 0;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  margin-top: 0.45rem;
  background: var(--info-color, #0ea5e9);
}

.zt-notify-item__dot--success {
  background: var(--success-color, #10b981);
}

.zt-notify-item__dot--error {
  background: var(--danger-color, #ef4444);
}

.zt-notify-item__dot--warning {
  background: var(--warning-color, #f59e0b);
}

.zt-notify-item__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.zt-notify-item__title {
  font-size: 0.9375rem;
  color: var(--text-dark, #1e293b);
  line-height: 1.35;
}

.zt-notify-item--unread .zt-notify-item__title {
  font-weight: 600;
}

.zt-notify-item__preview {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-muted, #64748b);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.zt-notify-item__time {
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
  flex-shrink: 0;
}

.zt-notify-detail__back {
  border: none;
  background: transparent;
  color: var(--primary-color, #2196f3);
  font-size: 0.875rem;
  padding: 0;
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.zt-notify-detail__kind {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.zt-notify-detail__text {
  margin: 0 0 0.75rem;
  line-height: 1.55;
  color: var(--text-dark, #1e293b);
}

.zt-notify-detail__when {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted, #64748b);
}

html[data-theme="dark"] .zt-notify-item {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] .zt-notify-item--unread,
html[data-theme="dark"] .zt-notify-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .zt-notify-toolbar__sort select {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
}
