/* ══════════════════════════════════════════════════════════════════════════
   CROP & ROTATE  ·  tools/image-crop/crop.css
   All rules scoped to [data-tool="image-crop"] so nothing leaks into the suite.

   ⚠ Two suite traps this file is written around:
     · shell.css strips vertical padding from any <section> inside main.app,
       so every block here is a <div>. Do not convert them to sections.
     · shell.css enforces [hidden]{display:none!important}. Panels are shown
       by clearing the ATTRIBUTE in crop.js, never by a display rule.
   ══════════════════════════════════════════════════════════════════════════ */

[data-tool="image-crop"] {
  --cr-line: #e4e7ec;
  --cr-ink: #101828;
  --cr-mut: #667085;
  --cr-blue: #1159da;
  --cr-soft: #f7f9fc;
}

[data-tool="image-crop"] .cr-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
  padding: 18px;
}

/* ── drop zone ─────────────────────────────────────────────────────────────
   Uses the suite's shared upload-zone vocabulary (.upload-zone / -icon /
   -title / -sub / -mini) so it reads as the same product as Resize, Convert
   and the rest. The names are shared; the styling is per-tool, which is the
   convention across all 12 sheets that use them. */
[data-tool="image-crop"] .cr-upload {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 300px;
  padding: 34px 22px;
  border: 2px dashed #bfe3f7;
  border-radius: 16px;
  background: linear-gradient(180deg, #f8fbff, #f2f7fd);
  text-align: center;
  transition: border-color .15s, background .15s;
}
[data-tool="image-crop"] .cr-upload.over {
  border-color: var(--cr-blue);
  background: #eef4ff;
}
[data-tool="image-crop"] .cr-drop-cloud {
  width: 72px; height: 72px;
  display: grid;
  place-items: center;
  margin-bottom: 7px;
  border-radius: 50%;
  background: linear-gradient(140deg, #fb923c, #ea580c);
  color: #fff;
  font-size: 29px;
  box-shadow: 0 10px 24px rgba(234, 88, 12, .28);
}
[data-tool="image-crop"] .upload-title { font-size: 18px; font-weight: 800; color: var(--cr-ink); }
[data-tool="image-crop"] .upload-sub   { font-size: 12.5px; color: var(--cr-mut); margin: 1px 0; }
[data-tool="image-crop"] .upload-mini {
  margin-top: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--cr-mut);
}
[data-tool="image-crop"] .upload-note {
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  color: #067647;
}
[data-tool="image-crop"] .cr-choose {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 4px;
  padding: 9.5px 22px;
  border: 1px solid var(--cr-line);
  border-radius: 11px;
  background: #fff;
  color: var(--cr-ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(16,24,40,.06);
  transition: border-color .12s, box-shadow .12s;
}
[data-tool="image-crop"] .cr-choose:hover {
  border-color: #ea580c;
  box-shadow: 0 6px 16px rgba(234,88,12,.16);
}
/* Floating format chips, same device the Resize dropzone uses. */
[data-tool="image-crop"] .cr-float {
  position: absolute;
  padding: 5px 10px;
  border: 1px solid #ffedd5;
  border-radius: 10px;
  background: #fff;
  font-size: 11px;
  font-weight: 800;
  color: var(--cr-mut);
  box-shadow: 0 6px 16px rgba(16,24,40,.08);
  pointer-events: none;
}
[data-tool="image-crop"] .cr-float-1 { top: 16%;  left: 9%; }
[data-tool="image-crop"] .cr-float-2 { bottom: 18%; left: 14%; }
[data-tool="image-crop"] .cr-float-3 { top: 22%;  right: 11%; }
[data-tool="image-crop"] .cr-float-4 { bottom: 15%; right: 8%; }
@media (max-width: 1100px) { [data-tool="image-crop"] .cr-float { display: none; } }

html.dark [data-tool="image-crop"] .cr-upload {
  border-color: #2a3a4a;
  background: linear-gradient(180deg, #141922, #12151c);
}
html.dark [data-tool="image-crop"] .cr-float,
html.dark [data-tool="image-crop"] .cr-choose { background: #12151c; border-color: var(--cr-line); }

/* ── stage ─────────────────────────────────────────────────────────────── */
[data-tool="image-crop"] .cr-stage {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 380px;
  padding: 16px;
  border-radius: 16px;
  /* ⚠ MUST clip. The crop scrim is a 0 0 0 9999px spread shadow on .cr-box, and
     with nothing clipping it that shadow paints over the ENTIRE page — the whole
     screen turns black the moment the selection is smaller than the image.
     Clipping here rather than on .cr-canvas-wrap is deliberate: the handles
     overhang the box by 7px and this container has 16px of padding, so they
     survive even when the selection is flush against an image edge. */
  overflow: hidden;
  /* Checkerboard: a transparent PNG must read as transparent, not as white. */
  background-color: #f2f4f7;
  background-image:
    linear-gradient(45deg, #e4e7ec 25%, transparent 25%, transparent 75%, #e4e7ec 75%),
    linear-gradient(45deg, #e4e7ec 25%, transparent 25%, transparent 75%, #e4e7ec 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
}
[data-tool="image-crop"] .cr-canvas-wrap {
  position: relative;
  line-height: 0;
  touch-action: none;          /* pointer drag must not scroll the page */
  cursor: crosshair;
}
[data-tool="image-crop"] .cr-canvas-wrap canvas { display: block; border-radius: 4px; }

/* ── crop box ──────────────────────────────────────────────────────────── */
[data-tool="image-crop"] .cr-box {
  position: absolute;
  box-sizing: border-box;
  border: 1.5px solid #fff;
  cursor: move;
  /* The scrim outside the selection, done with a huge spread shadow so there
     is no second element to keep in sync with the box. */
  box-shadow: 0 0 0 9999px rgba(16, 24, 40, 0.55);
}
[data-tool="image-crop"] .cr-box::before,
[data-tool="image-crop"] .cr-box::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-repeat: no-repeat;
}
/* rule-of-thirds guides */
[data-tool="image-crop"] .cr-box::before {
  background-image:
    linear-gradient(rgba(255,255,255,.45) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.45) 1px, transparent 1px);
  background-size: 100% 33.333%, 100% 66.666%;
  background-position: 0 33.333%, 0 66.666%;
}
[data-tool="image-crop"] .cr-box::after {
  background-image:
    linear-gradient(90deg, rgba(255,255,255,.45) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.45) 1px, transparent 1px);
  background-size: 33.333% 100%, 66.666% 100%;
  background-position: 33.333% 0, 66.666% 0;
}
[data-tool="image-crop"] .cr-h {
  position: absolute;
  width: 12px; height: 12px;
  background: #fff;
  border: 1.5px solid var(--cr-blue);
  border-radius: 3px;
  z-index: 2;
}
[data-tool="image-crop"] .cr-h-nw { top: -7px; left: -7px; cursor: nwse-resize; }
[data-tool="image-crop"] .cr-h-ne { top: -7px; right: -7px; cursor: nesw-resize; }
[data-tool="image-crop"] .cr-h-sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
[data-tool="image-crop"] .cr-h-se { bottom: -7px; right: -7px; cursor: nwse-resize; }
[data-tool="image-crop"] .cr-h-n  { top: -7px; left: 50%; margin-left: -6px; cursor: ns-resize; }
[data-tool="image-crop"] .cr-h-s  { bottom: -7px; left: 50%; margin-left: -6px; cursor: ns-resize; }
[data-tool="image-crop"] .cr-h-w  { left: -7px; top: 50%; margin-top: -6px; cursor: ew-resize; }
[data-tool="image-crop"] .cr-h-e  { right: -7px; top: 50%; margin-top: -6px; cursor: ew-resize; }

[data-tool="image-crop"] .cr-dim {
  position: absolute;
  left: 50%; bottom: -30px;
  transform: translateX(-50%);
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(16,24,40,.86);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

/* ── side panel ────────────────────────────────────────────────────────── */
[data-tool="image-crop"] .cr-side {
  border: 1px solid var(--cr-line);
  border-radius: 14px;
  background: #fff;
  padding: 16px;
}
[data-tool="image-crop"] .cr-grp { margin-bottom: 16px; }
[data-tool="image-crop"] .cr-grp-h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 9px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--cr-mut);
}
[data-tool="image-crop"] .cr-unit { font-weight: 600; letter-spacing: 0; text-transform: none; }

[data-tool="image-crop"] .cr-ratios { display: flex; flex-wrap: wrap; gap: 6px; }
[data-tool="image-crop"] .cr-chip {
  padding: 6px 11px;
  border: 1px solid var(--cr-line);
  border-radius: 999px;
  background: #fff;
  color: var(--cr-ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
[data-tool="image-crop"] .cr-chip:hover { border-color: var(--cr-blue); }
[data-tool="image-crop"] .cr-chip.on {
  background: var(--cr-blue);
  border-color: var(--cr-blue);
  color: #fff;
}

[data-tool="image-crop"] .cr-nums {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 9px;
}
[data-tool="image-crop"] .cr-num { display: flex; align-items: center; gap: 7px; }
[data-tool="image-crop"] .cr-num span {
  width: 15px;
  font-size: 11px;
  font-weight: 800;
  color: var(--cr-mut);
}
[data-tool="image-crop"] .cr-num input {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--cr-line);
  border-radius: 8px;
  font: inherit;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--cr-ink);
  background: #fff;
}
[data-tool="image-crop"] .cr-num input:focus {
  outline: none;
  border-color: var(--cr-blue);
  box-shadow: 0 0 0 3px rgba(17,89,218,.12);
}

[data-tool="image-crop"] .cr-row { display: flex; gap: 8px; margin-bottom: 8px; }
[data-tool="image-crop"] .cr-row-4 > * { flex: 1; }
[data-tool="image-crop"] .cr-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--cr-line);
  border-radius: 9px;
  background: #fff;
  color: var(--cr-ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
[data-tool="image-crop"] .cr-btn:hover { background: var(--cr-soft); border-color: var(--cr-blue); }
[data-tool="image-crop"] .cr-btn-primary {
  background: var(--cr-blue);
  border-color: var(--cr-blue);
  color: #fff;
}
[data-tool="image-crop"] .cr-btn-primary:hover { background: #0d3f9e; border-color: #0d3f9e; }
[data-tool="image-crop"] .cr-ico { flex: 1; padding: 0; font-size: 14px; }
[data-tool="image-crop"] .cr-wide { flex: 1 1 100%; }

[data-tool="image-crop"] .cr-out {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 11px 12px;
  border-radius: 10px;
  background: var(--cr-soft);
}
[data-tool="image-crop"] .cr-out b {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--cr-ink);
}
[data-tool="image-crop"] .cr-out span { font-size: 11.5px; color: var(--cr-mut); }

[data-tool="image-crop"] .cr-note {
  margin: 10px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--cr-mut);
}

@media (max-width: 900px) {
  [data-tool="image-crop"] .cr-wrap { grid-template-columns: minmax(0, 1fr); }
}

/* ── dark ──────────────────────────────────────────────────────────────── */
html.dark [data-tool="image-crop"] {
  --cr-line: #2a2f3a;
  --cr-ink: #e8eaef;
  --cr-mut: #9aa1ad;
  --cr-soft: #161a22;
}
html.dark [data-tool="image-crop"] .cr-side,
html.dark [data-tool="image-crop"] .cr-chip,
html.dark [data-tool="image-crop"] .cr-btn,
html.dark [data-tool="image-crop"] .cr-num input { background: #12151c; }
html.dark [data-tool="image-crop"] .cr-stage { background-color: #1b1f27; }
html.dark [data-tool="image-crop"] .cr-stage {
  background-image:
    linear-gradient(45deg, #232833 25%, transparent 25%, transparent 75%, #232833 75%),
    linear-gradient(45deg, #232833 25%, transparent 25%, transparent 75%, #232833 75%);
}
html.dark [data-tool="image-crop"] .cr-chip.on,
html.dark [data-tool="image-crop"] .cr-btn-primary { background: var(--cr-blue); color: #fff; }

/* ── hero band ─────────────────────────────────────────────────────────────
   Deliberately minimal. The suite's global wordmark rule already styles
   .cr-hero-title in Anton; this only spaces the band and the badge. */
[data-tool="image-crop"] .cr-hero-band { position: relative; padding: 6px 18px 2px; }
[data-tool="image-crop"] .cr-hero-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
[data-tool="image-crop"] .cr-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #ecfdf3;
  color: #067647;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .02em;
  white-space: nowrap;
}
[data-tool="image-crop"] .cr-hero-lead {
  margin: 6px 0 0;
  max-width: 68ch;
  font-size: 13px;
  line-height: 1.55;
  color: var(--cr-mut);
}
html.dark [data-tool="image-crop"] .cr-hero-badge { background: #12261c; color: #6ee7b7; }

/* ── delivery preset + output size ─────────────────────────────────────── */
[data-tool="image-crop"] .cr-sel {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--cr-line);
  border-radius: 9px;
  background: #fff;
  color: var(--cr-ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
[data-tool="image-crop"] .cr-sel:focus {
  outline: none;
  border-color: var(--cr-blue);
  box-shadow: 0 0 0 3px rgba(17,89,218,.12);
}
[data-tool="image-crop"] .cr-nums-out { margin-bottom: 8px; }
[data-tool="image-crop"] .cr-warn {
  margin: 2px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fffaeb;
  color: #93370d;
  font-size: 11px;
  line-height: 1.45;
}
/* The canvas takes keyboard focus for arrow-key nudging, so it must SHOW that
   it has focus — otherwise the keys look broken until you happen to click. */
[data-tool="image-crop"] .cr-canvas-wrap:focus-visible {
  outline: 2px solid var(--cr-blue);
  outline-offset: 3px;
}
html.dark [data-tool="image-crop"] .cr-sel { background: #12151c; }
html.dark [data-tool="image-crop"] .cr-warn { background: #2a2416; color: #fbbf24; }

/* ── panel: visible always, actionable only with an image ──────────────────
   The controls are the tool's pitch, so they stay on screen from the first
   moment. Dimmed + disabled reads as "not yet", where a hidden panel reads as
   "not here". */
[data-tool="image-crop"] .cr-side.is-empty .cr-grp,
[data-tool="image-crop"] .cr-side.is-empty .cr-out,
[data-tool="image-crop"] .cr-side.is-empty .cr-row { opacity: .55; }
[data-tool="image-crop"] .cr-side.is-empty .cr-note { opacity: .8; }
[data-tool="image-crop"] .cr-side :disabled { cursor: not-allowed; }
[data-tool="image-crop"] .cr-side .cr-chip:disabled:hover { border-color: var(--cr-line); }
[data-tool="image-crop"] .cr-side .cr-btn:disabled:hover { background: #fff; border-color: var(--cr-line); }
[data-tool="image-crop"] .cr-side .cr-btn-primary:disabled { background: #98a2b3; border-color: #98a2b3; }
[data-tool="image-crop"] .cr-side .cr-btn-primary:disabled:hover { background: #98a2b3; border-color: #98a2b3; }
html.dark [data-tool="image-crop"] .cr-side .cr-btn:disabled:hover { background: #12151c; }
