/**
 * Currency Input Fields Styling
 * VinFast Project - Vietnamese Currency Formatting
 */

/* Base Currency Input Styling - Only for actual currency fields */
.currency-input,
input[data-format="currency"],
input[data-type="currency"] {
    text-align: right !important;
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    padding: 8px 25px 8px 12px !important; /* Extra padding for VND suffix */
    border: 2px solid #dee2e6 !important;
    border-radius: 4px !important;
    background-color: #f8f9fa !important;
    transition: all 0.3s ease !important;
    min-width: 150px !important;
    box-sizing: border-box !important;
}

/* Non-currency number and text fields */
.non-currency-field,
input[data-format="number"],
input[data-format="text"],
input[name*="number"]:not(.currency-input),
input[name*="code"]:not(.currency-input),
input[name*="_id"]:not(.currency-input) {
    text-align: left !important;
    font-family: inherit !important;
    padding: 8px 12px !important;
    font-weight: normal !important;
}

/* Focus State */
.currency-input:focus {
    background-color: #fffbf0 !important;
    border-color: #f0ad4e !important;
    box-shadow: 0 0 0 0.2rem rgba(240, 173, 78, 0.25) !important;
    outline: none !important;
}

/* Hover State */
.currency-input:hover:not(:focus) {
    border-color: #adb5bd !important;
    background-color: #ffffff !important;
}

/* Valid State */
.currency-input.currency-valid {
    border-color: #28a745 !important;
    background-color: #f8fff9 !important;
}

/* Error State */
.currency-input.currency-error-field {
    border-color: #dc3545 !important;
    background-color: #fff5f5 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

/* Calculated State (visual feedback) */
.currency-input.currency-calculated {
    background-color: #d4edda !important;
    border-color: #28a745 !important;
    transition: all 0.3s ease !important;
}

/* Currency Error Messages */
.currency-error {
    display: block;
    color: #dc3545;
    font-size: 12px;
    margin-top: 5px;
    font-style: italic;
    font-weight: normal;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 3px;
    padding: 4px 8px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Currency field in inline forms */
.inline-related .currency-input {
    width: 140px !important;
    min-width: 140px !important;
    font-size: 13px !important;
}

/* Currency field in tabular inlines */
.tabular .currency-input {
    width: 120px !important;
    min-width: 120px !important;
    margin: 2px !important;
}

/* Readonly currency fields */
.currency-input[readonly],
.currency-input:disabled {
    background-color: #e9ecef !important;
    color: #495057 !important;
    font-weight: bold !important;
    border-color: #ced4da !important;
    cursor: not-allowed !important;
}

/* Currency input wrapper for positioning */
.currency-input-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* Date fields should never be formatted as currency */
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[name*="date"]:not(.currency-input) {
    text-align: left !important;
    font-family: inherit !important;
    padding: 8px 12px !important;
}

/* VND suffix for currency fields only */
.currency-input-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.currency-input-wrapper::after,
.currency-input[data-currency="VND"]::after {
    content: "₫";
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    pointer-events: none;
    font-size: 14px;
    font-weight: normal;
}

/* Large number styling for better readability */
.currency-input.large-number {
    font-size: 16px !important;
    font-weight: 600 !important;
    min-width: 200px !important;
}

/* Success feedback animation */
.currency-input.success-feedback {
    background-color: #d4edda !important;
    border-color: #28a745 !important;
    animation: successPulse 0.6s ease-in-out;
}

@keyframes successPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

/* Form row styling for currency fields */
.form-row .currency-input {
    max-width: 250px;
}

/* Fieldset styling for currency groups */
.currency-fieldset {
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 15px;
    margin: 10px 0;
    background-color: #f8f9fa;
}

.currency-fieldset legend {
    font-weight: bold;
    color: #495057;
    padding: 0 10px;
    font-size: 14px;
}

/* Mobile responsive */
@media (max-width: 767px) {
    .currency-input {
        width: 100% !important;
        min-width: auto !important;
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    
    .inline-related .currency-input,
    .tabular .currency-input {
        width: 100% !important;
        min-width: auto !important;
    }
    
    .currency-error {
        font-size: 11px;
        padding: 3px 6px;
    }
}

/* Tablet responsive */
@media (min-width: 768px) and (max-width: 991px) {
    .currency-input {
        min-width: 120px !important;
    }
    
    .inline-related .currency-input {
        width: 120px !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .currency-input {
        border-width: 3px !important;
    }
    
    .currency-input:focus {
        border-color: #000000 !important;
        box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.5) !important;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .currency-input,
    .currency-error,
    .currency-input.success-feedback {
        transition: none !important;
        animation: none !important;
    }
}

/* Print styles */
@media print {
    .currency-input {
        border: 1px solid #000 !important;
        background: transparent !important;
        box-shadow: none !important;
    }
    
    .currency-error {
        display: none !important;
    }
}

/* Dark mode support (if implemented) */
@media (prefers-color-scheme: dark) {
    .currency-input {
        background-color: #2d3748 !important;
        border-color: #4a5568 !important;
        color: #e2e8f0 !important;
    }
    
    .currency-input:focus {
        background-color: #1a202c !important;
        border-color: #f6ad55 !important;
    }
    
    .currency-error {
        background-color: #742a2a !important;
        border-color: #e53e3e !important;
        color: #fed7d7 !important;
    }
}

/* Integration with existing admin styles */
.vTextField.currency-input,
.vIntegerField.currency-input,
.vPositiveIntegerField.currency-input {
    text-align: right !important;
}

/* Override Django admin default styles */
.form-row .currency-input,
.grp-row .currency-input {
    background-color: #f8f9fa !important;
}

/* Specific styling for vehicle sale forms */
.vehicle-sale-form .currency-input {
    min-width: 180px !important;
    font-size: 15px !important;
}

/* Specific styling for parts service forms */
.parts-service-form .currency-input {
    min-width: 120px !important;
}

/* Loading state */
.currency-input.loading {
    background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><circle cx="10" cy="10" r="8" fill="none" stroke="%23999" stroke-width="2" stroke-dasharray="12.566" stroke-dashoffset="12.566"><animateTransform attributeName="transform" type="rotate" values="0 10 10;360 10 10" dur="1s" repeatCount="indefinite"/></circle></svg>') !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    background-size: 16px 16px !important;
}
