
.modal-window,
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1600;
}

.modal-window[aria-hidden="false"],
.overlay[aria-hidden="false"] {
  display: flex;
}

.modal-window::before,
.overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
}


.overlay__dialog {
  position: relative;
  z-index: 1;
  background: #ffffff;
  padding: 0;
  border-radius: 16px;
  width: min(1000px, 96vw);
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.overlay__dialog--compact {
  width: min(520px, 90vw);
}

.modal-window__dialog {
  position: relative;
  z-index: 1;
  background: #ffffff;
  padding: 0;
  border-radius: 16px;
  width: min(720px, 94vw);
  max-height: calc(100vh - 50px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.modal-window--wide .modal-window__dialog {
  width: min(1300px, 96vw);
}

.tablet-mode .modal-window--wide .modal-window__dialog {
  width: min(900px, 96vw);
}


.overlay__header,
.modal-window__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  
  border-bottom: 1px solid #f0f2f5;
  background: #fafbfc;
  flex-shrink: 0;
  
}

.photo-sketch-header-text h3 {
  margin: 0;
  font-size: 20px;
  
  font-weight: 700;
  color: #1a1d29;
  line-height: 1.3;
}

.overlay__header button,
.modal-window__header button {
  width: 32px;
  
  height: 32px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  color: #6b7280;
  font-size: 18px;
  font-weight: 300;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.overlay__header button:hover,
.modal-window__header button:hover {
  background: #f8f9fa;
  border-color: #d1d5db;
  color: #374151;
  transform: scale(1.05);
}


.overlay__body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 0;
  overflow-y: auto;
}

.photo-sketch-body {
  gap: 0;
  overflow: auto;
}

.photo-sketch-tablet-tabs {
  display: none;
  gap: 10px;
  padding: 12px 14px;
  background: #fafbfc;
  border-bottom: 1px solid #f0f2f5;
  position: static;
}

.photo-sketch-tablet-tabs button {
  flex: 1;
  width: 100%;
  border-radius: 999px;
  min-width: 0;
}

.photo-sketch-tablet-tabs button[aria-selected="true"] {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #ffffff;
}


.photo-sketch-grid {
  display: grid;
  grid-template-columns: 1fr 1.7fr;
  
  gap: 0;
  min-height: 500px;
  
}


.photo-sketch-panel {
  padding: 20px;
  
  display: flex;
  flex-direction: column;
  gap: 16px;
  
  background: #ffffff;
  border-right: 1px solid #f0f2f5;
  height: 100%;
  overflow-y: auto;
  max-width: 380px;
  
}

.madol .form-field {
  display: flex;
  flex-direction: column;
  min-height: auto;
  gap: 6px;
  
}

.madol .form-field label {
  font-size: 12px;
  
  font-weight: 600;
  color: #374151;
  margin-bottom: 1px;
}

.form-hint {
  font-size: 11px;
  
  color: #9ca3af;
  line-height: 1.4;
  margin: 2px 0 0;
}


.photo-sketch-file {
  display: flex;
  align-items: center;
  gap: 10px;
}

.photo-sketch-file__name {
  font-size: 12px;
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}


.photo-sketch-range {
  display: flex;
  align-items: center;
  gap: 10px;
}

.photo-sketch-range input[type="range"] {
  flex: 1;
  height: 4px;
  
  border-radius: 2px;
  background: #e5e7eb;
  outline: none;
  -webkit-appearance: none;
}

.photo-sketch-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  
  height: 16px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.photo-sketch-range span {
  min-width: 45px;
  font-weight: 600;
  color: #1f2937;
  font-size: 13px;
}


select,
input[type="number"] {
  padding: 8px 10px;
  
  border: 1.5px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  
  background: #ffffff;
  transition: all 0.15s ease;
}

select:focus,
input[type="number"]:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}


.photo-sketch-align-inputs,
.photo-sketch-crop-inputs {
  display: flex;
  gap: 12px;
  
  flex-wrap: wrap;
  align-items: flex-end;
}

.photo-sketch-align-inputs label,
.photo-sketch-crop-inputs label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  flex: 1;
  min-width: 100px;
  
}

.photo-sketch-crop-inputs input {
  width: 100%;
}

.photo-sketch-align-inputs input[type="range"] {
  width: 100%;
}


.photo-sketch-dither-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  
}

.photo-sketch-dither-options label {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #374151;
  align-items: center;
  padding: 6px 10px;
  
  border-radius: 6px;
  transition: background 0.15s ease;
  cursor: pointer;
}

.photo-sketch-dither-options label:hover {
  background: #f8f9fa;
}


.photo-sketch-summary {
  padding: 12px 14px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e40af;
  font-weight: 600;
  font-size: 13px;
  border-left: 3px solid #3b82f6;
  margin-top: 6px;
}


.photo-sketch-panel--preview {
  padding: 20px;
  
  background: #fafbfc;
  gap: 20px;
  
  border-right: none;
  max-width: 1000px;
}

.photo-sketch-panel--preview header {
  font-size: 15px;
  
  font-weight: 700;
  color: #1f2937;
  margin: 0;
}

.photo-sketch-preview-tabs {
  display: flex;
  gap: 10px;
}

.photo-sketch-preview-tabs button {
  flex: 1;
  width: 100%;
  border-radius: 999px;
  min-width: 0;
}

.photo-sketch-preview-tabs button[aria-selected="true"] {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #ffffff;
}

.photo-sketch-preview-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.photo-sketch-preview-pane {
  display: none;
  flex-direction: column;
  gap: 10px;
}

#photoSketchOverlay .photo-sketch-preview-pane[data-pane="pixel"] {
  display: flex;
}

#photoSketchOverlay[data-photo-sketch-preview="original"] .photo-sketch-preview-pane[data-pane="pixel"] {
  display: none;
}

#photoSketchOverlay[data-photo-sketch-preview="original"] .photo-sketch-preview-pane[data-pane="original"] {
  display: flex;
}

#photoSketchOverlay[data-photo-sketch-preview="pixel"] .photo-sketch-preview-pane[data-pane="original"] {
  display: none;
}

#photoSketchOverlay[data-photo-sketch-preview="pixel"] .photo-sketch-preview-pane[data-pane="pixel"] {
  display: flex;
}

.photo-sketch-preview-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.photo-sketch-preview-card h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}


.photo-sketch-preview-card canvas,
.photo-sketch-preview-pane canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 2px solid #e5e7eb;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
  aspect-ratio: var(--preview-aspect, 1);
  object-fit: contain;
}

.photo-sketch-preview-card canvas:hover,
.photo-sketch-preview-pane canvas:hover {
  border-color: #3b82f6;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.photo-sketch-preview__info {
  margin: 6px 0 0;
  font-size: 12px;
  color: #6b7280;
  text-align: center;
  padding: 6px;
  background: #f8f9fa;
  border-radius: 5px;
}


.overlay__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  
  border-top: 1px solid #f0f2f5;
  background: #fafbfc;
  position: sticky;
  
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  flex-shrink: 0;
  
}

.photo-sketch-status {
  font-size: 12px;
  color: #6b7280;
  min-height: 18px;
  flex: 1;
}

.photo-sketch-status[data-status-type="error"] {
  color: #dc2626;
  font-weight: 500;
}

.photo-sketch-status[data-status-type="success"] {
  color: #16a34a;
  font-weight: 500;
}

.photo-sketch-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  
}


.ghost-button,
.primary-button {
  padding: 8px 16px;
  
  border-radius: 6px;
  font-size: 12px;
  
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1.5px solid;
  min-width: 90px;
  
}

.ghost-button {
  background: #ffffff;
  border-color: #d1d5db;
  color: #374151;
}

.ghost-button:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.primary-button {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #ffffff;
}

.primary-button:hover {
  background: #2563eb;
  border-color: #2563eb;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
  
}


@media (max-width: 1024px) {
  .photo-sketch-grid {
    grid-template-columns: 1fr;
  }

  .photo-sketch-panel {
    border-right: none;
    border-bottom: 1px solid #f0f2f5;
    max-width: none;
    
  }

  .overlay__dialog {
    width: min(95vw, 800px);
    max-height: calc(100vh - 40px);
  }
}

/* Tablet mode: split params / preview as two screens */
body.tablet-mode #photoSketchOverlay .photo-sketch-tablet-tabs {
  display: flex;
  background-color: transparent;
}

body.tablet-mode #photoSketchOverlay.overlay {
  z-index: 260;
}

body.tablet-mode #photoSketchOverlay .photo-sketch-dialog {
  width: min(920px, 94vw);
  height: calc(100vh - 220px);
  max-height: calc(100vh - 220px);
}

body.tablet-mode #photoSketchOverlay .overlay__header {
  padding: 14px 16px;
}

body.tablet-mode #photoSketchOverlay .photo-sketch-footer {
  padding: 12px 16px;
}

body.tablet-mode #photoSketchOverlay .photo-sketch-grid {
  grid-template-columns: 1fr;
  min-height: 0;
}

body.tablet-mode #photoSketchOverlay .photo-sketch-panel {
  max-width: none;
  height: auto;
  overflow: visible;
  border-right: none;
}

body.tablet-mode #photoSketchOverlay:not([data-photo-sketch-view="preview"]) .photo-sketch-panel--preview {
  display: none;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="preview"] .photo-sketch-grid > .photo-sketch-panel:first-child {
  display: none;
}

body.tablet-mode #photoSketchOverlay .photo-sketch-panel--preview {
  background: #ffffff;
}

body.tablet-mode #photoSketchOverlay .photo-sketch-preview-pane canvas {
  max-height: 42vh;
}

@media (max-width: 640px) {

  .overlay__header,
  .photo-sketch-panel,
  .photo-sketch-panel--preview,
  .overlay__footer {
    padding: 16px;
    
  }

  .photo-sketch-actions {
    flex-direction: column;
    width: 100%;
    gap: 8px;
  }

  .ghost-button,
  .primary-button {
    width: 100%;
    min-width: auto;
  }
}


.photo-sketch-dialog {
  gap: 0;
}

.overlay-warning {
  padding: 10px 14px;
  
  border-radius: 6px;
  border: 1px solid rgba(245, 158, 11, 0.3);
  background: rgba(254, 243, 199, 0.6);
  color: #92400e;
  font-size: 12px;
  line-height: 1.5;
  margin: 0 24px;
  
}

.overlay-warning:empty {
  display: none;
}


.photo-sketch-dialog {
  width: min(1240px, 98vw);
  height: min(94vh, 1020px);
  background: linear-gradient(125deg, rgba(244, 247, 255, 0.96), rgba(233, 239, 255, 0.86));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.photo-sketch-body {
  flex: 1 1 auto;
  padding: 30px 34px;
  overflow: hidden;
}

.photo-sketch-grid {
  display: flex;
  gap: 28px;
  height: 100%;
  overflow: hidden;
}

.photo-sketch-grid > .photo-sketch-panel:first-child {
  width: 420px;
  min-width: 360px;
  max-width: 460px;
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 24px;
}

.photo-sketch-grid > .photo-sketch-panel:last-child {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: 28px;
  background: rgba(248, 250, 255, 0.92);
}

.photo-sketch-panel {
  background: #ffffff;
  border-radius: 20px;
  border: 1px solid rgba(117, 124, 255, 0.14);
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.08);
  padding: 22px 26px;
  gap: 22px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.photo-sketch-panel--preview {
  padding: 28px 32px;
}

.photo-sketch-file,
.photo-sketch-range,
.photo-sketch-align-inputs,
.photo-sketch-crop-inputs {
  background: #f7f8ff;
  border-radius: 14px;
  padding: 14px 18px;
  border: 1px solid rgba(124, 132, 255, 0.14);
}

.photo-sketch-preview-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.photo-sketch-preview-card {
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  padding: 18px;
  background: #ffffff;
}

.photo-sketch-preview-card canvas {
  border-radius: 12px;
  border: 1px dashed rgba(126, 136, 255, 0.3);
  width: 100%;
  height: auto;
}

.photo-sketch-footer {
  padding: 22px 34px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 255, 0.98));
  gap: 20px;
}

.photo-sketch-status {
  flex: 1 1 auto;
  min-height: 20px;
}

@media (max-width: 1180px) {
  .photo-sketch-body {
    padding: 24px;
  }

  .photo-sketch-grid {
    flex-direction: column;
  }

  .photo-sketch-grid > .photo-sketch-panel:first-child {
    width: 100%;
    max-width: none;
    overflow: visible;
    padding-right: 0;
  }

  .photo-sketch-grid > .photo-sketch-panel:last-child {
    min-height: 420px;
  }
}

@media (max-width: 760px) {
  .photo-sketch-body {
    padding: 18px;
  }

  .photo-sketch-grid {
    gap: 16px;
  }

  .photo-sketch-panel {
    padding: 18px;
  }

  .photo-sketch-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Tablet mode: redesign photo sketch params screen (keep features unchanged) */
body.tablet-mode #photoSketchOverlay .photo-sketch-body {
  padding: 12px 14px;
  overflow-y: auto;
  overflow-x: hidden;
}

body.tablet-mode #photoSketchOverlay .photo-sketch-grid {
  display: block;
  height: auto;
  overflow: visible;
}

body.tablet-mode #photoSketchOverlay .photo-sketch-grid > .photo-sketch-panel:first-child {
  width: 100%;
  min-width: 0;
  max-width: none;
  padding-right: 0;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-grid > .photo-sketch-panel:first-child {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(26, 115, 232, 0.14);
  background: rgba(255, 255, 255, 0.96);
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-grid > .photo-sketch-panel:first-child .form-field {
  padding: 10px 10px;
  border-radius: 14px;
  border: 1px solid #e8eaed;
  background: #ffffff;
  gap: 8px;
  margin: 0;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-grid > .photo-sketch-panel:first-child .form-field label {
  font-size: 12px;
  margin-bottom: 0;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-grid > .photo-sketch-panel:first-child .form-hint {
  font-size: 10px;
  margin: 0;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-grid > .photo-sketch-panel:first-child .form-field:nth-of-type(1),
body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-grid > .photo-sketch-panel:first-child .form-field:nth-of-type(4),
body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-grid > .photo-sketch-panel:first-child .form-field:nth-of-type(5),
body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-grid > .photo-sketch-panel:first-child .form-field:nth-of-type(8),
body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] #photoSketchSummary {
  grid-column: 1 / -1;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-file {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-file__name {
  white-space: normal;
  line-height: 1.25;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-range span {
  min-width: 52px;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] select,
body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] input[type="number"] {
  padding: 7px 9px;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-range-input {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 8px;
  align-items: center;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-align-inputs,
body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-crop-inputs {
  gap: 10px;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-dither-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] .photo-sketch-dither-options label {
  margin: 0;
  padding: 8px 10px;
}

body.tablet-mode #photoSketchOverlay[data-photo-sketch-view="params"] #photoSketchSummary {
  padding: 10px 12px;
  border-radius: 14px;
  margin-top: 0;
}
