/* Liste d'Épicerie - Styles spécifiques */

/* ========== LAYOUT FLEX POUR SCROLL INTERNE ========== */
/* Container de la liste scrollable - permet l'auto-scroll mobile */
.list-scroll-container {
    /* CRITIQUE: Hauteur maximale basée sur le viewport pour forcer le scroll */
    max-height: 70vh; /* 70% de la hauteur du viewport */
    min-height: 300px; /* Minimum pour petits écrans */
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling pour desktop */
    scroll-behavior: auto; /* Désactiver smooth pour l'auto-scroll programmatique */
}

/* Assurer que le conteneur parent flex fonctionne correctement */
.card.d-flex.flex-column[style*="flex: 1"] {
    display: flex !important;
    flex-direction: column !important;
}

/* Heading size adjustments for proper hierarchy */
.card-header h2 {
    font-size: 1.25rem;
}

/* Items list styling */
#listeItems .item-row {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    background: var(--bs-body-bg);
    transition: all 0.3s ease;
}

#listeItems .item-row.item-checked {
    opacity: 0.6;
    background: var(--bs-secondary-bg);
}

#listeItems .item-row:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* New 3-line layout structure */
.item-container {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.item-checkbox-wrapper {
    flex-shrink: 0;
}

.item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.item-actions {
    flex-shrink: 0;
}

/* Line 1: Item name - prominent and clear */
.item-name {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--bs-body-color);
}

/* Line 2: Details - compact inline display */
.item-details {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.9rem;
    color: var(--bs-secondary-color);
    line-height: 1.4;
}

.detail-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.detail-label {
    font-weight: 500;
    color: var(--bs-body-color);
}

.detail-separator {
    color: var(--bs-border-color);
    font-weight: bold;
}

/* Line 3: Total price - visually distinct */
.item-total {
    font-size: 1rem;
    font-weight: 600;
    color: var(--bs-success);
    line-height: 1.3;
}

.total-breakdown {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--bs-secondary-color);
}

/* Tax breakdown section for taxed items - single line layout */
.item-tax-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.95rem;
    margin-top: 0.25rem;
    line-height: 1.4;
}

.tax-section {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.tax-label {
    font-weight: 500;
    color: var(--bs-body-color);
}

.tax-value {
    font-weight: 600;
    color: var(--bs-body-color);
}

.tax-details-inline {
    color: var(--bs-secondary-color);
    font-weight: 400;
}

.tax-separator {
    color: var(--bs-border-color);
    font-weight: bold;
}

.tax-section.tax-final {
    margin-left: 0;
    color: var(--bs-success);
}

.tax-section.tax-final .tax-label {
    color: var(--bs-success);
}

.tax-value-final {
    font-weight: 700;
    color: var(--bs-success);
    font-size: 1.05rem;
}

/* Inline editing styles */
.editable-field {
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease, border-bottom 0.2s ease;
    min-height: 1.5rem;
    display: inline-block;
    min-width: 50px;
    border-bottom: 2px dotted var(--bs-primary);
    position: relative;
}

.editable-field::after {
    content: "";
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    margin-left: 0.25rem;
    /* Using Bootstrap Icons pencil-fill as base64 SVG */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%230d6efd' viewBox='0 0 16 16'%3E%3Cpath d='M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0;
    transition: opacity 0.2s ease;
    vertical-align: middle;
}

/* Dark mode icon color adjustment */
[data-bs-theme="dark"] .editable-field::after {
    /* Use a lighter blue for dark mode visibility */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236ea8fe' viewBox='0 0 16 16'%3E%3Cpath d='M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z'/%3E%3C/svg%3E");
}

.editable-field:hover {
    background-color: var(--bs-primary-bg-subtle);
    border-bottom: 2px solid var(--bs-primary);
}

.editable-field:hover::after {
    opacity: 1;
}

.editable-field.editing {
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-primary);
    border-bottom: 2px solid var(--bs-primary);
    padding: 0.5rem;
}

.editable-field.editing::after {
    display: none;
}

.editable-field input[type="text"],
.editable-field input[type="number"],
.editable-field select:not(.form-select) {
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    width: 100%;
    min-width: 60px;
}

.editable-field input[type="text"]:focus,
.editable-field input[type="number"]:focus,
.editable-field select:not(.form-select):focus {
    outline: none;
}

/* Edit action buttons */
.save-edit-btn,
.cancel-edit-btn {
    white-space: nowrap;
    flex-shrink: 0;
}

.save-edit-btn {
    min-width: 80px;
}

.cancel-edit-btn {
    min-width: 80px;
}

/* Item checkbox */
.item-checkbox {
    width: 1.5rem;
    height: 1.5rem;
    cursor: pointer;
}

/* Delete button */
.btn-delete-item {
    padding: 0.25rem 0.5rem;
    font-size: 1.2rem;
    line-height: 1;
}

/* Tax option inline editing */
.tax-options-inline {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.tax-options-inline .form-check {
    margin-bottom: 0;
}

.tax-options-inline .form-check-inline {
    margin-right: 0.5rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    /* Maintain 3-line structure on screens ≤768px with adjusted spacing */
    .item-container {
        gap: 0.5rem;
    }
    
    .item-name {
        font-size: 1rem;
    }
    
    .item-details {
        font-size: 0.85rem;
        gap: 0.4rem;
    }
    
    .item-total {
        font-size: 0.95rem;
    }
    
    .total-breakdown {
        font-size: 0.8rem;
    }
    
    /* Tax breakdown responsiveness */
    .item-tax-breakdown {
        font-size: 0.9rem;
        gap: 0.4rem;
    }
    
    .tax-section {
        gap: 0.3rem;
    }
    
    .tax-separator {
        display: none; /* Hide separators on medium screens for cleaner wrapping */
    }
    
    /* Allow details to wrap naturally on smaller screens */
    .detail-item {
        flex-shrink: 0;
    }
    
    .tax-options-inline {
        flex-direction: column;
        gap: 0.25rem;
    }
}

/* Extra compact for very small screens */
@media (max-width: 480px) {
    #listeItems .item-row {
        padding: 0.4rem 0.6rem;
        margin-bottom: 0.4rem;
    }
    
    .item-container {
        gap: 0.4rem;
    }
    
    .item-name {
        font-size: 0.95rem;
    }
    
    .item-details {
        font-size: 0.8rem;
        gap: 0.35rem;
    }
    
    .detail-separator {
        /* Hide separators on screens ≤480px for better wrapping */
        display: none;
    }
    
    /* Tax breakdown extra compact */
    .item-tax-breakdown {
        font-size: 0.85rem;
        gap: 0.3rem;
    }
    
    .tax-section {
        gap: 0.25rem;
    }
    
    .tax-value-final {
        font-size: 1rem;
    }
}

/* Totals card emphasis */
.border-primary {
    border-width: 2px !important;
}

/* Empty state */
.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--bs-secondary-color);
}

/* Animation for new items */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.item-row.new-item {
    animation: slideIn 0.3s ease;
}

/* Focus indicators for accessibility */
*:focus-visible {
    outline: 3px solid var(--bs-primary);
    outline-offset: 2px;
}

button:focus-visible,
.btn:focus-visible {
    outline: 3px solid var(--bs-primary);
    outline-offset: 3px;
}

/* Dark mode adjustments */
[data-bs-theme="dark"] .item-row {
    border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .item-row:hover {
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .editable-field:hover {
    background-color: var(--bs-primary-bg-subtle);
}

/* Drag and drop handle - customizations spécifiques pour l'outil */
/* Note: Les styles de base pour .drag-handle sont dans outilspratiques.ca/style.css */

/* ========== DRAGULA DRAG & DROP - STYLES SPÉCIFIQUES À L'ÉPICERIE ========== */
/* Note: Les styles de base Dragula (.gu-mirror, .gu-hide, etc.) sont dans outilspratiques.ca/style.css */

/* Prevent text selection on all item content during any drag operation - spécifique à #listeItems */
#listeItems.sortable-drag-active .item-row,
#listeItems.sortable-drag-active .item-row * {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

/* Placeholder pour la zone de dépôt - spécifique à #listeItems */
#listeItems .gu-mirror + * {
    margin-top: 80px !important;
    position: relative;
}

#listeItems .gu-mirror + *::before {
    content: "⬇ Déposer ici ⬇";
    position: absolute;
    top: -80px;
    left: 0;
    right: 0;
    height: 75px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bs-primary-bg-subtle) 0%, var(--bs-secondary-bg-subtle) 100%);
    border: 3px dashed var(--bs-primary);
    border-radius: var(--bs-border-radius);
    color: var(--bs-primary);
    font-weight: 700;
    font-size: 1rem;
    opacity: 0.9;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    animation: pulse-gap 0.6s ease-in-out infinite alternate; /* Animation définie dans outilspratiques.ca/style.css */
    pointer-events: none;
}

/* Responsive adjustments pour la zone de dépôt spécifique */
@media (max-width: 768px) {
    #listeItems .gu-mirror + *::before {
        font-size: 0.9rem;
        height: 60px;
    }
    
    #listeItems .gu-mirror + * {
        margin-top: 65px !important;
    }
}

/* Animation de l'espace (gap) entre les items - spécifique aux item-row */
.item-row {
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s ease, opacity 0.2s ease, margin 0.2s ease;
}
