/* EWTOS Bulk-Crop — Frontend-Styles
   @author Dario | ewtos.com

   Alle Farben stehen als Variablen im Block auf #ebc-app. Ein Theme belegt nur
   diesen Block neu und muss keine einzelne Regel ueberschreiben — sonst bleibt
   zwangslaeufig eine liegen. Die Defaults sind absichtlich neutral-hell, damit
   das Werkzeug auch ohne Theme brauchbar aussieht. */

#ebc-app {
  --ebc-surface: #fff;
  --ebc-surface-2: #f4f4f5;
  --ebc-surface-3: #ebebed;
  --ebc-border: #dcdce0;
  --ebc-border-strong: #b9b9c0;

  --ebc-strong: #16161a;
  --ebc-text: #3a3a42;
  --ebc-dim: #71717a;

  --ebc-accent: #2271b1;
  --ebc-accent-soft: rgba(34, 113, 177, 0.10);
  --ebc-accent-border: rgba(34, 113, 177, 0.35);
  --ebc-on-accent: #fff;

  --ebc-ok: #15803d;
  --ebc-err: #dc2626;

  /* Der Cropper: Maske ausserhalb des Ausschnitts, Linien darin. Bewusst dunkel
     auch im hellen Kontext — ein Bildausschnitt ist nur gegen Abdunklung
     erkennbar, nicht gegen eine hellere Flaeche. */
  --ebc-mask: rgba(6, 6, 12, 0.62);
  --ebc-win-edge: rgba(255, 255, 255, 0.92);
  --ebc-win-line: rgba(255, 255, 255, 0.34);

  --ebc-radius: 12px;
  --ebc-radius-sm: 9px;

  color: var(--ebc-text);
  font-size: 15px;
  line-height: 1.55;
}

#ebc-app *,
#ebc-app *::before,
#ebc-app *::after { box-sizing: border-box; }

/* Eigene Regeln setzen display, das wuerde den Browser-Default schlagen. */
#ebc-app [hidden] { display: none !important; }

.ebc-vh {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

.ebc-title { margin: 0 0 8px; color: var(--ebc-strong); }
.ebc-intro { margin: 0 0 22px; color: var(--ebc-dim); max-width: 68ch; }

/* --- Schrittmarken ------------------------------------------------------- */

.ebc-step {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 12px;
  font-weight: 700; font-size: 15px; color: var(--ebc-strong);
}
.ebc-step-n {
  flex: 0 0 auto;
  width: 23px; height: 23px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--ebc-accent-soft); border: 1px solid var(--ebc-accent-border);
  color: var(--ebc-accent);
  font-size: 12px; font-weight: 800; line-height: 1;
}
.ebc-side .ebc-step { margin-top: 26px; }
.ebc-side .ebc-step:first-child { margin-top: 0; }

/* --- Ablagefeld ---------------------------------------------------------- */

.ebc-drop {
  border: 2px dashed var(--ebc-border-strong); border-radius: var(--ebc-radius);
  background: var(--ebc-surface-2);
  padding: 30px 20px; text-align: center;
  transition: border-color .15s, background .15s;
}
.ebc-drop.is-over { border-color: var(--ebc-accent); background: var(--ebc-accent-soft); }
.ebc-drop-main { margin: 0; font-size: 16px; color: var(--ebc-text); }
.ebc-drop-hint { margin: 8px 0 0; font-size: 13px; color: var(--ebc-dim); }
#ebc-input-label { color: var(--ebc-accent); text-decoration: underline; cursor: pointer; }
#ebc-input-label:hover { color: var(--ebc-strong); }
#ebc-input:focus-visible + .ebc-drop-hint,
#ebc-input:focus-visible ~ #ebc-input-label { outline: 2px solid var(--ebc-accent); }
.ebc-drop:has(#ebc-input:focus-visible) { border-color: var(--ebc-accent); }

/* --- Zweispalter --------------------------------------------------------- */

.ebc-main { display: flex; gap: 26px; align-items: flex-start; margin-top: 26px; }
.ebc-tiles-col { flex: 3 1 560px; min-width: 0; }
.ebc-side {
  flex: 1 1 300px; max-width: 340px; min-width: 0;
  position: sticky; top: 18px;
}

.ebc-tiles-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.ebc-tiles-head .ebc-step { margin-bottom: 0; }
.ebc-tiles-tools { display: flex; align-items: center; gap: 14px; }
.ebc-count { font-size: 13px; color: var(--ebc-dim); }
.ebc-inline { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ebc-dim); }
.ebc-hint { margin: 10px 0 16px; font-size: 13px; color: var(--ebc-dim); }
.ebc-hint b { color: var(--ebc-strong); }

/* --- Kachelgitter --------------------------------------------------------
   minmax(0,1fr) statt auto: sonst sprengt ein langer Dateiname die Spur.
   repeat() nimmt kein min()/clamp(), die Deckelung auf kleinen Schirmen muss
   deshalb fest sein. */
.ebc-grid {
  display: grid;
  grid-template-columns: repeat(var(--ebc-cols, 3), minmax(0, 1fr));
  gap: 16px;
}

.ebc-tile {
  margin: 0;
  background: var(--ebc-surface);
  border: 1px solid var(--ebc-border); border-radius: var(--ebc-radius);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.ebc-tile.is-done { border-color: var(--ebc-accent-border); }
.ebc-tile.is-error { border-color: var(--ebc-err); }

/* Die Buehne haelt ein festes Quadrat, damit die Zeilen ruhig bleiben, egal wie
   hoch das einzelne Bild ist. Der Rahmen darin traegt das echte Verhaeltnis. */
.ebc-stage {
  position: relative;
  aspect-ratio: 1;
  display: grid; place-items: center;
  background: var(--ebc-surface-3);
  overflow: hidden;
}
/* Die Rahmengroesse setzt das Skript in Prozent der Buehne — beide Kanten
   ausgerechnet, statt eine dem Browser zu ueberlassen. `aspect-ratio` mit
   `max-height: 100%` klemmt nur die Hoehe und quetscht Hochformate in die Breite;
   `height: 100%` mit `width: auto` loest gegen ein zentriertes Element nicht
   zuverlaessig auf. Die Buehne ist quadratisch, damit ergeben w/max und h/max
   genau ein contain. */
.ebc-frame {
  position: relative;
  width: var(--ebc-fw, 100%);
  height: var(--ebc-fh, 100%);
  touch-action: none;
  cursor: grab;
  /* Beschneidet die Maske am Bildrand. Ohne das dunkelt sie auch die leere
     Buehne neben dem Bild ab — im dunklen Theme unsichtbar, im hellen ein
     grauer Rahmen um jede Kachel. */
  overflow: hidden;
}
.ebc-frame.is-dragging { cursor: grabbing; }
.ebc-img {
  display: block; width: 100%; height: 100%; object-fit: contain;
  user-select: none; -webkit-user-drag: none;
}

/* Ein Element statt vier Balken: der riesige box-shadow dunkelt alles ausserhalb
   des Fensters ab. Die Buehne schneidet ihn per overflow ab. */
.ebc-win {
  position: absolute;
  box-shadow: 0 0 0 9999px var(--ebc-mask);
  outline: 1px solid var(--ebc-win-edge);
  pointer-events: none;
}
.ebc-thirds {
  position: absolute; inset: 0;
  opacity: 0; transition: opacity .15s ease;
  background-image:
    linear-gradient(var(--ebc-win-line), var(--ebc-win-line)),
    linear-gradient(var(--ebc-win-line), var(--ebc-win-line)),
    linear-gradient(var(--ebc-win-line), var(--ebc-win-line)),
    linear-gradient(var(--ebc-win-line), var(--ebc-win-line));
  background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px;
  background-position: 33.333% 0, 66.667% 0, 0 33.333%, 0 66.667%;
  background-repeat: no-repeat;
}
.ebc-frame:hover .ebc-thirds,
.ebc-frame.is-dragging .ebc-thirds { opacity: 1; }

.ebc-flag {
  position: absolute; top: 8px; right: 8px;
  padding: 3px 9px; border-radius: 20px;
  background: var(--ebc-mask); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .2px;
  opacity: 0; transition: opacity .15s ease;
}
.ebc-flag.is-shown { opacity: 1; }
.ebc-flag.is-error { background: var(--ebc-err); }

.ebc-tile-foot {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 9px 11px 0;
  font-size: 12px; color: var(--ebc-dim);
}
.ebc-name {
  color: var(--ebc-strong); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ebc-dims { flex: 0 0 auto; font-variant-numeric: tabular-nums; }

.ebc-tile-bar {
  display: flex; align-items: center; gap: 3px;
  padding: 7px 8px 8px;
}
.ebc-bar-sep { flex: 1 1 auto; }
.ebc-zoom {
  font-size: 11.5px; color: var(--ebc-dim);
  min-width: 42px; text-align: center; font-variant-numeric: tabular-nums;
}
.ebc-ico {
  width: 27px; height: 27px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid var(--ebc-border); border-radius: 7px;
  background: var(--ebc-surface-2); color: var(--ebc-text);
  font: inherit; font-size: 14px; line-height: 1; cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.ebc-ico:hover { border-color: var(--ebc-accent-border); color: var(--ebc-strong); background: var(--ebc-accent-soft); }
.ebc-ico:disabled { opacity: .4; cursor: default; }
.ebc-ico-dl { border-color: var(--ebc-accent-border); color: var(--ebc-accent); }
.ebc-ico-del:hover { border-color: var(--ebc-err); color: var(--ebc-err); background: transparent; }

/* --- Einstellungen ------------------------------------------------------- */

.ebc-panel {
  background: var(--ebc-surface-2);
  border: 1px solid var(--ebc-border); border-radius: var(--ebc-radius);
  padding: 4px 16px 16px;
}
.ebc-group { border: 0; margin: 0; padding: 14px 0 0; }
.ebc-group + .ebc-group { border-top: 1px solid var(--ebc-border); margin-top: 14px; }
.ebc-group legend {
  padding: 0; margin-bottom: 9px;
  font-size: 11.5px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase;
  color: var(--ebc-dim);
}

.ebc-field { display: block; margin-bottom: 10px; font-size: 13px; color: var(--ebc-text); }
.ebc-field:last-child { margin-bottom: 0; }
.ebc-field select,
.ebc-field input[type="number"],
.ebc-field input[type="text"] {
  display: block; width: 100%; margin-top: 4px;
  padding: 7px 9px;
  background: var(--ebc-surface); color: var(--ebc-strong);
  border: 1px solid var(--ebc-border); border-radius: var(--ebc-radius-sm);
  font: inherit; font-size: 13.5px;
}
.ebc-field select:focus,
.ebc-field input:focus { border-color: var(--ebc-accent); outline: none; }
.ebc-unit { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ebc-dim); }
.ebc-unit input { margin-top: 0 !important; }
.ebc-narrow { flex: 1 1 0; margin-bottom: 0; }
.ebc-ratio-custom { display: flex; align-items: flex-end; gap: 8px; margin-top: 10px; }
.ebc-colon { padding-bottom: 8px; color: var(--ebc-dim); }

.ebc-radio, .ebc-check {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 7px; font-size: 13.5px; cursor: pointer;
}
.ebc-radio input, .ebc-check input { accent-color: var(--ebc-accent); margin: 0; flex: 0 0 auto; }
.ebc-check { margin-bottom: 0; margin-top: 10px; }

.ebc-sub { margin-top: 11px; padding-left: 11px; border-left: 2px solid var(--ebc-border); }
.ebc-note { margin: 9px 0 0; font-size: 12px; color: var(--ebc-dim); line-height: 1.5; }

#ebc-quality-field { display: block; }
#ebc-quality-out { font-weight: 700; color: var(--ebc-strong); font-variant-numeric: tabular-nums; }
#ebc-quality { width: 100%; margin-top: 5px; accent-color: var(--ebc-accent); }

/* --- Aktionen und Protokoll ---------------------------------------------- */

.ebc-actions { display: flex; flex-direction: column; gap: 8px; }
.ebc-btn {
  padding: 11px 16px;
  border: 1px solid var(--ebc-border-strong); border-radius: 10px;
  background: var(--ebc-surface); color: var(--ebc-strong);
  font: inherit; font-weight: 700; font-size: 14.5px; cursor: pointer;
  transition: border-color .15s, background .15s, filter .15s;
}
.ebc-btn:hover:not(:disabled) { border-color: var(--ebc-accent-border); background: var(--ebc-accent-soft); }
.ebc-btn:disabled { opacity: .45; cursor: default; }
.ebc-btn-primary { background: var(--ebc-accent); color: var(--ebc-on-accent); border-color: transparent; }
.ebc-btn-primary:hover:not(:disabled) { background: var(--ebc-accent); border-color: transparent; filter: brightness(1.08); }
.ebc-btn-quiet { font-weight: 600; font-size: 13.5px; padding: 8px 14px; }

.ebc-log-wrap { margin-top: 16px; font-size: 13px; }
.ebc-log-wrap summary { cursor: pointer; color: var(--ebc-dim); }
.ebc-log-wrap summary:hover { color: var(--ebc-strong); }
.ebc-log {
  margin-top: 9px; max-height: 190px; overflow-y: auto;
  padding: 9px 11px;
  background: var(--ebc-surface); border: 1px solid var(--ebc-border); border-radius: 10px;
  font-size: 12px; line-height: 1.6; color: var(--ebc-dim);
}
.ebc-log p { margin: 0 0 3px; }
.ebc-log .is-error { color: var(--ebc-err); }
.ebc-log .is-ok { color: var(--ebc-ok); }
.ebc-log time { color: var(--ebc-border-strong); margin-right: 6px; font-variant-numeric: tabular-nums; }

.ebc-app.is-busy .ebc-drop { pointer-events: none; opacity: .55; }
.ebc-app.is-busy .ebc-frame { pointer-events: none; }

/* --- Schmalere Schirme --------------------------------------------------- */

@media (max-width: 980px) {
  .ebc-main { flex-direction: column; gap: 22px; }
  .ebc-side { position: static; max-width: none; width: 100%; }
  .ebc-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 560px) and (max-width: 980px) {
  /* Nebeneinander statt untereinander: sonst liegen die Aktionen sehr weit unten. */
  .ebc-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; align-items: start; }
  .ebc-group + .ebc-group { border-top: 0; margin-top: 0; }
  .ebc-group { padding-top: 16px; }
}
@media (max-width: 620px) {
  .ebc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ebc-tiles-head { align-items: flex-start; }
}
@media (max-width: 400px) {
  .ebc-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  #ebc-app *, #ebc-app *::before, #ebc-app *::after { transition: none !important; }
}
