/* ========================================
   Tailwind CSS overrides for Crispy Forms
   Pure CSS - No @apply directives
   Modern Polished Styling v2.0
   ======================================== */

/* ==========================================================================
   FIELDSET STYLING
   ========================================================================== */

fieldset {
    background-color: #ffffff !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05) !important;
    border: 1px solid #e5e7eb !important;
    padding: 1.75rem !important;
    margin-bottom: 1.5rem !important;
    transition: box-shadow 0.2s ease-in-out !important;
}

fieldset:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05) !important;
}

fieldset legend {
    font-size: 1rem !important;
    font-weight: 600 !important;
    color: #111827 !important;
    margin-bottom: 1.25rem !important;
    padding: 0 0.75rem !important;
    background-color: #ffffff !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
}

fieldset legend::before {
    content: '' !important;
    display: inline-block !important;
    width: 4px !important;
    height: 1em !important;
    background: linear-gradient(135deg, #1a8da9 0%, #147188 100%) !important;
    border-radius: 2px !important;
    margin-right: 0.5rem !important;
}

/* ==========================================================================
   FORM GROUPS / FIELDS
   ========================================================================== */

.form-group,
.control-group {
    margin-bottom: 1.25rem !important;
    position: relative !important;
}

.form-group:last-child {
    margin-bottom: 0 !important;
}

/* ==========================================================================
   LABELS
   ========================================================================== */

label,
.control-label {
    display: block !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    color: #374151 !important;
    margin-bottom: 0.5rem !important;
    transition: color 0.15s ease !important;
}

label.requiredField::after,
.control-label.requiredField::after {
    content: " *" !important;
    color: #ef4444 !important;
    font-weight: 600 !important;
}

/* Focus state for labels */
.form-group:focus-within > label,
.control-group:focus-within > .control-label {
    color: #1a8da9 !important;
}

/* ==========================================================================
   INPUT FIELDS - BASE STYLES
   ========================================================================== */

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="url"],
input[type="tel"],
input[type="password"],
textarea,
select,
.form-control {
    width: 100% !important;
    padding: 0.75rem 1rem !important;
    border: 1.5px solid #d1d5db !important;
    border-radius: 0.5rem !important;
    background-color: #ffffff !important;
    color: #111827 !important;
    font-size: 0.9375rem !important;
    line-height: 1.5 !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-sizing: border-box !important;
}

/* Placeholder styling */
input::placeholder,
textarea::placeholder {
    color: #9ca3af !important;
    opacity: 1 !important;
}

/* Hover state */
input[type="text"]:hover:not(:focus):not(:disabled),
input[type="email"]:hover:not(:focus):not(:disabled),
input[type="number"]:hover:not(:focus):not(:disabled),
input[type="date"]:hover:not(:focus):not(:disabled),
input[type="datetime-local"]:hover:not(:focus):not(:disabled),
input[type="time"]:hover:not(:focus):not(:disabled),
input[type="url"]:hover:not(:focus):not(:disabled),
input[type="tel"]:hover:not(:focus):not(:disabled),
input[type="password"]:hover:not(:focus):not(:disabled),
textarea:hover:not(:focus):not(:disabled),
select:hover:not(:focus):not(:disabled),
.form-control:hover:not(:focus):not(:disabled) {
    border-color: #9ca3af !important;
}

/* Focus state - enhanced ring */
input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus,
.form-control:focus {
    outline: none !important;
    border-color: #1a8da9 !important;
    box-shadow: 0 0 0 3px rgba(26, 141, 169, 0.15), 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;
}

/* Disabled state */
input[type="text"]:disabled,
input[type="email"]:disabled,
input[type="number"]:disabled,
input[type="date"]:disabled,
input[type="datetime-local"]:disabled,
input[type="time"]:disabled,
input[type="url"]:disabled,
input[type="tel"]:disabled,
input[type="password"]:disabled,
textarea:disabled,
select:disabled,
.form-control:disabled {
    background-color: #f9fafb !important;
    color: #9ca3af !important;
    cursor: not-allowed !important;
    border-color: #e5e7eb !important;
}

/* ==========================================================================
   TEXTAREA SPECIFIC
   ========================================================================== */

textarea {
    min-height: 120px !important;
    resize: vertical !important;
    line-height: 1.6 !important;
}

/* ==========================================================================
   SELECT DROPDOWNS - ENHANCED
   ========================================================================== */

select,
select.form-control {
    background-color: #ffffff !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    padding-right: 2.75rem !important;
    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") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.75rem center !important;
    background-size: 1.25em 1.25em !important;
    cursor: pointer !important;
}

select:focus {
    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='%231a8da9' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E") !important;
}

/* ==========================================================================
   CHECKBOXES AND RADIOS - MODERN STYLE
   ========================================================================== */

input[type="checkbox"],
input[type="radio"] {
    width: 1.125rem !important;
    height: 1.125rem !important;
    border: 2px solid #d1d5db !important;
    cursor: pointer !important;
    accent-color: #1a8da9 !important;
    transition: all 0.15s ease !important;
}

input[type="checkbox"]:hover:not(:disabled),
input[type="radio"]:hover:not(:disabled) {
    border-color: #1a8da9 !important;
}

input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(26, 141, 169, 0.15) !important;
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background-color: #1a8da9 !important;
    border-color: #1a8da9 !important;
}

input[type="checkbox"]:disabled,
input[type="radio"]:disabled {
    background-color: #f3f4f6 !important;
    cursor: not-allowed !important;
    opacity: 0.6 !important;
}

input[type="checkbox"] {
    border-radius: 0.25rem !important;
}

input[type="radio"] {
    border-radius: 50% !important;
}

/* Checkbox/Radio labels */
.checkbox label,
.radio label {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.625rem !important;
    font-weight: 400 !important;
    cursor: pointer !important;
    color: #374151 !important;
    transition: color 0.15s ease !important;
}

.checkbox label:hover,
.radio label:hover {
    color: #111827 !important;
}

/* ==========================================================================
   HELP TEXT
   ========================================================================== */

.help-block,
.form-text {
    margin-top: 0.375rem !important;
    font-size: 0.8125rem !important;
    color: #6b7280 !important;
    line-height: 1.5 !important;
}

/* ==========================================================================
   ERROR MESSAGES - ENHANCED
   ========================================================================== */

.has-error .help-block,
.invalid-feedback,
.error {
    display: flex !important;
    align-items: center !important;
    gap: 0.375rem !important;
    margin-top: 0.375rem !important;
    font-size: 0.8125rem !important;
    color: #dc2626 !important;
    font-weight: 500 !important;
}

.has-error .help-block::before,
.invalid-feedback::before {
    content: '!' !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 1rem !important;
    height: 1rem !important;
    background-color: #dc2626 !important;
    color: white !important;
    border-radius: 50% !important;
    font-size: 0.625rem !important;
    font-weight: 700 !important;
}

.has-error input,
.has-error select,
.has-error textarea,
.is-invalid {
    border-color: #dc2626 !important;
    background-color: #fef2f2 !important;
}

.has-error input:focus,
.has-error select:focus,
.has-error textarea:focus,
.is-invalid:focus {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
    background-color: #ffffff !important;
}

/* ==========================================================================
   SUCCESS STATES
   ========================================================================== */

.has-success input,
.has-success select,
.has-success textarea {
    border-color: #10b981 !important;
}

.has-success input:focus,
.has-success select:focus,
.has-success textarea:focus {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
}

.has-success .help-block {
    color: #059669 !important;
}

/* ==========================================================================
   FILE INPUTS - MODERN STYLE
   ========================================================================== */

input[type="file"] {
    display: block !important;
    width: 100% !important;
    padding: 0.75rem !important;
    font-size: 0.875rem !important;
    color: #374151 !important;
    cursor: pointer !important;
    border: 2px dashed #d1d5db !important;
    border-radius: 0.5rem !important;
    background-color: #f9fafb !important;
    transition: all 0.2s ease !important;
}

input[type="file"]:hover {
    border-color: #1a8da9 !important;
    background-color: rgba(26, 141, 169, 0.05) !important;
}

input[type="file"]::file-selector-button {
    margin-right: 1rem !important;
    padding: 0.5rem 1.25rem !important;
    border-radius: 0.375rem !important;
    border: none !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    background-color: #1a8da9 !important;
    color: #ffffff !important;
    cursor: pointer !important;
    transition: opacity 0.2s !important;
}

input[type="file"]::file-selector-button:hover {
    opacity: 0.9 !important;
}

/* Buttons in forms */
.btn,
button[type="submit"],
input[type="submit"] {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0.625rem 1.5rem !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    border-radius: 0.5rem !important;
    border: none !important;
    cursor: pointer !important;
    transition: all 0.2s ease-in-out !important;
}

.btn:focus,
button[type="submit"]:focus,
input[type="submit"]:focus {
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3) !important;
}

.btn:disabled,
button[type="submit"]:disabled,
input[type="submit"]:disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
}

.btn-primary {
    background-color: #1a8da9 !important;
    color: #ffffff !important;
}

.btn-primary:hover:not(:disabled) {
    opacity: 0.9 !important;
}

.btn-success {
    background-color: #10b981 !important;
    color: #ffffff !important;
}

.btn-success:hover:not(:disabled) {
    opacity: 0.9 !important;
}

.btn-danger {
    background-color: #ef4444 !important;
    color: #ffffff !important;
}

.btn-danger:hover:not(:disabled) {
    opacity: 0.9 !important;
}

.btn-warning {
    background-color: #f59e0b !important;
    color: #ffffff !important;
}

.btn-warning:hover:not(:disabled) {
    opacity: 0.9 !important;
}

.btn-secondary,
.btn-default {
    background-color: #e5e7eb !important;
    color: #374151 !important;
}

.btn-secondary:hover:not(:disabled),
.btn-default:hover:not(:disabled) {
    background-color: #d1d5db !important;
}

.btn-outline-danger {
    background-color: #ffffff !important;
    color: #ef4444 !important;
    border: 2px solid #ef4444 !important;
}

.btn-outline-danger:hover:not(:disabled) {
    background-color: #ef4444 !important;
    color: #ffffff !important;
}

/* Form actions (button container) */
.form-actions,
.form-group.form-actions {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 0.75rem !important;
    padding-top: 1rem !important;
    margin-top: 1.5rem !important;
    border-top: 1px solid #e5e7eb !important;
}

/* Asterisk for required fields */
.asteriskField {
    color: #ef4444 !important;
    margin-left: 0.25rem !important;
}

/* Read-only fields */
input[readonly],
select[disabled],
textarea[readonly] {
    background-color: #f9fafb !important;
    cursor: not-allowed !important;
}

/* CKEditor wrapper */
.django-ckeditor-widget {
    width: 100% !important;
}

/* Image cropping */
.image-ratio {
    margin-bottom: 1rem !important;
}

/* DatePicker */
.datepicker,
.datetimepicker {
    width: 100% !important;
}

/* Inline formsets */
.inline-group {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
}

.inline-related {
    background-color: #f9fafb !important;
    border-radius: 0.5rem !important;
    padding: 1rem !important;
    border: 1px solid #e5e7eb !important;
}

/* Clearfix utility (mantido para compatibilidade) */
.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* Grid system overrides */
.row,
div[class*="grid-cols-12"] {
    display: grid !important;
    grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
    gap: 1rem !important;
    margin-bottom: 1rem !important;
}

/* Tailwind col-span classes */
.col-span-1 { grid-column: span 1 / span 1 !important; }
.col-span-2 { grid-column: span 2 / span 2 !important; }
.col-span-3 { grid-column: span 3 / span 3 !important; }
.col-span-4 { grid-column: span 4 / span 4 !important; }
.col-span-5 { grid-column: span 5 / span 5 !important; }
.col-span-6 { grid-column: span 6 / span 6 !important; }
.col-span-7 { grid-column: span 7 / span 7 !important; }
.col-span-8 { grid-column: span 8 / span 8 !important; }
.col-span-9 { grid-column: span 9 / span 9 !important; }
.col-span-10 { grid-column: span 10 / span 10 !important; }
.col-span-11 { grid-column: span 11 / span 11 !important; }
.col-span-12 { grid-column: span 12 / span 12 !important; }

/* Bootstrap col-md-* compatibility (fallback) */
.col-md-1 { grid-column: span 1 / span 1 !important; }
.col-md-2 { grid-column: span 2 / span 2 !important; }
.col-md-3 { grid-column: span 3 / span 3 !important; }
.col-md-4 { grid-column: span 4 / span 4 !important; }
.col-md-5 { grid-column: span 5 / span 5 !important; }
.col-md-6 { grid-column: span 6 / span 6 !important; }
.col-md-7 { grid-column: span 7 / span 7 !important; }
.col-md-8 { grid-column: span 8 / span 8 !important; }
.col-md-9 { grid-column: span 9 / span 9 !important; }
.col-md-10 { grid-column: span 10 / span 10 !important; }
.col-md-11 { grid-column: span 11 / span 11 !important; }
.col-md-12 { grid-column: span 12 / span 12 !important; }

/* Responsive adjustments */
@media (max-width: 768px) {
    .row,
    div[class*="grid-cols-12"] {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
    
    [class*="col-span-"] {
        grid-column: 1 / -1 !important;
    }
    
    .form-actions {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    
    .form-actions .btn,
    .form-actions a {
        width: 100% !important;
        justify-content: center !important;
    }
}
