/**
 * formpress Public Styles
 * Modern, clean form styling with enhanced validation
 */

:root {
    --fsp-primary: #0f172a;
    --fsp-accent: #6366f1;
    --fsp-accent-2: #4f46e5;
    --fsp-text: #2c3e50;
    --fsp-bg: #ffffff;
    --fsp-border: #e0e0e0;
    --fsp-radius: 8px;
    --fsp-gap: 16px;
    --fsp-success-bg: #d4edda;
    --fsp-success-border: #c3e6cb;
    --fsp-success-text: #155724;
    --fsp-error-bg: #f8d7da;
    --fsp-error-border: #f5c6cb;
    --fsp-error-text: #721c24;
    --fsp-muted: #95a5a6;
    --fsp-label: #2c3e50;
    --fsp-font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Form Container */
.fsp-form-container {
    max-width: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    font-family: var(--fsp-font);
    color: var(--fsp-text);
    background: #fff;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
}

/* Form Header */
.fsp-form-header {
    padding: 20px 0;
    margin: 0;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    width: 100%;
}

.fsp-form-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: #212529;
}

/* Form Body */
.fsp-form-body {
    padding: 24px 0;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* Form Footer */
.fsp-form-footer {
    padding: 16px 24px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Messages */
.fsp-message {
    padding: 16px 20px;
    margin-bottom: 24px;
    border-radius: var(--fsp-radius);
    font-size: 15px;
    line-height: 1.5;
}

.fsp-message-success {
    background-color: var(--fsp-success-bg);
    border: 1px solid var(--fsp-success-border);
    color: var(--fsp-success-text);
}

.fsp-message-error {
    background-color: var(--fsp-error-bg);
    border: 1px solid var(--fsp-error-border);
    color: var(--fsp-error-text);
}

/* Form */
.fsp-form {
    background: var(--fsp-bg);
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    gap: 0;
    position: relative;
    transition: all 0.3s ease;
    border-radius: 0;
    overflow: hidden;
    width: 100%;
}

/* Progress Bar */
.fsp-progress {
    width: 100%;
    height: 8px;
    background-color: #f0f0f0;
    border-radius: 4px;
    margin-bottom: 24px;
    overflow: hidden;
}

.fsp-progress-bar {
    height: 100%;
    background-color: var(--fsp-accent);
    transition: width 0.3s ease;
    color: white;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    text-indent: -9999px;
}

/* Form Sections */
.fsp-section {
    width: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
}

.fsp-section-header {
    margin: 0 0 20px 0;
    padding: 0;
    border: none;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
    border: 1px solid #dee2e6;
    border-bottom: none;
}

/* Tab Navigation */
.fsp-section-tabs {
    display: flex;
    flex-wrap: wrap;
    padding-left: 0;
    margin: 0;
    list-style: none;
    border-bottom: 1px solid #dee2e6;
}

.fsp-section-tab {
    padding: 12px 24px;
    margin-bottom: -1px;
    border: 1px solid transparent;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    background: none;
    color: #6c757d;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    margin-right: 4px;
}

.fsp-section-tab.active {
    color: #0d6efd;
    background-color: #fff;
    border-color: #dee2e6 #dee2e6 #fff;
    border-bottom-color: transparent;
}

.fsp-section-tab:not(.active):hover {
    color: #0a58ca;
    background-color: #f8f9fa;
    border-color: #e9ecef #e9ecef #dee2e6;
}

/* Section Content */
.fsp-section-content {
    background: #fff;
    padding: 24px;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 8px 8px;
    margin-bottom: 24px;
}

.fsp-section-header h3 {
    margin: 0;
    color: var(--fsp-primary);
    font-size: 18px;
    font-weight: 600;
}

.fsp-section-status {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    transition: all 0.3s ease;
}

.fsp-section-started .fsp-section-status {
    background: #ffc107;
}

.fsp-section-complete .fsp-section-status {
    background: #4caf50;
}

.fsp-section-complete .fsp-section-status::after {
    content: '✓';
}

.fsp-section-invalid {
    border-color: #ff5252;
    box-shadow: 0 0 0 1px #ff5252;
}

.fsp-section-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--fsp-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Fields */
.fsp-field {
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
    position: relative;
    transition: all 0.2s ease;
}

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

/* Field Focus State */
.fsp-field:focus-within .fsp-label {
    color: var(--fsp-accent);
}

/* Required Field Indicator */
.fsp-label.required::after {
    content: '*';
    color: #ff5252;
    margin-left: 4px;
}

/* Character Counter */
.fsp-char-count {
    font-size: 12px;
    color: var(--fsp-muted);
    margin-top: 4px;
    text-align: right;
}

.fsp-char-count .current {
    font-weight: 600;
    color: var(--fsp-primary);
}

.fsp-row-group {
    display: flex;
    gap: var(--fsp-gap, 16px);
    flex-wrap: nowrap;
    width: 100%;
    flex: 1 1 100%;
}

.fsp-row-item {
    flex: 1 1 0;
    min-width: 0;
}

.fsp-row-item-half {
    flex-basis: 50%;
    max-width: 50%;
}

.fsp-row-item-third {
    flex-basis: 33.3333%;
    max-width: 33.3333%;
}

/* Allow auto splitting in flex rows even when width is full */
.fsp-layout-row > .fsp-row-group .fsp-row-item {
    flex: 1 1 0;
    min-width: 220px;
}

.fsp-layout-row > .fsp-field,
.fsp-layout-row > .fsp-layout-wrapper,
.fsp-layout-row > .fsp-row-group {
    flex: 1 1 0;
    min-width: 220px;
}

@media (max-width: 768px) {
    .fsp-row-group {
        flex-wrap: wrap;
        gap: 12px;
        width: 100%;
    }
    .fsp-row-item-half,
    .fsp-row-item-third {
        flex-basis: 100%;
        max-width: 100%;
    }
}

.fsp-field:last-of-type {
    margin-bottom: 32px;
}

.fsp-divider {
    border: 0;
    border-top: 1px dashed var(--fsp-border, #e0e0e0);
    margin: 12px 0;
}

.fsp-layout-container {
    width: 100%;
    box-sizing: border-box;
}

.fsp-layout-row {
    width: 100%;
    display: flex;
    gap: var(--fsp-gap, 16px);
    flex-wrap: wrap;
}

.fsp-layout-column {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--fsp-gap, 16px);
}

/* Make children follow container flex */
.fsp-layout-wrapper {
    box-sizing: border-box;
}

.fsp-layout-wrapper > .fsp-field,
.fsp-layout-wrapper > .fsp-row-group,
.fsp-layout-wrapper > .fsp-layout-wrapper {
    flex: 1 1 0;
    min-width: 220px;
    width: auto;
}

.fsp-layout-wrapper > .fsp-field.fsp-width-half,
.fsp-layout-wrapper > .fsp-row-group .fsp-row-item-half {
    flex-basis: 50%;
    max-width: 50%;
}

.fsp-layout-wrapper > .fsp-field.fsp-width-third,
.fsp-layout-wrapper > .fsp-row-group .fsp-row-item-third {
    flex-basis: 33.3333%;
    max-width: 33.3333%;
}

.fsp-layout-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--fsp-muted, #6b7280);
    margin-bottom: 8px;
}

.fsp-button-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    color: var(--fsp-text, #2c3e50);
    border: 2px solid var(--fsp-border, #e0e0e0);
    border-radius: var(--fsp-radius, 8px);
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fsp-button-secondary:hover {
    border-color: var(--fsp-accent, #6366f1);
    color: var(--fsp-accent, #6366f1);
    box-shadow: 0 4px 12px -6px rgba(99,102,241,0.3);
}

/* RTL/LTR helpers */
.fsp-dir-rtl {
    direction: rtl;
    text-align: right;
}
.fsp-dir-ltr {
    direction: ltr;
    text-align: left;
}
.fsp-dir-rtl .fsp-label { text-align: right; }
.fsp-dir-rtl .fsp-help-text,
.fsp-dir-rtl .fsp-error-inline { text-align: right; }
.fsp-dir-rtl .fsp-radio-label,
.fsp-dir-rtl .fsp-checkbox-label { justify-content: flex-end; }

.fsp-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 15px;
    color: var(--fsp-label);
}

.fsp-required {
    color: #e74c3c;
    margin-left: 3px;
}

.fsp-help-text {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--fsp-muted);
    line-height: 1.4;
}

.fsp-error-inline {
    margin: 8px 0 0;
    font-size: 13px;
    color: var(--fsp-error-text);
    line-height: 1.4;
}

/* Input Fields */
.fsp-input,
.fsp-textarea,
.fsp-select,
.fsp-file {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    line-height: 1.5;
    color: var(--fsp-text);
    background-color: var(--fsp-bg);
    border: 2px solid var(--fsp-border);
    border-radius: var(--fsp-radius);
    transition: all 0.2s ease;
    font-family: inherit;
}

.fsp-input:focus,
.fsp-textarea:focus,
.fsp-select:focus,
.fsp-file:focus {
    outline: none;
    border-color: var(--fsp-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.fsp-input-error,
.fsp-input-error:focus {
    border-color: var(--fsp-error-border);
    box-shadow: 0 0 0 3px rgba(245, 198, 203, 0.35);
}

.fsp-input::placeholder,
.fsp-textarea::placeholder {
    color: var(--fsp-muted);
}

.fsp-textarea {
    resize: vertical;
    min-height: 120px;
}

/* Select */
.fsp-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%232c3e50' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 12px;
    padding-right: 40px;
}

/* Date & time pickers */
.fsp-input[type="date"],
.fsp-input[type="time"],
.fsp-input[type="datetime-local"] {
    appearance: none;
    -webkit-appearance: none;
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24'%3E%3Cpath fill='%232c3e50' d='M7 2a1 1 0 0 0-1 1v1H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-1V3a1 1 0 1 0-2 0v1H9V3a1 1 0 0 0-1-1Zm0 6h10a1 1 0 0 1 1 1v9H6V9a1 1 0 0 1 1-1Zm2 3a1 1 0 1 0 0 2h6a1 1 0 1 0 0-2H9Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 18px;
    padding-right: 48px;
}

.fsp-input[type="date"]::-webkit-calendar-picker-indicator,
.fsp-input[type="time"]::-webkit-calendar-picker-indicator,
.fsp-input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.fsp-input[type="date"]:focus,
.fsp-input[type="time"]:focus,
.fsp-input[type="datetime-local"]:focus {
    border-color: var(--fsp-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Flatpickr theming to match FormPress tokens */
.flatpickr-calendar {
    font-family: var(--fsp-font, "Inter", sans-serif);
    border: 1px solid var(--fsp-border, #e0e0e0);
    box-shadow: 0 10px 30px -12px rgba(17,24,39,0.2);
    border-radius: calc(var(--fsp-radius, 8px) * 1);
}
.flatpickr-calendar.arrowTop:before,
.flatpickr-calendar.arrowBottom:before,
.flatpickr-calendar.arrowTop:after,
.flatpickr-calendar.arrowBottom:after {
    display: none;
}
.flatpickr-months .flatpickr-month {
    background: var(--fsp-bg, #fff);
    color: var(--fsp-text, #2c3e50);
}
.flatpickr-weekdays,
.flatpickr-days {
    background: var(--fsp-bg, #fff);
}
.flatpickr-day {
    border-radius: 6px;
    color: var(--fsp-text, #2c3e50);
}
.flatpickr-day:hover,
.flatpickr-day:focus {
    background: rgba(99,102,241,0.08);
    color: var(--fsp-accent, #6366f1);
}
.flatpickr-day.today {
    border-color: var(--fsp-accent, #6366f1);
    color: var(--fsp-accent, #6366f1);
}
.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
    background: var(--fsp-accent, #6366f1);
    color: #fff;
    border-color: var(--fsp-accent, #6366f1);
}
.flatpickr-time input {
    font-weight: 600;
    color: var(--fsp-text, #2c3e50);
}

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

.fsp-radio-label,
.fsp-checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 15px;
    color: var(--fsp-text);
    transition: color 0.2s ease;
}

.fsp-radio-label:hover,
.fsp-checkbox-label:hover {
    color: var(--fsp-accent);
}

.fsp-radio,
.fsp-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #3498db;
}

/* File Upload */
.fsp-file {
    padding: 10px 16px;
    cursor: pointer;
}

.fsp-file::-webkit-file-upload-button {
    padding: 8px 16px;
    margin-right: 12px;
    background: var(--fsp-accent);
    color: #fff;
    border: none;
    border-radius: var(--fsp-radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s ease;
}

.fsp-file::-webkit-file-upload-button:hover {
    background: var(--fsp-accent-2);
}

/* Submit Button */
.fsp-submit-wrapper {
    margin-top: 32px;
    width: 100%;
}

.fsp-submit-button {
    display: inline-block;
    padding: 14px 32px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--fsp-accent) 0%, var(--fsp-accent-2) 100%);
    border: none;
    border-radius: var(--fsp-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.fsp-submit-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.fsp-submit-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.fsp-submit-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.fsp-heading {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 6px 0;
}

.fsp-heading-sub {
    margin: 0 0 12px 0;
    color: #4b5563;
    font-size: 0.95rem;
}

.fsp-html {
    font-size: 0.95rem;
    color: #374151;
}

.fsp-html p {
    margin-bottom: 0.5rem;
}

/* Layout widths */
.fsp-width-half {
    width: calc(50% - 8px);
}

.fsp-width-third {
    width: calc(33.333% - 10px);
}

@media (max-width: 768px) {
    .fsp-width-half,
    .fsp-width-third {
        width: 100%;
    }

    .fsp-row-group {
        flex-wrap: wrap;
        gap: 12px;
    }
    .fsp-row-item-half,
    .fsp-row-item-third {
        flex-basis: 100%;
        max-width: 100%;
    }
}

/* Conditional visibility */
.fsp-hidden-conditional {
display: none !important;
}

/* Error States */
.fsp-has-error .fsp-input,
.fsp-has-error .fsp-select,
.fsp-has-error .fsp-textarea {
border-color: #ff5252;
background-color: #fff8f8;
padding-right: 36px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23ff5252' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 8px center;
background-size: 20px;
}

.fsp-field-error {
display: flex;
align-items: center;
margin-top: 6px;
padding: 8px 12px;
font-size: 13px;
color: #d32f2f;
background-color: #ffebee;
border-radius: 4px;
line-height: 1.4;
}

.fsp-error-icon {
display: inline-flex;
margin-right: 6px;
font-weight: bold;
}

/* Success State */
.fsp-has-success .fsp-input:not([type="checkbox"]):not([type="radio"]),
.fsp-has-success .fsp-select,
.fsp-has-success .fsp-textarea {
border-color: #4caf50;
background-color: #f8f9fa;
padding-right: 36px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%234caf50' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 8px center;
background-size: 20px;
}

/* Loading State */
.fsp-loading {
position: relative;
pointer-events: none;
opacity: 0.8;
}

.fsp-loading::after {
content: '';
display: inline-block;
width: 16px;
height: 16px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: fsp-spin 0.8s linear infinite;
margin-left: 8px;
vertical-align: middle;
}

@keyframes fsp-spin {
to { transform: rotate(360deg); }
}

/* Responsive Adjustments */
@media (max-width: 768px) {
.fsp-row-group {
flex-direction: column;
gap: 16px;
}
  
.fsp-row-item,
.fsp-row-item-half,
.fsp-row-item-third {
width: 100%;
max-width: 100%;
flex-basis: 100%;
}
  
.fsp-section {
padding: 16px;
}
}

/* Loading State */
.fsp-form.fsp-loading {
opacity: 0.6;
pointer-events: none;
}

.fsp-form.fsp-loading .fsp-submit-button::after {
    content: '...';
    animation: dots 1.5s steps(3, end) infinite;
}

@keyframes dots {

    0%,
    20% {
        content: '.';
    }

    40% {
        content: '..';
    }

    60%,
    100% {
        content: '...';
    }
}

/* Responsive */
@media (max-width: 600px) {
    .fsp-form-container {
        padding: 0 16px;
    }

    .fsp-input,
    .fsp-textarea,
    .fsp-select {
        font-size: 16px;
        /* Prevents zoom on iOS */
    }
}
