/**
 * CWP Custom Forms - Frontend Styles
 *
 * @package ContactWidgetProOS
 * @since 0.6.0
 */

/* CSS Variables */
.cwp-custom-form-container {
    --cwp-form-primary: #1922fb;
    --cwp-form-btn-bg: #1922fb;
    --cwp-form-btn-text: #ffffff;
    --cwp-form-btn-hover-bg: #0010d9;
    --cwp-form-btn-hover-text: #ffffff;
    --cwp-form-bg: #ffffff;
    --cwp-form-text: #333333;
    --cwp-form-input-bg: #ffffff;
    --cwp-form-input-border: #d1d5db;
    --cwp-form-radius: 8px;
    --cwp-form-overlay: #000000;
    --cwp-form-overlay-opacity: 0.5;
}

/* Container */
.cwp-custom-form-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--cwp-form-text);
    background: var(--cwp-form-bg);
    box-sizing: border-box;
}

.cwp-custom-form-container *,
.cwp-custom-form-container *::before,
.cwp-custom-form-container *::after {
    box-sizing: inherit;
}

/* Embed Form */
.cwp-form-embed {
    padding: 24px;
    border-radius: var(--cwp-form-radius);
    border: 1px solid #e5e7eb;
}

/* Form Fields */
.cwp-form-fields {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cwp-form-field {
    display: flex;
    flex-direction: column;
}

.cwp-field-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--cwp-form-text);
}

.cwp-required {
    color: #dc2626;
    margin-left: 2px;
}

/* Input Fields */
.cwp-input,
.cwp-textarea,
.cwp-select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--cwp-form-input-border);
    border-radius: var(--cwp-form-radius);
    font-size: 14px;
    font-family: inherit;
    color: var(--cwp-form-text);
    background: var(--cwp-form-input-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.cwp-input:focus,
.cwp-textarea:focus,
.cwp-select:focus {
    outline: none;
    border-color: var(--cwp-form-primary);
    box-shadow: 0 0 0 3px rgba(25, 34, 251, 0.1);
}

.cwp-input::placeholder,
.cwp-textarea::placeholder {
    color: #9ca3af;
    opacity: 0.8;
}

.cwp-input.cwp-error,
.cwp-textarea.cwp-error,
.cwp-select.cwp-error {
    border-color: #dc2626;
}

.cwp-input.cwp-valid,
.cwp-textarea.cwp-valid,
.cwp-select.cwp-valid {
    border-color: #22c55e;
}

.cwp-textarea {
    resize: vertical;
    min-height: 100px;
}

.cwp-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-color: var(--cwp-form-input-bg);
    background-position: right 10px center;
    background-repeat: no-repeat;
    background-size: 20px;
    padding-right: 40px;
}

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

.cwp-checkbox-label,
.cwp-radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}

.cwp-checkbox,
.cwp-radio {
    width: 18px;
    height: 18px;
    accent-color: var(--cwp-form-primary);
    cursor: pointer;
}

/* File Upload */
.cwp-file-wrapper {
    border: 2px dashed var(--cwp-form-input-border);
    border-radius: var(--cwp-form-radius);
    padding: 24px;
    text-align: center;
    background: var(--cwp-form-input-bg);
    transition: border-color 0.2s, background-color 0.2s;
    cursor: pointer;
}

.cwp-file-wrapper:hover,
.cwp-file-wrapper.cwp-drag-over {
    border-color: var(--cwp-form-primary);
    background-color: rgba(25, 34, 251, 0.02);
}

.cwp-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.cwp-file-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cwp-file-text {
    color: var(--cwp-form-text);
    font-weight: 500;
}

.cwp-file-types {
    font-size: 12px;
    color: #6b7280;
}

.cwp-file-list {
    margin-top: 12px;
    text-align: left;
}

.cwp-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--cwp-form-input-bg);
    border: 1px solid var(--cwp-form-input-border);
    border-radius: 4px;
    margin-top: 8px;
    font-size: 13px;
}

.cwp-file-remove {
    background: none;
    border: none;
    color: #dc2626;
    cursor: pointer;
    padding: 4px;
}

/* GDPR */
.cwp-form-gdpr {
    margin-top: 16px;
}

.cwp-gdpr-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13px;
    color: #6b7280;
    cursor: pointer;
}

.cwp-gdpr-label input {
    margin-top: 2px;
    accent-color: var(--cwp-form-primary);
}

/* Submit Button */
.cwp-form-actions {
    margin-top: 20px;
}

.cwp-form-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 24px;
    background: var(--cwp-form-btn-bg);
    color: var(--cwp-form-btn-text);
    border: none;
    border-radius: var(--cwp-form-radius);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, transform 0.1s;
}

.cwp-form-submit:hover {
    background: var(--cwp-form-btn-hover-bg);
    color: var(--cwp-form-btn-hover-text);
}

.cwp-form-submit:active {
    transform: scale(0.98);
}

.cwp-form-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.cwp-submit-loading {
    display: inline-flex;
}

.cwp-spinner {
    animation: cwp-spin 1s linear infinite;
}

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

/* Field Error */
.cwp-field-error {
    margin-top: 6px;
    font-size: 12px;
    color: #dc2626;
}

/* Form Message */
.cwp-form-message {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--cwp-form-radius);
    font-size: 14px;
}

.cwp-form-message.cwp-message-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.cwp-form-message.cwp-message-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* Success State */
.cwp-form-success {
    text-align: center;
    padding: 40px 20px;
}

.cwp-success-icon {
    margin-bottom: 16px;
    color: #22c55e;
}

.cwp-success-icon svg {
    width: 64px;
    height: 64px;
}

.cwp-success-message {
    font-size: 18px;
    font-weight: 600;
    color: var(--cwp-form-text);
    margin: 0 0 8px;
}

.cwp-success-redirect {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
}

/* ====================== */
/* POPUP STYLES           */
/* ====================== */

.cwp-form-popup {
    position: relative;
}

/* Popup Overlay */
.cwp-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--cwp-form-overlay);
    opacity: var(--cwp-form-overlay-opacity);
    z-index: 99998;
}

/* Popup Container */
.cwp-popup-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    display: none;
}

.cwp-popup-container.cwp-popup-active {
    display: block;
}

.cwp-popup-container.cwp-popup-hidden {
    display: none !important;
}

/* Popup Content Wrapper */
.cwp-popup-content {
    position: relative;
    z-index: 100000;
}

/* Modal Preset */
.cwp-popup-modal .cwp-popup-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 480px;
    width: calc(100% - 40px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    animation: cwp-modal-in 0.3s ease-out;
}

.cwp-popup-modal .cwp-custom-form-container {
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

@keyframes cwp-modal-in {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Slide Right Preset */
.cwp-popup-slide-right .cwp-popup-content {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    max-width: 100%;
    height: 100%;
    animation: cwp-slide-right-in 0.3s ease-out;
}

.cwp-popup-slide-right .cwp-custom-form-container {
    height: 100%;
    padding: 32px;
    border-radius: 0;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
}

@keyframes cwp-slide-right-in {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

/* Slide Left Preset */
.cwp-popup-slide-left .cwp-popup-content {
    position: fixed;
    top: 0;
    left: 0;
    width: 400px;
    max-width: 100%;
    height: 100%;
    animation: cwp-slide-left-in 0.3s ease-out;
}

.cwp-popup-slide-left .cwp-custom-form-container {
    height: 100%;
    padding: 32px;
    border-radius: 0;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
}

@keyframes cwp-slide-left-in {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

/* Bottom Bar Preset */
.cwp-popup-bottom-bar .cwp-popup-content {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    animation: cwp-bottom-bar-in 0.3s ease-out;
}

.cwp-popup-bottom-bar .cwp-custom-form-container {
    padding: 24px;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
}

.cwp-popup-bottom-bar .cwp-form-fields {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
}

.cwp-popup-bottom-bar .cwp-form-field {
    flex: 1;
    min-width: 200px;
}

.cwp-popup-bottom-bar .cwp-form-actions {
    margin-top: 0;
    display: flex;
    align-items: flex-end;
}

.cwp-popup-bottom-bar .cwp-form-submit {
    white-space: nowrap;
}

@keyframes cwp-bottom-bar-in {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* Close Button */
.cwp-popup-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    color: #6b7280;
    transition: background 0.2s, color 0.2s;
    z-index: 100001;
}

.cwp-popup-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #1f2937;
}

/* Body scroll lock when popup open */
body.cwp-popup-open {
    overflow: hidden;
}

/* ====================== */
/* RESPONSIVE             */
/* ====================== */

@media (max-width: 768px) {
    .cwp-form-embed {
        padding: 20px;
    }

    .cwp-popup-modal {
        width: calc(100% - 20px);
        max-height: calc(100vh - 20px);
    }

    .cwp-popup-modal .cwp-custom-form-container {
        padding: 24px;
    }

    .cwp-popup-slide-right,
    .cwp-popup-slide-left {
        width: 100%;
    }

    .cwp-popup-bottom-bar .cwp-form-fields {
        flex-direction: column;
    }

    .cwp-popup-bottom-bar .cwp-form-field {
        min-width: 100%;
    }
}
