/* Contest Manager - New Designer Styles */

/* Container */
.cm-designer-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Progress Bar */
.cm-progress-bar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
    position: relative;
}

.cm-progress-bar::before {
    content: '';
    position: absolute;
    top: 20px;
    left: 10%;
    right: 10%;
    height: 2px;
    background: #e0e0e0;
    z-index: 0;
}

.cm-progress-step {
    position: relative;
    z-index: 1;
    text-align: center;
    flex: 1;
}

.cm-step-number {
    display: inline-block;
    width: 40px;
    height: 40px;
    line-height: 40px;
    border-radius: 50%;
    background: #e0e0e0;
    color: #999;
    font-weight: 600;
    margin-bottom: 8px;
    transition: all 0.3s ease;
}

.cm-progress-step.active .cm-step-number,
.cm-progress-step.completed .cm-step-number {
    background: #007cba;
    color: white;
}

.cm-progress-step.completed .cm-step-number::after {
    content: '✓';
}

.cm-step-label {
    display: block;
    font-size: 14px;
    color: #666;
}

.cm-progress-step.active .cm-step-label {
    color: #007cba;
    font-weight: 600;
}

/* Steps */
.cm-step {
    display: none;
}

.cm-step.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.cm-step-header {
    text-align: center;
    margin-bottom: 40px;
}

.cm-step-header h2 {
    font-size: 32px;
    margin-bottom: 10px;
    color: #333;
}

.cm-step-header p {
    font-size: 16px;
    color: #666;
}

/* Step 1: Product Grid */
.cm-products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

.cm-product-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    cursor: pointer;
}

.cm-product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

.cm-product-image {
    width: 100%;
    height: 280px;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.cm-product-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.cm-no-image {
    color: #999;
    font-size: 14px;
}

.cm-product-info {
    padding: 20px;
}

.cm-product-info h3 {
    font-size: 20px;
    margin-bottom: 8px;
    color: #333;
}

.cm-product-type {
    color: #666;
    font-size: 14px;
    margin-bottom: 8px;
}

.cm-product-colors {
    color: #007cba;
    font-size: 14px;
    margin-bottom: 16px;
}

.cm-select-product-btn {
    width: 100%;
    padding: 12px 20px;
    background: #007cba;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
}

.cm-select-product-btn:hover {
    background: #005a87;
}

/* Step 2: Customize Layout */
.cm-customize-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    align-items: start;
}

.cm-customize-preview {
    position: sticky;
    top: 20px;
}

.cm-product-display {
    background: #f8f8f8;
    border-radius: 12px;
    padding: 20px;
}

#cm-product-preview {
    width: 100%;
    height: auto;
    max-height: 500px;
    object-fit: contain;
}

.cm-image-toggle {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

.cm-view-btn {
    padding: 8px 20px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cm-view-btn.active {
    background: #007cba;
    color: white;
    border-color: #007cba;
}

.cm-customize-options {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.cm-product-name h3 {
    font-size: 24px;
    margin-bottom: 30px;
    color: #333;
}

.cm-option-group {
    margin-bottom: 30px;
}

.cm-option-group label {
    display: block;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    color: #333;
}

/* Color Grid */
.cm-color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.cm-color-option {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.cm-color-option:hover {
    transform: scale(1.1);
}

.cm-color-option.selected {
    border-color: #007cba;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.2);
}

.cm-color-option.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 0 3px rgba(0,0,0,0.5);
}

.cm-selected-color-name {
    font-size: 14px;
    color: #666;
    height: 20px;
}

/* Size Grid */
.cm-size-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 10px;
}

.cm-size-option {
    padding: 12px;
    text-align: center;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.cm-size-option:hover {
    border-color: #007cba;
}

.cm-size-option.selected {
    background: #007cba;
    color: white;
    border-color: #007cba;
}

.cm-size-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f0f0f0;
}

/* Step Actions */
.cm-step-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
}

/* Buttons */
.cm-btn-primary,
.cm-btn-secondary {
    padding: 14px 30px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cm-btn-primary {
    background: #007cba;
    color: white;
}

.cm-btn-primary:hover:not(:disabled) {
    background: #005a87;
}

.cm-btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cm-btn-secondary {
    background: white;
    color: #666;
    border: 2px solid #e0e0e0;
}

.cm-btn-secondary:hover {
    border-color: #999;
    color: #333;
}

/* Step 3: Design Layout */
.cm-design-layout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 30px;
    align-items: start; /* allow JS to synchronize heights precisely */
}

.cm-design-canvas-area {
    background: #f8f8f8;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.cm-canvas-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Stage: wrapper around product image and design area to avoid container padding/offsets */
.cm-design-stage {
    position: relative;
    width: auto; /* shrink-wrap image */
    height: auto;
    display: inline-block;
}

/* Make image fill the stage without adding external offsets */
.cm-design-stage #cm-design-product-bg {
    position: relative !important;
    width: auto !important; /* let height cap drive width via aspect */
    height: auto !important;
    max-width: 100% !important;
    max-height: 70vh !important; /* limit product image height to 70% viewport */
    object-fit: contain !important;
    display: block !important;
    z-index: 0 !important; /* najniższa warstwa dla obrazka produktu */
}

.cm-design-area {
    position: absolute;
    border: 2px dashed #007cba;
    background: rgba(255, 255, 255, 0.1);
    z-index: 10;
}

#cm-design-drop-zone {
    position: absolute;
    z-index: 100; /* obszar projektu powyżej obrazka produktu */
    overflow: visible; /* Changed from hidden to visible for controls */
    border: 2px dashed #007cba;
    background: rgba(255, 255, 255, 0.05); /* More transparent background */
    min-width: 100px;
    min-height: 100px;
}

/* Remove the canvas positioning - let Fabric handle it */
#cm-design-canvas {
    /* Fabric.js will handle positioning */
}

/* Ensure Fabric.js container and canvases are properly positioned */
#cm-design-drop-zone .canvas-container {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
}

#cm-design-drop-zone .lower-canvas {
    position: absolute !important;
    top: 0; left: 0;
    z-index: 101 !important;
}
#cm-design-drop-zone .upper-canvas {
    position: absolute !important;
    top: 0; left: 0;
    z-index: 102 !important;
}

/* Remove the border overlay as it's now on the drop zone itself */
.cm-design-area-border {
    display: none;
}

/* Design Toolbar */
.cm-design-toolbar {
    display: flex;
    gap: 5px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    margin-top: 20px;
    justify-content: center;
}

.cm-design-toolbar button {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cm-design-toolbar button:hover {
    background: #007cba;
    color: white;
    border-color: #007cba;
}

.cm-toolbar-separator {
    width: 1px;
    background: #e0e0e0;
    margin: 0 5px;
}

/* Elements Panel */
.cm-design-elements {
    background: white;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cm-element-categories {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 10px;
    margin-bottom: 16px;
}

.cm-category-btn {
    padding: 8px 14px;
    background: #ffffff !important;
    border: 1px solid #e5e7eb !important; /* slate-200 */
    color: #334155 !important; /* slate-700 */
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    width: 100%;
    text-align: center;
}

.cm-category-btn:hover { background: #f8fafc !important; /* slate-50 */ }

.cm-category-btn.active { background: #eef2ff !important; border-color: #93c5fd !important; color: #1e40af !important; }

.cm-elements-container {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
}

.cm-element-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.cm-element-item {
    width: 100%;
    height: 100px;
    background: #f8f8f8;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: all 0.3s ease;
    overflow: hidden;
    padding: 10px;
}

.cm-element-item:hover {
    background: #e8e8e8;
    transform: scale(1.05);
}

.cm-element-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.cm-element-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.cm-element-item svg {
    width: 60px;
    height: 60px;
    fill: #333;
    color: #333;
}

.cm-element-placeholder {
    font-size: 12px;
    color: #666;
    text-align: center;
}

/* Properties Panel */
.cm-properties-panel {
    border-top: 1px solid #e0e0e0;
    padding-top: 20px;
}

.cm-properties-panel h4 {
    margin-bottom: 15px;
    color: #333;
}

.cm-property-group {
    margin-bottom: 15px;
}

.cm-property-group label {
    display: block;
    font-size: 14px;
    color: #666;
    margin-bottom: 5px;
}

.cm-property-group input[type="text"],
.cm-property-group select {
    width: 100%;
    padding: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.cm-property-group input[type="range"] {
    width: 100%;
}

.cm-property-group input[type="color"] {
    width: 50px;
    height: 35px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
}

/* Design Actions */
.cm-design-actions {
    display: flex;
    justify-content: space-between;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

/* Step 4: Submit Layout */
.cm-submit-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 40px;
    align-items: start;
}

.cm-final-preview {
    position: sticky;
    top: 20px;
}

.cm-final-preview h3 {
    margin-bottom: 20px;
    font-size: 20px;
    color: #333;
}

.cm-preview-container {
    background: #f8f8f8;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.cm-preview-container h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #333;
    font-size: 16px;
}

#cm-final-design {
    width: 100%;
    height: auto;
    object-fit: contain;
}

.cm-design-details {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.cm-design-details p {
    margin: 8px 0;
    font-size: 14px;
}

/* Final summary table */
.cm-final-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.cm-final-table th,
.cm-final-table td {
    border: 1px solid #e6e6e6;
    padding: 8px 10px;
    text-align: left;
}
.cm-final-table th {
    width: 40%;
    color: #444;
    background: #fafafa;
    font-weight: 600;
}

/* Design Only Canvas */
.cm-design-only {
    text-align: center;
}

#cm-design-only-canvas {
    max-width: 400px;
    width: 100%;
    height: auto;
    background: white;
    display: block;
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    object-fit: contain;
}

/* Download Section */
.cm-download-section {
    margin-top: 20px;
    text-align: center;
}

.cm-btn-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
}

.cm-btn-download:hover {
    background: #218838;
}

.cm-btn-download .dashicons {
    font-size: 20px;
    width: 20px;
    height: 20px;
}

.cm-submit-form {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.cm-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.cm-form-field {
    margin-bottom: 20px;
}

.cm-form-field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.cm-form-field input,
.cm-form-field textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 15px;
}

.cm-form-field input:focus,
.cm-form-field textarea:focus {
    outline: none;
    border-color: #007cba;
}

.cm-form-checkbox {
    margin-bottom: 15px;
}

.cm-form-checkbox label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    font-size: 14px;
}

.cm-form-checkbox input {
    margin-right: 10px;
    margin-top: 2px;
}

.cm-form-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
}

/* Success Message */
.cm-success-container {
    text-align: center;
    padding: 60px 20px;
    max-width: 500px;
    margin: 0 auto;
}

.cm-success-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 30px;
    background: #4caf50;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cm-success-icon .dashicons {
    font-size: 40px;
    color: white;
}

.cm-success-container h2 {
    font-size: 32px;
    margin-bottom: 20px;
    color: #333;
}

.cm-success-container p {
    font-size: 16px;
    color: #666;
    margin-bottom: 15px;
}

.cm-success-container .cm-btn-primary {
    margin-top: 30px;
}

/* Tooltips */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-5px);
    background: #333;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1000;
}

[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #333;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1000;
}

[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

/* Toolbar button tooltips */
.cm-design-toolbar button[data-tooltip]::after {
    bottom: 100%;
    margin-bottom: 10px;
}

.cm-design-toolbar button[data-tooltip]::before {
    bottom: 100%;
    margin-bottom: 5px;
}

/* Color option tooltips */
.cm-color-option {
    position: relative;
}

.cm-color-option::after {
    content: attr(data-color-name);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-5px);
    background: #333;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1000;
}

.cm-color-option:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

/* Element item tooltips */
.cm-element-item::after {
    content: attr(data-element-name);
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%) translateX(5px);
    background: #333;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1000;
}

.cm-element-item:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(10px);
}

/* Size option tooltips */
.cm-size-option:not(.disabled) {
    position: relative;
}

.cm-size-option:not(.disabled)::after {
    content: 'Wybierz rozmiar';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-5px);
    background: #333;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1000;
}

.cm-size-option:not(.disabled):hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

.cm-size-option.disabled::after {
    content: 'Niedostępny';
}

/* Responsive */
@media (max-width: 1024px) {
    .cm-customize-layout,
    .cm-design-layout,
    .cm-submit-layout {
        grid-template-columns: 1fr;
    }
    
    .cm-customize-preview,
    .cm-final-preview {
        position: static;
    }
    
    .cm-design-layout {
        height: auto;
    }
    
    .cm-design-canvas-area {
        height: 500px;
        margin-bottom: 30px;
    }
}

@media (max-width: 768px) {
    .cm-products-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
    
    .cm-form-row {
        grid-template-columns: 1fr;
    }
    
    .cm-element-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
