/* ============================================================
   Crop tool — client-side canvas editor.
   Palette and radii come from style.css tokens; nothing new is
   introduced here beyond layout for the editor itself.
   ============================================================ */

.crop-section { padding: 40px 0 56px; background: var(--c-bg); }

/* ---------- Drop zone (shown before an image is loaded) ---------- */
.crop-dropzone {
    background: var(--c-surface);
    border: 2px dashed rgba(240, 114, 38, .35);
    border-radius: var(--radius-lg);
    padding: 56px 24px;
    text-align: center;
    transition: var(--transition);
    cursor: pointer;
}
.crop-dropzone:hover,
.crop-dropzone.is-over {
    border-color: var(--c-primary);
    background: var(--c-bg2);
    box-shadow: 0 12px 40px var(--c-shadow);
}
.crop-dropzone__icon {
    width: 72px; height: 72px; margin: 0 auto 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--c-primary), var(--c-accent2));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 2rem;
}
.crop-dropzone__title {
    font-family: var(--font-head); font-weight: 700;
    font-size: 1.25rem; color: var(--c-text); margin-bottom: 6px;
}
.crop-dropzone__hint { font-size: .9rem; color: var(--c-text-muted); margin-bottom: 20px; }
.crop-dropzone__formats { font-size: .8rem; color: var(--c-text-muted); margin-top: 16px; }
.crop-dropzone__btn {
    background: linear-gradient(135deg, var(--c-primary), var(--c-accent2));
    color: #fff; border: none; border-radius: var(--radius-sm);
    font-family: var(--font-head); font-weight: 700; font-size: .95rem;
    padding: 12px 30px; cursor: pointer; transition: var(--transition);
}
.crop-dropzone__btn:hover { transform: translateY(-2px); box-shadow: 0 10px 26px var(--c-shadow); }

/* ---------- Editor shell ---------- */
.crop-editor { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; }
@media (max-width: 991px) { .crop-editor { grid-template-columns: minmax(0, 1fr); } }

.crop-stage {
    position: relative;
    background: var(--c-surface);
    border: 1.5px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 16px;
    min-height: 380px;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
/* Checkerboard so transparent source images stay readable */
.crop-canvas-wrap {
    position: relative;
    line-height: 0;
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #eee 25%, transparent 25%),
        linear-gradient(-45deg, #eee 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #eee 75%),
        linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    box-shadow: 0 6px 26px rgba(0, 0, 0, .1);
    touch-action: none;
    user-select: none;
}
.crop-canvas-wrap img { display: block; max-width: 100%; height: auto; pointer-events: none; }

/* Dim everything outside the selection */
.crop-shade { position: absolute; inset: 0; pointer-events: none; }
.crop-shade > div { position: absolute; background: rgba(26, 18, 9, .55); }

.crop-box {
    position: absolute;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1px rgba(26, 18, 9, .35);
    cursor: move;
}
.crop-box.is-circle { border-radius: 50%; }

/* Rule-of-thirds guides */
.crop-box__grid { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .18s; }
.crop-box.is-active .crop-box__grid { opacity: 1; }
.crop-box__grid::before,
.crop-box__grid::after {
    content: ''; position: absolute; background: rgba(255, 255, 255, .5);
}
.crop-box__grid::before { left: 33.33%; right: 33.33%; top: 0; bottom: 0; border-left: 1px solid rgba(255,255,255,.5); border-right: 1px solid rgba(255,255,255,.5); background: none; }
.crop-box__grid::after  { top: 33.33%; bottom: 33.33%; left: 0; right: 0; border-top: 1px solid rgba(255,255,255,.5); border-bottom: 1px solid rgba(255,255,255,.5); background: none; }

.crop-handle {
    position: absolute; width: 14px; height: 14px;
    background: var(--c-primary); border: 2px solid #fff; border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.crop-handle[data-h="nw"] { left: -7px;  top: -7px;    cursor: nwse-resize; }
.crop-handle[data-h="ne"] { right: -7px; top: -7px;    cursor: nesw-resize; }
.crop-handle[data-h="sw"] { left: -7px;  bottom: -7px; cursor: nesw-resize; }
.crop-handle[data-h="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-handle[data-h="n"]  { left: 50%; top: -7px;    margin-left: -7px; cursor: ns-resize; }
.crop-handle[data-h="s"]  { left: 50%; bottom: -7px; margin-left: -7px; cursor: ns-resize; }
.crop-handle[data-h="w"]  { top: 50%; left: -7px;    margin-top: -7px;  cursor: ew-resize; }
.crop-handle[data-h="e"]  { top: 50%; right: -7px;   margin-top: -7px;  cursor: ew-resize; }
/* A circular selection can only be resized from the corners */
.crop-box.is-circle .crop-handle[data-h="n"],
.crop-box.is-circle .crop-handle[data-h="s"],
.crop-box.is-circle .crop-handle[data-h="w"],
.crop-box.is-circle .crop-handle[data-h="e"] { display: none; }

/* Live size readout pinned to the selection. The pill is centred by layout
   rather than by translateX(-50%): a half-pixel transform offset makes the
   browser rasterise the label off the pixel grid, which reads as blurry text. */
.crop-box__size {
    position: absolute; left: 0; right: 0; bottom: -30px;
    text-align: center; pointer-events: none;
}
.crop-box__size b {
    display: inline-block; white-space: nowrap;
    background: rgba(26, 18, 9, .82); color: #fff;
    font-size: .72rem; font-weight: 600; letter-spacing: .3px;
    padding: 3px 9px; border-radius: 999px;
}

/* ---------- Control panel ---------- */
.crop-panel {
    background: var(--c-surface);
    border: 1.5px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 18px 18px 20px;
    align-self: start;
}
.crop-panel__group + .crop-panel__group {
    margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--c-border);
}
.crop-panel__title {
    font-family: var(--font-head); font-size: .74rem; font-weight: 700;
    letter-spacing: 1.1px; text-transform: uppercase;
    color: var(--c-text-muted); margin-bottom: 10px;
}
.crop-panel__sublabel {
    font-size: .7rem; color: var(--c-text-muted);
    margin: 12px 0 6px; font-weight: 600;
}

/* Ratio chips */
.crop-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.crop-chip {
    background: var(--c-bg2); border: 1.5px solid transparent;
    border-radius: 999px; padding: 5px 12px;
    font-size: .78rem; font-weight: 600; color: var(--c-text-2);
    cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.crop-chip:hover { border-color: var(--c-primary-l); color: var(--c-primary-d); }
.crop-chip.is-active {
    background: linear-gradient(135deg, var(--c-primary), var(--c-accent2));
    color: #fff; border-color: transparent;
}

/* Numeric fields */
.crop-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.crop-field label {
    display: block; font-size: .72rem; color: var(--c-text-muted);
    margin-bottom: 3px; font-weight: 600;
}
.crop-field input {
    width: 100%; border: 1.5px solid var(--c-border); border-radius: var(--radius-sm);
    padding: 7px 10px; font-family: var(--font-body); font-size: .88rem;
    color: var(--c-text); background: var(--c-surface); transition: var(--transition);
}
.crop-field input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(240,114,38,.12); }

/* Segmented control (shape) */
.crop-seg { display: flex; background: var(--c-bg2); border-radius: var(--radius-sm); padding: 3px; }
.crop-seg button {
    flex: 1; border: none; background: none; border-radius: calc(var(--radius-sm) - 3px);
    padding: 7px 8px; font-family: var(--font-head); font-weight: 600; font-size: .82rem;
    color: var(--c-text-2); cursor: pointer; transition: var(--transition);
}
.crop-seg button.is-active { background: var(--c-surface); color: var(--c-primary-d); box-shadow: 0 1px 4px var(--c-shadow); }
.crop-hint { font-size: .74rem; color: var(--c-text-muted); margin-top: 8px; line-height: 1.5; }

/* Transform buttons */
.crop-transform { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.crop-transform button {
    border: 1.5px solid var(--c-border); background: var(--c-surface);
    border-radius: var(--radius-sm); padding: 9px 0; cursor: pointer;
    color: var(--c-text-2); font-size: 1.05rem; transition: var(--transition);
}
.crop-transform button:hover { border-color: var(--c-primary); color: var(--c-primary); background: var(--c-bg2); }

/* Output */
.crop-select {
    width: 100%; appearance: none;
    border: 1.5px solid var(--c-border); border-radius: var(--radius-sm);
    background: var(--c-surface) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%239C7B6B' d='M4 6l4 4 4-4z'/%3E%3C/svg%3E") no-repeat right 10px center/14px;
    padding: 8px 30px 8px 10px; font-family: var(--font-body); font-size: .88rem;
    color: var(--c-text); cursor: pointer; transition: var(--transition);
}
.crop-select:focus { outline: none; border-color: var(--c-primary); }
.crop-range { width: 100%; accent-color: var(--c-primary); }
.crop-range-row { display: flex; align-items: center; justify-content: space-between; font-size: .78rem; color: var(--c-text-muted); margin-bottom: 4px; }

/* Readout */
.crop-readout { font-size: .78rem; color: var(--c-text-muted); line-height: 1.9; }
.crop-readout b { color: var(--c-text-2); font-weight: 600; }

/* Actions */
.crop-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.crop-btn-primary {
    background: linear-gradient(135deg, var(--c-primary), var(--c-accent2));
    color: #fff; border: none; border-radius: var(--radius-sm);
    font-family: var(--font-head); font-weight: 700; font-size: .95rem;
    padding: 13px 18px; cursor: pointer; transition: var(--transition);
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.crop-btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 26px var(--c-shadow); }
.crop-btn-ghost {
    background: var(--c-surface); border: 1.5px solid var(--c-border);
    border-radius: var(--radius-sm); color: var(--c-text-2);
    font-family: var(--font-head); font-weight: 600; font-size: .86rem;
    padding: 9px 14px; cursor: pointer; transition: var(--transition);
}
.crop-btn-ghost:hover { border-color: var(--c-primary); color: var(--c-primary); }
.crop-actions-row { display: flex; gap: 8px; }
.crop-actions-row .crop-btn-ghost { flex: 1; }

.crop-hidden { display: none !important; }
