/* ==========================================================================
   STYLE ADMINISTRATION - VEGAPP V2.1
   ==========================================================================
   1. Layout Principal & Header
   2. Navigation (Onglets)
   3. Statistiques (Dashboard)
   4. Gestion Utilisateurs (Tableaux & Contrôles)
   5. Messagerie (Split View)
   6. Modales (Fiche Client & Édition)
   7. Banque d'Images
   8. Gestion Plantes
   ========================================================================== */

/* --- 1. LAYOUT PRINCIPAL & HEADER --- */

/* --- FIX ADMIN PANEL (Écran coupé) --- */
#adminPanel.admin-view {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: #f4f6f8;
    z-index: 1;
    display: none; /* Caché par défaut via JS, devient flex quand actif */
    flex-direction: column;
    margin: 0 !important;
    padding: 0 !important;
}

/* --- BOUTONS MODERNES (Adieu Windows XP) --- */
.btn-mini {
    padding: 6px 12px;
    border: 1px solid #166534;
    background-color: #ffffff;
    color: #166534;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.btn-mini:hover {
    background-color: #166534;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-mini:active {
    transform: translateY(0);
}

.admin-tabs-modern {
    background: #fff;
    padding: 10px 20px 0 20px;
    border-bottom: 1px solid #ddd;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    margin-bottom: 0; /* Collé au contenu */
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between; /* Pour placer le bouton fermer à droite */
}

.admin-tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.admin-title {
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    color: #386641;
    font-size: 1.8rem;
}

.admin-controls {
    display: flex;
    gap: 10px;
}

.btn-admin {
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    transition: background-color 0.2s;
}

.btn-back { background-color: #eee; color: #333; }
.btn-back:hover { background-color: #ddd; }

.btn-logout { background-color: #c5221f; color: white; }
.btn-logout:hover { background-color: #a01b19; }

.btn-refresh { background-color: #386641; color: white; }
.btn-refresh:hover { background-color: #2e5435; }

.admin-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #333;
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    z-index: 400;
    font-size: 1.5rem;
    transition: transform 0.2s;
}

.admin-toggle-btn:hover { transform: scale(1.1); }


/* --- 2. NAVIGATION (ONGLETS) --- */

.admin-tabs-modern {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 0;
    overflow-x: auto; /* Sécurité responsive */
    min-height: 50px;
}

.admin-tab-btn {
    background: none;
    border: none;
    padding: 12px 20px;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    white-space: nowrap;
}

.admin-tab-btn:hover {
    color: #386641;
    background-color: #f0fdf4;
    border-radius: 6px 6px 0 0;
}

.admin-tab-btn.active {
    color: #386641;
    border-bottom-color: #386641;
}

.tab-icon { font-size: 1.2rem; }

.badge-count {
    background-color: #c5221f;
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 5px;
}


/* --- 3. STATISTIQUES (DASHBOARD) --- */

.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    text-align: center;
}

.stat-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: #386641;
    display: block;
}

.stat-label {
    color: #666;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}


/* --- 4. GESTION UTILISATEURS --- */

.users-container {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    margin-bottom: 20px; /* Espace si plusieurs conteneurs */
}

.users-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.search-box input {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    width: 300px;
    font-family: 'Open Sans', sans-serif;
}

/* Tableau */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Open Sans', sans-serif;
}

.admin-table th {
    text-align: left;
    padding: 15px;
    background-color: #f8f9fa;
    color: #555;
    font-weight: 600;
    border-bottom: 2px solid #eee;
    position: relative; /* Pour les icônes de tri */
    user-select: none;
    transition: background-color 0.2s;
}

.admin-table th:hover { background-color: #f0f2f5; }

.admin-table th[title]:hover::after {
    content: '⇅';
    position: absolute;
    right: 5px;
    color: #ccc;
    font-size: 0.8em;
}

.admin-table td {
    padding: 15px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}

/* Badges Statut */
.status-badge {
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}
.status-active { background-color: #dcfce7; color: #166534; }
.status-inactive { background-color: #fee2e2; color: #991b1b; }
.status-expiring { background-color: #fef3c7; color: #92400e; }

/* Actions Tableau */
.action-cell {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.action-row {
    display: flex;
    gap: 5px;
}

.btn-icon {
    padding: 5px 8px;
    font-size: 0.75rem;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.1s;
}
.btn-icon:hover { background: #f5f5f5; }
.btn-icon.warning { color: #d97706; border-color: #d97706; }
.btn-icon.warning:hover { background: #fffbeb; }

.client-link {
    color: #2563eb;
    cursor: pointer;
    text-decoration: underline;
}
.client-link:hover { color: #1d4ed8; }

/* Formulaire Ajout Rapide */
.add-user-form {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr auto;
    gap: 10px;
    background: #f0f9f0;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    align-items: end;
}

.add-user-form input, 
.add-user-form select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 100%;
}


/* --- 5. MESSAGERIE (SPLIT VIEW) --- */

.messaging-container {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 20px;
    height: 100%;
    min-height: 600px;
}

/* Liste des messages (Gauche) */
.msg-list-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.msg-list-header {
    padding: 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    gap: 5px;
}

.msg-filter-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid #eee;
    background: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    transition: all 0.2s;
}

.msg-filter-btn:hover { background-color: #f9f9f9; }
.msg-filter-btn.active {
    background-color: #386641;
    color: white;
    border-color: #386641;
}

.msg-list-items {
    overflow-y: auto;
    flex-grow: 1;
}

.msg-item {
    padding: 15px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s;
    border-left: 4px solid transparent;
}

.msg-item:hover { background-color: #f9fafb; }
.msg-item.selected {
    background-color: #f0fdf4;
    border-left-color: #386641;
}
.msg-item.unread {
    font-weight: bold;
    background-color: #fff;
}
.msg-item.unread .msg-subject { color: #386641; }
.msg-item.outgoing { /* Messages envoyés par l'admin */
    border-left-color: #ddd;
}
.msg-item.outgoing .msg-subject { color: #666; }

.msg-meta {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}
.msg-subject {
    font-size: 1rem;
    margin-bottom: 4px;
    display: block;
}
.msg-preview {
    font-size: 0.85rem;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Détail Message (Droite) */
.msg-detail-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    padding: 30px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.msg-detail-header {
    border-bottom: 1px solid #eee;
    padding-bottom: 20px;
    margin-bottom: 20px;
}

.msg-detail-header h2 {
    margin: 0 0 10px 0;
    font-size: 1.5rem;
    color: #333;
}

.msg-detail-body {
    font-family: 'Open Sans', sans-serif;
    line-height: 1.6;
    color: #333;
    white-space: pre-wrap;
    margin-bottom: 30px;
    flex-grow: 1;
}

.msg-reply-area {
    background: #f9fafb;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #eee;
}

.reply-option-btn {
    padding: 8px 15px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
}
.reply-option-btn.active {
    background-color: #386641;
    color: white;
    border-color: #386641;
}

.admin-reply-textarea {
    width: 100%;
    padding: 15px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-family: inherit;
    margin-top: 10px;
    box-sizing: border-box;
}


/* --- 6. MODALES (FICHE CLIENT & ÉDITION) --- */

.client-modal-wide {
    max-width: 1000px !important;
    width: 95%;
    text-align: left;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #fdfdfd;
}

.client-modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 35px;
    margin-top: 20px;
}

input,
select,
textarea {
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
    background-color: white;
}

.client-modal-grid input:focus,
.client-modal-grid textarea:focus {
    border-color: #386641;
    outline: none;
    box-shadow: 0 0 0 3px rgba(56, 102, 65, 0.1);
}

.client-modal-grid label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #4b5563;
    margin-bottom: 6px;
}

.client-modal-grid textarea { resize: vertical; }

.modal-section-title {
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: #1f2937;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 10px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.grid-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.control-group { margin-bottom: 15px; }

.input-prefix-group {
    display: flex;
    align-items: center;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    overflow: hidden;
    width: 100%;
    background-color: white;
}
.input-prefix-group:focus-within {
    border-color: #386641;
    box-shadow: 0 0 0 3px rgba(56, 102, 65, 0.1);
}
.input-prefix-group span {
    background: #f3f4f6;
    padding: 10px 12px;
    color: #6b7280;
    font-size: 0.9rem;
    border-right: 1px solid #d1d5db;
    white-space: nowrap;
    font-weight: 500;
}
.input-prefix-group input {
    border: none !important;
    border-radius: 0 !important;
    padding: 10px 12px !important;
    flex-grow: 1;
    width: auto;
    box-shadow: none !important;
}

.modal-footer-actions {
    display: flex;
    gap: 12px;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
    justify-content: flex-end;
    background: #f9fafb;
    margin-left: -30px;
    margin-right: -30px;
    margin-bottom: -30px;
    padding: 20px 30px;
    border-radius: 0 0 8px 8px;
}

/* Mini stats dans fiche client */
.stat-box-mini {
    flex: 1;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
}

.stat-box-mini .stat-label {
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
}

.stat-box-mini .stat-value {
    font-size: 1.2rem;
    font-weight: 800;
    color: #386641;
}

@media (max-width: 900px) {
    .client-modal-grid { grid-template-columns: 1fr; gap: 20px; }
    .client-modal-wide { width: 100%; height: 100%; max-height: 100vh; border-radius: 0; padding: 15px; }
    .modal-footer-actions { margin: 20px -15px -15px -15px; padding: 15px; }
}


/* --- 7. BANQUE D'IMAGES --- */

.bank-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.bank-controls-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* Formulaire Ajout */
.bank-add-panel {
    flex: 0 0 350px;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

/* Mode Édition */
.bank-add-panel.edit-mode {
    background-color: #fffdeb;
    border-color: #fbc02d;
}
.bank-add-panel.edit-mode .panel-group-title { color: #f57f17; }
.bank-add-panel.edit-mode .btn-refresh {
    background-color: #fbc02d;
    color: #333;
}
.bank-add-panel.edit-mode .btn-refresh:hover { background-color: #f9a825; }

/* Grille Images */
.bank-grid-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.bank-filter-bar {
    display: flex;
    gap: 10px;
    background: white;
    padding: 10px 15px;
    border-radius: 8px;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.bank-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
}

.bank-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #eee;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
}

.bank-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    border-color: #386641;
}

.bank-img-preview {
    height: 140px;
    width: 100%;
    background-color: #f9f9f9;
    /* Damier de transparence */
    background-image: 
        linear-gradient(45deg, #eee 25%, transparent 25%), 
        linear-gradient(-45deg, #eee 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #eee 75%), 
        linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.bank-img-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.bank-card-body {
    padding: 10px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.bank-filename {
    font-weight: 700;
    font-size: 0.85rem;
    word-break: break-all;
    color: #333;
}

.bank-category-badge {
    display: inline-block;
    background: #e6f4ea;
    color: #1B5E20;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    align-self: flex-start;
    font-weight: 600;
}

.bank-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 5px;
}

.bank-tag {
    font-size: 0.65rem;
    color: #666;
    background: #f0f0f0;
    padding: 1px 4px;
    border-radius: 3px;
}

.bank-actions {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: flex-end;
    gap: 5px;
}

/* Gestion Catégories (Mini liste) */
.cat-manager-list {
    margin-top: 10px;
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 4px;
}

.cat-manager-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 0.85rem;
    border-bottom: 1px solid #f9f9f9;
}
.cat-manager-item:last-child { border-bottom: none; }
.cat-manager-item:hover { background-color: #f9f9f9; }


/* --- 8. GESTION PLANTES --- */

.csv-import-box {
    background: #f0fdf4;
    border: 1px dashed #386641;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.plant-thumb-mini {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
    background-color: #f5f5f5;
}

.plant-edit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #eee;
}

.plant-edit-full-width {
    grid-column: span 2;
}

.plant-img-preview-large {
    width: 100%;
    height: 200px;
    object-fit: contain;
    background-color: #eee;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-top: 5px;
}