/* ============================================
   TVA Tunisie - Styles Globaux
   ============================================ */

:root {
    --primary: #2a5298;
    --primary-dark: #1e3c72;
    --secondary: #764ba2;
    --accent: #667eea;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --info: #2196f3;
    --light: #f5f5f5;
    --dark: #333;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.2);
    --radius: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--accent) 0%, var(--secondary) 100%);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

/* Container principal */
.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: white;
    padding: 30px;
    text-align: center;
    position: relative;
}

.header h1 {
    font-size: 2em;
    margin-bottom: 10px;
    font-weight: 600;
}

.header p {
    opacity: 0.9;
    font-size: 0.95em;
}

.user-info {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 0.9em;
}

.btn-logout {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.3s;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.3);
}

/* Navigation */
.nav-tabs {
    display: flex;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
    padding: 0 30px;
}

.nav-tab {
    padding: 15px 25px;
    cursor: pointer;
    border: none;
    background: none;
    font-size: 1em;
    font-weight: 500;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-tab:hover {
    color: var(--primary);
    background: rgba(42, 82, 152, 0.05);
}

.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: white;
}

.tab-content {
    display: none;
    padding: 30px;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

/* Sections */
.section {
    margin-bottom: 30px;
    border: 2px solid #e0e0e0;
    border-radius: var(--radius);
    padding: 25px;
    background: #fafafa;
}

.section-title {
    font-size: 1.4em;
    color: var(--primary);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Grilles de formulaires */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    position: relative;
}

.form-group label {
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
    font-size: 0.95em;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: var(--radius-sm);
    font-size: 1em;
    transition: all 0.3s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(42, 82, 152, 0.1);
}

.form-group small {
    color: #666;
    margin-top: 5px;
    font-size: 0.85em;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

/* Input avec devise */
.input-dt {
    position: relative;
    display: flex;
    align-items: center;
}

.input-dt input {
    flex: 1;
    padding-right: 50px;
    text-align: right;
}

.input-dt .currency {
    position: absolute;
    right: 12px;
    color: #666;
    font-weight: 600;
    pointer-events: none;
    font-size: 0.9em;
}

/* Barre des déclarants */
.declarants-bar {
    background: #e3f2fd;
    border: 2px solid var(--info);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.declarants-bar h3 {
    color: #1565c0;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
    min-height: 40px;
}

.declarant-tag {
    background: white;
    border: 2px solid var(--info);
    border-radius: 20px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95em;
}

.declarant-tag:hover {
    background: var(--info);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.declarant-tag .remove-btn {
    font-weight: bold;
    margin-left: 5px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.declarant-tag:hover .remove-btn {
    opacity: 1;
}

/* Boutons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    transition: all 0.3s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-info {
    background: var(--info);
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-outline {
    background: transparent;
    border: 2px solid currentColor;
}

.btn-new {
    background: var(--success);
    color: white;
}

.btn-generate {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px 50px;
    font-size: 1.3em;
    display: block;
    margin: 30px auto;
}

.btn-icon-small {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.btn-icon-small:hover {
    background: rgba(0,0,0,0.1);
}

/* Toggle vue */
.view-toggle {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    background: #e3f2fd;
    padding: 10px;
    border-radius: var(--radius-sm);
    justify-content: center;
}

.toggle-btn {
    padding: 10px 20px;
    border: 2px solid var(--info);
    background: white;
    color: var(--info);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.toggle-btn.active {
    background: var(--info);
    color: white;
}

/* Groupes clients */
.client-group {
    background: white;
    border: 2px solid #ddd;
    border-radius: var(--radius);
    margin-bottom: 15px;
    overflow: hidden;
    transition: all 0.3s;
}

.client-group.dragging {
    opacity: 0.5;
    border: 2px dashed var(--info);
}

.client-header {
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    user-select: none;
    transition: background 0.3s;
}

.client-group.expanded .client-header {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-bottom: 2px solid #ddd;
}

.expand-icon {
    font-size: 1.2em;
    transition: transform 0.3s;
    color: #666;
}

.client-group.expanded .expand-icon {
    transform: rotate(90deg);
}

.drag-handle {
    cursor: grab;
    color: #999;
    font-size: 1.2em;
    padding: 5px;
    border-radius: 4px;
    transition: background 0.2s;
}

.drag-handle:hover {
    background: rgba(0,0,0,0.1);
}

.drag-handle:active {
    cursor: grabbing;
}

.client-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.client-name {
    font-weight: bold;
    color: var(--dark);
    font-size: 1.1em;
}

.client-id {
    color: #666;
    font-size: 0.9em;
    background: #fff;
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid #ddd;
}

.client-stats {
    display: flex;
    gap: 15px;
    margin-right: 20px;
}

.stat-badge {
    background: #fff;
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.85em;
    border: 1px solid #ddd;
}

.client-actions {
    display: flex;
    gap: 10px;
}

.factures-container {
    display: none;
    padding: 20px;
    background: #fafafa;
    min-height: 50px;
}

.client-group.expanded .factures-container {
    display: block;
}

.factures-container.drag-over {
    background: #e8f5e9;
    border: 3px dashed var(--success);
}

/* Formulaires de factures */
.facture-form {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: var(--radius-sm);
    padding: 20px;
    margin-bottom: 15px;
    position: relative;
    transition: all 0.3s;
}

.facture-form:hover {
    border-color: var(--info);
    box-shadow: var(--shadow);
}

.facture-form.dragging {
    opacity: 0.5;
    border: 2px dashed var(--success);
}

.form-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.form-number {
    font-weight: bold;
    color: var(--info);
    font-size: 1.1em;
}

/* Liste de factures */
.facture-list-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: var(--radius-sm);
    padding: 15px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: all 0.2s;
}

.facture-list-item:hover {
    border-color: var(--info);
    background: #f5f5f5;
}

.facture-list-item.dragging {
    opacity: 0.5;
    border: 2px dashed var(--success);
}

.facture-list-item.drag-over {
    border-top: 3px solid var(--success);
}

.list-number {
    font-weight: bold;
    color: var(--info);
    min-width: 60px;
}

.list-info {
    flex: 1;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 15px;
    align-items: center;
}

.montant-dt {
    font-weight: 600;
    color: #2e7d32;
}

/* Barre des totaux */
.totals-bar {
    background: #fff3e0;
    border: 2px solid var(--warning);
    border-radius: var(--radius);
    padding: 20px;
    margin: 20px 0;
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 20px;
}

.total-box {
    text-align: center;
    min-width: 120px;
}

.total-box .label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.total-box .value {
    font-size: 1.8em;
    font-weight: bold;
    color: #e65100;
}

.dt-suffix {
    font-size: 0.6em;
    color: #999;
    margin-left: 5px;
}

/* Menu de déplacement */
.move-menu {
    display: none;
    position: absolute;
    background: white;
    border: 2px solid #9c27b0;
    border-radius: var(--radius-sm);
    padding: 10px;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
}

.move-menu.active {
    display: block;
}

.move-menu h4 {
    margin-bottom: 10px;
    color: #9c27b0;
    font-size: 0.9em;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.move-option {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 5px;
    font-size: 0.9em;
    transition: background 0.2s;
}

.move-option:hover {
    background: #f3e5f5;
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    padding: 30px;
    max-width: 700px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #eee;
}

.modal-title {
    font-size: 1.3em;
    color: var(--dark);
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: #666;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.btn-close:hover {
    background: #f5f5f5;
    color: var(--danger);
}

/* Preview box */
.preview-box {
    background: #1e1e1e;
    color: #00ff00;
    font-family: 'Courier New', monospace;
    padding: 20px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin-top: 20px;
    display: none;
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 0.9em;
    line-height: 1.5;
}

.preview-box.active {
    display: block;
}

.preview-box .preview-label {
    color: #fff;
    margin-bottom: 10px;
    font-weight: bold;
}

/* Info boxes */
.info-box {
    background: #e8f5e9;
    border-left: 4px solid var(--success);
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.info-box.warning {
    background: #fff3e0;
    border-left-color: var(--warning);
}

.info-box.error {
    background: #ffebee;
    border-left-color: var(--danger);
}

/* Historique */
.history-section {
    background: #f3e5f5;
    border-color: #9c27b0;
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    background: white;
    border: 1px solid #ce93d8;
    border-radius: var(--radius-sm);
    padding: 15px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.history-item:hover {
    background: #fafafa;
    transform: translateX(5px);
}

.history-info h4 {
    color: var(--dark);
    margin-bottom: 5px;
}

.history-meta {
    color: #666;
    font-size: 0.9em;
}

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

/* Login page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-box h1 {
    color: var(--primary);
    margin-bottom: 10px;
}

.login-box .subtitle {
    color: #666;
    margin-bottom: 30px;
}

.login-form .form-group {
    margin-bottom: 20px;
    text-align: left;
}

.login-form input {
    width: 100%;
}

.error-message {
    background: #ffebee;
    color: var(--danger);
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    display: none;
}

.error-message.show {
    display: block;
}

/* Outils d'administration */
.admin-tools {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.tool-card {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.3s;
}

.tool-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.tool-card h4 {
    color: var(--primary);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tool-card p {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 15px;
}

/* Loading spinner */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--info);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Status messages */
.status-message {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    display: none;
    align-items: center;
    gap: 10px;
    animation: slideDown 0.3s ease;
}

.status-message.show {
    display: flex;
}

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

.status-success {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid var(--success);
}

.status-error {
    background: #ffebee;
    color: #c62828;
    border: 1px solid var(--danger);
}

.status-warning {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid var(--warning);
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .header {
        padding: 20px;
    }
    
    .header h1 {
        font-size: 1.5em;
    }
    
    .user-info {
        position: static;
        margin-top: 15px;
        justify-content: center;
    }
    
    .nav-tabs {
        flex-wrap: wrap;
        padding: 0 10px;
    }
    
    .nav-tab {
        padding: 10px 15px;
        font-size: 0.9em;
    }
    
    .tab-content {
        padding: 20px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .list-info {
        grid-template-columns: 1fr;
        gap: 5px;
    }
    
    .client-stats {
        display: none;
    }
    
    .totals-bar {
        flex-direction: column;
        align-items: center;
    }
    
    .history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .modal-content {
        padding: 20px;
        margin: 10px;
    }
}

/* Print styles */
@media print {
    body {
        background: white;
        padding: 0;
    }
    
    .container {
        box-shadow: none;
    }
    
    .nav-tabs,
    .btn-generate,
    .client-actions,
    .btn-icon-small {
        display: none !important;
    }
}

/* Styles pour l'import */
.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}

.preview-table th,
.preview-table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

.preview-table th {
    background: #f5f5f5;
    font-weight: 600;
}

.preview-table tr:nth-child(even) {
    background: #fafafa;
}

#import-mapping select {
    width: 100%;
    padding: 8px;
}

#import-step1,
#import-step2,
#import-step3 {
    animation: fadeIn 0.3s ease;
}
/* Styles pour l'import amélioré */
#import-step1 .tool-card {
    text-align: center;
    padding: 20px;
}

#import-step1 .tool-card h4 {
    margin-bottom: 10px;
    color: var(--primary);
}

#import-step1 .tool-card p {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 15px;
}

#import-file-name {
    animation: fadeIn 0.3s ease;
}

/* Drag and drop zone */
#import-step1 .form-group {
    transition: all 0.3s;
}

#import-step1 .form-group.drag-over {
    border-color: var(--info) !important;
    background: #e3f2fd;
}

/* Code dans l'aide */
code {
    font-family: 'Courier New', monospace;
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* Liste dans info-box */
.info-box ul {
    margin: 10px 0;
}

.info-box li {
    margin-bottom: 5px;
}

.info-box code {
    background: #fff;
    padding: 2px 8px;
    border: 1px solid #ddd;
}
/* Conteneur flex pour alignement */
.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin: 25px 0;
}

/* Style commun pour les deux boutons */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 28px;
    border: none;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 200px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

.action-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.action-btn:active {
    transform: translateY(-1px);
}

/* Variante verte (Ajouter) */
.action-btn-primary {
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    color: white;
}

.action-btn-primary:hover {
    background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
}

/* Variante bleue (Importer) */
.action-btn-secondary {
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    color: white;
}

.action-btn-secondary:hover {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
}

/* Icônes */
.action-btn .icon {
    font-size: 1.3em;
}

/* Responsive */
@media (max-width: 480px) {
    .action-buttons {
        flex-direction: column;
    }
    
    .action-btn {
        width: 100%;
        max-width: 300px;
    }
}