/* OpenPress Image Cropper interface (task 043 foundation, task 043A crop workspace). Loaded on the Image Cropper Free Tool page only, after
   free-tool-single.css, inside the .op-free-tool-interface frame. Uses the theme's global tokens and the shared .op-btn, so light and
   dark follow the theme switch. Same visual language as the Image Resizer; all selectors start with .op-ic. Presentation only.
   Reduced motion: main.css zeroes transitions globally; the transitions here are also switched off below. */

.op-ic { --op-ic-error: #B42318; --op-ic-zone: #F1F3F5; display: grid; gap: 1.5rem; min-width: 0; }
@media (prefers-color-scheme: dark) {
	.op-ic { --op-ic-error: #F97066; --op-ic-zone: #171D33; }
	:root[data-theme="light"] .op-ic { --op-ic-error: #B42318; --op-ic-zone: #F1F3F5; }
}
:root[data-theme="dark"] .op-ic { --op-ic-error: #F97066; --op-ic-zone: #171D33; }

/* Heading ----------------------------------------------------------------- */
.op-ic__intro { display: grid; gap: 0.25rem; min-width: 0; }
.op-ic__heading { margin: 0; color: var(--op-text); font-family: var(--op-font-display); font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; overflow-wrap: anywhere; }
.op-ic__lede { margin: 0; color: var(--op-text-muted); font-size: 0.875rem; line-height: 1.4; }
.op-ic__section-title { margin: 0; color: var(--op-text-muted); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }

/* Upload zone -------------------------------------------------------------- */
.op-ic__zone { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; min-width: 0; padding: 2.5rem 1.5rem; background: var(--op-ic-zone); border: 1.5px dashed var(--op-border-strong); border-radius: 1.25rem; text-align: center; transition: border-color var(--op-transition), background-color var(--op-transition); }
.op-ic__zone[hidden] { display: none; }
.op-ic__zone:hover,
.op-ic__zone:focus-within { border-color: var(--op-btn-bg); }
.op-ic__zone[data-dragging="true"] { border-style: solid; border-color: var(--op-btn-bg); background: color-mix(in srgb, var(--op-btn-bg) 12%, var(--op-ic-zone)); }
.op-ic__zone:has(.op-ic__input:focus-visible) { border-style: solid; border-color: var(--op-focus); }
.op-ic__zone-icon { display: grid; place-items: center; color: var(--op-link); }
.op-ic__zone-title { margin: 0; color: var(--op-text); font-size: 1.0625rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.op-ic__zone-or { margin: 0; color: var(--op-text-muted); font-size: 0.875rem; }
.op-ic__input { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; opacity: 0; clip-path: inset(50%); pointer-events: none; }
.op-ic__choose { min-width: 12rem; max-width: 100%; min-height: 3rem; padding: 0 1.5rem; border-radius: 0.75rem; font-size: 0.9375rem; font-weight: 600; cursor: pointer; }
.op-ic__input:focus-visible + .op-ic__choose { outline: 3px solid var(--op-focus); outline-offset: 3px; }
.op-ic__hint { display: grid; gap: 0.25rem; margin-top: 0.5rem; min-width: 0; }
.op-ic__formats,
.op-ic__limit { margin: 0; color: var(--op-text-muted); font-size: 0.8125rem; line-height: 1.4; }
.op-ic__trust { display: flex; align-items: flex-start; justify-content: center; gap: 0.5rem; margin: 0.25rem 0 0; color: var(--op-text-muted); font-size: 0.8125rem; line-height: 1.4; text-align: left; }
.op-ic__trust svg { flex: none; margin-top: 1px; color: var(--op-link); }
.op-ic__trust span { min-width: 0; overflow-wrap: anywhere; }

/* Message box: error (default) and info ------------------------------------ */
.op-ic__message { display: flex; align-items: flex-start; gap: 0.75rem; min-width: 0; padding: 0.75rem 1rem; color: var(--op-ic-error); background: color-mix(in srgb, var(--op-ic-error) 8%, var(--op-bg-elevated)); border: 1px solid color-mix(in srgb, var(--op-ic-error) 40%, var(--op-border)); border-radius: 0.75rem; }
.op-ic__message[data-kind="info"] { color: var(--op-text); background: var(--op-bg-elevated); border-color: var(--op-border-strong); }
.op-ic__message[hidden] { display: none; }
.op-ic__message-icon { flex: none; margin-top: 1px; }
.op-ic__message-body { display: grid; gap: 0.125rem; min-width: 0; }
.op-ic__message-title { font-size: 0.9375rem; font-weight: 700; line-height: 1.3; }
.op-ic__message-text { margin: 0; color: var(--op-text); font-size: 0.875rem; line-height: 1.4; overflow-wrap: anywhere; }

/* Selected image ----------------------------------------------------------- */
.op-ic__file { display: grid; gap: 0.75rem; min-width: 0; padding: 1rem; background: var(--op-bg-elevated); border: 1px solid var(--op-border); border-radius: 0.75rem; box-shadow: var(--op-shadow-sm); }
.op-ic__file[hidden] { display: none; }
.op-ic__file-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; min-width: 0; }
.op-ic__name { min-width: 0; color: var(--op-text); font-size: 1rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.op-ic__remove { flex: none; min-height: 2.75rem; }
.op-ic__facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.75rem; margin: 0; min-width: 0; }
.op-ic__fact { display: grid; gap: 0.125rem; min-width: 0; }
.op-ic__fact dt { color: var(--op-text-muted); font-size: 0.8125rem; font-weight: 500; }
.op-ic__fact dd { margin: 0; color: var(--op-text); font-size: 0.9375rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }

/* Controls ----------------------------------------------------------------- */
.op-ic__controls { display: grid; gap: 0.75rem; min-width: 0; }
.op-ic__fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; min-width: 0; }
.op-ic__field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.375rem; min-width: 0; }
.op-ic__label { color: var(--op-text); font-size: 0.9375rem; font-weight: 600; line-height: 1.3; }
.op-ic__number { display: block; width: 100%; min-width: 0; min-height: 2.75rem; margin: 0; padding: 0 0.75rem; background: var(--op-bg); border: 1px solid var(--op-border-strong); border-radius: 0.75rem; color: var(--op-text); font-family: inherit; font-size: 1rem; font-variant-numeric: tabular-nums; transition: border-color var(--op-transition), background-color var(--op-transition); }
.op-ic__number::placeholder { color: var(--op-text-muted); opacity: 1; }
.op-ic__number:hover:not(:disabled) { border-color: color-mix(in srgb, var(--op-btn-bg) 45%, var(--op-border-strong)); }
.op-ic__number:focus { border-color: var(--op-focus); background: var(--op-bg-elevated); }
.op-ic__number:focus-visible { outline: 3px solid var(--op-focus); outline-offset: 2px; }
.op-ic__number:disabled { opacity: 0.5; cursor: not-allowed; }
.op-ic__lock { display: inline-flex; align-items: center; gap: 0.75rem; min-height: 2.75rem; color: var(--op-text); font-size: 0.9375rem; line-height: 1.3; cursor: pointer; }
.op-ic__checkbox { flex: none; width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--op-btn-bg); cursor: pointer; }
.op-ic__checkbox:focus-visible { outline: 3px solid var(--op-focus); outline-offset: 2px; }
.op-ic__checkbox:disabled { opacity: 0.5; cursor: not-allowed; }
.op-ic__lock:has(:disabled) { color: var(--op-text-muted); cursor: not-allowed; }

.op-ic__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; min-width: 0; }
.op-ic__crop,
.op-ic__clear,
.op-ic__download { min-height: 2.75rem; }
.op-ic__clear:focus-visible,
.op-ic__download:focus-visible,
.op-ic__remove:focus-visible { outline: 3px solid var(--op-focus); outline-offset: 2px; }
.op-ic__clear[aria-disabled="true"],
.op-ic__download[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: auto; }
.op-ic__clear[aria-disabled="true"]:active,
.op-ic__download[aria-disabled="true"]:active { transform: none; box-shadow: none; }

/* Unit suffix on the crop fields ---------------------------------------------------------------------- */
.op-ic__control { position: relative; display: block; min-width: 0; }
.op-ic__control .op-ic__number { padding-right: 2.5rem; }
.op-ic__unit { position: absolute; top: 50%; right: 0.75rem; transform: translateY(-50%); color: var(--op-text-muted); font-size: 0.875rem; pointer-events: none; }

/* Result panel ------------------------------------------------------------- */
.op-ic__output { display: grid; gap: 0.75rem; min-width: 0; padding: 1rem; background: var(--op-bg-elevated); border: 1px solid var(--op-border); border-radius: 0.75rem; box-shadow: var(--op-shadow-sm); }
.op-ic__empty { display: grid; place-items: center; min-height: 8rem; padding: 1.5rem 1rem; text-align: center; border: 1px dashed var(--op-border-strong); border-radius: 0.75rem; }
.op-ic__empty-title { margin: 0; color: var(--op-text-muted); font-size: 1rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.op-ic__result { display: grid; gap: 0.75rem; min-width: 0; }
.op-ic__result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; }
.op-ic__empty[hidden],
.op-ic__result[hidden],
.op-ic__result-actions[hidden] { display: none; }

@media (min-width: 768px) {
	.op-ic__output { padding: 1.25rem; }
	.op-ic__zone { padding: 3rem 1.5rem; }
}
@media (max-width: 480px) {
	.op-ic__zone { padding: 2rem 1rem; }
	.op-ic__actions > .op-btn { flex: 1 1 100%; }
	.op-ic__choose { width: 100%; min-width: 0; }
}

/* Crop workspace (foundation: an empty message and a reserved stage for task 043A) ------------------------ */
.op-ic__workspace { display: grid; gap: 0.75rem; min-width: 0; padding: 1rem; background: var(--op-bg-elevated); border: 1px solid var(--op-border); border-radius: 0.75rem; box-shadow: var(--op-shadow-sm); }
.op-ic__workspace-empty { display: grid; place-items: center; min-height: 12rem; padding: 1.5rem 1rem; text-align: center; background: var(--op-ic-zone); border: 1px dashed var(--op-border-strong); border-radius: 0.75rem; }
.op-ic__stage { display: grid; place-items: center; min-width: 0; padding: 0.5rem; overflow: hidden; background: var(--op-ic-zone); border: 1px solid var(--op-border); border-radius: 0.75rem; user-select: none; -webkit-user-select: none; }
.op-ic__presets { min-width: 0; }
.op-ic__workspace-empty[hidden],
.op-ic__stage[hidden],
.op-ic__presets[hidden] { display: none; }
.op-ic__crop,
.op-ic__clear { min-width: 8rem; }
.op-ic__crop[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: auto; }
.op-ic__crop:focus-visible { outline: 3px solid var(--op-focus); outline-offset: 2px; }
.op-ic__result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; }
.op-ic__result-actions .op-btn { min-width: 12rem; }
@media (min-width: 768px) { .op-ic__workspace { padding: 1.25rem; } .op-ic__workspace-empty { min-height: 16rem; } }
@media (max-width: 480px) { .op-ic__result-actions .op-btn { flex: 1 1 100%; } }
@media (prefers-reduced-motion: reduce) { .op-ic__zone, .op-ic__number { transition: none; } }

/* 043A crop workspace -------------------------------------------------------------------------------------------------
   The frame has the image's own aspect ratio (--op-ic-w / --op-ic-h are the source pixel size) and never grows taller than 70vh, so a
   portrait image does not push the controls off screen. The selection is placed with percentages of the frame: the crop numbers are
   source pixels and are the same at any display size. Only the selection (and its handles) capture touches: the rest of the page scrolls. */
.op-ic { --op-ic-crop-line: #FFFFFF; --op-ic-crop-edge: rgba(0, 0, 0, 0.7); --op-ic-dim: rgba(0, 0, 0, 0.38); }
.op-ic__frame { position: relative; width: min(100%, calc(70vh * var(--op-ic-w, 1) / var(--op-ic-h, 1))); max-width: 100%; aspect-ratio: var(--op-ic-w, 1) / var(--op-ic-h, 1); margin: 0 auto; overflow: hidden; background-color: var(--op-bg); background-image: linear-gradient(45deg, color-mix(in srgb, var(--op-text) 8%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--op-text) 8%, transparent) 75%), linear-gradient(45deg, color-mix(in srgb, var(--op-text) 8%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--op-text) 8%, transparent) 75%); background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.op-ic__stage-img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; max-width: none; margin: 0; object-fit: fill; pointer-events: none; -webkit-user-drag: none; user-select: none; }
.op-ic__selection { position: absolute; box-sizing: border-box; border: 2px solid var(--op-ic-crop-line); outline: 1px solid var(--op-ic-crop-edge); outline-offset: 0; box-shadow: 0 0 0 100vmax var(--op-ic-dim); cursor: move; touch-action: none; -webkit-tap-highlight-color: transparent; }
.op-ic__selection:focus { outline: 1px solid var(--op-ic-crop-edge); }
.op-ic__selection:focus-visible { outline: 3px solid var(--op-focus); outline-offset: 2px; }
.op-ic__frame[data-dragging] { cursor: grabbing; }
.op-ic__stage[data-busy="true"] .op-ic__selection { cursor: progress; opacity: 0.85; }
.op-ic__handle { position: absolute; width: 14px; height: 14px; box-sizing: border-box; background: var(--op-ic-crop-line); border: 2px solid var(--op-ic-crop-edge); border-radius: 3px; touch-action: none; }
.op-ic__handle::after { content: ""; position: absolute; inset: -15px; } /* a 44 x 44 px touch target around the 14 px square */
.op-ic__handle--nw { top: 0; left: 0; transform: translate(-50%, -50%); cursor: nwse-resize; }
.op-ic__handle--ne { top: 0; left: 100%; transform: translate(-50%, -50%); cursor: nesw-resize; }
.op-ic__handle--sw { top: 100%; left: 0; transform: translate(-50%, -50%); cursor: nesw-resize; }
.op-ic__handle--se { top: 100%; left: 100%; transform: translate(-50%, -50%); cursor: nwse-resize; }
@media (pointer: coarse) { .op-ic__handle { width: 18px; height: 18px; } }

/* Result: cropped image, facts, out-of-date notice -------------------------------------------------------------------- */
.op-ic__result-title { margin: 0; color: var(--op-text); font-size: 1rem; font-weight: 700; line-height: 1.3; }
.op-ic__preview { display: grid; place-items: center; min-width: 0; padding: 0.5rem; overflow: hidden; border: 1px solid var(--op-border); border-radius: 0.75rem; background-color: var(--op-ic-zone); background-image: linear-gradient(45deg, color-mix(in srgb, var(--op-text) 6%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--op-text) 6%, transparent) 75%), linear-gradient(45deg, color-mix(in srgb, var(--op-text) 6%, transparent) 25%, transparent 25%, transparent 75%, color-mix(in srgb, var(--op-text) 6%, transparent) 75%); background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.op-ic__preview-img { display: block; max-width: 100%; height: auto; max-height: 24rem; object-fit: contain; transition: opacity var(--op-transition); }
.op-ic__note { margin: 0; color: var(--op-text-muted); font-size: 0.8125rem; line-height: 1.4; }
.op-ic__stale { margin: 0; padding: 0.5rem 0.75rem; color: var(--op-text); font-size: 0.875rem; font-weight: 600; line-height: 1.4; background: var(--op-ic-zone); border: 1px solid var(--op-border-strong); border-left-width: 4px; border-radius: 0.5rem; }
.op-ic__stale[hidden] { display: none; }
.op-ic__result[data-stale="true"] .op-ic__preview-img { opacity: 0.45; filter: grayscale(0.6); }
.op-ic__result[data-stale="true"] .op-ic__facts { opacity: 0.6; }
/* While cropping the button is aria-disabled too, but its "Cropping…" text is a status message and must stay readable: keep it nearly opaque. */
.op-ic__crop[aria-busy="true"] { cursor: progress; opacity: 0.9; }
@media (prefers-color-scheme: dark) {
	.op-ic { --op-ic-dim: rgba(0, 0, 0, 0.45); }
	:root[data-theme="light"] .op-ic { --op-ic-dim: rgba(0, 0, 0, 0.38); }
}
:root[data-theme="dark"] .op-ic { --op-ic-dim: rgba(0, 0, 0, 0.45); }
@media (max-width: 480px) { .op-ic__stage { padding: 0.25rem; } }
@media (prefers-reduced-motion: reduce) { .op-ic__preview-img { transition: none; } }

/* 043B button hierarchy -------------------------------------------------------------------------------------------------
   One primary action at a time. With a current result Download Image is the primary action and Crop Image steps back to the shared
   secondary look; as soon as the result is stale (or there is no result) Crop Image is primary again and Download is inactive and
   secondary. Both buttons carry .op-btn--primary in the markup; the root's data-state / data-stale decide. Same tokens as .op-btn--secondary. */
.op-ic[data-stale="true"] .op-ic__download,
.op-ic[data-state="result"]:not([data-stale="true"]) .op-ic__crop {
	background: color-mix(in srgb, var(--op-bg-elevated) 80%, transparent);
	border-color: var(--op-border-strong);
	color: var(--op-text);
	box-shadow: none;
}
.op-ic[data-stale="true"] .op-ic__download:hover:not([aria-disabled="true"]),
.op-ic[data-state="result"]:not([data-stale="true"]) .op-ic__crop:hover:not([aria-disabled="true"]) {
	background: var(--op-bg-elevated);
	border-color: var(--op-link);
	color: var(--op-link);
}
