/* Composants réutilisables du design system */

/* --- Boutons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 44px;
    padding: 0 var(--space-5);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    white-space: nowrap;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

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

.btn-sm {
    height: 36px;
    padding: 0 var(--space-4);
    font-size: var(--text-sm);
}

.btn-primary {
    /* primary-600 (pas 500) : le texte blanc sur primary-500 n'atteint que 3.5:1,
       insuffisant pour du texte normal en WCAG AA (4.5:1 requis). */
    background: var(--color-primary-600);
    color: var(--color-neutral-0);
}
.btn-primary:hover { background: var(--color-primary-700); }
.btn-primary:active { background: var(--color-primary-700); }

.btn-secondary {
    background: var(--surface-card);
    border-color: var(--border-default);
    color: var(--text-primary);
}
.btn-secondary:hover { background: var(--surface-sunken); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface-sunken); color: var(--text-primary); }

.btn-danger {
    background: var(--color-error-500);
    color: var(--color-neutral-0);
}
.btn-danger:hover { background: var(--color-error-700); }

.btn-block { width: 100%; }

/* --- Formulaires --- */
.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.field-label {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
}

.field-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.field-error {
    font-size: var(--text-xs);
    color: var(--color-error-500);
    font-weight: var(--weight-medium);
}

.input, .select, .textarea {
    height: 46px;
    padding: 0 var(--space-4);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-card);
    color: var(--text-primary);
    font-size: var(--text-base);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    width: 100%;
}

.textarea {
    height: auto;
    min-height: 110px;
    padding: var(--space-3) var(--space-4);
    resize: vertical;
}

.input:hover, .select:hover, .textarea:hover {
    border-color: var(--color-neutral-400);
}

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 3px var(--color-primary-100);
}

.input.has-error, .textarea.has-error {
    border-color: var(--color-error-500);
}

.input.has-error:focus {
    box-shadow: 0 0 0 3px var(--color-error-50);
}

.input::placeholder, .textarea::placeholder {
    color: var(--text-muted);
}

/* --- Cartes --- */
.card {
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-padded {
    padding: var(--space-6);
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    height: 26px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    line-height: 1;
}

.badge-prospect { background: var(--color-info-50); color: var(--color-info-700); }
.badge-client { background: var(--color-success-50); color: var(--color-success-700); }
.badge-vip { background: var(--color-accent-100); color: var(--color-accent-700); }
.badge-warning { background: var(--color-warning-50); color: var(--color-warning-700); }
.badge-error { background: var(--color-error-50); color: var(--color-error-700); }
.badge-neutral { background: var(--surface-sunken); color: var(--text-secondary); }

/* --- Alertes / messages flash --- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    border: 1px solid transparent;
}

.alert-success { background: var(--color-success-50); color: var(--color-success-700); border-color: var(--color-success-500); }
.alert-error { background: var(--color-error-50); color: var(--color-error-700); border-color: var(--color-error-500); }
.alert-info { background: var(--color-info-50); color: var(--color-info-700); border-color: var(--color-info-500); }

/* --- Tableaux --- */
.table {
    font-size: var(--text-sm);
}

/* Permet aux tableaux larges de défiler horizontalement sur petit écran sans
   casser la mise en page de la page (le débordement reste local à la table). */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table thead th {
    text-align: left;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.table tbody td {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr {
    transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--surface-sunken);
}

/* --- Avatar --- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--color-secondary-500);
    color: var(--color-neutral-0);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    flex-shrink: 0;
}

/* --- Utilitaires d'agencement --- */
.stack { display: flex; flex-direction: column; }
.cluster { display: flex; align-items: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

/* --- Cartes de documents (aperçu pièces jointes) --- */
.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-4);
}

.document-card {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--surface-card);
    display: flex;
    flex-direction: column;
}

.document-thumb {
    height: 110px;
    background: var(--surface-sunken);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    overflow: hidden;
}

.document-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.document-thumb.is-clickable {
    cursor: zoom-in;
    transition: filter var(--transition-fast);
}

.document-thumb.is-clickable:hover {
    filter: brightness(0.94);
}

.document-info {
    padding: var(--space-3) var(--space-4);
    flex: 1;
}

.document-label {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.document-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.document-actions {
    display: flex;
    border-top: 1px solid var(--border-subtle);
}

.document-actions a {
    flex: 1;
    text-align: center;
    padding: var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.document-actions a:hover {
    background: var(--surface-sunken);
    color: var(--color-primary-600);
}

.document-actions a + a {
    border-left: 1px solid var(--border-subtle);
}

/* --- Lightbox (aperçu image plein écran) --- */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(27, 24, 21, 0.88);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: var(--space-8);
}

.lightbox.is-open {
    display: flex;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.lightbox-close {
    position: absolute;
    top: var(--space-6);
    right: var(--space-6);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.12);
    color: var(--color-neutral-0);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xl);
    line-height: 1;
    transition: background-color var(--transition-fast);
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

.notif-bell-wrap {
    position: relative;
}

.notif-bell {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    background: transparent;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.notif-bell:hover {
    background: var(--surface-sunken);
    color: var(--text-primary);
}

.notif-bell-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    background: var(--color-error-500);
    color: var(--color-neutral-0);
    font-size: 10px;
    font-weight: var(--weight-semibold);
    line-height: 16px;
    text-align: center;
}

.notif-panel {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 340px;
    max-height: 420px;
    overflow-y: auto;
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 40;
}

.notif-panel.is-open {
    display: block;
}

.notif-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    font-weight: var(--weight-semibold);
}

.notif-panel-empty {
    padding: var(--space-6);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.notif-panel-item {
    display: block;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    color: inherit;
}

.notif-panel-item:last-child {
    border-bottom: none;
}

.notif-panel-item:hover {
    background: var(--surface-sunken);
}

.notif-panel-item.is-unread {
    background: var(--color-info-50);
}

.notif-panel-item-title {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    margin-bottom: 2px;
}

.notif-panel-item-message {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}
