/* ===== Компоненты ===== */

/* --- Кнопки --- */
.md-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}
.md-btn.full-width { width: 100%; }
.md-btn-primary { background-color: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.md-btn-tonal {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.md-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.md-fab {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 20px;
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-radius: var(--md-sys-shape-corner-large);
  border: none;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--md-sys-elevation-3);
  cursor: pointer;
}
.md-text-btn {
  border: 0;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 6px 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
}
.md-text-btn:hover:not(:disabled) {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
}
.md-text-btn:disabled { opacity: .4; cursor: default; }
.md-text-btn .material-symbols-outlined { font-size: 17px; }
.md-text-btn:disabled .material-symbols-outlined { opacity: .5; }

button:disabled { pointer-events: none; }

/* Единые микро-переходы (отключаются при prefers-reduced-motion через base.css) */
.md-btn, .md-icon-btn, .seg-btn, .chip, .palette-card,
.preview-expand-btn, .modal-close-btn, .lock-btn, .gallery-chip {
  transition: background-color .16s ease, color .16s ease,
              border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
.md-btn:active, .md-icon-btn:active, .seg-btn:active, .chip:active,
.preview-expand-btn:active, .lock-btn:active { transform: scale(.98); }

/* Спиннер занятости (экспорт) */
.is-busy { pointer-events: none; opacity: .85; }
.is-busy .material-symbols-outlined { animation: md3-spin 900ms linear infinite; }
@keyframes md3-spin { to { transform: rotate(360deg); } }

/* --- Сегментированные контролы --- */
.segmented-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg-btn {
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid transparent;
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-sys-shape-corner-small);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}
.seg-btn:hover { background-color: var(--md-sys-color-surface-container-highest); }
.seg-btn.active {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

 .segmented-chips {
  display: flex;
  background-color: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 3px;
  gap: 3px;
  min-width: 0;
}
.chip {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}
.chip.active {
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-1);
}
.chip:disabled { opacity: .4; cursor: not-allowed; }

/* Группы с длинными подписями не должны сжимать кнопки до наложения текста. */
#colorModeSelector,
#deviceTypeSelector,
#drawModeSelector {
  flex-wrap: wrap;
  border-radius: 12px;
}
#colorModeSelector .chip,
#deviceTypeSelector .chip,
#drawModeSelector .chip {
  flex: 1 1 calc(50% - 3px);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
#colorModeSelector .chip {
  min-height: 30px;
}


/* --- Поля ввода --- */
.md-select {
  width: 100%;
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}
.custom-res-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.input-field { display: flex; flex-direction: column; gap: 4px; }
.input-field label { font-size: 11px; color: var(--md-sys-color-on-surface-variant); }
.input-field input {
  width: 100%;
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-sys-shape-corner-small);
  padding: 6px 8px;
  font-size: 13px;
}

/* --- Палитры и цвета --- */
.palette-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 150px;
  overflow-y: auto;
}
.palette-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background-color: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-small);
  cursor: pointer;
  border: 1px solid transparent;
}
.palette-card:hover { background-color: var(--md-sys-color-surface-container-highest); }
.palette-card.active { border-color: var(--md-sys-color-primary); background-color: var(--md-sys-color-surface-container-highest); }
.palette-title { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-dots { display: flex; gap: 4px; flex: 0 0 auto; }
.p-dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .1); }

.mode-subgroup { display: flex; flex-direction: column; gap: 10px; }
.sub-label { font-size: 12px; color: var(--md-sys-color-on-surface-variant); }
.hint { font-size: 11px; color: var(--md-sys-color-on-surface-variant); }

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--md-sys-color-surface-container-high);
  padding: 8px;
  border-radius: var(--md-sys-shape-corner-small);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.custom-colors-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.color-node {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  background: var(--md-sys-color-surface-container-high);
  padding: 6px;
  border-radius: var(--md-sys-shape-corner-small);
}
.smart-palette-preview {
  background: var(--md-sys-color-surface-container-high);
  padding: 8px 12px;
  border-radius: var(--md-sys-shape-corner-small);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.md-color-picker {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  width: 100%;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  background: none;
  padding: 0;
}
.md-color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.md-color-picker::-webkit-color-swatch { border: 1px solid rgba(255, 255, 255, .2); border-radius: 4px; }

/* --- Слайдеры и переключатели --- */
.slider-group { display: flex; flex-direction: column; gap: 6px; }
.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}
.md-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  cursor: pointer;
}
.md-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
  cursor: pointer;
  border: none;
}
.md-slider::-moz-range-track {
  height: 6px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
}
.md-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
  cursor: pointer;
  border: none;
}
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}
.md-switch { accent-color: var(--md-sys-color-primary); width: 16px; height: 16px; cursor: pointer; }

/* --- Замки рандомизации --- */
.lock-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--md-sys-color-outline);
  cursor: pointer;
}
.lock-btn .material-symbols-outlined { font-size: 18px; }
.lock-btn[aria-pressed="true"] { color: var(--md-sys-color-on-primary-container); background: var(--md-sys-color-primary-container); }

/* --- Быстрые варианты / история --- */
.quick-variant-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 3px;
}
.quick-variant { padding-inline: 5px; }
.variant-actions { display: flex; gap: 4px; flex-wrap: wrap; }

.gallery-strip { display: flex; gap: 6px; overflow-x: auto; padding: 2px; min-height: 40px; align-items: center; }
.gallery-empty { font-size: 11px; color: var(--md-sys-color-outline); }
.gallery-chip {
  position: relative;
  flex: 0 0 auto;
  width: 96px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-small);
  padding: 4px;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  text-align: left;
}
.gallery-chip:hover { border-color: var(--md-sys-color-outline); }
.gallery-chip img { width: 100%; height: 44px; object-fit: cover; border-radius: 6px; display: block; }
.gallery-chip .g-label {
  display: block;
  font-size: 9px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gallery-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.gallery-del .material-symbols-outlined { font-size: 13px; }
.gallery-chip:hover .gallery-del,
.gallery-chip:focus-within .gallery-del { display: inline-flex; }

/* --- Seed / ссылка --- */
.seed-row { display: flex; gap: 6px; align-items: center; }
.seed-input {
  flex: 1;
  min-width: 0;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-sys-shape-corner-small);
  padding: 7px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}
.seed-input:focus { outline: 2px solid var(--md-sys-color-primary); outline-offset: 1px; }

/* --- Экспорт --- */
.quality-group { display: flex; flex-direction: column; gap: 6px; }

/* --- Диалоги --- */
dialog {
  border: none;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  padding: 0;
  max-width: min(94vw, 1100px);
  box-shadow: var(--md-sys-elevation-3);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(6px); }
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 0;
}
.dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* Базовое (закрытое) состояние лайтбокса — полностью скрыто от пользователя */
.lightbox-dialog {
  display: none;          /* Убираем отображение, пока не открыт */
  background: transparent;
  box-shadow: none;
  border: 0;
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  overflow: hidden;
}

/* Активное состояние открытого лайтбокса (срабатывает при .showModal() в JS) */
.lightbox-dialog[open] {
  display: flex;          /* Показываем flex-контейнером только при открытии */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: fixed;        /* Фиксируем поверх всего экрана */
  top: 0;
  left: 0;
  z-index: 999;           /* Убедимся, что он лежит выше всех панелей */
}

.lightbox-dialog::backdrop { background: rgba(0, 0, 0, .88); backdrop-filter: blur(10px); }
.lightbox-dialog canvas {
  display: block;
  max-width: 94vw;
  max-height: calc(100dvh - 120px);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: 0 12px 48px rgba(0, 0, 0, .6);
}
.lightbox-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}
.modal-close-btn {
  background: rgba(255, 255, 255, .15);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.variations-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.variation-cell {
  padding: 6px;
  background: var(--md-sys-color-surface-container-high);
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.variation-cell:hover { border-color: var(--md-sys-color-primary); }
.variation-cell canvas { display: block; width: 100%; height: auto; border-radius: 8px; background: #000; }
.variation-cell .vc-label {
  font-size: 10px;
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shortcuts-table {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  font-size: 13px;
  align-items: center;
}
kbd {
  background: var(--md-sys-color-surface-container-highest);
  padding: 2px 8px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  white-space: nowrap;
}

/* --- Тост --- */
.md3-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 12px;
  box-shadow: var(--md-sys-elevation-3);
  transition: opacity .16s ease, transform .16s ease;
  max-width: min(90vw, 480px);
}
.md3-toast.show { opacity: 1; transform: translate(-50%, 0); }