/**
 * Recortar imagem — crop studio (full-width).
 * Layout: top bar + left settings rail (ImageResizer-inspired) + main stage.
 * Light default; follows html[data-theme="dark"].
 */

/* ---- Workspace shell ---- */
body.is-fullscreen .fs-workspace.icrop-fs {
  --ic-bg: #eef1f6;
  --ic-app: #ffffff;
  --ic-line: #e2e8f0;
  --ic-text: var(--dica-ink, #0f172a);
  --ic-muted: var(--dica-muted, #64748b);
  --ic-faint: #94a3b8;
  --ic-accent: #fa5b0f;
  --ic-accent-2: #e04f0a;
  --ic-btn: #eef2f7;
  --ic-btn-hover: #e2e8f0;
  --ic-stage: #e8ecf2;
  --ic-stage-inner: #eef1f6;
  --ic-topbar: #f8fafc;
  --ic-side: #f8fafc;
  --ic-card: #ffffff;
  --ic-input: #ffffff;
  --ic-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 32px rgba(15, 23, 42, 0.07);
  --ic-handle: #fff;
  --ic-dim: rgba(15, 23, 42, 0.45);
  --ic-crop-line: #2563eb;
  --ic-good: #079455;
  --ic-drop-border: #cbd5e1;
  --ic-drop-bg: rgba(255, 255, 255, 0.72);
  --ic-drop-text: var(--dica-ink, #0f172a);
  --ic-drop-muted: var(--dica-muted, #64748b);
  --ic-meta-bg: rgba(15, 23, 42, 0.72);
  --ic-canvas-shadow: 0 4px 24px rgba(15, 23, 42, 0.12);

  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  padding: 12px 14px 16px !important;
  box-sizing: border-box;
  background: var(--ic-bg) !important;
  border-color: var(--ic-line) !important;
  color: var(--ic-text);
  min-height: min(78vh, 900px) !important;
  height: min(calc(100vh - 120px), 920px);
  overflow: hidden;
}

html[data-theme="dark"] body.is-fullscreen .fs-workspace.icrop-fs {
  --ic-bg: #0b0e14;
  --ic-app: #151922;
  --ic-line: #2a3140;
  --ic-text: #e8eef6;
  --ic-muted: rgba(232, 238, 246, 0.62);
  --ic-faint: rgba(232, 238, 246, 0.42);
  --ic-btn: rgba(255, 255, 255, 0.08);
  --ic-btn-hover: rgba(255, 255, 255, 0.14);
  --ic-stage: #080b11;
  --ic-stage-inner: #0a0e14;
  --ic-topbar: #1a2030;
  --ic-side: #1a2030;
  --ic-card: rgba(255, 255, 255, 0.04);
  --ic-input: rgba(0, 0, 0, 0.28);
  --ic-shadow: none;
  --ic-handle: #fff;
  --ic-dim: rgba(0, 0, 0, 0.62);
  --ic-crop-line: #93c5fd;
  --ic-drop-border: rgba(255, 255, 255, 0.18);
  --ic-drop-bg: rgba(255, 255, 255, 0.04);
  --ic-drop-text: rgba(255, 255, 255, 0.88);
  --ic-drop-muted: rgba(255, 255, 255, 0.55);
  --ic-meta-bg: rgba(0, 0, 0, 0.55);
  --ic-canvas-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  background: var(--ic-bg) !important;
  border-color: #0a0e14 !important;
}

.icrop-app {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  height: 100%;
  min-height: min(70vh, 860px);
  width: 100%;
  min-width: 0;
  background: var(--ic-app);
  color: var(--ic-text);
  border-radius: 18px;
  border: 1px solid var(--ic-line);
  box-shadow: var(--ic-shadow);
  overflow: hidden;
  position: relative;
}

.icrop-app * {
  box-sizing: border-box;
}

.icrop-app p {
  margin: 0;
}

/* Studio chrome (topbar + stage) keeps remaining height; pipeline never covers canvas */
.icrop-shell {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.icrop-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---- Top bar ---- */
.icrop-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--ic-line);
  background: var(--ic-topbar);
  min-height: 52px;
}

.icrop-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 0 1 auto;
}

.icrop-brand {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ic-accent);
  color: #fff;
  flex-shrink: 0;
}

.icrop-brand svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.icrop-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.icrop-brand-text strong {
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.icrop-file-meta {
  font-size: 0.72rem;
  color: var(--ic-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(320px, 42vw);
}

.icrop-aspect-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
}

.icrop-tool {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ic-muted);
  background: var(--ic-btn);
  border: 1px solid var(--ic-line);
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.icrop-tool:hover:not(:disabled) {
  background: var(--ic-btn-hover);
  color: var(--ic-text);
}

.icrop-tool.is-active {
  color: var(--ic-accent);
  border-color: rgba(250, 91, 15, 0.45);
  background: rgba(250, 91, 15, 0.1);
}

.icrop-tool:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icrop-tool-ico {
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0.9;
}

.icrop-topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
}

/* Buttons */
.icrop-btn {
  appearance: none;
  border: 1px solid var(--ic-line);
  background: var(--ic-btn);
  color: var(--ic-text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease,
    transform 0.12s ease;
}

.icrop-btn:hover:not(:disabled) {
  background: var(--ic-btn-hover);
}

.icrop-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icrop-btn:not(:disabled):active {
  transform: scale(0.98);
}

.icrop-btn:focus-visible {
  outline: 2px solid var(--ic-accent);
  outline-offset: 2px;
}

.icrop-btn-ghost {
  background: transparent;
}

.icrop-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--ic-accent);
  border-color: var(--ic-accent);
  color: #fff;
  min-width: 120px;
  box-shadow: 0 2px 10px rgba(250, 91, 15, 0.28);
}

.icrop-btn-primary:hover:not(:disabled) {
  background: var(--ic-accent-2);
  border-color: var(--ic-accent-2);
}

.icrop-btn-primary svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.icrop-btn-block {
  width: 100%;
  min-width: 0;
  padding: 12px 16px;
  font-size: 0.92rem;
}

/* ---- Body: sidebar + main ---- */
.icrop-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* ---- Left rail (ImageResizer-style Crop settings) ---- */
.icrop-sidebar {
  flex: 0 0 min(280px, 34vw);
  width: min(280px, 34vw);
  max-width: 300px;
  min-width: 230px;
  display: flex;
  flex-direction: column;
  gap: 0;
  border-right: 1px solid var(--ic-line);
  background: var(--ic-side);
  overflow: auto;
  overscroll-behavior: contain;
}

.icrop-side-head {
  padding: 14px 14px 8px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ic-faint);
}

.icrop-side-block {
  padding: 0 14px 14px;
  border-bottom: 1px solid var(--ic-line);
}

.icrop-side-block:last-of-type {
  border-bottom: 0;
}

.icrop-side-title {
  display: block;
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ic-text);
  letter-spacing: -0.01em;
}

.icrop-field {
  margin-bottom: 10px;
}

.icrop-field:last-child {
  margin-bottom: 0;
}

.icrop-field label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ic-faint);
  margin: 0 0 4px 1px;
}

.icrop-field select,
.icrop-field input[type="number"],
.icrop-field input[type="text"] {
  width: 100%;
  background: var(--ic-input);
  color: var(--ic-text);
  border: 1px solid var(--ic-line);
  border-radius: 10px;
  padding: 9px 11px;
  font: inherit;
  font-size: 0.88rem;
  outline: none;
}

.icrop-field select {
  cursor: pointer;
}

.icrop-field select option {
  color: #111;
}

.icrop-field select:disabled,
.icrop-field input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icrop-field input:focus-visible,
.icrop-field select:focus-visible {
  outline: 2px solid var(--ic-accent);
  outline-offset: 1px;
}

.icrop-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.icrop-field input[type="range"] {
  width: 100%;
  accent-color: var(--ic-accent);
  cursor: pointer;
}

.icrop-range-val {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ic-text);
}

.icrop-hint {
  margin-top: 8px;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--ic-muted);
}

.icrop-hint a {
  color: var(--ic-accent);
  text-decoration: none;
  font-weight: 600;
}

.icrop-hint a:hover {
  text-decoration: underline;
}

.icrop-status {
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--ic-muted);
  min-height: 1.2em;
}

.icrop-status.is-ok {
  color: var(--ic-good);
}

.icrop-status.is-error {
  color: #d92d20;
}

.icrop-status.is-loading {
  color: var(--ic-accent);
}

.icrop-side-actions {
  padding: 14px;
  margin-top: auto;
  border-top: 1px solid var(--ic-line);
  background: var(--ic-side);
  position: sticky;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Result card in sidebar */
.icrop-result {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.icrop-app.has-result .icrop-result {
  display: flex;
}

.icrop-result-name {
  font-size: 0.78rem;
  font-weight: 700;
  word-break: break-all;
  color: var(--ic-text);
}

.icrop-result-sub {
  font-size: 0.72rem;
  color: var(--ic-muted);
}

.icrop-result-img {
  display: block;
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--ic-line);
  background:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-color: #f8fafc;
}

html[data-theme="dark"] .icrop-result-img {
  background-color: #1a2030;
}

/* ---- Main stage ---- */
.icrop-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--ic-stage);
  overflow: hidden;
}

.icrop-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--ic-stage-inner);
}

/* Drop zone (empty state) */
.icrop-drop {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 20px;
  padding: 36px 24px;
  max-width: 480px;
  width: calc(100% - 40px);
  border: 2px dashed var(--ic-drop-border);
  border-radius: 16px;
  background: var(--ic-drop-bg);
  cursor: pointer;
  text-align: center;
  outline: none;
  color: var(--ic-drop-text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.icrop-app.is-empty .icrop-drop {
  display: flex;
}

.icrop-drop:hover,
.icrop-drop:focus-visible,
.icrop-drop.is-dragover {
  border-color: var(--ic-accent);
  background: rgba(250, 91, 15, 0.08);
}

.icrop-drop-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(250, 91, 15, 0.12);
  color: var(--ic-accent);
  margin-bottom: 4px;
}

.icrop-drop-icon svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

.icrop-drop h3 {
  margin: 4px 0 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ic-drop-text);
}

.icrop-drop-hint {
  font-size: 0.82rem;
  color: var(--ic-drop-muted);
  line-height: 1.4;
}

.icrop-drop .icrop-btn-primary {
  margin-top: 10px;
}

/* Canvas viewport */
.icrop-viewport {
  display: none;
  position: relative;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  touch-action: none;
  user-select: none;
}

.icrop-app:not(.is-empty) .icrop-viewport {
  display: block;
}

.icrop-viewport canvas {
  display: block;
  max-width: 100%;
  max-height: min(70vh, 100%);
  width: auto;
  height: auto;
  cursor: crosshair;
  border-radius: 4px;
  box-shadow: var(--ic-canvas-shadow);
  border: 1px solid var(--ic-line);
}

.icrop-meta-bar {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: var(--ic-meta-bg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 5px 10px;
  pointer-events: none;
  backdrop-filter: blur(6px);
}

.icrop-app.is-empty .icrop-meta-bar {
  display: none;
}

/* Pipeline footer: Próximo + Recentes (below shell, never overlays the canvas) */
.icrop-pipeline {
  flex: 0 0 auto;
  max-height: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  border-top: 0;
  background: var(--ic-topbar);
  transition: max-height 0.15s ease;
}

.icrop-pipeline.is-open,
.icrop-app.has-pipeline .icrop-pipeline {
  max-height: min(160px, 24vh);
  overflow: auto;
  border-top: 1px solid var(--ic-line);
}

.icrop-app .itool-next,
.icrop-app .rbg-next,
.icrop-app .itool-hist-host,
.icrop-app .itool-history-host {
  margin: 0;
  padding: 8px 12px;
  border-top: 0;
  background: transparent;
  flex: 0 0 auto;
}

.icrop-pipeline > * + * {
  border-top: 1px solid var(--ic-line);
}

.icrop-app .itool-success {
  margin: 0;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}

/* Busy */
.icrop-app.is-busy {
  pointer-events: none;
}

.icrop-app .itool-busy-banner {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
}

/* Toast host */
.icrop-app .itool-toast {
  z-index: 40;
}

/* ---- Mobile ---- */
@media (max-width: 820px) {
  body.is-fullscreen .fs-workspace.icrop-fs {
    height: auto;
    min-height: min(88vh, 960px) !important;
    padding: 8px 8px 12px !important;
  }

  .icrop-app {
    min-height: min(82vh, 920px);
  }

  .icrop-body {
    flex-direction: column;
  }

  .icrop-sidebar {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    min-width: 0;
    border-right: 0;
    border-bottom: 1px solid var(--ic-line);
    max-height: 42vh;
  }

  .icrop-side-actions {
    position: static;
  }

  .icrop-aspect-tools {
    order: 3;
    width: 100%;
    flex-basis: 100%;
  }

  .icrop-tool-label {
    display: none;
  }

  .icrop-stage {
    min-height: 280px;
  }
}

@media (max-width: 480px) {
  .icrop-brand-text strong {
    font-size: 0.82rem;
  }

  .icrop-file-meta {
    max-width: 46vw;
  }

  .icrop-btn {
    padding: 7px 10px;
    font-size: 0.78rem;
  }
}

/* Feature cards under the tool (SEO body) */
.icrop-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 0 0 28px;
}

.icrop-feature {
  border: 1px solid var(--dica-border, #e4e9f2);
  border-radius: 14px;
  padding: 16px;
  background: var(--dica-surface, #fff);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
}

.icrop-feature-title {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--dica-ink, #0f172a);
}

.icrop-feature-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--dica-body, #344054);
}

.icrop-faq details {
  margin-bottom: 8px;
  border: 1px solid var(--dica-border, #e4e9f2);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--dica-surface, #fff);
}

.icrop-faq summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--dica-ink, #0f172a);
}

.icrop-faq details p {
  margin: 8px 0 0;
  color: var(--dica-body, #344054);
  line-height: 1.5;
}
