/**
 * CartTailor - Frontend Stylesheet
 */

.spo-frontend-container {
    margin: 20px 0;
    max-width: 100%;
    padding: 16px 20px;
    background: #fafafa;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-family: inherit;
    box-sizing: border-box;
}

.spo-group-wrap {
    margin-bottom: 16px;
}

.spo-group-wrap:last-child {
    margin-bottom: 0;
}

.spo-group-title {
    font-size: 1.15em;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 12px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid #e5e7eb;
}

/* Field Rows */
.spo-field-row {
    margin-bottom: 16px;
    position: relative;
    transition: opacity 0.25s ease, max-height 0.3s ease;
}

.spo-field-row:last-child {
    margin-bottom: 0;
}

.spo-field-row.spo-hidden-by-logic {
    display: none !important;
}

/* Labels */
.spo-field-label {
    display: block;
    font-weight: 600;
    font-size: 0.95em;
    color: #374151;
    margin-bottom: 6px;
    line-height: 1.4;
}

.spo-required-star {
    color: #ef4444;
    font-weight: 700;
    margin-left: 2px;
}

.spo-price-badge {
    display: inline-block;
    font-size: 0.85em;
    font-weight: 600;
    color: #059669;
    background: #ecfdf5;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

.spo-field-description {
    font-size: 0.85em;
    color: #6b7280;
    margin-bottom: 6px;
    line-height: 1.4;
}

/* Standard Inputs */
.spo-input {
    width: 100% !important;
    box-sizing: border-box !important;
    border: 1px solid #d1d5db !important;
    border-radius: 6px !important;
    padding: 10px 14px !important;
    /* 16px base size: readable on desktop and avoids iOS auto-zoom on focus. */
    font-size: 16px !important;
    background-color: #ffffff !important;
    color: #1f2937 !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
}

.spo-input:focus {
    outline: none !important;
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
}

.spo-input-textarea {
    resize: vertical;
    min-height: 70px;
}

.spo-char-counter {
    text-align: right;
    font-size: 0.75em;
    color: #9ca3af;
    margin-top: 4px;
}

/* Radio & Checkbox Choices */
.spo-radio-group,
.spo-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.spo-radio-item,
.spo-checkbox-item {
    display: flex;
    align-items: center;
    position: relative;
    cursor: pointer;
    font-size: 0.95em;
    color: #374151;
    margin: 0;
    min-height: 44px;
    box-sizing: border-box;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.spo-radio-item:hover,
.spo-checkbox-item:hover {
    background: #f9fafb;
    border-color: #cbd5e1;
}

.spo-radio-item:focus-within,
.spo-checkbox-item:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Rows flagged by JS validation (missing required field) */
.spo-field-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 10px 12px;
}

.spo-field-error .spo-field-label {
    color: #dc2626;
}

.spo-radio-item input,
.spo-checkbox-item input {
    margin-right: 8px !important;
    accent-color: #4f46e5;
    cursor: pointer;
}

.spo-choice-text {
    flex-grow: 1;
}

/* Multiselect: plain-click toggling (see frontend.js mousedown handler).
   Options are styled as tappable rows; :checked highlighting works in
   Chromium/Firefox listboxes (Safari largely ignores option styling). */
.spo-input-multiselect {
    min-height: 128px;
}

.spo-frontend-container .spo-input-multiselect option {
    padding: 8px 10px;
    cursor: pointer;
}

.spo-frontend-container .spo-input-multiselect option:checked {
    background: #eef2ff;
    color: #1f2937;
}

/* Multiselect Helper */
.spo-multiselect-hint {
    font-size: 0.8em;
    color: #6b7280;
    margin-top: 4px;
}

/* File Upload Field */
.spo-upload-box {
    position: relative;
}

.spo-upload-dropzone {
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    padding: 24px 16px;
    text-align: center;
    background: #ffffff;
    cursor: pointer;
    position: relative;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.spo-upload-dropzone:hover {
    border-color: #a5b4fc;
    background: #f9fafb;
}

/* Visible drag-over state (JS adds .spo-drag-over on dragover/dragenter) */
.spo-upload-dropzone.spo-drag-over {
    border-color: #4f46e5;
    border-style: solid;
    background: #eef2ff;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
}

.spo-upload-dropzone.spo-drag-over .spo-upload-icon {
    transform: scale(1.2);
}

/* Keyboard users tab onto the covering file input */
.spo-upload-dropzone:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.spo-input-file {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.spo-upload-icon {
    width: 28px;
    height: 28px;
    margin: 0 auto 6px auto;
    color: #6366f1;
    display: block;
    transition: transform 0.2s ease;
}

.spo-upload-text {
    display: block;
    font-size: 0.9em;
    color: #374151;
    margin-bottom: 4px;
}

.spo-upload-meta {
    display: block;
    font-size: 0.75em;
    color: #9ca3af;
}

.spo-file-preview {
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85em;
    color: #065f46;
}

.spo-file-preview .spo-file-name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.spo-file-remove {
    background: none;
    border: none;
    font-size: 1.2em;
    color: #ef4444;
    cursor: pointer;
    padding: 0 4px;
}

/* Dynamic Price Breakdown Summary Card */
.spo-price-summary-card {
    margin-top: 20px;
    background: #ffffff;
    border: 1px solid #e0e7ff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.spo-summary-header {
    background: #f8fafc;
    padding: 10px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.spo-summary-title {
    font-weight: 700;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #475569;
}

.spo-summary-body {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.spo-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95em;
    color: #4b5563;
}

.spo-summary-row.spo-row-total {
    border-top: 1px dashed #cbd5e1;
    padding-top: 8px;
    margin-top: 4px;
    font-size: 1.1em;
    color: #111827;
}

.spo-options-total-display {
    color: #059669;
    font-weight: 600;
}

.spo-final-total-display {
    color: #4f46e5;
    font-weight: 700;
}

/* Prominent live total: last row inside the options container, directly
   above the Add to cart button (default display position). It mirrors the
   breakdown card's Final Total from the same JS calculation. */
.spo-live-total {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 8px;
    padding: 12px 16px;
    box-sizing: border-box;
}

.spo-live-total-label {
    font-weight: 700;
    font-size: 1em;
    color: #1e1b4b;
}

.spo-live-total-value {
    font-weight: 800;
    font-size: 1.3em;
    line-height: 1.2;
    color: #4338ca;
    white-space: nowrap;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .spo-frontend-container {
        padding: 12px 14px;
    }

    .spo-field-row {
        margin-bottom: 14px;
    }

    .spo-summary-row {
        gap: 8px;
    }

    .spo-summary-row.spo-row-total {
        font-size: 1.05em;
    }

    .spo-live-total {
        padding: 10px 12px;
    }

    .spo-live-total-value {
        font-size: 1.15em;
    }

    .spo-upload-dropzone {
        padding: 20px 12px;
    }

    .spo-file-preview {
        flex-wrap: wrap;
    }
}

/* Unavailable radio/checkbox choices (v1.0.5) */
.spo-option-unavailable {
    opacity: .6;
    cursor: not-allowed;
}

/* Range slider (Phase 3): slider + live value display side by side. */
.spo-range-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.spo-input-range {
    flex: 1;
    min-width: 120px;
    accent-color: #4f46e5;
}

.spo-range-value {
    min-width: 44px;
    text-align: center;
    font-weight: 700;
    color: #1f2937;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 4px 8px;
}

/* Checkbox selection counter (Phase 3). The message is a hint only;
   server-side validation in CartValidator is the real enforcement. */
.spo-selection-counter {
    margin-top: 6px;
    font-size: 0.85em;
    color: #6b7280;
}

.spo-selection-counter .spo-selection-limits {
    color: #9ca3af;
}

.spo-selection-counter .spo-selection-message {
    color: #dc2626;
    font-weight: 600;
    margin-left: 6px;
}

.spo-selection-counter.spo-out-of-range .spo-selected-count {
    color: #dc2626;
    font-weight: 700;
}
