/* ===== Variables CSS ===== */
:root {
    /* Variables originales */
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1f2937;
    --light: #f9fafb;
    --gray: #6b7280;
    --gray-light: #e5e7eb;
    --white: #ffffff;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --transition: all 0.3s ease;
    
    /* Variables Pharma Toolkit (harmonisation avec perimes) */
    --primary-color: #2E7D32;
    --primary-dark-pharma: #1B5E20;
    --header-height: 60px;
    --text-primary: #212121;
    --text-secondary: #757575;
}

/* ===== Reset ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--light);
    color: var(--dark);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ===== Unified App Header (style perimes) ===== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    min-height: var(--header-height);
    background: var(--primary-color);
    color: white;
    z-index: 1001;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    gap: 1rem;
}

.home-link {
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
}

.home-link:hover {
    opacity: 0.8;
}

.app-header .header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
    padding: 0;
}

.auth-section {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.header-icon {
    font-size: 20px;
    margin-right: 8px;
}

.header-text h1 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.5px;
    color: white;
}

.header-text p {
    font-size: 10px;
    opacity: 0.9;
    margin: 0;
    font-weight: 400;
}

.header-status {
    display: flex;
    align-items: center;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #f44336;
    transition: background-color 0.3s ease;
}

.status-dot.online {
    background: #4CAF50;
}

.status-dot.offline {
    background: #f44336;
}

/* User Dropdown */
.user-dropdown {
    position: relative;
    display: inline-block;
}

.profile-settings-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.4rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    backdrop-filter: blur(10px);
}

.profile-settings-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
    z-index: 2000;
    animation: dropdownSlideIn 0.2s ease-out;
}

.dropdown-menu.show {
    display: block;
}

@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-header {
    padding: 16px;
    border-bottom: 1px solid #e9ecef;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px 12px 0 0;
}

.dropdown-header strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.dropdown-header span {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
}

.dropdown-divider {
    height: 1px;
    background: #e9ecef;
    margin: 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
}

.dropdown-item:hover {
    background: #f8f9fa;
    color: var(--primary-color);
}

.dropdown-item.logout-item {
    border-radius: 0 0 12px 12px;
    color: #dc3545;
}

.dropdown-item.logout-item:hover {
    background: #fff5f5;
    color: #c82333;
}

/* Responsive Header */
@media (max-width: 480px) {
    .app-header {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        padding-bottom: 0.5rem;
        gap: 0.5rem;
    }
    
    .home-link {
        font-size: 18px;
        min-width: 32px;
        padding: 0.3rem;
    }
    
    .app-header .header-content {
        gap: 4px;
    }
    
    .header-icon {
        display: none;
    }
    
    .header-text h1 {
        font-size: 13px;
    }
    
    .header-text p {
        font-size: 8px;
    }
    
    .profile-settings-btn {
        width: 1.8rem;
        height: 1.8rem;
        font-size: 0.85rem;
    }
}

/* ===== Legacy Header (kept for compatibility) ===== */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-light);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header > .container > .header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.nav {
    display: flex;
    gap: 1.5rem;
}

.nav-link {
    text-decoration: none;
    color: var(--gray);
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition: var(--transition);
}

.nav-link:hover {
    background: var(--light);
    color: var(--primary);
}

.nav-link.active {
    color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
}

/* ===== Main ===== */
.main {
    padding: 2rem 0;
    padding-top: calc(var(--header-height) + 1rem); /* Espace pour le header fixed */
}

/* ===== Stats Section ===== */
.stats-section {
    margin-bottom: 2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    font-size: 2.5rem;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    color: var(--gray);
    font-size: 0.9rem;
}

/* ===== Section Headers ===== */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark);
}

.section-desc {
    color: var(--gray);
    margin-top: 0.5rem;
}

/* ===== Upload Section ===== */
.upload-section {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--gray-light);
}

.tab-btn {
    background: none;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--primary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.upload-area {
    border: 2px dashed var(--gray-light);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--light);
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.05);
}

.upload-area.dragging {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 0.5rem;
}

.upload-subtext {
    color: var(--gray);
    font-size: 0.9rem;
}

.upload-options {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
    gap: 2rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-label input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.select-label {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.select-label select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
}

/* ===== Upload Progress ===== */
.upload-progress {
    margin-top: 1.5rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-light);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    margin-top: 0.5rem;
    color: var(--gray);
}

/* ===== Results Section ===== */
.results-section {
    margin-bottom: 2rem;
}

.results-container {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.results-empty {
    text-align: center;
    padding: 3rem 0;
    color: var(--gray);
}

.result-card {
    background: var(--light);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.result-filename {
    font-weight: 600;
    color: var(--dark);
}

.result-status {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.result-status.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.result-status.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.result-data {
    background: var(--white);
    padding: 1rem;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    max-height: 300px;
    overflow-y: auto;
}

/* ===== Templates Section ===== */
.templates-section {
    margin-bottom: 2rem;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.templates-empty {
    text-align: center;
    padding: 3rem 0;
    color: var(--gray);
    grid-column: 1 / -1;
}

.template-card {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.template-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.template-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.template-name {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--dark);
}

.template-meta {
    color: var(--gray);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.template-actions {
    display: flex;
    gap: 0.5rem;
}

/* ===== Buttons ===== */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-light);
    color: var(--dark);
}

.btn-secondary:hover {
    background: var(--gray);
    color: var(--white);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-clear {
    background: transparent;
    color: var(--danger);
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
}

.btn-clear:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--white);
    border-radius: var(--radius);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-light);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--gray);
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding: 1.5rem;
    border-top: 1px solid var(--gray-light);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    font-size: 1rem;
}

.upload-area.small {
    padding: 2rem 1rem;
    font-size: 0.9rem;
}

.files-list {
    margin-top: 1rem;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--light);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.file-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.2rem;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 2000;
}

.toast {
    background: var(--white);
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    margin-bottom: 1rem;
    min-width: 300px;
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

/* ===== Utilities ===== */
.hidden {
    display: none !important;
}

.text-muted {
    color: var(--gray);
    font-size: 0.9rem;
}

/* ===== Auth Modal ===== */
.auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.auth-modal-content {
    background: var(--white);
    border-radius: var(--radius);
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.auth-modal-header {
    padding: 2rem 2rem 1rem 2rem;
    text-align: center;
}

.auth-modal-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 0.5rem;
}

.auth-modal-header p {
    color: var(--gray);
    font-size: 0.95rem;
}

.auth-modal-body {
    padding: 1rem 2rem 2rem 2rem;
}

.auth-input {
    width: 100%;
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--gray-light);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: var(--transition);
}

.auth-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.auth-input.error {
    border-color: var(--danger);
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.auth-hint {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(79, 70, 229, 0.05);
    border-left: 3px solid var(--primary);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--gray);
    line-height: 1.5;
}

.auth-modal-footer {
    padding: 0 2rem 2rem 2rem;
}

.auth-modal-footer .btn {
    width: 100%;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .nav {
        gap: 0.5rem;
    }
    
    .nav-link {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .templates-grid {
        grid-template-columns: 1fr;
    }
    
    .auth-modal-content {
        width: 95%;
    }
    
    .auth-modal-header {
        padding: 1.5rem 1.5rem 0.75rem 1.5rem;
    }
    
    .auth-modal-body {
        padding: 0.75rem 1.5rem 1.5rem 1.5rem;
    }
    
    .auth-modal-footer {
        padding: 0 1.5rem 1.5rem 1.5rem;
    }
}
