@import url('shared-topbar.css');

.cropper-shell {
  width: calc(100% - 32px);
  max-width: 1600px;
  padding-inline: 0;
}

.aspect-lock-control {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, var(--paper));
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
}

.aspect-lock-control input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.aspect-lock-control:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.preview-wrap {
  position: relative;
}

.crop-card .preview-wrap > img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  place-self: center;
  object-fit: contain;
  object-position: center;
}

.results.grid-view .crop-card .preview-wrap {
  width: min(100%, 360px);
  height: auto;
  aspect-ratio: var(--preview-ratio, 16 / 9);
  align-self: center;
}

.results.grid-view .crop-card .preview-wrap > img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.results.medium-grid-view {
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 18px;
}

.results.medium-grid-view .crop-card .preview-wrap {
  width: min(100%, 520px);
}

.results.medium-grid-view .file-info strong,
.results.large-grid-view .file-info strong {
  font-size: 15px;
}

.results.medium-grid-view .file-info span,
.results.large-grid-view .file-info span {
  font-size: 12px;
}

.results.large-grid-view {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.results.large-grid-view .crop-card .preview-wrap {
  width: min(100%, 720px);
}

.results.card-view {
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

.results.card-view .crop-card .preview-wrap {
  width: 100%;
  max-width: none;
}

.results.card-medium-view .crop-card .preview-wrap {
  width: min(100%, 1120px);
}

.results.card-small-view .crop-card .preview-wrap {
  width: min(100%, 900px);
}

.results.card-medium-view .crop-card .preview-wrap,
.results.card-small-view .crop-card .preview-wrap {
  align-self: center;
}

.view-select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.legacy-view-buttons {
  display: none !important;
}

.view-select-wrap select {
  min-width: 170px;
  height: 36px;
  padding: 7px 34px 7px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  font: 600 11px inherit;
  cursor: pointer;
}

@media (max-width: 520px) {
  .view-select-wrap {
    align-items: stretch;
    flex-direction: column;
  }

  .view-select-wrap select {
    width: 100%;
  }
}

.results.card-view .file-info strong {
  font-size: 16px;
}

@media (max-width: 860px) {
  .results.medium-grid-view {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .results.medium-grid-view,
  .results.large-grid-view {
    grid-template-columns: minmax(0, 1fr);
  }
}

.inline-crop {
  position: absolute;
  z-index: 3;
  min-width: 10px;
  min-height: 10px;
  border: 2px solid #fff;
  background: rgba(91, 111, 245, .16);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .38);
  cursor: move;
  touch-action: none;
}

.inline-crop::before,
.inline-crop::after,
.inline-crop i {
  content: '';
  position: absolute;
  pointer-events: none;
  background: rgba(255, 255, 255, .72);
}

.inline-crop::before,
.inline-crop::after {
  top: 0;
  width: 1px;
  height: 100%;
}

.inline-crop::before { left: 33.333%; }
.inline-crop::after { left: 66.666%; }
.inline-crop i { left: 0; width: 100%; height: 1px; }
.inline-crop i:nth-child(1) { top: 33.333%; }
.inline-crop i:nth-child(2) { top: 66.666%; }
.inline-crop i:nth-child(n+3) { display: none; }

.inline-crop b {
  position: absolute;
  z-index: 4;
  display: block;
  border: 0;
  border-radius: 0;
  background: transparent;
  transform: translate(-50%, -50%);
}

.inline-crop b.nw,.inline-crop b.ne,.inline-crop b.se,.inline-crop b.sw{width:16px;height:16px;border-color:#fff;border-style:solid;filter:drop-shadow(0 1px 2px rgba(0,0,0,.7))}
.inline-crop b.nw { left: 0; top: 0; border-width:3px 0 0 3px; cursor: nwse-resize; }
.inline-crop b.ne { left: 100%; top: 0; border-width:3px 3px 0 0; cursor: nesw-resize; }
.inline-crop b.se { left: 100%; top: 100%; border-width:0 3px 3px 0; cursor: nwse-resize; }
.inline-crop b.sw { left: 0; top: 100%; border-width:0 0 3px 3px; cursor: nesw-resize; }
.inline-crop b.n,.inline-crop b.s{width:20px;height:5px;border:1px solid rgba(20,40,70,.55);border-radius:2px;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.4)}
.inline-crop b.e,.inline-crop b.w{width:5px;height:20px;border:1px solid rgba(20,40,70,.55);border-radius:2px;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.4)}
.inline-crop b.n { left: 50%; top: 0; cursor: ns-resize; }
.inline-crop b.e { left: 100%; top: 50%; cursor: ew-resize; }
.inline-crop b.s { left: 50%; top: 100%; cursor: ns-resize; }
.inline-crop b.w { left: 0; top: 50%; cursor: ew-resize; }

.ratio-presets {
  grid-template-columns: repeat(11, minmax(58px, 1fr));
}

.ratio-presets button {
  min-height: 64px;
  padding: 7px 6px;
  flex-direction: column;
  gap: 5px;
  font-family: 'DM Mono', monospace;
}

.ratio-shape {
  display: block;
  flex: 0 0 auto;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  opacity: .82;
}

.ratio-crop-icon {
  position: relative;
  display: block;
  width: 22px;
  height: 22px;
}

.ratio-crop-icon::before,
.ratio-crop-icon::after {
  content: '';
  position: absolute;
  width: 13px;
  height: 13px;
  border-color: currentColor;
}

.ratio-crop-icon::before {
  top: 1px;
  left: 1px;
  border-right: 1.5px solid;
  border-bottom: 1.5px solid;
}

.ratio-crop-icon::after {
  right: 1px;
  bottom: 1px;
  border-top: 1.5px solid;
  border-left: 1.5px solid;
}

/* Keep ratio controls and numeric crop fields in two clean full-width rows. */
.crop-settings {
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  gap: 12px;
}

.crop-settings .ratio-presets,
.crop-settings .pixel-fields {
  width: 100%;
}

.crop-settings .pixel-fields {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  gap: 10px;
}

.crop-settings .pixel-fields label {
  gap: 7px;
}

.crop-settings .pixel-fields input {
  min-height: 42px;
  height: 42px;
}

.crop-settings .ratio-presets button,
.crop-settings .ratio-presets .aspect-lock-control {
  min-height: 64px;
  height: 64px;
}

.crop-settings .ratio-presets .aspect-lock-control {
  padding-inline: 8px;
  white-space: nowrap;
}

.editor-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.editor-head {
  order: 1;
  grid-column: 1 / -1;
}

.editor-viewport {
  order: 2;
  grid-column: 1 / -1;
}

.editor-ratio-bar {
  order: 3;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 0;
}

.editor-panel > p {
  order: 4;
  grid-column: 1;
  grid-row: 4;
  align-self: center;
  margin: 12px 16px 0 0;
}

.editor-actions {
  order: 5;
  grid-column: 2;
  grid-row: 4;
  align-self: center;
  margin-top: 12px;
}

.editor-ratio-bar > strong {
  color: var(--muted);
  font-size: 11px;
}

.editor-ratios {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.editor-ratios button {
  display: inline-flex;
  min-width: 64px;
  min-height: 62px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: 600 11px inherit;
  cursor: pointer;
}

.editor-ratios button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Give the crop editor enough room for detailed positioning on desktop. */
.crop-editor {
  padding: 12px;
}

.crop-editor .editor-panel {
  width: min(1240px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 22px;
}

.crop-editor .editor-viewport {
  min-height: clamp(420px, 64vh, 720px);
  padding: 20px;
}

@media (max-width: 900px) {
  .ratio-presets {
    grid-template-columns: repeat(6, minmax(58px, 1fr));
  }
}

@media (max-width: 620px) {
  .ratio-presets {
    grid-template-columns: repeat(3, minmax(58px, 1fr));
  }

  .crop-settings .pixel-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-panel {
    grid-template-columns: 1fr;
  }

  .editor-panel > p,
  .editor-actions {
    grid-column: 1;
  }

  .editor-panel > p {
    grid-row: 4;
    margin-right: 0;
  }

  .editor-actions {
    grid-row: 5;
    flex-wrap: wrap;
  }

  .editor-ratio-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .editor-ratios {
    width: 100%;
  }

  .editor-ratios button {
    flex: 1;
  }

  .crop-editor {
    padding: 8px;
  }

  .crop-editor .editor-panel {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    padding: 12px;
  }

  .crop-editor .editor-viewport {
    min-height: 300px;
    padding: 10px;
  }
}

@media (max-width: 380px) {
  .cropper-shell {
    width: calc(100% - 20px);
  }

  .crop-settings .pixel-fields {
    grid-template-columns: 1fr;
  }
}
