:root {
  --am-bg: #ffffff;
  --am-surface: #f8fafc;
  --am-border: #e2e8f0;
  --am-text: #1e293b;
  --am-text-muted: #64748b;
  --am-primary: #4f46e5;
  --am-primary-hover: #4338ca;
  --am-danger: #e11d48;
  --am-danger-hover: #be123c;
  --am-backdrop: rgba(15, 23, 42, 0.52);
  --am-radius: 14px;
  --am-shadow: 0 20px 45px -10px rgba(15, 23, 42, 0.22), 0 4px 14px rgba(15, 23, 42, 0.08);
  --am-font: 'Open Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body.am-scroll-locked {
  overflow: hidden !important;
}

/* Бекдроп */
.am-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--am-backdrop);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 0.2s ease;
  font-family: var(--am-font);
  box-sizing: border-box;
}

.am-backdrop.is-open {
  opacity: 1;
}

/* Вікно модалки */
.am-dialog {
  background: var(--am-bg);
  color: var(--am-text);
  border: 1px solid var(--am-border);
  border-radius: var(--am-radius);
  box-shadow: var(--am-shadow);
  width: 100%;
  max-width: 460px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px) scale(0.97);
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  box-sizing: border-box;
}

.am-backdrop.is-open .am-dialog {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Розміри */
.am-dialog--sm {
  max-width: 380px;
}

.am-dialog--md {
  max-width: 480px;
}

.am-dialog--lg {
  max-width: 680px;
}

.am-dialog--image {
  max-width: min(92vw, 860px);
  background: #0f172a;
  border-color: #1e293b;
  color: #f8fafc;
}

/* Потягушка для мобільного bottom-sheet */
.am-sheet-handle {
  display: none;
  width: 100%;
  height: 28px;
  margin: 0 auto -6px;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
  flex-shrink: 0;
}

.am-sheet-handle::before {
  content: "";
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.15s ease, width 0.15s ease;
}

.am-sheet-handle:active {
  cursor: grabbing;
}

.am-sheet-handle:active::before {
  background: #94a3b8;
  width: 46px;
}

/* Шапка */
.am-head {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--am-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.am-dialog--image .am-head {
  border-bottom-color: #1e293b;
}

.am-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  color: inherit;
}

.am-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--am-text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.am-close:hover {
  background: #f1f5f9;
  color: var(--am-text);
}

.am-dialog--image .am-close:hover {
  background: #1e293b;
  color: #ffffff;
}

/* Тіло модалки (скролиться при великому контенті) */
.am-body {
  padding: 18px 20px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--am-text);
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
}

.am-dialog--image .am-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #020617;
}

.am-lightbox-img {
  max-width: 100%;
  max-height: 70dvh;
  border-radius: 8px;
  object-fit: contain;
  display: block;
}

.am-lightbox-caption {
  margin-top: 10px;
  font-size: 13px;
  color: #94a3b8;
  text-align: center;
}

/* Футер з кнопками */
.am-foot {
  padding: 13px 20px;
  background: var(--am-surface);
  border-top: 1px solid var(--am-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Кнопки */
.am-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 16px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.am-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.am-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.am-btn--ghost {
  background: #ffffff;
  border-color: var(--am-border);
  color: #475569;
}

.am-btn--ghost:hover:not(:disabled) {
  background: #f1f5f9;
  color: #0f172a;
}

.am-btn--primary {
  background: var(--am-primary);
  color: #ffffff;
}

.am-btn--primary:hover:not(:disabled) {
  background: var(--am-primary-hover);
}

.am-btn--danger {
  background: var(--am-danger);
  color: #ffffff;
}

.am-btn--danger:hover:not(:disabled) {
  background: var(--am-danger-hover);
}

/* Спінер усередині кнопки при setLoading(true) */
.am-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: am-spin 0.65s linear infinite;
}

@keyframes am-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Допоміжні блоки для confirm / alert / форм */
.am-confirm-box {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.am-confirm-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.am-confirm-icon--danger {
  background: #fff1f2;
  color: #e11d48;
}

.am-confirm-icon--info {
  background: #eef2ff;
  color: #4f46e5;
}

.am-confirm-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: #475569;
}

.am-field {
  margin-bottom: 12px;
}

.am-field:last-child {
  margin-bottom: 0;
}

.am-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 5px;
}

.am-input,
.am-select,
.am-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13.5px;
  color: #1e293b;
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.am-input:focus,
.am-select:focus,
.am-textarea:focus {
  outline: none;
  border-color: var(--am-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}

.am-quote {
  background: #f8fafc;
  border-left: 3px solid #94a3b8;
  padding: 9px 12px;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  color: #475569;
  margin-bottom: 12px;
}

/* Адаптив: Мобільний Bottom-Sheet (< 600px або примусовий клас .am-force-sheet) */
@media (max-width: 600px) {
  .am-backdrop:not(.am-backdrop--image) {
    align-items: flex-end;
    padding: 0;
  }

  .am-backdrop:not(.am-backdrop--image) .am-dialog {
    max-width: 100%;
    max-height: 90dvh;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    transform: translateY(100%);
  }

  .am-backdrop:not(.am-backdrop--image).is-open .am-dialog {
    transform: translateY(0);
  }

  .am-backdrop:not(.am-backdrop--image) .am-sheet-handle {
    display: flex;
  }

  .am-backdrop:not(.am-backdrop--image) .am-head {
    touch-action: none;
    cursor: grab;
  }

  .am-backdrop:not(.am-backdrop--image) .am-head:active {
    cursor: grabbing;
  }

  .am-foot .am-btn {
    flex: 1 1 auto;
  }
}

/* Примусовий прев'ю-режим Bottom-Sheet для десктопу в демці */
body.am-force-sheet .am-backdrop:not(.am-backdrop--image) {
  align-items: flex-end;
  padding: 0;
}

body.am-force-sheet .am-backdrop:not(.am-backdrop--image) .am-dialog {
  max-width: 540px;
  max-height: 85dvh;
  border-radius: 18px 18px 0 0;
  border-bottom: none;
  transform: translateY(100%);
}

body.am-force-sheet .am-backdrop:not(.am-backdrop--image).is-open .am-dialog {
  transform: translateY(0);
}

body.am-force-sheet .am-backdrop:not(.am-backdrop--image) .am-sheet-handle {
  display: flex;
}

body.am-force-sheet .am-backdrop:not(.am-backdrop--image) .am-head {
  touch-action: none;
  cursor: grab;
}

body.am-force-sheet .am-backdrop:not(.am-backdrop--image) .am-head:active {
  cursor: grabbing;
}
