/**
 * Working Papers Form Styles
 * WDM Working Paper Library
 */

/* Ensure all elements use border-box for consistent sizing */
.wdm-working-paper-form-wrap *,
.wdm-working-paper-form-wrap *::before,
.wdm-working-paper-form-wrap *::after {
    box-sizing: border-box;
}

/* Form Container */
.wdm-working-paper-form-wrap {
    margin: 0 auto;
    padding: 15px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    position: relative; /* Required for Select2 dropdown positioning */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: visible;
}

.wdm-working-paper-form-wrap .wdm-working-paper-form {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: visible;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Form Header - Scoped to Working Paper Form */
.wdm-working-paper-form-wrap .wdm-form-header {
    background: #fff;
    color: #212529;
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
}

.wdm-working-paper-form-wrap .wdm-form-title {
    font-size: 24px;
    font-weight: 600;
    margin: 0 0 10px 0;
    line-height: 1.3;
    color: #212529;
}

.wdm-working-paper-form-wrap .wdm-form-description {
    font-size: 16px;
    color: #6c757d;
    line-height: 1.5;
    margin: 0;
}

/* Form Content - Scoped to Working Paper Form */
.wdm-working-paper-form-wrap #wdm-working-paper-submit-form {
    padding: 20px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Form Fields - Scoped to Working Paper Form */
.wdm-working-paper-form-wrap .wdm-form-field {
    margin-bottom: 15px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* 2-Column Layout for Desktop */
@media (min-width: 768px) {
    .wdm-working-paper-form-wrap .wdm-form-fields-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 12px;
        align-items: start;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    
    /* Ensure form fields are properly sized */
    .wdm-working-paper-form-wrap .wdm-form-field {
        min-width: 0;
        width: 100%;
    }
}

/* Large Desktop - Prevent form from becoming too wide */
@media (min-width: 1200px) {
    .wdm-working-paper-form-wrap {
        max-width: 1200px;
    }
}

/* Force 2-column layout on desktop - override any conflicting styles */
@media (min-width: 768px) {
    .wdm-working-paper-form-wrap .wdm-form-fields-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        grid-gap: 12px !important;
        gap: 12px !important;
    }
    
    .wdm-working-paper-form-wrap .wdm-form-field:not(.full-width) {
        display: block !important;
        width: 100% !important;
    }
    
}

.wdm-working-paper-form-wrap .wdm-form-label {
    display: block;
    font-weight: 600;
    color: #212529;
    margin-bottom: 8px;
    font-size: 14px;
}

.wdm-working-paper-form-wrap .wdm-required {
    color: #dc3545;
    margin-left: 2px;
}

.wdm-working-paper-form-wrap .wdm-help-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    background: #6c757d;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    margin-left: 6px;
    cursor: help;
    vertical-align: middle;
    transition: all 0.2s ease;
}

.wdm-working-paper-form-wrap .wdm-help-icon:hover {
    background: #fd7e14;
    transform: scale(1.1);
}

.wdm-working-paper-form-wrap .wdm-form-input,
.wdm-working-paper-form-wrap .wdm-form-textarea,
.wdm-working-paper-form-wrap .wdm-form-select {
    width: 100%;
    height: 44px; /* Unified height */
    padding: 10px 12px; /* Unified padding */
    border: 1px solid #ced4da; /* Unified border */
    border-radius: 6px;
    font-size: 14px;
    font-weight: 400; /* Unified font weight */
    line-height: 1.5;
    color: #495057; /* Unified color */
    transition: all 0.2s ease;
    box-sizing: border-box;
    font-family: inherit;
    background: #fff;
}

.wdm-working-paper-form-wrap .wdm-form-input:focus,
.wdm-working-paper-form-wrap .wdm-form-textarea:focus,
.wdm-working-paper-form-wrap .wdm-form-select:focus {
    outline: none;
    border-color: #fd7e14;
    box-shadow: 0 0 0 3px rgba(253, 126, 20, 0.1);
}

.wdm-working-paper-form-wrap .wdm-form-textarea {
    resize: vertical;
    min-height: 60px;
    height: auto; /* Override fixed height for textarea */
}

/* Select2 Customization */
.wdm-keywords-select {
    width: 100%;
}

.select2-container--default .select2-selection--multiple {
    border: 2px solid #e9ecef;
    border-radius: 6px;
    min-height: 45px;
}

.select2-container--default.select2-container--focus .select2-selection--multiple {
    border-color: #fd7e14;
    box-shadow: 0 0 0 3px rgba(253, 126, 20, 0.1);
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background: #fd7e14;
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 4px 10px;
    margin: 2px;
}


/* Character Count and Field Help - Combined Layout */
.wdm-working-paper-form-wrap .wdm-field-help-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 5px;
    font-size: 12px;
    color: #6c757d;
    line-height: 1.4;
}

.wdm-working-paper-form-wrap .wdm-field-help {
    flex: 1;
    margin: 0;
}

.wdm-working-paper-form-wrap .wdm-char-count {
    text-align: right;
    margin: 0;
    margin-left: 10px;
}

.wdm-working-paper-form-wrap .wdm-char-warning {
    color: #dc3545;
    font-weight: 600;
}

.wdm-working-paper-form-wrap .wdm-char-minimum {
    color: #ffc107;
    font-weight: 600;
}

/* Field Errors */
.wdm-field-error {
    color: #dc3545;
    font-size: 12px;
    margin-top: 5px;
    font-weight: 500;
}

.wdm-form-input.error,
.wdm-form-textarea.error,
.wdm-form-select.error {
    border-color: #dc3545;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

/* Checkbox Field */
.wdm-checkbox-field {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.wdm-form-checkbox {
    margin: 0;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}

.wdm-checkbox-label {
    font-size: 14px;
    line-height: 1.5;
    color: #495057;
    cursor: pointer;
    margin: 0;
}

.wdm-checkbox-label a {
    color: #fd7e14;
    text-decoration: none;
}

.wdm-checkbox-label a:hover {
    text-decoration: underline;
}

/* Form Actions */
.wdm-form-actions {
    display: flex;
    gap: 15px;
}

.wdm-working-paper-form-wrap .wdm-form-submit,
.wdm-working-paper-form-wrap .wdm-form-cancel {
    height: 44px; /* Match input height */
    padding: 10px 16px; /* Unified padding */
    border: none;
    border-radius: 6px;
    font-size: 14px; /* Match input font size */
    font-weight: 500; /* Slightly bolder than inputs */
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    box-sizing: border-box;
    justify-content: center;
    min-width: 120px;
}

.wdm-working-paper-form-wrap .wdm-form-submit {
    background: var(--ast-global-color-8);
    color: #fff;
    flex: 1;
}

.wdm-working-paper-form-wrap .wdm-form-submit:hover:not(:disabled) {
    background: var(--ast-global-color-8);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(253, 126, 20, 0.3);
}

.wdm-working-paper-form-wrap .wdm-form-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.wdm-working-paper-form-wrap .wdm-form-cancel {
    background: #6c757d;
    color: #fff;
    flex: 1;
}

.wdm-working-paper-form-wrap .wdm-form-cancel:hover {
    background: #5a6268;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.3);
}

/* Loading State */
.wdm-submit-loading {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wdm-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid #fff;
    border-radius: 50%;
    animation: wdm-spin 1s linear infinite;
}

@keyframes wdm-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Success Message */
.wdm-form-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 6px;
    padding: 20px;
    margin: 20px 0;
}

.wdm-success-content {
    display: flex;
    align-items: center;
    gap: 15px;
    color: #155724;
}

.wdm-success-content .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
    color: #28a745;
}

.wdm-success-content h3 {
    margin: 0 0 5px 0;
    font-size: 18px;
    font-weight: 600;
}

.wdm-success-content p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

/* Error Message */
.wdm-form-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    padding: 20px;
    margin: 20px 0;
}

.wdm-error-content {
    display: flex;
    align-items: center;
    gap: 15px;
    color: #721c24;
}

.wdm-error-content .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
    color: #dc3545;
}

.wdm-error-content h3 {
    margin: 0 0 5px 0;
    font-size: 18px;
    font-weight: 600;
}

.wdm-error-content p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

/* Honeypot Field */
.wdm-honeypot {
    position: absolute;
    left: -9999px;
    top: -9999px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .wdm-working-paper-form-wrap {
        padding: 10px;
    }
    
    .wdm-form-header {
        padding: 15px;
    }
    
    .wdm-form-title {
        font-size: 20px;
    }
    
    .wdm-form-description {
        font-size: 14px;
    }
    
    #wdm-working-paper-submit-form {
        padding: 15px;
    }
    
    .wdm-form-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .wdm-form-submit,
    .wdm-form-cancel {
        flex: none;
        width: 100%;
    }
    
    .wdm-form-field {
        margin-bottom: 15px;
    }
}

@media (max-width: 480px) {
    .wdm-form-header {
        padding: 15px;
    }
    
    .wdm-form-title {
        font-size: 18px;
    }
    
    #wdm-working-paper-submit-form {
        padding: 15px;
    }
    
    .wdm-form-field {
        margin-bottom: 20px;
    }
    
    .wdm-form-input,
    .wdm-form-textarea,
    .wdm-form-select {
        padding: 10px 12px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .wdm-form-submit,
    .wdm-form-cancel {
        padding: 14px 20px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Accessibility */
.wdm-form-input:focus,
.wdm-form-textarea:focus,
.wdm-form-checkbox:focus,
.wdm-form-select:focus {
    outline: 2px solid #fd7e14;
    outline-offset: 2px;
}

.wdm-form-submit:focus,
.wdm-form-cancel:focus {
    outline: 2px solid #fd7e14;
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .wdm-form-input,
    .wdm-form-textarea,
    .wdm-form-select {
        border: 2px solid #000;
    }
    
    .wdm-form-submit,
    .wdm-form-cancel {
        border: 2px solid #000;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .wdm-form-input,
    .wdm-form-textarea,
    .wdm-form-select,
    .wdm-form-submit,
    .wdm-form-cancel {
        transition: none;
    }
    
    .wdm-spinner {
        animation: none;
    }
}

/* Print Styles */
@media print {
    .wdm-working-paper-form-wrap {
        max-width: none;
        padding: 0;
    }
    
    .wdm-working-paper-form {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .wdm-form-actions {
        display: none;
    }
    
    .wdm-form-success,
    .wdm-form-error {
        border: 1px solid #000;
        background: #fff;
    }
}


/* Form Validation Styles - Removed automatic CSS validation styling */

/* Custom File Input Styling */
.wdm-form-input[type="file"] {
    padding: 8px 12px;
    background: #f8f9fa;
    cursor: pointer;
}

.wdm-form-input[type="file"]:hover {
    background: #e9ecef;
}

/* Date Input Styling */
.wdm-form-input[type="date"] {
    padding: 10px 12px;
}

/* URL Input Styling */
.wdm-form-input[type="url"] {
    padding: 10px 12px;
}

/* Required Field Indicator */
.wdm-form-field.required .wdm-form-label::after {
    content: ' *';
    color: #dc3545;
    font-weight: bold;
}

/* Form Progress Indicator */
.wdm-form-progress {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    padding: 0 20px;
}

.wdm-progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    position: relative;
}

.wdm-progress-step:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 15px;
    left: 50%;
    width: 100%;
    height: 2px;
    background: #e9ecef;
    z-index: 1;
}

.wdm-progress-step.active:not(:last-child)::after {
    background: #fd7e14;
}

.wdm-progress-circle {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #e9ecef;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    position: relative;
    z-index: 2;
}

.wdm-progress-step.active .wdm-progress-circle {
    background: #fd7e14;
    color: #fff;
}

.wdm-progress-step.completed .wdm-progress-circle {
    background: #28a745;
    color: #fff;
}

.wdm-progress-label {
    margin-top: 8px;
    font-size: 12px;
    color: #6c757d;
    text-align: center;
}

.wdm-progress-step.active .wdm-progress-label {
    color: #fd7e14;
    font-weight: 600;
}

.wdm-progress-step.completed .wdm-progress-label {
    color: #28a745;
    font-weight: 600;
}

/* ======================================
   Select2 Styles - Scoped to Form
   ====================================== */

/* Container */
.wdm-working-paper-form-wrap .select2-container {
    width: 100%;
    position: relative;
    z-index: 1;
}

.wdm-working-paper-form-wrap .select2-container--open .select2-dropdown {
    z-index: 9999;
}

/* Single Selection (Category) */
.wdm-working-paper-form-wrap .select2-container--default .select2-selection--single {
    border: 1px solid #ced4da;
    border-radius: 6px;
    height: 44px;
    font-size: 14px;
    font-weight: 400;
    color: #495057;
    background: #fff;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 3 !important;
    padding-left: 12px;
    color: #212529;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 40px;
    top: 2px;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--single .select2-selection__clear {
    margin-right: 25px;
    font-size: 18px;
}

/* Dropdown */
.wdm-working-paper-form-wrap .select2-dropdown {
    border: 1px solid #ced4da;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    position: fixed;
    left: auto;
}

.wdm-working-paper-form-wrap .select2-dropdown--below {
    margin-top: 8px;
}

.wdm-working-paper-form-wrap .select2-dropdown--above {
    margin-bottom: 8px;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 6px 12px;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #fd7e14;
    color: #fff;
}

/* Multiple Selection (Tags) */
.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple {
    border: 1px solid #ced4da;
    border-radius: 6px;
    min-height: 44px;
    padding: 10px 12px; /* Match regular inputs */
    background: #fff;
    font-size: 14px;
    font-weight: 400;
    color: #495057;
    cursor: text;
}

.wdm-working-paper-form-wrap .select2-container--default.select2-container--focus .select2-selection--multiple {
    border-color: #fd7e14;
    box-shadow: 0 0 0 0.2rem rgba(253, 126, 20, 0.25);
    outline: none;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-selection__rendered {
    display: block;
    width: 100%;
    padding: 0;
    margin: 0;
    list-style: none;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-search--inline {
    display: inline-block;
    width: 100%;
    min-width: 150px;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-search__field {
    width: 100%;
    min-width: 150px;
    height: 22px; /* Match input height minus padding */
    padding: 0; /* No padding for search field */
    margin: 0;
    font-size: 14px;
    font-weight: 400;
    color: #495057;
    border: none;
    background: transparent;
    line-height: 1.5;
    box-sizing: border-box;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-search__field:focus {
    outline: none;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: #fd7e14;
    color: #fff;
    border: 1px solid #fd7e14;
    border-radius: 4px;
    padding: 4px 8px;
    margin: 2px 4px 2px 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    line-height: 1.4;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-selection__choice__display {
    padding-left: 7px;
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: #fff;
    font-size: 14px;
    font-weight: bold;
    margin-right: 6px; /* Gap between × and option name */
    cursor: pointer;
    border: none;
    background: none;
    padding: 2px 4px; /* Padding around × button */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    min-height: 18px;
    flex-shrink: 0;
    order: -1; /* Ensure × appears before text */
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #fff;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

/* Clear All Button (X) for multiple selection */
.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-selection__clear {
    color: #495057;
    font-size: 18px;
    font-weight: bold;
    margin-right: 5px;
    cursor: pointer;
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
}

.wdm-working-paper-form-wrap .select2-container--default .select2-selection--multiple .select2-selection__clear:hover {
    color: #dc3545;
}

/* Loading/Disabled State */
.wdm-working-paper-form-wrap .select2-container--default.select2-container--disabled .select2-selection--multiple {
    background-color: #f8f9fa;
    cursor: not-allowed;
    opacity: 0.7;
}
