/**
 * DOLIBARR MANAGER CSS
 * Styles pour l'interface de synchronisation Dolibarr
 * Version: 2.0.0
 */

/* ====================================================================
   CONTENEUR PRINCIPAL
   ==================================================================== */
.dolibarr-container {
    max-width: 1400px;
    margin: 0 auto;
}

.dolibarr-container .dolibarr-container {
    padding: 0;
}

/* ====================================================================
   HEADER
   ==================================================================== */
.dolibarr-header {
    margin-bottom: 30px;
}

.dolibarr-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.dolibarr-title h1 {
    font-size: 24px;
    font-weight: 600;
    color: #111827;
    margin: 0;
    font-family: var(--font-title, 'Outfit', sans-serif);
}

.dolibarr-title svg {
    width: 28px;
    height: 28px;
    color: #009FE3;
}

.dolibarr-subtitle {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
}

/* ====================================================================
   STATS CARDS
   ==================================================================== */
.dolibarr-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

@media (max-width: 1024px) {
    .dolibarr-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .dolibarr-stats {
        grid-template-columns: 1fr;
    }
}

.dolibarr-stats .stat-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.2s ease;
}

.dolibarr-stats .stat-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.dolibarr-stats .stat-card.loading {
    opacity: 0.6;
}

.dolibarr-stats .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dolibarr-stats .stat-card:nth-child(1) .stat-icon {
    background: rgba(0, 159, 227, 0.12);
    color: #009FE3;
}

.dolibarr-stats .stat-card:nth-child(2) .stat-icon {
    background: rgba(76, 175, 80, 0.12);
    color: #4CAF50;
}

.dolibarr-stats .stat-card:nth-child(3) .stat-icon {
    background: rgba(156, 39, 176, 0.12);
    color: #9C27B0;
}

.dolibarr-stats .stat-card:nth-child(4) .stat-icon {
    background: rgba(255, 152, 0, 0.12);
    color: #FF9800;
}

.dolibarr-stats .stat-icon svg {
    width: 24px;
    height: 24px;
}

.dolibarr-stats .stat-content {
    display: flex;
    flex-direction: column;
}

.dolibarr-stats .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #111827;
    line-height: 1.2;
    font-family: var(--font-title, 'Outfit', sans-serif);
}

.dolibarr-stats .stat-label {
    font-size: 13px;
    color: #6b7280;
    margin-top: 2px;
}

/* ====================================================================
   ACTIONS BUTTONS
   ==================================================================== */
.dolibarr-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.dolibarr-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.dolibarr-actions .btn svg {
    width: 18px;
    height: 18px;
}

.dolibarr-actions .btn-primary {
    background: #009FE3;
    color: white;
}

.dolibarr-actions .btn-primary:hover {
    background: #007AB3;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 159, 227, 0.3);
}

.dolibarr-actions .btn-success {
    background: #4CAF50;
    color: white;
}

.dolibarr-actions .btn-success:hover {
    background: #43A047;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.dolibarr-actions .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* ====================================================================
   TABS
   ==================================================================== */
.dolibarr-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 0;
}

.dolibarr-tabs .tab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    background: transparent;
    border: none;
    font-size: 14px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.dolibarr-tabs .tab-btn svg {
    width: 18px;
    height: 18px;
}

.dolibarr-tabs .tab-btn:hover {
    color: #009FE3;
    background: rgba(0, 159, 227, 0.05);
}

.dolibarr-tabs .tab-btn.active {
    color: #009FE3;
}

.dolibarr-tabs .tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: #009FE3;
}

/* ====================================================================
   TAB CONTENT
   ==================================================================== */
.dolibarr-content {
    background: white;
    border: 1px solid #e5e7eb;
    border-top: none;
    border-radius: 0 0 12px 12px;
    min-height: 400px;
}

.dolibarr-content .tab-content {
    display: none;
    padding: 24px;
}

.dolibarr-content .tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

/* ====================================================================
   SECTION HEADERS
   ==================================================================== */
.section-header {
    margin-bottom: 24px;
}

.section-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #111827;
    margin: 0 0 6px 0;
    font-family: var(--font-title, 'Outfit', sans-serif);
}

.section-header p {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
}

/* ====================================================================
   MAPPING LIST
   ==================================================================== */
.mapping-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mapping-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #f9fafb;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    transition: all 0.2s ease;
}

.mapping-card:hover {
    border-color: #d1d5db;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.mapping-card.linked {
    border-left: 4px solid #4CAF50;
}

.mapping-card.unlinked {
    border-left: 4px solid #FF9800;
}

.mapping-info {
    flex: 1;
    min-width: 0;
}

.mapping-name {
    font-weight: 600;
    font-size: 15px;
    color: #111827;
    margin-bottom: 4px;
}

.mapping-dolibarr {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #009FE3;
}

.mapping-dolibarr svg {
    width: 14px;
    height: 14px;
}

.mapping-status {
    margin: 0 20px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge svg {
    width: 14px;
    height: 14px;
}

.status-badge.linked {
    background: rgba(76, 175, 80, 0.12);
    color: #2e7d32;
}

.status-badge.unlinked {
    background: rgba(255, 152, 0, 0.12);
    color: #e65100;
}

.mapping-actions {
    display: flex;
    gap: 8px;
}

.mapping-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.mapping-actions .btn svg {
    width: 16px;
    height: 16px;
}

.mapping-actions .btn-sm {
    padding: 6px 10px;
}

.mapping-actions .btn-outline {
    background: white;
    color: #374151;
    border: 1px solid #d1d5db;
}

.mapping-actions .btn-outline:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.mapping-actions .btn-primary {
    background: #009FE3;
    color: white;
}

.mapping-actions .btn-primary:hover {
    background: #007AB3;
}

.mapping-actions .btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.mapping-actions .btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ====================================================================
   TIERS SECTION
   ==================================================================== */
.tiers-filters {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box {
    flex: 1;
    min-width: 250px;
    position: relative;
}

.search-box svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: #9ca3af;
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 12px 14px 12px 44px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s ease;
}

.search-box input:focus {
    outline: none;
    border-color: #009FE3;
    box-shadow: 0 0 0 3px rgba(0, 159, 227, 0.1);
}

.filter-select {
    padding: 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    min-width: 160px;
    cursor: pointer;
    background: white;
    transition: all 0.2s ease;
}

.filter-select:focus {
    outline: none;
    border-color: #009FE3;
}

/* ====================================================================
   TIERS LIST
   ==================================================================== */
.tiers-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tiers-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #f9fafb;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    transition: all 0.2s ease;
}

.tiers-card:hover {
    border-color: #d1d5db;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.tiers-card.has-client {
    opacity: 0.6;
}

.tiers-info {
    flex: 1;
    min-width: 0;
}

.tiers-name {
    font-weight: 600;
    font-size: 15px;
    color: #111827;
}

.tiers-name .tiers-alias {
    font-weight: 400;
    font-size: 13px;
    color: #6b7280;
    margin-left: 8px;
}

.tiers-details {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 6px;
    font-size: 13px;
    color: #6b7280;
}

.tiers-details span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tiers-details svg {
    width: 14px;
    height: 14px;
    color: #9ca3af;
}

.tiers-location {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 12px;
    color: #9ca3af;
}

.tiers-location svg {
    width: 12px;
    height: 12px;
}

.tiers-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.tiers-meta .code {
    font-family: monospace;
    background: #e5e7eb;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.type-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.type-badge.client {
    background: rgba(0, 159, 227, 0.12);
    color: #0077b6;
}

.type-badge.prospect {
    background: rgba(255, 152, 0, 0.12);
    color: #e65100;
}

.type-badge.other {
    background: #e5e7eb;
    color: #6b7280;
}

.client-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(76, 175, 80, 0.12);
    color: #2e7d32;
}

.client-badge svg {
    width: 12px;
    height: 12px;
}

.text-muted {
    font-size: 13px;
    color: #9ca3af;
}

.tiers-actions {
    display: flex;
    gap: 8px;
}

.tiers-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.tiers-actions .btn svg {
    width: 16px;
    height: 16px;
}

.tiers-actions .btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.tiers-actions .btn-success {
    background: #4CAF50;
    color: white;
}

.tiers-actions .btn-success:hover {
    background: #43A047;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.tiers-actions .btn-activate {
    background: #009FE3;
    color: white;
}

.tiers-actions .btn-activate:hover {
    background: #007AB3;
}

.tiers-actions .btn-disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
}

/* ====================================================================
   PAGINATION
   ==================================================================== */
.tiers-pagination {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    background: white;
    color: #374151;
    border: 1px solid #e5e7eb;
    transition: all 0.2s ease;
}

.pagination-btn svg {
    width: 16px;
    height: 16px;
}

.pagination-btn:hover:not(:disabled):not(.active) {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.pagination-btn.active {
    background: #009FE3;
    color: white;
    border-color: #009FE3;
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-dots {
    padding: 0 8px;
    color: #9ca3af;
}

.pagination-info {
    font-size: 13px;
    color: #6b7280;
    text-align: center;
    margin-top: 12px;
}

/* ====================================================================
   LOADING & EMPTY STATES
   ==================================================================== */
.loading-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #6b7280;
    font-size: 14px;
}

.loading-placeholder svg {
    width: 32px;
    height: 32px;
    margin-bottom: 12px;
    color: #009FE3;
}

.loading-placeholder .spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #6b7280;
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    color: #d1d5db;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: #374151;
    margin: 0 0 8px 0;
}

.empty-state p {
    font-size: 14px;
    margin: 0;
}

/* ====================================================================
   MODAL (modal-overlay class used in JS)
   ==================================================================== */
.modal-overlay,
.dolibarr-modal {
    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: 1000;
    animation: fadeInOverlay 0.2s ease;
}

@keyframes fadeInOverlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-overlay .modal-content,
.dolibarr-modal .modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideInModal 0.3s ease;
}

@keyframes slideInModal {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-overlay .modal-header,
.dolibarr-modal .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-overlay .modal-header h3,
.dolibarr-modal .modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: #111827;
    margin: 0;
    font-family: var(--font-title, 'Outfit', sans-serif);
}

.modal-overlay .modal-close,
.dolibarr-modal .modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-overlay .modal-close:hover,
.dolibarr-modal .modal-close:hover {
    background: #f3f4f6;
    color: #111827;
}

.modal-overlay .modal-close svg,
.dolibarr-modal .modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-overlay .modal-body,
.dolibarr-modal .modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

/* Suggestions section in link modal */
.suggestions-section,
.search-results-section {
    margin-top: 16px;
}

.suggestions-section h4,
.search-results-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin: 0 0 12px 0;
}

.suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.suggestion-item {
    padding: 14px 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggestion-item:hover {
    background: rgba(0, 159, 227, 0.08);
    border-color: #009FE3;
    transform: translateX(4px);
}

.suggestion-info {
    margin-bottom: 4px;
}

.suggestion-info strong {
    font-weight: 600;
    color: #111827;
}

.suggestion-info .alias {
    font-size: 13px;
    color: #6b7280;
    margin-left: 8px;
}

.suggestion-details {
    font-size: 12px;
    color: #6b7280;
}

.no-results {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
    font-size: 14px;
}

.modal-overlay .modal-search {
    margin-bottom: 16px;
}

.modal-overlay .modal-search input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
}

.modal-overlay .modal-search input:focus {
    outline: none;
    border-color: #009FE3;
}

.dolibarr-modal .modal-list {
    max-height: 350px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.dolibarr-modal .modal-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: all 0.15s ease;
}

.dolibarr-modal .modal-item:last-child {
    border-bottom: none;
}

.dolibarr-modal .modal-item:hover {
    background: rgba(0, 159, 227, 0.05);
}

.dolibarr-modal .modal-item.selected {
    background: rgba(0, 159, 227, 0.1);
    border-left: 3px solid #009FE3;
}

.dolibarr-modal .modal-item-info {
    flex: 1;
}

.dolibarr-modal .modal-item-name {
    font-weight: 600;
    font-size: 14px;
    color: #111827;
}

.dolibarr-modal .modal-item-alias {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}

.dolibarr-modal .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.dolibarr-modal .modal-footer .btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dolibarr-modal .modal-footer .btn-cancel {
    background: white;
    color: #374151;
    border: 1px solid #d1d5db;
}

.dolibarr-modal .modal-footer .btn-cancel:hover {
    background: #f3f4f6;
}

.dolibarr-modal .modal-footer .btn-confirm {
    background: #009FE3;
    color: white;
    border: none;
}

.dolibarr-modal .modal-footer .btn-confirm:hover {
    background: #007AB3;
}

.dolibarr-modal .modal-footer .btn-confirm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ====================================================================
   RESPONSIVE
   ==================================================================== */
@media (max-width: 768px) {
    .dolibarr-actions {
        flex-direction: column;
    }

    .dolibarr-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .dolibarr-tabs {
        overflow-x: auto;
    }

    .dolibarr-tabs .tab-btn {
        white-space: nowrap;
        padding: 12px 16px;
    }

    .mapping-card,
    .tiers-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .mapping-status {
        margin: 0;
    }

    .mapping-actions,
    .tiers-actions {
        width: 100%;
    }

    .mapping-actions .btn,
    .tiers-actions .btn {
        flex: 1;
        justify-content: center;
    }

    .tiers-filters {
        flex-direction: column;
    }

    .search-box {
        min-width: 100%;
    }

    .tiers-pagination {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
}
