/* ============================================================
   Courto CRM — Feuille de style principale
   ============================================================ */

/* ─── Variables ─────────────────────────────────────────────── */
:root {
    --brand-primary:      #0d6efd;
    --brand-primary-dark: #0a58ca;
    --sidebar-width:      260px;
    --sidebar-bg:         #1a2332;
    --sidebar-text:       #8fa4b8;
    --sidebar-border:     rgba(255,255,255,0.06);
    --sidebar-active-bg:  var(--brand-primary);
    --topbar-height:      60px;
    --content-bg:         #f4f6f9;
    --card-radius:        .75rem;
    --transition:         all 0.22s ease;
}

[data-bs-theme="dark"] {
    --content-bg: #121b2e;
}

/* ─── Layout général ─────────────────────────────────────────── */
html, body { height: 100%; }

body {
    background: var(--content-bg);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 0.9rem;
}

.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    overflow-x: hidden;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: var(--topbar-height);
    text-decoration: none;
}

.sidebar-brand-logo {
    width: 36px;
    height: 36px;
    border-radius: .5rem;
    object-fit: contain;
    background: rgba(255,255,255,.1);
    padding: 4px;
}

.sidebar-brand-logo-placeholder {
    width: 36px;
    height: 36px;
    border-radius: .5rem;
    background: var(--brand-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .9rem;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-brand-name {
    font-size: .95rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-brand-tagline {
    font-size: .68rem;
    color: var(--sidebar-text);
    font-weight: 400;
}

/* Navigation */
.sidebar-section-title {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.25);
    padding: 1.25rem 1.25rem .4rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: .5rem 0;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.sidebar-nav .nav-item { padding: 0 .625rem; }

.sidebar-nav .nav-link {
    color: var(--sidebar-text);
    padding: .6rem .875rem;
    border-radius: .5rem;
    margin-bottom: 2px;
    transition: var(--transition);
    font-size: .855rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: .75rem;
    white-space: nowrap;
}

.sidebar-nav .nav-link i {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    opacity: .7;
    transition: var(--transition);
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,.07);
    color: #fff;
}

.sidebar-nav .nav-link:hover i { opacity: 1; }

.sidebar-nav .nav-link.active {
    background: var(--brand-primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(13, 110, 253, .3);
}

.sidebar-nav .nav-link.active i { opacity: 1; }

.sidebar-nav .nav-link .badge {
    margin-left: auto;
    font-size: .65rem;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 1rem .625rem;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .875rem;
    border-radius: .5rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    color: var(--sidebar-text);
}

.sidebar-user:hover { background: rgba(255,255,255,.07); color: #fff; }

.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--brand-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: .82rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: .72rem; color: var(--sidebar-text); }

/* ─── Main content ───────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: var(--transition);
}

/* ─── Topbar ─────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

[data-bs-theme="dark"] .topbar {
    background: #1e2d42;
    border-bottom-color: rgba(255,255,255,.06);
}

.topbar-toggle {
    background: none;
    border: none;
    padding: .375rem .5rem;
    border-radius: .375rem;
    color: #6c757d;
    font-size: 1.1rem;
    cursor: pointer;
    display: none;
}

.topbar-breadcrumb { flex: 1; }
.topbar-breadcrumb .breadcrumb { margin: 0; font-size: .82rem; }

.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.topbar-btn {
    background: none;
    border: none;
    padding: .4rem .5rem;
    border-radius: .5rem;
    color: #6c757d;
    font-size: 1.05rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.topbar-btn:hover {
    background: #f4f6f9;
    color: #212529;
}

[data-bs-theme="dark"] .topbar-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

.topbar-btn .notif-dot {
    width: 8px;
    height: 8px;
    background: #dc3545;
    border-radius: 50%;
    position: absolute;
    top: 4px;
    right: 4px;
    border: 2px solid #fff;
}

/* ─── Page content ───────────────────────────────────────────── */
.page-content {
    flex: 1;
    padding: 1.75rem;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.page-title { font-size: 1.35rem; font-weight: 700; margin: 0; }
.page-subtitle { font-size: .82rem; color: #6c757d; margin-top: .2rem; }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
    border-radius: var(--card-radius);
    border: 1px solid rgba(0,0,0,.07);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    transition: var(--transition);
}

[data-bs-theme="dark"] .card {
    border-color: rgba(255,255,255,.07);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid rgba(0,0,0,.07);
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: .9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

[data-bs-theme="dark"] .card-header { border-bottom-color: rgba(255,255,255,.07); }

/* Stats cards */
.stat-card {
    border-radius: var(--card-radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #fff;
    border: 1px solid rgba(0,0,0,.07);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

[data-bs-theme="dark"] .stat-card { background: #1e2d42; border-color: rgba(255,255,255,.07); }

.stat-card-icon {
    width: 52px;
    height: 52px;
    border-radius: .625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-card-label { font-size: .78rem; color: #6c757d; margin-top: .2rem; }
.stat-card-trend { font-size: .75rem; margin-top: .3rem; }

/* ─── Tables ─────────────────────────────────────────────────── */
.table { font-size: .85rem; }
.table th { font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: #6c757d; border-top: none; }
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { cursor: pointer; }

.table-actions { display: flex; gap: .375rem; }
.table-actions .btn { padding: .25rem .55rem; font-size: .78rem; }

/* ─── Badges personnalisés ───────────────────────────────────── */
.badge { font-weight: 500; font-size: .72rem; padding: .35em .65em; }

/* ─── Formulaires ────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: .83rem; margin-bottom: .35rem; }
.form-control, .form-select { font-size: .875rem; border-radius: .5rem; }
.form-control:focus, .form-select:focus { box-shadow: 0 0 0 .2rem rgba(13,110,253,.15); }

.input-group-text { border-radius: .5rem 0 0 .5rem; }

/* ─── Auth layout ────────────────────────────────────────────── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a2332 0%, #0d1b2e 100%);
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    overflow: hidden;
}

.auth-header {
    background: var(--brand-primary);
    padding: 2rem;
    text-align: center;
    color: #fff;
}

.auth-logo {
    width: 56px;
    height: 56px;
    border-radius: .75rem;
    background: rgba(255,255,255,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    margin: 0 auto .75rem;
}

.auth-body { padding: 2rem; }

/* ─── Overlay sidebar mobile ─────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1039;
}

/* ─── Collapse sidebar ───────────────────────────────────────── */
.sidebar-collapsed .sidebar { width: 68px; }
.sidebar-collapsed .sidebar-brand-name,
.sidebar-collapsed .sidebar-brand-tagline,
.sidebar-collapsed .sidebar-section-title,
.sidebar-collapsed .sidebar-nav .nav-link span,
.sidebar-collapsed .sidebar-nav .nav-link .badge,
.sidebar-collapsed .sidebar-user-info { display: none; }
.sidebar-collapsed .sidebar-nav .nav-link { justify-content: center; padding: .7rem; }
.sidebar-collapsed .sidebar-nav .nav-link i { width: auto; }
.sidebar-collapsed .sidebar-user { justify-content: center; padding: .6rem; }
.sidebar-collapsed .main-content { margin-left: 68px; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .topbar-toggle { display: flex; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .main-content { margin-left: 0 !important; }
}

/* ─── Utilitaires ────────────────────────────────────────────── */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.avatar-sm {
    width: 32px; height: 32px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .72rem; font-weight: 700; flex-shrink: 0;
}

.avatar-md {
    width: 44px; height: 44px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .875rem; font-weight: 700; flex-shrink: 0;
}

.status-dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}

/* ─── Timeline (dossier) ─────────────────────────────────────── */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before { content: ''; position: absolute; left: .5rem; top: 0; bottom: 0; width: 2px; background: #e9ecef; }
[data-bs-theme="dark"] .timeline::before { background: rgba(255,255,255,.1); }
.timeline-item { position: relative; padding-bottom: 1.25rem; }
.timeline-dot {
    position: absolute; left: -1.75rem; top: .25rem;
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid #fff; flex-shrink: 0;
}
[data-bs-theme="dark"] .timeline-dot { border-color: #1a2332; }
.timeline-date { font-size: .75rem; color: #6c757d; }

/* ─── Upload zone ────────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed #dee2e6;
    border-radius: .75rem;
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--brand-primary);
    background: rgba(13,110,253,.04);
}
.upload-zone i { font-size: 2rem; color: #adb5bd; margin-bottom: .75rem; display: block; }

/* ─── Messages ───────────────────────────────────────────────── */
.message-item { border-left: 3px solid transparent; transition: var(--transition); cursor: pointer; }
.message-item:hover, .message-item.active { border-left-color: var(--brand-primary); background: rgba(13,110,253,.04); }
.message-item.unread .message-subject { font-weight: 700; }

/* ─── Scrollbar globale ──────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #dee2e6; border-radius: 3px; }
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); }

/* ─── Badges doux (soft) ─────────────────────────────────────── */
/* Bootstrap 5.3 utilise color: var(--bs-badge-color) sur .badge
   Il faut redéfinir la variable ET la propriété color pour éviter
   que le blanc par défaut (#fff) écrase notre couleur de texte.   */
.badge-soft-success  { --bs-badge-color: #198754; background: rgba(25,135,84,.13)   !important; color: #198754  !important; }
.badge-soft-danger   { --bs-badge-color: #dc3545; background: rgba(220,53,69,.13)   !important; color: #dc3545  !important; }
.badge-soft-warning  { --bs-badge-color: #856404; background: rgba(255,193,7,.18)   !important; color: #856404  !important; }
.badge-soft-primary  { --bs-badge-color: #0d6efd; background: rgba(13,110,253,.13)  !important; color: #0d6efd  !important; }
.badge-soft-info     { --bs-badge-color: #087990; background: rgba(13,202,240,.13)  !important; color: #087990  !important; }
.badge-soft-secondary{ --bs-badge-color: #495057; background: rgba(108,117,125,.13) !important; color: #495057  !important; }
.badge-soft-dark     { --bs-badge-color: #212529; background: rgba(33,37,41,.13)    !important; color: #212529  !important; }

[data-bs-theme="dark"] .badge-soft-success  { --bs-badge-color: #75b798; background: rgba(25,135,84,.2)   !important; color: #75b798 !important; }
[data-bs-theme="dark"] .badge-soft-danger   { --bs-badge-color: #ea868f; background: rgba(220,53,69,.2)   !important; color: #ea868f !important; }
[data-bs-theme="dark"] .badge-soft-warning  { --bs-badge-color: #ffda6a; background: rgba(255,193,7,.2)   !important; color: #ffda6a !important; }
[data-bs-theme="dark"] .badge-soft-primary  { --bs-badge-color: #6ea8fe; background: rgba(13,110,253,.2)  !important; color: #6ea8fe !important; }
[data-bs-theme="dark"] .badge-soft-secondary{ --bs-badge-color: #adb5bd; background: rgba(108,117,125,.2) !important; color: #adb5bd !important; }
[data-bs-theme="dark"] .badge-soft-dark     { --bs-badge-color: #dee2e6; background: rgba(255,255,255,.1) !important; color: #dee2e6 !important; }

/* ─── Animations ─────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fadeIn .2s ease forwards; }
