/**
 * Styles principaux
 * AI Smart Mail Sorter
 * Couleurs: Bleu #00A3E0, Vert #73C92D, Gris #91999F
 * Police: Trebuchet MS
 */

/* ============================================
   VARIABLES CSS
   ============================================ */
:root {
    --primary: #00A3E0;
    --primary-dark: #0088c7;
    --primary-light: #e6f7fc;
    --success: #73C92D;
    --success-dark: #5ba324;
    --success-light: #eaf7e4;
    --grey: #91999F;
    --grey-dark: #6a7179;
    --grey-light: #d4d8db;
    --grey-bg: #f4f6f8;
    --text: #333333;
    --text-light: #666666;
    --white: #ffffff;
    --danger: #e74c3c;
    --danger-light: #fdf2f2;
    --border: #e0e4e8;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --radius: 8px;
    --radius-sm: 4px;
    --transition: all 0.3s ease;
}

/* ============================================
   RESET ET BASE
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', sans-serif;
    background-color: var(--grey-bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================
   TYPOGRAPHIE
   ============================================ */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Trebuchet MS', sans-serif;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }

p {
    margin-bottom: 1em;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
}

/* ============================================
   LAYOUT PRINCIPAL
   ============================================ */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--white);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s ease;
}

.main-content {
    flex: 1;
    margin-left: 280px;
    padding: 2rem;
    min-height: 100vh;
}

/* ============================================
   EN-TÊTE
   ============================================ */
.app-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--white);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-lg);
}

.app-header h1 {
    color: var(--white);
    margin: 0;
    font-size: 1.5rem;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--grey);
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background: var(--success);
}

.status-dot.disconnected {
    background: var(--danger);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ============================================
   BOUTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-family: 'Trebuchet MS', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-transform: capitalize;
}

.btn i {
    font-size: 1.1rem;
}

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

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

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

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

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

.btn-secondary:hover {
    background: var(--grey-dark);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

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

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ============================================
   FORMULAIRES
   ============================================ */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-family: 'Trebuchet MS', sans-serif;
    font-size: 1rem;
    transition: var(--transition);
    background: var(--white);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 163, 224, 0.1);
}

.form-control::placeholder {
    color: var(--grey);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2391999F' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

/* ============================================
   CARTES
   ============================================ */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.card-body {
    padding: 0.5rem 0;
}

/* ============================================
   LISTE DES EMAILS
   ============================================ */
.emails-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.email-item {
    background: var(--white);
    border-radius: var(--radius);
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: start;
    transition: var(--transition);
    position: relative;
}

.email-item:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-lg);
}

.email-item.approved {
    border-left-color: var(--success);
    background: linear-gradient(to right, var(--success-light), var(--white) 30%);
}

.email-item.pending {
    border-left-color: var(--primary);
}

.email-item.rejected {
    border-left-color: var(--grey);
    opacity: 0.7;
}

.email-item.error {
    border-left-color: var(--danger);
    background: linear-gradient(to right, var(--danger-light), var(--white) 30%);
}

.email-content {
    min-width: 0;
}

.email-subject {
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 0.75rem;
}

.email-meta i {
    color: var(--grey);
    margin-right: 0.25rem;
}

.email-preview {
    font-size: 0.9rem;
    color: var(--text-light);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.email-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 200px;
}

.confidence-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 700;
}

.confidence-badge.high {
    background: var(--success-light);
    color: var(--success-dark);
}

.confidence-badge.medium {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.confidence-badge.low {
    background: var(--grey-bg);
    color: var(--grey-dark);
}

.folder-select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Trebuchet MS', sans-serif;
    font-size: 0.9rem;
    background: var(--white);
    min-width: 150px;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn-approve {
    background: var(--success);
    color: var(--white);
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'Trebuchet MS', sans-serif;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    transition: var(--transition);
}

.btn-approve:hover {
    background: var(--success-dark);
}

.btn-reject {
    background: var(--grey);
    color: var(--white);
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'Trebuchet MS', sans-serif;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    transition: var(--transition);
}

.btn-reject:hover {
    background: var(--grey-dark);
}

/* ============================================
   BARRES D'OUTILS
   ============================================ */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.toolbar-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.filter-tabs {
    display: flex;
    background: var(--white);
    border-radius: var(--radius);
    padding: 0.25rem;
    box-shadow: var(--shadow);
}

.filter-tab {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    font-family: 'Trebuchet MS', sans-serif;
    font-size: 0.9rem;
    color: var(--text-light);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.filter-tab:hover {
    color: var(--text);
}

.filter-tab.active {
    background: var(--primary);
    color: var(--white);
}

/* ============================================
   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: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--white);
    border-radius: var(--radius);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: translateY(-20px);
    transition: var(--transition);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--grey);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ============================================
   ÉTATS DE CHARGEMENT
   ============================================ */
.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--grey-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

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

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.loading-container {
    text-align: center;
    padding: 2rem;
}

.loading-container .loading-spinner {
    width: 48px;
    height: 48px;
    border-width: 4px;
    margin-bottom: 1rem;
}

.loading-text {
    color: var(--text-light);
    font-size: 1rem;
}

/* ============================================
   STATISTIQUES
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--white);
}

.stat-icon.primary {
    background: var(--primary);
}

.stat-icon.success {
    background: var(--success);
}

.stat-icon.grey {
    background: var(--grey);
}

.stat-content h3 {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    color: var(--text);
}

.stat-content p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-light);
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar-section {
    margin-bottom: 2rem;
}

.sidebar-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--grey);
    margin-bottom: 1rem;
    letter-spacing: 0.5px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.nav-item:hover {
    background: var(--grey-bg);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-item i {
    width: 20px;
    text-align: center;
    color: var(--grey);
}

.nav-item.active i {
    color: var(--primary);
}

/* ============================================
   RÈGLES
   ============================================ */
.rules-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.rule-item {
    background: var(--grey-bg);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.rule-pattern {
    color: var(--text);
    font-weight: 600;
}

.rule-folder {
    color: var(--primary);
    font-size: 0.85rem;
}

.rule-delete {
    background: none;
    border: none;
    color: var(--grey);
    cursor: pointer;
    padding: 0.25rem;
    transition: var(--transition);
}

.rule-delete:hover {
    color: var(--danger);
}

/* ============================================
   LOGS
   ============================================ */
.log-console {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: var(--radius);
    padding: 1rem;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 1rem;
}

.log-entry {
    padding: 0.25rem 0;
    border-bottom: 1px solid #333;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-entry.info {
    color: #4fc3f7;
}

.log-entry.success {
    color: #81c784;
}

.log-entry.warning {
    color: #ffb74d;
}

.log-entry.error {
    color: #e57373;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .email-actions {
        min-width: auto;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .confidence-badge {
        order: -1;
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group {
        justify-content: center;
    }

    .email-item {
        grid-template-columns: 1fr;
    }

    .email-actions {
        width: 100%;
    }

    .folder-select {
        width: 100%;
    }

    .action-buttons {
        width: 100%;
    }

    .btn-approve,
    .btn-reject {
        flex: 1;
        justify-content: center;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .filter-tabs {
        width: 100%;
        justify-content: center;
    }

    .modal {
        width: 95%;
        margin: 1rem;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 0.5rem;
    }

    .main-content {
        padding: 1rem;
    }

    .card {
        padding: 1rem;
    }

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }
}

/* ============================================
   UTILITAIRES
   ============================================ */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.d-flex {
    display: flex;
}

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

.align-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-up {
    animation: slideUp 0.3s ease;
}

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.badge-success {
    background: var(--success-light);
    color: var(--success-dark);
}

.badge-grey {
    background: var(--grey-bg);
    color: var(--grey-dark);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}
