/**
 * Editable Table Styles
 * Styles pour les champs éditables inline (contenteditable, input, textarea)
 */

/* Contenteditable elements (td, div, span) */
[contenteditable="true"] {
    cursor: text;
    transition: background-color 0.3s ease, border 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

[contenteditable="true"]:hover {
    background-color: #f9f9f9;
    box-shadow: inset 0 0 0 1px rgba(91, 192, 222, 0.3);
}

[contenteditable="true"]:focus {
    background-color: #fff;
    outline: 2px solid #5bc0de;
    outline-offset: -2px;
    box-shadow: 0 0 8px rgba(91, 192, 222, 0.4);
}

/* Input and textarea with editable data attributes */
input[data-table][data-field],
textarea[data-table][data-field] {
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

input[data-table][data-field]:focus,
textarea[data-table][data-field]:focus {
    border-color: #5bc0de;
    box-shadow: 0 0 8px rgba(91, 192, 222, 0.4);
}

/* Loading state */
.edit-loading,
[contenteditable="true"].edit-loading,
input.edit-loading,
textarea.edit-loading {
    background-color: #fffacd !important;
    position: relative;
    pointer-events: none;
}

.edit-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 8px;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Success state (after save) */
.edit-success,
[contenteditable="true"].edit-success,
input.edit-success,
textarea.edit-success {
    background-color: #dff0d8 !important;
    border-color: #5cb85c !important;
    animation: fadeSuccess 2s ease forwards;
}

@keyframes fadeSuccess {
    0% {
        background-color: #dff0d8;
        border-color: #5cb85c;
    }
    100% {
        background-color: transparent;
        border-color: #ccc;
    }
}

/* Error state (after failed save) */
.edit-error,
[contenteditable="true"].edit-error,
input.edit-error,
textarea.edit-error {
    background-color: #f2dede !important;
    border-color: #d9534f !important;
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

/* Table specific styles */
table.table-bordered td[contenteditable="true"] {
    padding: 8px;
    min-height: 20px;
}

table.table-bordered td[contenteditable="true"]:empty::before {
    content: attr(data-placeholder);
    color: #999;
    font-style: italic;
}

/* Readonly state */
input[readonly],
textarea[readonly] {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

/* Helper class for non-editable computed fields */
.td-computed {
    background-color: #f9f9f9;
    color: #666;
    font-style: italic;
}

/* Mobile responsive */
@media (max-width: 768px) {
    [contenteditable="true"]:focus {
        outline-width: 3px;
    }

    input[data-table][data-field],
    textarea[data-table][data-field] {
        font-size: 16px; /* Prevent iOS zoom on focus */
    }
}
