/*
 * Photo Adjust — отдельный редактор яркости/контраста для готового фото.
 * Модальное окно с live-preview, точной попиксельной обработкой и экспортом.
 */

.padj-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 24, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.padj-overlay.is-open {
  opacity: 1;
}

.padj-shell {
  width: min(1100px, calc(100vw - 28px));
  height: min(720px, calc(100dvh - 28px));
  background: #fafafa;
  color: #18181b;
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  transform: translateY(10px) scale(0.98);
  transition: transform 0.18s ease;
}

html.dark .padj-shell {
  background: #0b0b10;
  color: #f4f4f5;
}

.padj-overlay.is-open .padj-shell {
  transform: translateY(0) scale(1);
}

.padj-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

html.dark .padj-header {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.padj-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.padj-title-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(201, 162, 39, 0.22), rgba(201, 162, 39, 0.08));
  color: #a8841f;
  font-size: 16px;
}

html.dark .padj-title-icon {
  background: linear-gradient(135deg, rgba(252, 211, 77, 0.18), rgba(252, 211, 77, 0.05));
  color: #fcd34d;
}

.padj-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: transparent;
  border: 0;
  color: #71717a;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: color 0.15s ease, background 0.15s ease;
}

.padj-close:hover {
  color: #18181b;
  background: rgba(0, 0, 0, 0.04);
}

html.dark .padj-close {
  color: #a1a1aa;
}

html.dark .padj-close:hover {
  color: #fafafa;
  background: rgba(255, 255, 255, 0.06);
}

.padj-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  min-height: 0;
}

@media (max-width: 860px) {
  .padj-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .padj-shell { height: 100dvh; max-height: 100dvh; width: 100vw; border-radius: 0; }
  .padj-stage { min-height: 0; flex: 1 1 auto; }
}

/* Десктоп: мобильные элементы скрыты */
.padj-mobile-tabs,
.padj-sheet-handle { display: none; }
.padj-mobile-panel.is-mobile-hidden { display: none !important; }

@media (max-width: 768px) {
  .padj-shell {
    display: flex;
    flex-direction: column;
  }
  .padj-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
  }
  .padj-stage {
    order: 1;
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px;
  }
  .padj-compare-btn {
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    min-height: 44px;
    padding: 10px 18px;
    font-size: 12px;
  }
  .padj-compare-btn:active { transform: translateX(-50%) scale(0.97); }

  .padj-side {
    order: 2;
    flex: 0 0 auto;
    border-left: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  html.dark .padj-side { border-top-color: rgba(255, 255, 255, 0.08); }

  .padj-sheet-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
    padding: 8px 12px 4px;
    border: 0;
    background: transparent;
    color: #71717a;
    cursor: pointer;
    flex-shrink: 0;
  }
  .padj-sheet-handle-bar {
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.18);
  }
  html.dark .padj-sheet-handle-bar { background: rgba(255, 255, 255, 0.22); }
  .padj-sheet-handle-label { font-size: 12px; font-weight: 600; }

  .padj-mobile-tabs {
    display: flex;
    gap: 6px;
    padding: 0 12px 8px;
    flex-shrink: 0;
  }
  .padj-mobile-tabs button {
    flex: 1;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.03);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: inherit;
  }
  html.dark .padj-mobile-tabs button {
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
  }
  .padj-mobile-tabs button.is-active {
    border-color: #a8841f;
    background: rgba(201, 162, 39, 0.16);
    color: #92400e;
  }
  html.dark .padj-mobile-tabs button.is-active { color: #fcd34d; }

  .padj-side--collapsed .padj-side-scroll {
    max-height: 0;
    overflow: hidden;
    padding: 0;
    opacity: 0;
    pointer-events: none;
  }
  .padj-side--expanded .padj-side-scroll {
    max-height: min(46dvh, 380px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    opacity: 1;
    pointer-events: auto;
    padding: 8px 14px 12px;
  }
  .padj-side.is-keyboard-open.padj-side--expanded .padj-side-scroll {
    max-height: min(34dvh, 280px);
  }

  .padj-presets { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .padj-preset { min-height: 48px; font-size: 13px; padding: 12px 8px; }
  .padj-sliders { gap: 18px; }

  .padj-footer {
    order: 3;
    flex-shrink: 0;
    padding: 8px 12px max(8px, env(safe-area-inset-bottom, 8px));
    flex-wrap: nowrap;
  }
  .padj-footer-info { display: none; }
  .padj-btn { min-height: 48px; flex: 1 1 0; font-size: 14px; }
  .padj-btn--primary { flex: 1.35 1 0; }
  .padj-close { width: 44px; height: 44px; }
}

.padj-side.is-keyboard-open .padj-side-scroll {
  max-height: calc(56vh - var(--keyboard-inset, 0px));
  scroll-padding-bottom: calc(12px + var(--keyboard-inset, 0px));
}

.padj-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  padding: 16px;
}

html.dark .padj-stage {
  background-color: #050507;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%);
}

.padj-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  background: #ffffff;
}

html.dark .padj-canvas {
  background: #18181b;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.padj-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.65);
  font-size: 13px;
  color: #525252;
}

html.dark .padj-loading {
  background: rgba(0, 0, 0, 0.55);
  color: #d4d4d8;
}

.padj-loading.is-hidden { display: none; }

.padj-spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid rgba(0, 0, 0, 0.12);
  border-top-color: #a8841f;
  border-radius: 50%;
  animation: padj-spin 0.85s linear infinite;
  margin-right: 12px;
}

@keyframes padj-spin { to { transform: rotate(360deg); } }

.padj-compare-btn {
  position: absolute;
  bottom: 14px;
  left: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(15, 17, 24, 0.78);
  color: #fafafa;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 0;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.padj-compare-btn:hover { background: rgba(15, 17, 24, 0.9); }
.padj-compare-btn:active { transform: scale(0.97); }
.padj-compare-btn.is-active {
  background: linear-gradient(180deg, #d4af37 0%, #a8841f 100%);
  color: #1c1917;
}

.padj-side {
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

html.dark .padj-side {
  border-left-color: rgba(255, 255, 255, 0.06);
  background: #101015;
}

@media (max-width: 860px) {
  .padj-side {
    border-left: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
  }
  html.dark .padj-side {
    border-top-color: rgba(255, 255, 255, 0.06);
  }
}

.padj-side-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 12px;
}

.padj-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a8841f;
  margin-bottom: 10px;
}

html.dark .padj-section-title { color: #fcd34d; }

.padj-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 18px;
}

.padj-preset {
  appearance: none;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(0, 0, 0, 0.025);
  color: #404040;
  border-radius: 10px;
  padding: 8px 6px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.padj-preset:hover {
  border-color: rgba(201, 162, 39, 0.5);
  color: #a8841f;
}

html.dark .padj-preset {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: #d4d4d8;
}

html.dark .padj-preset:hover {
  border-color: rgba(252, 211, 77, 0.45);
  color: #fcd34d;
}

.padj-sliders {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.padj-slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.padj-slider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  color: #404040;
}

html.dark .padj-slider-head { color: #d4d4d8; }

.padj-slider-number {
  font-variant-numeric: tabular-nums;
  color: #1c1917;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid transparent;
  padding: 4px 6px;
  border-radius: 8px;
  width: 64px;
  height: 32px;
  text-align: center;
  font-size: 13px;
  appearance: textfield;
  -moz-appearance: textfield;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.padj-slider-number::-webkit-outer-spin-button,
.padj-slider-number::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.padj-slider-number:focus {
  outline: none;
  border-color: #c9a227;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.2);
}

html.dark .padj-slider-number {
  color: #fafafa;
  background: rgba(255, 255, 255, 0.06);
}

html.dark .padj-slider-number:focus {
  background: #18181b;
  border-color: #fcd34d;
  box-shadow: 0 0 0 3px rgba(252, 211, 77, 0.18);
}

.padj-slider-number.is-modified {
  color: #a8841f;
  background: rgba(201, 162, 39, 0.14);
}

html.dark .padj-slider-number.is-modified {
  color: #fcd34d;
  background: rgba(252, 211, 77, 0.14);
}

.padj-range {
  position: relative;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.12);
  outline: none;
  cursor: pointer;
  touch-action: pan-y;
}

html.dark .padj-range { background: rgba(255, 255, 255, 0.12); }

.padj-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(180deg, #d4af37, #a8841f);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.padj-range::-webkit-slider-thumb:hover { transform: scale(1.12); }
.padj-range::-webkit-slider-thumb:active { transform: scale(1.18); }

.padj-range::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(180deg, #d4af37, #a8841f);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.padj-range:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.35);
}

html.dark .padj-range::-webkit-slider-thumb { border-color: #1c1c20; }
html.dark .padj-range::-moz-range-thumb { border-color: #1c1c20; }

/* Touch-устройства: расширенный thumb для удобного попадания пальцем */
@media (hover: none) and (pointer: coarse) {
  .padj-range {
    height: 10px;
    border-radius: 5px;
  }
  .padj-range::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
  }
  .padj-range::-moz-range-thumb {
    width: 28px;
    height: 28px;
  }
  .padj-slider { gap: 8px; padding: 4px 0; }
  .padj-slider-number {
    width: 72px;
    height: 38px;
    font-size: 15px;
  }
  .padj-preset { padding: 10px 6px; font-size: 12px; }
}

.padj-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.015);
}

html.dark .padj-footer {
  border-top-color: rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
}

.padj-footer-info {
  font-size: 11.5px;
  color: #71717a;
  line-height: 1.45;
  flex: 1;
  min-width: 0;
}

html.dark .padj-footer-info { color: #a1a1aa; }

.padj-btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.padj-btn:active { transform: translateY(1px); }

.padj-btn--ghost {
  background: transparent;
  color: #525252;
  border: 1px solid rgba(0, 0, 0, 0.14);
}

.padj-btn--ghost:hover {
  color: #a8841f;
  border-color: rgba(201, 162, 39, 0.5);
}

html.dark .padj-btn--ghost {
  color: #d4d4d8;
  border-color: rgba(255, 255, 255, 0.16);
}

html.dark .padj-btn--ghost:hover {
  color: #fcd34d;
  border-color: rgba(252, 211, 77, 0.45);
}

.padj-btn--primary {
  background: linear-gradient(180deg, #d4af37 0%, #c9a227 50%, #a8841f 100%);
  color: #1c1917;
  box-shadow: 0 4px 14px rgba(168, 132, 31, 0.32);
}

.padj-btn--primary:hover {
  box-shadow: 0 6px 18px rgba(168, 132, 31, 0.45);
}

.padj-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Кнопка-триггер на карточке вариантов */
.padj-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 8px;
  border: 1px dashed rgba(120, 130, 160, 0.45);
  background: transparent;
  color: #525b76;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.padj-trigger:hover {
  border-color: rgba(99, 102, 241, 0.6);
  color: #4f46e5;
  background: rgba(99, 102, 241, 0.06);
}

html.dark .padj-trigger {
  border-color: rgba(150, 158, 184, 0.35);
  color: #c4c8d8;
}

html.dark .padj-trigger:hover {
  border-color: rgba(165, 180, 252, 0.55);
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.1);
}

@media (hover: none) and (pointer: coarse) {
  .padj-trigger { min-height: 44px; padding: 10px 8px; font-size: 13px; }
}

.padj-trigger-icon { font-size: 14px; line-height: 1; }

.padj-history-trigger {
  appearance: none;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.08);
  color: #4338ca;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.padj-history-trigger:hover {
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(99, 102, 241, 0.6);
}

html.dark .padj-history-trigger {
  border-color: rgba(165, 180, 252, 0.32);
  background: rgba(99, 102, 241, 0.14);
  color: #c7d2fe;
}

html.dark .padj-history-trigger:hover {
  background: rgba(99, 102, 241, 0.22);
  border-color: rgba(165, 180, 252, 0.5);
}

/* Компактная строка edit-кнопок под карточкой варианта в истории */
.history-edit-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 0 6px 6px;
}

.history-edit-btn {
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 34px;
  padding: 4px 6px;
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: none) and (pointer: coarse) {
  .history-edit-btn { min-height: 38px; }
}

.history-edit-btn > span:first-child { font-size: 12px; line-height: 1; }
.history-edit-label { overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.history-edit-btn--inscribe {
  border-color: rgba(201, 162, 39, 0.35);
  background: rgba(252, 211, 77, 0.12);
  color: #92400e;
}

.history-edit-btn--inscribe:hover {
  border-color: rgba(201, 162, 39, 0.65);
  background: rgba(252, 211, 77, 0.22);
}

.history-edit-btn--adjust {
  border-color: rgba(99, 102, 241, 0.32);
  background: rgba(99, 102, 241, 0.08);
  color: #4338ca;
}

.history-edit-btn--adjust:hover {
  border-color: rgba(99, 102, 241, 0.6);
  background: rgba(99, 102, 241, 0.16);
}

html.dark .history-edit-btn--inscribe {
  border-color: rgba(252, 211, 77, 0.35);
  background: rgba(252, 211, 77, 0.14);
  color: #fcd34d;
}

html.dark .history-edit-btn--inscribe:hover {
  border-color: rgba(252, 211, 77, 0.55);
  background: rgba(252, 211, 77, 0.22);
}

html.dark .history-edit-btn--adjust {
  border-color: rgba(165, 180, 252, 0.32);
  background: rgba(99, 102, 241, 0.16);
  color: #c7d2fe;
}

html.dark .history-edit-btn--adjust:hover {
  border-color: rgba(165, 180, 252, 0.5);
  background: rgba(99, 102, 241, 0.24);
}

/* На очень узких колонках (3 варианта в карточке истории) подпись прячется,
   остаётся только иконка — кнопка точно не вылазит за ячейку. */
@media (max-width: 540px) {
  .history-edit-label { display: none; }
  .history-edit-btn { padding: 6px 4px; }
}

/* Мобильная оптимизация редактора коррекции */
@media (max-width: 860px) {
  .padj-header { padding: 12px 14px; gap: 8px; }
  .padj-title { font-size: 14px; }
  .padj-close { width: 40px; height: 40px; font-size: 22px; }
  .padj-side-scroll { padding: 14px 14px 8px; }
  .padj-presets { grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 14px; }
  .padj-preset { padding: 10px 4px; font-size: 11.5px; min-height: 40px; }
  .padj-sliders { gap: 16px; }
  .padj-footer {
    padding: 12px 14px max(12px, env(safe-area-inset-bottom, 12px));
    gap: 8px;
    flex-wrap: wrap;
  }
  .padj-footer-info { font-size: 11px; flex-basis: 100%; order: 3; }
  .padj-btn { padding: 11px 14px; font-size: 13px; min-height: 44px; flex: 1 1 auto; }
  .padj-compare-btn { bottom: 10px; left: 10px; padding: 9px 14px; font-size: 11px; min-height: 44px; }
  .padj-close { width: 44px; height: 44px; }
}

@media (max-width: 480px) {
  .padj-presets { grid-template-columns: repeat(2, 1fr); }
  .padj-slider-head { font-size: 12.5px; }
  .padj-slider-number { width: 64px; }
}

/* Предотвращаем зум при фокусе на input в iOS — нужно >=16px */
@supports (-webkit-touch-callout: none) {
  .padj-slider-number { font-size: 16px; }
}
