/* ============================================================
   Crop PDF Tool — crop-pdf.css
   Prefix: cp-
   Accent: #8B5CF6  (violet)
   Accent RGB: 139, 92, 246
   ============================================================ */

/* ── Accent override for tool-base shared classes ─────────── */
.cp-section {
    --tool-accent: #8B5CF6;
    --tool-accent-rgb: 139, 92, 246;
    padding: 40px 0 80px;
}

/* ── Section badge ─────────────────────────────────────────── */
.cp-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 18px;
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.22);
    border-radius: 50px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #8B5CF6;
    margin-bottom: 12px;
}

.cp-badge i {
    font-size: 0.875rem;
}

/* ── Upload Zone ───────────────────────────────────────────── */
.cp-upload-zone {
    display: block; /* label is inline by default — must be block for full-width layout */
    border: 2px dashed rgba(139, 92, 246, 0.32);
    border-radius: 16px;
    background: rgba(139, 92, 246, 0.03);
    padding: 56px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    outline: none;
}

.cp-upload-zone:hover,
.cp-upload-zone:focus-visible {
    border-color: rgba(139, 92, 246, 0.6);
    background: rgba(139, 92, 246, 0.07);
}

.cp-upload-zone.cp-drag-over {
    border-color: #8B5CF6;
    background: rgba(139, 92, 246, 0.1);
}

.cp-upload-icon {
    font-size: 3rem;
    color: #8B5CF6;
    opacity: 0.65;
    margin-bottom: 14px;
    display: block;
}

.cp-upload-title {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 6px;
}

.cp-upload-sub {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 0 0 10px;
}

.cp-upload-formats {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    margin: 0;
}

/* ── Workspace ─────────────────────────────────────────────── */
.cp-workspace {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Settings Bar ──────────────────────────────────────────── */
.cp-settings-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--bg-secondary, #F8FAFC);
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 12px;
}

/* Page Navigation */
.cp-page-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cp-page-indicator {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 70px;
    text-align: center;
}

/* Scope Toggle */
.cp-scope-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cp-scope-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.cp-scope-btns {
    display: flex;
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 8px;
    overflow: hidden;
}

.cp-scope-btn {
    padding: 6px 14px;
    font-size: 0.8125rem;
    font-weight: 500;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    line-height: 1;
    height: 32px;
}

.cp-scope-btn:hover {
    background: rgba(139, 92, 246, 0.08);
    color: #8B5CF6;
}

.cp-scope-btn.cp-scope-active {
    background: #8B5CF6;
    color: #fff;
}

/* Divider */
.cp-settings-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color, #E2E8F0);
    flex-shrink: 0;
}

/* Settings right actions */
.cp-settings-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* ── Loading ───────────────────────────────────────────────── */
.cp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px;
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

/* ── Crop Canvas Area ──────────────────────────────────────── */
.cp-crop-area {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #E2E8F0;
    border-radius: 12px;
    padding: 24px;
    overflow: auto;
    max-height: 65vh;
    min-height: 200px;
    position: relative;
}

/* Canvas wrapper — sized to the rendered page */
.cp-canvas-wrap {
    position: relative;
    cursor: default;
    flex-shrink: 0;
    /* No overflow:hidden so handles at edges stay fully visible */
}

/* Rendered page image */
.cp-page-img {
    display: block;
    max-width: 100%;
    /* Actual width/height set by JS */
    user-select: none;
    -webkit-user-drag: none;
}

/* ── Dark masks outside the crop rect ─────────────────────── */
.cp-mask {
    position: absolute;
    background: rgba(0, 0, 0, 0.48);
    pointer-events: none;
    z-index: 1;
    /* left/top/width/height set by JS */
}

/* ── Crop Rectangle ────────────────────────────────────────── */
.cp-crop-rect {
    position: absolute;
    border: 2px solid #8B5CF6;
    cursor: move;
    z-index: 2;
    box-sizing: border-box;
    /* left/top/width/height set by JS */
}

.cp-crop-rect:focus-visible {
    outline: 3px solid rgba(139, 92, 246, 0.5);
    outline-offset: 2px;
}

/* Grid lines inside crop rect (rule-of-thirds guides) */
.cp-crop-rect::before,
.cp-crop-rect::after {
    content: '';
    position: absolute;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.2);
}

.cp-crop-rect::before {
    /* Two horizontal thirds lines */
    top: 33.333%;
    left: 0;
    right: 0;
    height: 1px;
    box-shadow: 0 calc(33.333% + 1px) 0 rgba(255, 255, 255, 0.2);
}

.cp-crop-rect::after {
    /* Two vertical thirds lines */
    left: 33.333%;
    top: 0;
    bottom: 0;
    width: 1px;
    box-shadow: calc(33.333% + 1px) 0 0 rgba(255, 255, 255, 0.2);
}

/* ── Resize Handles ────────────────────────────────────────── */
.cp-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #8B5CF6;
    border: 2px solid #fff;
    border-radius: 2px;
    z-index: 5;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
}

.cp-handle:hover {
    transform: scale(1.25);
}

/* Corner handles */
.cp-handle-nw { top: -6px;  left: -6px;  cursor: nw-resize; }
.cp-handle-ne { top: -6px;  right: -6px; cursor: ne-resize; }
.cp-handle-se { bottom: -6px; right: -6px; cursor: se-resize; }
.cp-handle-sw { bottom: -6px; left: -6px;  cursor: sw-resize; }

/* Mid-edge handles */
.cp-handle-n { top: -6px;    left: 50%;  transform: translateX(-50%); cursor: n-resize; }
.cp-handle-s { bottom: -6px; left: 50%;  transform: translateX(-50%); cursor: s-resize; }
.cp-handle-e { top: 50%;  right: -6px; transform: translateY(-50%); cursor: e-resize; }
.cp-handle-w { top: 50%;  left: -6px;  transform: translateY(-50%); cursor: w-resize; }

.cp-handle-n:hover,
.cp-handle-s:hover { transform: translateX(-50%) scale(1.25); }
.cp-handle-e:hover,
.cp-handle-w:hover { transform: translateY(-50%) scale(1.25); }

/* ── Crop Info Row ─────────────────────────────────────────── */
.cp-info-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 0 4px;
}

.cp-info-dims {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #8B5CF6;
    white-space: nowrap;
}

.cp-info-hint {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
}

/* ── Margin Inputs ─────────────────────────────────────────── */
.cp-margins-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 16px;
    background: var(--bg-secondary, #F8FAFC);
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 12px;
}

.cp-margin-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cp-margin-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: default;
}

.cp-margin-label i {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.cp-margin-input {
    width: 64px;
    padding: 5px 8px;
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 6px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary);
    text-align: center;
    transition: border-color 0.15s;
    -moz-appearance: textfield;
}

.cp-margin-input::-webkit-inner-spin-button,
.cp-margin-input::-webkit-outer-spin-button {
    opacity: 0.6;
}

.cp-margin-input:focus {
    outline: none;
    border-color: #8B5CF6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.cp-margin-unit {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* ── Action Panel ──────────────────────────────────────────── */
.cp-action-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    background: var(--bg-secondary, #F8FAFC);
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 12px;
}

.cp-output-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.cp-output-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.cp-output-input-wrap {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color, #E2E8F0);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-primary, #fff);
    flex: 1;
    min-width: 180px;
    max-width: 360px;
}

.cp-output-input {
    flex: 1;
    padding: 7px 12px;
    font-size: 0.875rem;
    border: none;
    background: transparent;
    color: var(--text-primary);
    outline: none;
}

.cp-output-ext {
    padding: 0 12px 0 0;
    font-size: 0.875rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.cp-action-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Progress Bar ──────────────────────────────────────────── */
.cp-progress-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cp-progress-bar {
    height: 6px;
    background: var(--border-color, #E2E8F0);
    border-radius: 99px;
    overflow: hidden;
}

.cp-progress-fill {
    height: 100%;
    background: #8B5CF6;
    border-radius: 99px;
    width: 0%;
    transition: width 0.2s ease;
}

.cp-progress-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
    .cp-settings-bar {
        gap: 10px;
        padding: 10px 12px;
    }

    .cp-settings-divider--hide-mobile {
        display: none;
    }

    .cp-settings-actions {
        margin-left: 0;
        flex-wrap: wrap;
    }

    .cp-scope-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .cp-crop-area {
        padding: 12px;
        max-height: 55vh;
    }

    .cp-margins-bar {
        gap: 10px;
        padding: 10px 12px;
    }

    .cp-margin-input {
        width: 56px;
    }

    .cp-output-input-wrap {
        min-width: 140px;
    }
}

@media (max-width: 480px) {
    .cp-page-nav .tool-btn--sm {
        padding: 5px 8px;
    }

    .cp-margin-group {
        flex: 1;
        min-width: 100px;
    }

    .cp-margins-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}
