/**
 * Frontend calculator styles
 * Minimal CSS - main styling is inline in JS/PHP for reliability
 *
 * @package KrystalMeble
 */

/* Reset box-sizing for calculator */
#krystalmeble-calculator,
#krystalmeble-calculator * {
    box-sizing: border-box;
}

/* Ensure inputs don't overflow */
#krystalmeble-calculator input,
#krystalmeble-calculator select,
#krystalmeble-calculator textarea {
    max-width: 100%;
}

/* Focus states */
#krystalmeble-calculator input:focus,
#krystalmeble-calculator select:focus,
#krystalmeble-calculator textarea:focus {
    outline: none;
    border-color: #2563eb !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Button hover states */
#krystalmeble-calculator button:hover {
    opacity: 0.95;
}

#krystalmeble-calculator button:disabled {
    opacity: 0.6;
    cursor: not-allowed !important;
}

/* Producer-first guidance for material selection */
#krystalmeble-calculator .km-material-dependent-field.km-field-disabled {
    opacity: 0.75;
}

#krystalmeble-calculator .km-material-dependent-field input:disabled,
#krystalmeble-calculator .km-material-dependent-field select:disabled {
    background-color: #f3f4f6 !important;
    border-color: #d1d5db !important;
    color: #9ca3af !important;
    cursor: not-allowed !important;
}

#krystalmeble-calculator .km-material-dependent-field input:disabled::placeholder {
    color: #9ca3af;
}

#krystalmeble-calculator .km-producer-field-wrap {
    position: relative;
    border-radius: 10px;
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
}

#krystalmeble-calculator .km-producer-field-wrap.km-producer-guidance-active {
    background-color: #eff6ff;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
    padding: 10px;
}

#krystalmeble-calculator .km-producer-guidance-hint {
    margin-top: 6px;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 600;
}

/* Payment method (chevron in CSS — avoids broken HTML from quotes inside inline style url()) */
#krystalmeble-calculator select#km-payment-method.km-payment-method-select {
    width: 100%;
    max-width: 400px;
    padding: 12px 40px 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    height: 44px;
    background-color: #ffffff;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

/* ===================================================
   Step progress bar (4 steps)
   =================================================== */
.km-progress-steps {
    display: flex !important;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
}
.km-progress-steps[style*="display: none"] {
    display: none !important;
}
.km-step {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    color: #6b7280;
    font-weight: 500;
}
.km-step.km-step-active {
    background: #059669;
    color: #fff;
    font-weight: 600;
}
.km-step.km-step-completed {
    background: #d1fae5;
    color: #065f46;
}
.km-step-sep {
    color: #9ca3af;
    font-weight: 600;
    user-select: none;
}
.km-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.1);
    font-size: 12px;
    font-weight: 700;
}
.km-step.km-step-active .km-step-num,
.km-step.km-step-completed .km-step-num {
    background: rgba(255,255,255,0.3);
}
.km-step:not(.km-step-active):not(.km-step-completed) .km-step-num {
    background: #e5e7eb;
    color: #4b5563;
}
@media (max-width: 480px) {
    .km-step-label {
        display: none;
    }
    .km-progress-steps {
        gap: 6px;
        padding: 10px 12px;
    }
}

/* ===================================================
   Fittings skeleton loader
   =================================================== */
.km-fittings-skeleton {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 0;
}
.km-skeleton-card {
    height: 80px;
    border-radius: 8px;
    background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
    background-size: 200% 100%;
    animation: km-shimmer 1.5s infinite;
}
@keyframes km-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===================================================
   MOBILE RESPONSIVE - Part Row Fields Stacking
   =================================================== */

/* Mobile-specific styles */
@media (max-width: 768px) {
    #krystalmeble-calculator {
        padding: 8px !important;
    }
    
    #krystalmeble-calculator > div {
        padding: 16px !important;
        border-radius: 12px !important;
    }
    
    /* Material block adjustments */
    .km-material-block {
        padding: 16px !important;
        margin-bottom: 16px !important;
    }
    
    /* Part row adjustments for mobile - stack all fields */
    .km-part-row {
        padding: 16px 12px !important;
        padding-right: 36px !important; /* Space for delete button */
    }
    
    /* Row 1: Stack all input fields vertically */
    .km-part-row-1 {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        gap: 12px !important;
        margin-bottom: 12px !important;
    }
    
    /* Row 1 fields should be full width */
    .km-part-row-1 > div {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
    }
    
    /* Row 2: Stack edge banding and notes */
    .km-part-row-2 {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        gap: 12px !important;
        align-items: stretch !important;
    }
    
    /* Row 2 fields should be full width */
    .km-part-row-2 > div {
        width: 100% !important;
        max-width: 100% !important;
        grid-column: auto !important;
        flex: none !important;
    }
    
    /* Edge banding section - make internal container responsive */
    .km-part-row-2 > div:first-child {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    /* Edge banding fields row - allow wrapping on mobile */
    .km-edge-fields-row {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    /* Edge banding fields - full width when wrapped */
    .km-edge-fields-row > div {
        flex: none !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Oklejanie checkboxes - keep 2x2 grid but ensure visibility */
    .km-edge-fields-row > div:nth-child(2) > div {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        height: auto !important;
        padding: 8px !important;
        background: #f0f9ff !important;
        border-radius: 4px !important;
    }
    
    /* Checkbox labels - ensure full text is visible */
    .km-part-row-2 label[style*="cursor: pointer"] {
        font-size: 13px !important;
        padding: 4px 0 !important;
        white-space: normal !important;
    }
    
    /* Załącznik container - reset grid-column */
    .km-attachment-container {
        grid-column: auto !important;
    }
    
    /* Uwagi textarea - full width */
    .km-part-notes {
        width: 100% !important;
        min-height: 60px !important;
    }
    
    /* Delete button repositioning on mobile */
    .km-remove-part {
        top: 12px !important;
        right: 8px !important;
    }
    
    /* Labels - ensure visibility */
    .km-part-row label {
        font-size: 12px !important;
        margin-bottom: 4px !important;
        display: block !important;
    }
    
    /* Inputs - proper sizing on mobile */
    .km-part-row input[type="number"],
    .km-part-row select {
        width: 100% !important;
        height: 44px !important; /* Larger touch targets */
        font-size: 16px !important; /* Prevent iOS zoom */
    }
    
    /* Searchable select on mobile */
    .km-searchable-select-input {
        width: 100% !important;
        height: 44px !important;
        font-size: 16px !important;
    }
    
    /* Add part button full width on mobile */
    .km-add-part {
        width: 100% !important;
        justify-content: center !important;
    }
    
    /* Block header adjustments */
    .km-material-block > div:first-child {
        flex-direction: column !important;
        gap: 12px !important;
        align-items: flex-start !important;
    }
    
    /* Make remove block button full width on mobile */
    .km-remove-block {
        width: 100% !important;
        justify-content: center !important;
    }
}

/* Very small screens (phones in portrait) */
@media (max-width: 480px) {
    #krystalmeble-calculator {
        padding: 4px !important;
    }
    
    #krystalmeble-calculator > div {
        padding: 12px !important;
    }
    
    .km-material-block {
        padding: 12px !important;
    }
    
    .km-part-row {
        padding: 12px 8px !important;
        padding-right: 32px !important;
    }
    
    /* Stack Lp with dimensions on same row for space efficiency */
    .km-part-row-1 {
        gap: 10px !important;
    }
    
    /* Make Lp smaller since it's just a number */
    .km-part-row-1 > div:first-child {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 8px !important;
    }
    
    .km-part-row-1 > div:first-child label {
        margin-bottom: 0 !important;
        margin-right: 8px !important;
    }
    
    .km-part-row-1 > div:first-child > div {
        flex: 0 0 50px !important;
    }
    
    /* Oklejanie - single column on very small screens */
    .km-edge-fields-row > div:nth-child(2) > div {
        grid-template-columns: 1fr !important;
    }
}

/* Tablet and medium screens - adjust part row grids */
@media (max-width: 1024px) and (min-width: 769px) {
    .km-part-row-1,
    .km-part-row-2 {
        grid-template-columns: minmax(35px, 40px) minmax(75px, 1fr) minmax(75px, 1fr) minmax(55px, 80px) minmax(55px, 80px) minmax(65px, 90px) minmax(55px, 80px) minmax(110px, 1fr) !important;
        gap: 8px !important;
    }
}

/* Print styles */
@media print {
    #krystalmeble-calculator button,
    #km-add-block,
    #km-calculate,
    #km-save-draft,
    #km-submit-order,
    .km-add-part,
    .km-remove-block,
    .km-remove-part {
        display: none !important;
    }
}

/* ===================================================
   Grid / table view (parts list)
   =================================================== */
.km-grid-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.km-grid-table thead th {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 600;
    color: #4b5563;
    text-transform: uppercase;
    white-space: nowrap;
    text-align: left;
}
.km-grid-table tbody tr.km-part-row:nth-child(even) {
    background: #f9fafb;
}
.km-grid-table tbody tr.km-part-row:hover {
    background: #eff6ff;
}
.km-grid-table td {
    border: 1px solid #e5e7eb;
    padding: 4px 6px;
    vertical-align: middle;
}
.km-grid-table input[type="number"],
.km-grid-table select {
    width: 100%;
    min-width: 50px;
    height: 30px;
    padding: 2px 4px;
    font-size: 13px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
}
.km-grid-edge-cell {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

/* Edge banding board preview */
.km-edge-preview svg {
    width: 100%;
    height: auto;
    max-height: 100%;
    display: block;
}

/* Edge decor dropdown in card view (Oklejanie panel) — match row height */
.km-edge-decor-compact .km-searchable-select-input {
    height: 36px !important;
    min-height: 36px !important;
    padding: 6px 24px 6px 30px !important;
    font-size: 13px !important;
}
.km-view-toggle {
    display: inline-flex;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    overflow: hidden;
}
.km-view-btn {
    padding: 5px 12px;
    background: #f9fafb;
    border: none;
    cursor: pointer;
    font-size: 12px;
}
.km-view-btn.km-view-btn-active {
    background: #2563eb;
    color: #fff;
}

@media (max-width: 768px) {
    .km-grid-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .km-grid-table {
        min-width: 900px;
    }
    .km-edge-preview {
        max-width: 90px;
        margin: 0 auto;
    }
}
