* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Segoe UI', sans-serif;
    background: #e8edf5;
    padding: 20px;
}
.container {
    max-width: 1300px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
h1 { color: #1a202c; font-size: 28px; }
.subtitle { color: #718096; margin-bottom: 20px; }

/* ==================== ГОРЕН РЕД ==================== */

.top-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    align-items: stretch;
}

.upload-box {
    border: 2px dashed #cbd5e0;
    border-radius: 12px;
    padding: 20px 30px;
    text-align: center;
    cursor: pointer;
    flex-shrink: 0;
    width: 220px;
    background: #f7fafc;
    transition: 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.upload-box:hover { border-color: #4299e1; background: #edf2f7; }
.upload-box input[type="file"] { display: none; }

.tools-panel {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 10px 16px;
    background: #f7fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    overflow-x: auto;
}

.tools-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.tools-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.tools-label {
    font-size: 11px;
    font-weight: 600;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.tools-label strong {
    color: #2d3748;
    font-size: 13px;
}

.tools-buttons {
    display: flex;
    gap: 4px;
    align-items: center;
}

.tools-divider {
    width: 1px;
    align-self: stretch;
    margin: 2px 14px;
    background: #e2e8f0;
    flex-shrink: 0;
}

.size-slider {
    width: 80px;
    cursor: pointer;
    accent-color: #4299e1;
}

.actions-count {
    font-size: 12px;
    color: #a0aec0;
    white-space: nowrap;
}

/* ==================== БУТОНИ ==================== */

.btn {
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
.btn-primary { background: #4299e1; color: white; }
.btn-primary:hover { background: #3182ce; }
.btn-success { background: #48bb78; color: white; }
.btn-success:hover { background: #38a169; }
.btn-secondary { background: #a0aec0; color: white; }
.btn-secondary:hover { background: #718096; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #a0aec0;
    padding: 2px 6px;
    border-radius: 4px;
    transition: 0.2s;
}
.btn-ghost:hover { color: #e53e3e; background: #fff5f5; }

.tool-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: 0.2s;
    font-size: 16px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tool-btn:hover {
    background: #edf2f7;
    transform: scale(1.05);
}
.tool-btn.active {
    border-color: #2d3748;
    background: #edf2f7;
    box-shadow: 0 0 0 2px white, 0 0 0 4px #2d3748;
}

.color-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: 0.2s;
    flex-shrink: 0;
}
.color-btn:hover { transform: scale(1.1); }
.color-btn.active {
    border-color: #2d3748;
    box-shadow: 0 0 0 2px white, 0 0 0 4px #2d3748;
}
.color-btn.blur-pattern {
    background: repeating-conic-gradient(#4a5568 0% 25%, #e2e8f0 0% 50%) 0 0 / 8px 8px;
    border-color: #a0aec0;
}
.color-btn.blur-pattern.active {
    border-color: #2d3748;
}

/* ==================== КОНТРОЛ НА КАРТИНКАТА ==================== */

.image-controls {
    background: #f0f4fa;
    border: 1px solid #c3d0e4;
    border-radius: 12px;
    margin: 0 0 15px 0;
    overflow: hidden;
    animation: slideDown 0.25s ease-out;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.image-controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #dce4f0;
    border-bottom: 1px solid #c3d0e4;
    font-weight: 600;
    font-size: 14px;
    color: #2d3748;
}
.image-controls-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.image-controls-body {
    display: flex;
    gap: 20px;
    padding: 16px;
    align-items: flex-start;
}

.image-controls-left {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.image-preview-box {
    width: 140px;
    height: 140px;
    border-radius: 8px;
    border: 1px solid #cbd5e0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: repeating-conic-gradient(#d1d5db 0% 25%, #f3f4f6 0% 50%) 0 0 / 14px 14px;
    background-color: #f3f4f6;
}
.image-preview-box canvas {
    max-width: 130px;
    max-height: 130px;
    display: block;
}

.image-original-info {
    font-size: 11px;
    color: #718096;
    text-align: center;
}

.image-controls-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.image-scale-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.image-scale-row label {
    font-size: 13px;
    color: #4a5568;
}
.image-scale-row label strong {
    color: #2d3748;
    font-size: 15px;
}
.image-scale-row input[type="range"] {
    width: 100%;
    cursor: pointer;
    accent-color: #4299e1;
}

.image-dims-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.dim-field {
    flex: 1;
}
.dim-field label {
    display: block;
    font-size: 12px;
    color: #718096;
    margin-bottom: 4px;
    font-weight: 500;
}
.dim-input-wrap {
    display: flex;
    align-items: center;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    transition: border-color 0.2s;
}
.dim-input-wrap:focus-within {
    border-color: #4299e1;
}
.dim-input-wrap input[type="number"] {
    border: none;
    outline: none;
    padding: 8px 10px;
    font-size: 14px;
    font-weight: 600;
    color: #2d3748;
    width: 100%;
    -moz-appearance: textfield;
}
.dim-input-wrap input[type="number"]::-webkit-inner-spin-button,
.dim-input-wrap input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.dim-unit {
    padding: 0 10px;
    font-size: 12px;
    color: #a0aec0;
    font-weight: 500;
    background: #f7fafc;
    border-left: 1px solid #e2e8f0;
    height: 100%;
    display: flex;
    align-items: center;
    padding-top: 8px;
    padding-bottom: 8px;
}

.lock-btn {
    background: none;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    flex-shrink: 0;
}
.lock-btn:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
}
.lock-btn.active {
    border-color: #4299e1;
    background: #ebf8ff;
}

.image-hint {
    font-size: 12px;
    color: #718096;
    line-height: 1.5;
    padding: 8px 12px;
    background: rgba(66, 153, 225, 0.06);
    border-radius: 8px;
    border: 1px solid rgba(66, 153, 225, 0.15);
}

/* ==================== PDF ВЬЮЪР ==================== */

.pdf-viewer {
    background: #f7fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    padding: 15px;
    min-height: 500px;
    position: relative;
    overflow: auto;
    cursor: crosshair;
    user-select: none;
    max-height: 800px;
}
.pdf-viewer .page-container {
    position: relative;
    margin: 0 auto 30px auto;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.pdf-viewer .page-container:last-child { margin-bottom: 0; }
.pdf-viewer .page-container canvas {
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}
.pdf-viewer .page-number {
    text-align: center;
    font-size: 13px;
    color: #a0aec0;
    padding: 6px 0 4px 0;
    background: #f7fafc;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 4px 4px 0 0;
}

.draw-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}
.draw-layer canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ==================== ИНФО ЕЛЕМЕНТИ ==================== */

.info-box {
    padding: 12px 18px;
    border-radius: 8px;
    margin: 10px 0;
    display: none;
}
.info-box.success { background: #f0fff4; border-left: 4px solid #48bb78; display: block; }
.info-box.error { background: #fff5f5; border-left: 4px solid #fc8181; display: block; }
.info-box.warning { background: #fffff0; border-left: 4px solid #ecc94b; display: block; }
.info-box.info { background: #ebf8ff; border-left: 4px solid #4299e1; display: block; }

.file-info {
    display: flex;
    gap: 15px;
    padding: 8px 14px;
    background: #edf2f7;
    border-radius: 8px;
    font-size: 14px;
    color: #4a5568;
    margin-bottom: 10px;
}
.history-info {
    font-size: 13px;
    color: #718096;
}

/* ==================== МОДАЛ ==================== */

.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.modal.active { display: flex; }
.modal-content {
    background: white;
    border-radius: 16px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    padding: 25px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-close {
    position: sticky;
    top: 0;
    float: right;
    background: #fc8181;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 20px;
    cursor: pointer;
    z-index: 10;
}
.modal-close:hover { background: #f56565; }
.modal-content h3 { margin-bottom: 15px; color: #2d3748; }
.modal-content .result-image img {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

/* ==================== РЕСПОНСИВНОСТ ==================== */

@media (max-width: 860px) {
    .container { padding: 16px; }
    
    .top-row {
        flex-direction: column;
    }
    
    .upload-box {
        width: 100%;
        flex-direction: row;
        gap: 12px;
        padding: 14px 20px;
        justify-content: flex-start;
    }
    .upload-box div[style*="font-size:32px"] {
        font-size: 24px !important;
    }
    
    .tools-panel {
        flex-wrap: wrap;
        gap: 0;
    }
    
    .tools-section {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }
    
    .tools-actions {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .tools-divider {
        width: auto;
        height: 1px;
        align-self: auto;
        margin: 0 0;
        background: #e2e8f0;
    }
    
    .image-controls-body {
        flex-direction: column;
        align-items: stretch;
    }
    .image-controls-left {
        flex-direction: row;
        gap: 12px;
    }
    .image-preview-box {
        width: 100px;
        height: 100px;
    }
    .image-preview-box canvas {
        max-width: 90px;
        max-height: 90px;
    }
    
    .pdf-viewer { max-height: 500px; }
}

@media (max-width: 480px) {
    .tools-panel {
        padding: 8px 10px;
        gap: 0;
    }
    .tools-divider {
        display: none;
    }
    .tools-section {
        padding: 4px 0;
    }
    .btn-sm {
        padding: 5px 8px;
        font-size: 11px;
    }
}
