/**
 * Otospex Fast Checkout - Frontend Styles
 * Modern, responsive, and performance-optimized
 */

/* ===========================
   Variables
   =========================== */
:root {
    --ofc-primary: #e60000;
    --ofc-primary-hover: #cc0000;
    --ofc-text: #1a1a1a;
    --ofc-text-light: #666666;
    --ofc-border: #e0e0e0;
    --ofc-focus-border: #94a3b8;
    --ofc-bg: #ffffff;
    --ofc-bg-light: #f8f9fa;
    --ofc-success: #10b981;
    --ofc-error: #ef4444;
    --ofc-warning: #f59e0b;
    --ofc-radius: 12px;
    --ofc-radius-sm: 8px;
    --ofc-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --ofc-shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.12);
    --ofc-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===========================
   Main Wrapper
   =========================== */
.ofc-checkout-wrapper {
    background: var(--ofc-bg);
    border: 2px solid var(--ofc-border);
    border-radius: var(--ofc-radius);
    padding: 28px;
    margin: 24px 0;
    box-shadow: var(--ofc-shadow);
    transition: var(--ofc-transition);
}

.ofc-checkout-wrapper:hover {
    box-shadow: var(--ofc-shadow-lg);
}

/* ===========================
   Header
   =========================== */
.ofc-checkout-header {
    margin-bottom: 24px;
    text-align: center;
}

.ofc-checkout-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--ofc-text);
    margin: 0 0 8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.ofc-checkout-title .ofc-icon {
    color: var(--ofc-primary);
    animation: ofc-pulse 2s infinite;
}

@keyframes ofc-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

.ofc-checkout-subtitle {
    font-size: 14px;
    color: var(--ofc-text-light);
    margin: 0;
}

/* ===========================
   Order Summary
   =========================== */
.ofc-order-summary {
    background: var(--ofc-bg-light);
    border-radius: var(--ofc-radius-sm);
    padding: 16px;
    margin-bottom: 20px;
}

.ofc-summary-product {
    display: flex;
    gap: 12px;
    align-items: center;
}

.ofc-summary-image {
    flex-shrink: 0;
}

.ofc-summary-image img {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: 6px;
}

.ofc-summary-details {
    flex: 1;
}

.ofc-summary-title {
    margin: 0 0 6px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--ofc-text);
}

.ofc-summary-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--ofc-primary);
}

/* ===========================
   Quantity Selector
   =========================== */
.ofc-quantity-selector {
    margin-bottom: 20px;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--ofc-border);
    border-radius: var(--ofc-radius-sm);
}

.ofc-quantity-label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 14px;
    color: var(--ofc-text);
}

.ofc-quantity-options {
    display: flex;
    gap: 10px;
}

.ofc-quantity-option {
    flex: 1;
    position: relative;
    cursor: pointer;
}

.ofc-quantity-option input[type="radio"] {
    position: absolute;
    opacity: 0;
}

.ofc-quantity-option span {
    display: block;
    padding: 12px;
    text-align: center;
    border: 2px solid var(--ofc-border);
    border-radius: 6px;
    font-weight: 600;
    font-size: 16px;
    transition: var(--ofc-transition);
    background: #fff;
}

.ofc-quantity-option input[type="radio"]:checked + span {
    border-color: var(--ofc-primary);
    background: var(--ofc-primary);
    color: #fff;
}

.ofc-quantity-option:hover span {
    border-color: var(--ofc-primary);
    transform: translateY(-2px);
}

/* ===========================
   Form Grid
   =========================== */
.ofc-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .ofc-form-grid {
        grid-template-columns: 1fr;
    }
}

/* ===========================
   Form Fields
   =========================== */
.ofc-form-field {
    display: flex;
    flex-direction: column;
}

.ofc-field-half {
    grid-column: span 1;
}

.ofc-field-full {
    grid-column: span 2;
}

@media (max-width: 768px) {
    .ofc-field-half,
    .ofc-field-full {
        grid-column: span 1;
    }
}

.ofc-field-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ofc-text);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ofc-required {
    color: var(--ofc-error);
    font-weight: 700;
}

.ofc-field-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.ofc-field-icon {
    position: absolute;
    left: 14px;
    color: var(--ofc-text-light);
    pointer-events: none;
    z-index: 1;
    display: flex;
    align-items: center;
}

.ofc-field-input,
.ofc-field-select,
.ofc-field-textarea {
    width: 100%;
    padding: 12px 14px 12px 44px;
    font-size: 15px;
    color: var(--ofc-text);
    background: var(--ofc-bg);
    border: 2px solid var(--ofc-border);
    border-radius: var(--ofc-radius-sm);
    transition: var(--ofc-transition);
    font-family: inherit;
}

.ofc-field-input:focus,
.ofc-field-select:focus,
.ofc-field-textarea:focus {
    outline: none;
    border-color: var(--ofc-focus-border);
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.1);
}

.ofc-field-input::placeholder,
.ofc-field-textarea::placeholder {
    color: var(--ofc-text-light);
    opacity: 0.6;
}

.ofc-field-textarea {
    resize: vertical;
    min-height: 80px;
    padding-left: 14px;
}

.ofc-field-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23666666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
}

/* International Tel Input Adjustments */
.ofc-field-wrapper .iti {
    width: 100%;
    position: relative;
}

.ofc-field-wrapper .iti__flag-container {
    left: 0px;
    padding-left: 0px;
}

.ofc-field-wrapper .iti__selected-flag {
    padding-left: 14px;
}

.ofc-field-wrapper .ofc-intl-tel {
    padding-left: 90px;
    padding-right: 45px; /* Make room for validation icon */
}

/* Validation Icon */
.ofc-validation-icon {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.ofc-field-wrapper .iti + .ofc-validation-icon {
    right: 14px;
}

/* Valid/Invalid States */
.ofc-field-input.valid,
.ofc-field-select.valid,
.ofc-intl-tel.valid {
    border-color: #10b981;
}

.ofc-field-input.invalid,
.ofc-field-select.invalid,
.ofc-intl-tel.invalid {
    border-color: #ef4444;
}

/* ===========================
   Form Actions
   =========================== */
.ofc-form-actions {
    margin-top: 24px;
}

.ofc-submit-button {
    width: 100%;
    padding: 16px 24px;
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    background: var(--ofc-primary);
    border: none;
    border-radius: var(--ofc-radius-sm);
    cursor: pointer;
    transition: var(--ofc-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(230, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.ofc-submit-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.ofc-submit-button:hover {
    background: var(--ofc-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(230, 0, 0, 0.4);
}

.ofc-submit-button:hover::before {
    left: 100%;
}

.ofc-submit-button:active {
    transform: translateY(0);
}

.ofc-submit-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.ofc-button-text {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ofc-button-price {
    font-weight: 800;
}

.ofc-button-loader {
    display: none;
    align-items: center;
    gap: 8px;
}

.ofc-submit-button.loading .ofc-button-text {
    display: none;
}

.ofc-submit-button.loading .ofc-button-loader {
    display: flex;
}

/* ===========================
   Spinner Animation
   =========================== */
.ofc-spinner {
    animation: ofc-spin 1s linear infinite;
}

@keyframes ofc-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ===========================
   Messages
   =========================== */
.ofc-form-message {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: var(--ofc-radius-sm);
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: ofc-slideDown 0.3s ease-out;
}

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

.ofc-form-message.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.ofc-form-message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

.ofc-form-message.warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

/* ===========================
   Field Validation States
   =========================== */
.ofc-field-input.error,
.ofc-field-select.error,
.ofc-field-textarea.error {
    border-color: var(--ofc-error);
}

.ofc-field-input.success,
.ofc-field-select.success,
.ofc-field-textarea.success {
    border-color: var(--ofc-success);
}

/* ===========================
   Loading State
   =========================== */
.ofc-checkout-wrapper.loading {
    pointer-events: none;
    opacity: 0.7;
}

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 480px) {
    .ofc-checkout-wrapper {
        padding: 20px;
        margin: 16px 0;
    }
    
    .ofc-checkout-title {
        font-size: 18px;
    }
    
    .ofc-checkout-subtitle {
        font-size: 13px;
    }
    
    .ofc-form-grid {
        gap: 12px;
    }
    
    .ofc-field-input,
    .ofc-field-select,
    .ofc-field-textarea {
        font-size: 14px;
        padding: 10px 12px 10px 40px;
    }
    
    .ofc-submit-button {
        padding: 14px 20px;
        font-size: 15px;
    }
}

/* ===========================
   Print Styles
   =========================== */
@media print {
    .ofc-checkout-wrapper {
        display: none;
    }
}

/* ===========================
   Accessibility
   =========================== */
.ofc-field-input:focus-visible,
.ofc-field-select:focus-visible,
.ofc-field-textarea:focus-visible {
    outline: none;
    border-color: var(--ofc-focus-border);
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.2);
}

.ofc-submit-button:focus-visible {
    outline: 2px solid var(--ofc-primary);
    outline-offset: 2px;
}

/* Screen reader only */
.ofc-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ===========================
   Dark Mode Support
   =========================== */
@media (prefers-color-scheme: dark) {
    :root {
        --ofc-text: #f5f5f5;
        --ofc-text-light: #a0a0a0;
        --ofc-border: #3a3a3a;
        --ofc-bg: #1f1f1f;
        --ofc-bg-light: #2a2a2a;
    }
    
    .ofc-checkout-wrapper {
        background: var(--ofc-bg);
        border-color: var(--ofc-border);
    }
    
    .ofc-field-input,
    .ofc-field-select,
    .ofc-field-textarea {
        background: var(--ofc-bg-light);
        color: var(--ofc-text);
    }
}

/* ===========================
   RTL Support
   =========================== */
[dir="rtl"] .ofc-field-icon {
    left: auto;
    right: 14px;
}

[dir="rtl"] .ofc-field-input,
[dir="rtl"] .ofc-field-select {
    padding-left: 14px;
    padding-right: 44px;
}

[dir="rtl"] .ofc-field-select {
    background-position: left 12px center;
    padding-left: 40px;
    padding-right: 44px;
}

[dir="rtl"] .ofc-field-wrapper .iti__flag-container {
    left: auto;
    right: 14px;
}

[dir="rtl"] .ofc-field-wrapper .ofc-intl-tel {
    padding-left: 14px;
    padding-right: 90px;
}

/* ===========================
   WooCommerce Fields Integration
   =========================== */

/* WooCommerce wrapper containers */
.ofc-form-grid .woocommerce-billing-fields {
    display: contents; /* Make wrapper transparent to grid */
}

.ofc-form-grid .woocommerce-billing-fields__field-wrapper {
    display: contents; /* Make wrapper transparent to grid */
}

/* WooCommerce field wrappers - respect our grid classes */
.ofc-wc-field {
    margin-bottom: 0;
    box-sizing: border-box;
}

.ofc-wc-field.ofc-field-full {
    grid-column: 1 / -1; /* Full width */
}

.ofc-wc-field.ofc-field-half {
    grid-column: span 1; /* Half width */
}

/* Override WooCommerce's form-row-wide class inside our grid */
.ofc-form-grid .ofc-wc-field .form-row-wide {
    width: 100% !important;
    float: none !important;
    clear: none !important;
}

/* Style WooCommerce form fields to match our design */
.ofc-wc-field .form-row {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.ofc-wc-field label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--ofc-text);
    margin-bottom: 8px;
}

.ofc-wc-field label .required {
    color: var(--ofc-error);
    margin-left: 4px;
}

.ofc-wc-field .input-text,
.ofc-wc-field select,
.ofc-wc-field .select2-container {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box !important;
}

.ofc-wc-field .input-text,
.ofc-wc-field select {
    padding: 12px 14px;
    border: 2px solid var(--ofc-border);
    border-radius: var(--ofc-radius-sm);
    font-size: 15px;
    color: var(--ofc-text);
    background: var(--ofc-bg);
    transition: var(--ofc-transition);
    font-family: inherit;
    box-sizing: border-box !important;
}

.ofc-wc-field .input-text:focus,
.ofc-wc-field select:focus {
    outline: none;
    border-color: var(--ofc-focus-border);
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.1);
}

/* Select2 dropdown styling (if used by plugins) */
.ofc-wc-field .select2-container .select2-selection--single {
    height: 46px;
    border: 2px solid var(--ofc-border);
    border-radius: var(--ofc-radius-sm);
    padding: 10px 14px;
}

.ofc-wc-field .select2-container .select2-selection--single .select2-selection__rendered {
    line-height: 24px;
    padding-left: 0;
    color: var(--ofc-text);
}

.ofc-wc-field .select2-container .select2-selection--single .select2-selection__arrow {
    height: 44px;
    right: 10px;
}

.ofc-wc-field .select2-container--focus .select2-selection--single {
    border-color: var(--ofc-focus-border);
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.1);
}

/* International Telephone Input (intl-tel-input) styling */
.ofc-wc-field .iti {
    width: 100% !important;
    display: block !important;
}

.ofc-wc-field .iti__flag-container {
    position: absolute !important;
    top: 0 !important;
    bottom: 0 !important;
    right: auto !important;
    left: 0 !important;
}

.ofc-wc-field .iti__selected-flag {
    padding: 0 8px 0 12px !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
}

.ofc-wc-field .iti--allow-dropdown input,
.ofc-wc-field .iti--allow-dropdown input[type=tel],
.ofc-wc-field .iti--allow-dropdown input[type=text] {
    padding-left: 52px !important;
    width: 100% !important;
}

.ofc-wc-field .iti--separate-dial-code .iti__selected-flag {
    background-color: transparent !important;
}

.ofc-wc-field .iti--separate-dial-code .iti__selected-dial-code {
    margin-left: 6px !important;
}

/* Validation states */
.ofc-wc-field .woocommerce-invalid .input-text,
.ofc-wc-field .woocommerce-invalid select,
.ofc-wc-field select.error,
.ofc-wc-field input.error {
    border-color: var(--ofc-error) !important;
    background-color: rgba(239, 68, 68, 0.05);
}

.ofc-wc-field .woocommerce-validated .input-text,
.ofc-wc-field .woocommerce-validated select {
    border-color: var(--ofc-success);
}

/* Error messages */
.ofc-wc-field .woocommerce-error {
    color: var(--ofc-error);
    font-size: 13px;
    margin-top: 6px;
    display: block;
}

/* City/State dropdown plugin compatibility */
.ofc-wc-field .wc-city-select-field select,
.ofc-wc-field .wc-state-select-field select {
    padding: 12px 14px;
    border: 2px solid var(--ofc-border);
    border-radius: var(--ofc-radius-sm);
    font-size: 15px;
    color: var(--ofc-text);
    background: var(--ofc-bg);
    transition: var(--ofc-transition);
}

.ofc-wc-field .wc-city-select-field select:focus,
.ofc-wc-field .wc-state-select-field select:focus {
    outline: none;
    border-color: var(--ofc-focus-border);
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.1);
}

.ofc-wc-field .wc-city-select-field select.error,
.ofc-wc-field .wc-state-select-field select.error {
    border-color: var(--ofc-error) !important;
    background-color: rgba(239, 68, 68, 0.05);
}

/* ===========================
   Component System (v1.3.0)
   =========================== */
.ofc-component {
    margin-bottom: 24px;
}

.ofc-section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--ofc-text);
    margin: 0 0 16px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--ofc-border);
}

/* ===========================
   Shipping Methods Component
   =========================== */
.ofc-shipping-methods {
    background: var(--ofc-bg-light);
    border-radius: var(--ofc-radius-sm);
    padding: 20px;
}

.ofc-shipping-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ofc-shipping-option {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--ofc-bg);
    border: 2px solid var(--ofc-border);
    border-radius: var(--ofc-radius-sm);
    cursor: pointer;
    transition: var(--ofc-transition);
}

.ofc-shipping-option:hover {
    border-color: var(--ofc-primary);
    box-shadow: var(--ofc-shadow);
}

.ofc-shipping-option input[type="radio"] {
    margin: 0 12px 0 0;
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--ofc-primary);
}

.ofc-shipping-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
}

.ofc-shipping-name {
    font-weight: 500;
    color: var(--ofc-text);
}

.ofc-shipping-cost {
    font-weight: 600;
    color: var(--ofc-primary);
}

/* ===========================
   Payment Methods Component
   =========================== */
.ofc-payment-methods {
    background: var(--ofc-bg-light);
    border-radius: var(--ofc-radius-sm);
    padding: 20px;
}

.ofc-payment-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ofc-payment-option {
    display: flex;
    align-items: flex-start;
    padding: 14px 16px;
    background: var(--ofc-bg);
    border: 2px solid var(--ofc-border);
    border-radius: var(--ofc-radius-sm);
    cursor: pointer;
    transition: var(--ofc-transition);
}

.ofc-payment-option:hover {
    border-color: var(--ofc-primary);
    box-shadow: var(--ofc-shadow);
}

.ofc-payment-option input[type="radio"] {
    margin: 2px 12px 0 0;
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--ofc-primary);
}

.ofc-payment-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.ofc-payment-title {
    font-weight: 500;
    color: var(--ofc-text);
}

.ofc-payment-desc {
    font-size: 13px;
    color: var(--ofc-text-light);
    line-height: 1.5;
}

/* ===========================
   Order Summary Component
   =========================== */
.ofc-order-totals {
    background: var(--ofc-bg-light);
    border-radius: var(--ofc-radius-sm);
    padding: 20px;
}

.ofc-totals-table {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ofc-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--ofc-border);
}

.ofc-total-row:last-child {
    border-bottom: none;
}

.ofc-total-label {
    font-size: 14px;
    color: var(--ofc-text-light);
}

.ofc-total-value {
    font-size: 15px;
    font-weight: 500;
    color: var(--ofc-text);
}

.ofc-total-final {
    padding-top: 12px;
    margin-top: 8px;
    border-top: 2px solid var(--ofc-border);
}

.ofc-total-final .ofc-total-label,
.ofc-total-final .ofc-total-value {
    font-size: 18px;
    color: var(--ofc-primary);
}

/* Loading states */
.ofc-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.ofc-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 3px solid var(--ofc-border);
    border-top-color: var(--ofc-primary);
    border-radius: 50%;
    animation: ofc-spin 0.8s linear infinite;
}

@keyframes ofc-spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 768px) {
    .ofc-shipping-label,
    .ofc-payment-label {
        flex-direction: column;
        gap: 8px;
    }
    
    .ofc-shipping-cost {
        align-self: flex-start;
    }
}

/* ===========================
   Utility Classes
   =========================== */
.ofc-hidden-field {
    display: none !important;
}
