/* Enhanced Form Labels and Fields */

/* Base Field Label */
.field-label {
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
    color: #333;
    font-size: 14px;
    transition: color 0.2s ease;
}

/* Field Wrapper */
.field-wrapper {
    position: relative;
    margin-bottom: 16px;
}

/* Base Field Control */
[data-control="field"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
    background-color: #fff;
    transition: all 0.2s ease-in-out;
    transform-origin: top left;
    transition: 
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

/* Field States */
[data-control="field"]:hover {
    border-color: #999;
}

[data-control="field"]:focus {
    border-color: #4a90e2;
    outline: none;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

[data-control="field"].disabled,
[data-control="field"][disabled] {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Field Sizes */
[data-control="field"].field-sm {
    padding: 6px 8px;
    font-size: 12px;
}

[data-control="field"].field-lg {
    padding: 12px 16px;
    font-size: 16px;
}

/* Field Types */
[data-control="field"][type="search"] {
    padding-left: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 8px center;
    background-size: 16px;
}

/* Required Fields */
.field-required .field-label::after {
    content: "*";
    color: #dc3545;
    margin-left: 4px;
}

/* Field Help Text */
.field-help {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
}

/* Field Groups */
.field-group {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

/* RTL Support */
[dir="rtl"] {
    .field-label {
        text-align: right;
    }
    
    .field-required .field-label::after {
        margin-right: 4px;
        margin-left: 0;
    }
    
    [data-control="field"][type="search"] {
        padding-right: 32px;
        padding-left: 12px;
        background-position: calc(100% - 8px) center;
    }
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .field-label {
        font-size: 13px;
    }
    
    [data-control="field"] {
        font-size: 16px; /* Larger touch targets on mobile */
        padding: 12px;
    }
    
    .field-group {
        flex-direction: column;
    }
}

/* Custom Checkboxes and Radio Buttons */
.field-checkbox,
.field-radio {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.field-checkbox input[type="checkbox"],
.field-radio input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.field-checkbox .checkmark,
.field-radio .radiomark {
    position: relative;
    display: inline-block;
    width: 18px;
    height: 18px;
    background: #fff;
    border: 2px solid #ddd;
    transition: all 0.2s ease;
}

.field-checkbox .checkmark {
    border-radius: 3px;
}

.field-radio .radiomark {
    border-radius: 50%;
}

.field-checkbox input:checked ~ .checkmark,
.field-radio input:checked ~ .radiomark {
    border-color: #4a90e2;
    background: #4a90e2;
}

.field-checkbox .checkmark:after {
    content: '';
    position: absolute;
    display: none;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.field-radio .radiomark:after {
    content: '';
    position: absolute;
    display: none;
    top: 4px;
    left: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: white;
}

.field-checkbox input:checked ~ .checkmark:after,
.field-radio input:checked ~ .radiomark:after {
    display: block;
}

/* Field with Icons */
.field-with-icon {
    position: relative;
}

.field-with-icon [data-control="field"] {
    padding-right: 32px;
}

.field-icon {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    pointer-events: none;
}

/* RTL Support for Icons */
[dir="rtl"] .field-with-icon [data-control="field"] {
    padding-right: 12px;
    padding-left: 32px;
}

[dir="rtl"] .field-icon {
    right: auto;
    left: 8px;
}

/* Accessibility Enhancements */
[data-control="field"]:focus-visible {
    outline: 2px solid #4a90e2;
    outline-offset: 1px;
}

.field-label[for]:hover {
    cursor: pointer;
    color: #4a90e2;
}

/* ARIA Support */
[aria-invalid="true"] {
    border-color: #dc3545;
}

[aria-invalid="true"] + .field-help {
    color: #dc3545;
}

/* Advanced Field Layouts and Input Types */

/* Field Grid Layout */
.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

/* Field Inline Groups */
.field-inline {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

/* File Upload Field */
.field-upload {
    position: relative;
    padding: 20px;
    border: 2px dashed #ddd;
    border-radius: 6px;
    text-align: center;
    transition: border-color 0.3s ease;
}

.field-upload:hover,
.field-upload.dragover {
    border-color: #4a90e2;
    background-color: rgba(74, 144, 226, 0.05);
}

/* Date and Time Fields */
[data-control="field"][type="date"],
[data-control="field"][type="time"],
[data-control="field"][type="datetime-local"] {
    position: relative;
    appearance: none;
}

/* Prefix and Suffix Add-ons */
.field-addon {
    position: relative;
    display: flex;
    align-items: stretch;
}

.field-addon-prefix,
.field-addon-suffix {
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    color: #666;
}

.field-addon-prefix {
    border-right: none;
    border-radius: 4px 0 0 4px;
}

.field-addon-suffix {
    border-left: none;
    border-radius: 0 4px 4px 0;
}

/* RTL Support for Add-ons */
[dir="rtl"] .field-addon-prefix {
    border-right: 1px solid #ddd;
    border-left: none;
    border-radius: 0 4px 4px 0;
}

[dir="rtl"] .field-addon-suffix {
    border-left: 1px solid #ddd;
    border-right: none;
    border-radius: 4px 0 0 4px;
}

/* Animation and Transition Effects */

/* Field Focus Animation */
[data-control="field"] {
    transform-origin: top left;
    transition: 
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

/* Floating Label Effect */
.field-floating {
    position: relative;
}

.field-floating .field-label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: #fff;
    padding: 0 4px;
    transition: 
        transform 0.2s ease,
        font-size 0.2s ease,
        color 0.2s ease;
    pointer-events: none;
}

.field-floating [data-control="field"]:focus + .field-label,
.field-floating [data-control="field"]:not(:placeholder-shown) + .field-label {
    transform: translateY(-180%) scale(0.85);
    color: #4a90e2;
}

/* Loading State */
.field-loading::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top-color: #4a90e2;
    border-radius: 50%;
    animation: field-spin 0.8s linear infinite;
}

@keyframes field-spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Success/Error Animations */
.field-success [data-control="field"] {
    animation: field-success 0.4s ease;
}

.field-error [data-control="field"] {
    animation: field-error 0.4s ease;
}

@keyframes field-success {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@keyframes field-error {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* RTL Support for Animations */
[dir="rtl"] .field-floating .field-label {
    left: auto;
    right: 12px;
}

[dir="rtl"] .field-loading::after {
    right: auto;
    left: 12px;
}

/* Touch Device Hover Effects */
@media (hover: hover) {
    .field-wrapper:hover .field-label {
        color: #4a90e2;
    }
    
    [data-control="field"]:hover {
        transform: translateY(-1px);
    }
}