/* Styles pour la page de gestion des stocks */

:root {
    --color-accent: #0078C6;
    --color-accent-hover: #0056a3;
    --color-text-main: #0f1928;
    --color-text-light: #666;
    --color-bg-light: #f8fafc;
    --card-radius: 35px;
    --inner-radius: 25px;
}

.gestion-container {
    max-width: 1600px;
    margin: 0 auto 60px;
    font-family: inherit;
    padding: 0 20px;
}

/* Header */
.gestion-header {
    text-align: center;
    margin-bottom: 32px;
}

.gestion-title {
    color: var(--color-accent);
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 600;
    border: none;
    padding: 0;
}

.gestion-subtitle {
    color: var(--color-text-light);
    font-size: 1.1rem;
    max-width: 600px;
    margin: 0 auto;
}

/* Carte principale */
.gestion-card {
    background: #fff;
    border-radius: var(--card-radius);
    padding: 40px;
    margin-bottom: 40px;
    position: relative;
    box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.15);
    transition: transform .35s ease, box-shadow .35s ease;
    border: 1px solid rgba(0, 0, 0, 0.03);
    overflow: hidden;
}

/* Barre d'action et indicateurs Stocks */
.actions-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 25px;
    background: var(--color-bg-light);
    padding: 20px;
    border-radius: var(--inner-radius);
}

.gestion-actions-bar {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 12px;
    background: transparent;
    padding: 0;
    margin-bottom: 20px;
    flex-wrap: nowrap;
}

/* Ordre des éléments dans la barre */
.gestion-actions-bar .sheet-tabs-rail {
    order: 1;
    flex: 1 1 auto;
}

.gestion-actions-bar .sheet-add-btn {
    order: 2;
}

.gestion-actions-bar .status-indicator-container {
    order: 3;
}

/* Conteneur scrollable des tabs + dégradés */
.sheet-tabs-rail {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

/* Dégradés pour indiquer qu'on peut scroller les tabs */
.sheet-tabs-rail::before,
.sheet-tabs-rail::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sheet-tabs-rail::before {
    left: 0;
    background: linear-gradient(to right, rgba(255, 255, 255, 0.95), transparent);
}

.sheet-tabs-rail::after {
    right: 0;
    background: linear-gradient(to left, rgba(255, 255, 255, 0.95), transparent);
}

/* Afficher les dégradés quand il y a du scroll */
.sheet-tabs-rail.has-scroll-left::before {
    opacity: 1;
}

.sheet-tabs-rail.has-scroll-right::after {
    opacity: 1;
}

.sheet-tabs-container {
    position: relative;
    z-index: 2;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
    padding: 2px 0 8px 0;

    /* IMPORTANT: on réserve un espace pour la scrollbar sous les pilules.
       -> évite d'avoir à "compenser" avec des margin sur les boutons de droite.
       Fallback via padding-bottom; et amélioration via scrollbar-gutter (si supportée). */
    padding-bottom: 14px;
    scrollbar-gutter: stable both-edges;

    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    cursor: grab;
}

.sheet-tabs-container:active {
    cursor: grabbing;
}

.sheet-tabs-container::-webkit-scrollbar {
    height: 6px;
}

.sheet-tabs-container::-webkit-scrollbar-track {
    background: transparent;
}

.sheet-tabs-container::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 999px;
}

.sheet-tabs-container::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

/* Les actions à droite doivent s'aligner sur les pilules, pas sur la zone scrollbar */
.sheet-add-btn,
.status-indicator-container {
    margin-bottom: 0;
    align-self: flex-start;
}

/* Save pill à droite - indicateur de statut */
.status-indicator-container {
    margin-left: 0;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    font-size: 0.85rem;
    color: #666;
    height: 34px;
}

/* ============================================
   PILULES DE FEUILLES (Sheet Tabs)
   ============================================ */

.sheet-tab,
.sheet-add-btn {
    height: 34px;
}

.sheet-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px 0 14px;
    border-radius: 999px;
    cursor: pointer;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    user-select: none;
    height: 34px;
    line-height: 34px;
}

.sheet-tab:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}

.sheet-tab.active-sheet {
    background: var(--color-accent, #0078C6);
    color: white;
    border-color: var(--color-accent, #0078C6);
}

/* Label de la pilule */
.sheet-tab-label {
    display: inline-block;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    line-height: 1;
    padding: 0;
    margin: 0;
}

/* Boutons d'action - style épuré SANS FOND */
.sheet-edit-btn,
.sheet-delete-btn {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none !important;
    border: none;
    cursor: pointer;
    padding: 0;
    margin: 0;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
    color: #1e293b;
    vertical-align: middle;
}

/* Afficher les boutons au survol des pilules NON ACTIVES */
.sheet-tab:not(.active-sheet):hover .sheet-edit-btn,
.sheet-tab:not(.active-sheet):hover .sheet-delete-btn {
    opacity: 1;
    color: #0078C6;
}

/* Style pour pilules ACTIVES (fond bleu) - icônes blanches TOUJOURS VISIBLES */
.sheet-tab.active-sheet .sheet-edit-btn,
.sheet-tab.active-sheet .sheet-delete-btn {
    color: rgba(255, 255, 255, 0.9);
    opacity: 1;
}

/* SVG des icônes */
.sheet-edit-btn svg,
.sheet-delete-btn svg {
    width: 14px;
    height: 14px;
    pointer-events: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: block;
}

.sheet-tab:not(.active-sheet) .sheet-edit-btn:hover {
    color: var(--color-accent) !important;
    background: none !important;
}

.sheet-tab:not(.active-sheet) .sheet-delete-btn:hover {
    color: #ef4444 !important;
    background: none !important;
}

.sheet-tab.active-sheet .sheet-edit-btn:hover {
    color: #ffffff !important;
    background: none !important;
}

.sheet-tab.active-sheet .sheet-delete-btn:hover {
    color: #fecaca !important;
    background: none !important;
}

/* Input de renommage inline */
.sheet-rename-input {
    width: 180px;
    max-width: 220px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 0.9rem;
    outline: none;
    background: white;
}

.sheet-tab.active-sheet .sheet-rename-input {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.sheet-tab.active-sheet .sheet-rename-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

/* Bouton + (ajouter feuille) */
.sheet-add-btn {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px dashed #cbd5e1;
    background: #fff;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
    transition: all 0.15s ease;
    padding: 0;
}

.sheet-add-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
    background: #f8fafc;
}

.sheet-add-btn svg {
    width: 16px;
    height: 12px;
    pointer-events: none;
    stroke: currentColor;
}

/* ============================================
   MENU CONTEXTUEL (Excel-like)
   ============================================ */

#contextMenu {
    display: none;
    position: fixed;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    padding: 12px;
    min-width: 240px;
    z-index: 99999;
    font-size: 0.9rem;
}

.menu-section {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.menu-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.menu-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    font-weight: 600;
}

/* Grille de couleurs */
.color-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
}

.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.1);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.color-swatch:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

.custom-color-picker {
    cursor: pointer;
}

/* Boutons d'alignement et styles de texte */
.align-options {
    display: flex;
    gap: 4px;
}

.align-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
}

.align-btn:hover {
    background: #f8fafc;
    border-color: var(--color-accent);
}

.align-btn svg {
    width: 16px;
    height: 16px;
    fill: #64748b;
    pointer-events: none;
}

.align-btn:hover svg {
    fill: var(--color-accent);
}

.context-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.context-menu-item:hover {
    background: #f1f5f9;
}

/* ============================================
   GRILLE EXCEL - SELECTION
   ============================================ */

.excel-grid-container {
    margin-bottom: 25px;
}

.excel-grid {
    overflow-x: auto;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: #fff;
    border-radius: 8px;
    max-height: 500px;
    overflow-y: auto;
}

.excel-grid table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    font-size: 0.9rem;
    table-layout: fixed;
}

.excel-grid th,
.excel-grid td {
    border: 1px solid #e2e8f0;
    padding: 8px 12px;
    text-align: left;
    /* min-width défini dynamiquement en JS pour supporter les cellules fusionnées */
    position: relative;
}

.excel-grid th {
    background: #f1f5f9;
    color: var(--color-text-main);
    font-weight: 600;
    text-align: center;
    user-select: none;
}

.excel-grid .row-header {
    background: #f8fafc;
    color: #64748b;
    font-weight: 500;
    cursor: pointer;
    min-width: 40px;
    width: 40px;
    text-align: center;
    font-size: 0.85rem;
}

.excel-grid .col-header {
    background: #f8fafc;
    color: #64748b;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    font-size: 0.85rem;
    /* La largeur est définie inline par JavaScript */
}

.excel-grid .row-header:hover,
.excel-grid .col-header:hover {
    background: #e2e8f0;
}

.excel-grid td[contenteditable="true"] {
    background: #fff;
    cursor: cell;
}

.excel-grid td[contenteditable="true"]:focus {
    background: #fffbeb;
    outline: 2px solid var(--color-accent);
    z-index: 2;
    position: relative;
    border-radius: 4px;
}

/* Cellules sélectionnées */
.excel-grid .selected-cell {
    background: rgba(0, 120, 198, 0.1) !important;
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

.selection-handle {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 10px;
    height: 10px;
    background-color: var(--color-accent);
    border: 1px solid #fff;
    cursor: move;
    /* Curseur de déplacement comme demandé */
    z-index: 100;
    pointer-events: auto;
}

.loading-text {
    text-align: center;
    color: #666;
    padding: 20px;
}

.error-text {
    text-align: center;
    color: #ef4444;
    padding: 20px;
    font-weight: 500;
}

/* ============================================
   ANIMATIONS - SAVE STATUS
   ============================================ */

@keyframes jumpDot {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }
}

.jump-anim {
    animation: jumpDot 0.4s ease;
}

.unsaved-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    transition: background 0.3s ease;
}

.gestion-footer-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 25px;
    flex-wrap: wrap;
}

/* Boutons secondaires (import/export) */
.btn-secondary-action {
    display: inline-block;
    padding: 8px 20px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 30px;
    color: #666;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

.btn-secondary-action:hover {
    border-color: var(--color-accent);
    color: var(--color-accent) !important;
    background: #f8fafc !important;
}

/* ============================================
   FADE EFFECT FOR SHEET TABS SCROLLING
   ============================================ */

.sheet-tabs-fade {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 20px;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sheet-tabs-fade-left {
    left: 0;
    background: linear-gradient(to right, rgba(248, 250, 252, 1), rgba(248, 250, 252, 0));
}

.sheet-tabs-fade-right {
    right: 0;
    background: linear-gradient(to left, rgba(248, 250, 252, 1), rgba(248, 250, 252, 0));
}

/* ============================================
   MODALES
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: white;
    border-radius: 32px;
    padding: 32px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-box {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.modal-header {
    margin-bottom: 20px;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text-main);
    margin: 0;
}

.modal-body {
    padding: 10px 0;
    max-height: calc(90vh - 140px);
    overflow-y: auto;
}

.modal-body p {
    color: var(--color-text-light);
    line-height: 1.6;
    margin: 0;
}

.modal-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s ease;
    font-family: inherit;
    margin-top: 8px;
}

.modal-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(0, 120, 198, 0.1);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 0 0 20px;
    border-radius: 0 0 24px 24px;
}

.modal-btn {
    padding: 12px 28px;
    border-radius: 50px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: inherit;
    min-width: 110px;
    text-align: center;
}

.modal-btn-primary {
    background: var(--color-accent);
    color: white;
}

.modal-btn-primary:hover {
    background: var(--color-accent-hover);
    transform: translateY(-2px);
}

.modal-btn-primary:active {
    transform: translateY(0);
}

.modal-btn-secondary {
    background: #f1f5f9;
    color: #475569;
}

.modal-btn-secondary:hover {
    background: #e2e8f0;
    transform: translateY(-2px);
}

.modal-btn-secondary:active {
    transform: translateY(0);
}

.modal-btn-danger {
    background: #ef4444;
    color: white;
}

.modal-btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
}

.modal-btn-danger:active {
    transform: translateY(0);
}

/* Animation shake pour les erreurs */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-10px);
    }

    75% {
        transform: translateX(10px);
    }
}

.modal-box.shake {
    animation: shake 0.4s ease;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.d-none {
    display: none !important;
}

.d-flex {
    display: flex;
}

.mb-20 {
    margin-bottom: 20px;
}

.mt-10 {
    margin-top: 10px;
}

.m-0 {
    margin: 0;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .gestion-container {
        padding: 15px;
        margin-top: 30px;
    }

    .gestion-title {
        font-size: 2rem;
    }

    .gestion-card {
        padding: 25px 20px;
        border-radius: 25px;
    }

    .sheet-tabs-rail {
        order: 2;
        margin-top: 10px;
    }

    .status-indicator-container {
        order: 1;
        margin-bottom: 0;
    }
}

/* ============================================
   REDIMENSIONNEMENT DES COLONNES ET LIGNES
   ============================================ */

/* Poignée de redimensionnement des colonnes */
.excel-grid .col-header {
    position: relative;
    overflow: visible;
}

.col-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 20;
    background: transparent;
    transition: background 0.15s ease;
    transform: translateX(50%);
}

.col-resize-handle:hover,
.col-resize-handle.active {
    background: var(--color-accent);
}

/* Poignée de redimensionnement des lignes */
.excel-grid .row-header {
    position: relative;
    overflow: visible;
}

.row-resize-handle {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 8px;
    cursor: row-resize;
    z-index: 20;
    background: transparent;
    transition: background 0.15s ease;
    transform: translateY(50%);
}

.row-resize-handle:hover,
.row-resize-handle.active {
    background: var(--color-accent);
}

/* Ligne de prévisualisation lors du redimensionnement */
.resize-line {
    position: fixed;
    z-index: 100000;
    pointer-events: none;
}

.resize-line-col {
    width: 2px;
    background: var(--color-accent);
    top: 0;
    bottom: 0;
}

.resize-line-row {
    height: 2px;
    background: var(--color-accent);
    left: 0;
    right: 0;
}

/* Curseur lors du redimensionnement */
body.resizing-col,
body.resizing-col * {
    cursor: col-resize !important;
    user-select: none !important;
}

body.resizing-row,
body.resizing-row * {
    cursor: row-resize !important;
    user-select: none !important;
}

/* ============================================
   CELLULES FUSIONNÉES
   ============================================ */

.excel-grid td.merged-cell {
    background: #fff;
}

.excel-grid td.merged-hidden {
    display: none;
}