/**
 * Procdeg - Composants UI (Design compact)
 * Cards, badges, toasts, toolbar
 */

/* ==================== CARDS ==================== */

.card {
    background: var(--pico-card-background-color);
    border-radius: 4px;
    padding: 0.625rem 0.75rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-fast);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-prescription {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.375rem;
    cursor: grab;
}

.card-prescription:active {
    cursor: grabbing;
}

.card-prescription .card-content {
    flex: 1;
    min-width: 0;
}

.card-prescription .card-title {
    font-weight: 600;
    font-size: 0.8125rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.card-prescription .card-title i {
    font-size: 0.875rem;
    opacity: 0.8;
}

.card-prescription .card-subtitle {
    font-size: 0.75rem;
    color: var(--pico-muted-color);
    margin: 2px 0 0;
    line-height: 1.35;
}

.card-prescription .card-comment {
    font-size: 0.6875rem;
    font-style: italic;
    color: var(--pico-muted-color);
    margin-top: 2px;
}

.card-prescription .card-comment:empty {
    display: none;
}

.card-prescription .card-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

/* ==================== BADGES / LABELS ==================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    font-size: 0.625rem;
    font-weight: 600;
    border-radius: 10px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge-success {
    background-color: var(--color-success-bg);
    color: #2e7d32;
}

.badge-warning {
    background-color: var(--color-warning-bg);
    color: #b76a00;
}

.badge-danger {
    background-color: var(--color-danger-bg);
    color: #c62828;
}

.badge-info {
    background-color: var(--color-info-bg);
    color: #1565c0;
}

.badge-secondary {
    background-color: #e0e0e0;
    color: #666;
}

/* ==================== TOASTS ==================== */

#toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--pico-card-background-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    animation: toast-slide-in 200ms ease-out;
    max-width: 300px;
}

.toast.toast-exit {
    animation: toast-slide-out 150ms ease-in forwards;
}

.toast-success { border-left: 3px solid var(--color-success); }
.toast-warning { border-left: 3px solid var(--color-warning); }
.toast-danger { border-left: 3px solid var(--color-danger); }
.toast-info { border-left: 3px solid var(--color-info); }

.toast-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    font-size: 14px;
}

.toast-message {
    flex: 1;
    font-size: 0.8125rem;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 2px;
    cursor: pointer;
    opacity: 0.5;
    font-size: 12px;
}

.toast-close:hover {
    opacity: 1;
}

@keyframes toast-slide-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-slide-out {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* ==================== ICON BUTTONS ==================== */

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
    font-size: 14px;
    transition: all 150ms;
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--pico-primary);
}

.btn-icon:focus {
    outline: 2px solid var(--pico-primary-focus);
    outline-offset: 1px;
}

.btn-icon.btn-danger:hover {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

/* ==================== BUTTON GROUP ==================== */

.btn-group {
    display: inline-flex;
    gap: 0;
}

.btn-group > button,
.btn-group > a {
    border-radius: 0;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-group > :first-child {
    border-radius: 4px 0 0 4px;
}

.btn-group > :last-child {
    border-radius: 0 4px 4px 0;
}

/* ==================== TABLES ==================== */

.table-container {
    background: var(--pico-card-background-color);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

table {
    margin: 0;
    font-size: 0.8125rem;
}

table th,
table td {
    padding: 0.5rem 0.75rem;
}

/* ==================== PROGRESS ==================== */

progress {
    width: 100%;
    height: 6px;
    border-radius: 3px;
}

/* ==================== LOADING STATE ==================== */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--pico-background-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--pico-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== EMPTY STATE ==================== */

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--pico-muted-color);
}

.empty-state i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

/* ==================== SECTION HEADERS ==================== */

.section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.section-header h2,
.section-header h3 {
    margin: 0;
    font-size: 0.9375rem;
}

/* ==================== PRESCRIPTION STATUS ==================== */

#statut-ordonnance {
    margin-bottom: 0.5rem;
}

#statut-ordonnance:empty {
    display: none;
}

/* ==================== PATIENTS LIST ==================== */

.patients-list-section {
    background: var(--pico-card-background-color);
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    overflow: hidden;
}

.patients-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 0.75rem;
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.patients-list-header h3 {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
}

.btn-sm {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    border: 1px solid var(--pico-primary);
    background: transparent;
    color: var(--pico-primary);
    cursor: pointer;
    transition: all 150ms;
}

.btn-sm:hover {
    background: var(--pico-primary);
    color: white;
}

.patients-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 180px;
    overflow-y: auto;
}

.patients-list-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    cursor: pointer;
    transition: background 150ms;
}

.patients-list-item:last-child {
    border-bottom: none;
}

.patients-list-item:hover {
    background: rgba(0, 0, 0, 0.02);
}

.patients-list-item.active {
    background: var(--color-info-bg);
}

.patients-list-item .patient-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid var(--pico-muted-color);
    flex-shrink: 0;
}

.patients-list-item.active .patient-indicator {
    background: var(--pico-primary);
    border-color: var(--pico-primary);
}

.patients-list-item .patient-info {
    flex: 1;
    min-width: 0;
}

.patients-list-item .patient-name {
    font-weight: 600;
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.patients-list-item .patient-details {
    font-size: 0.6875rem;
    color: var(--pico-muted-color);
}

.patients-list-item .patient-status {
    flex-shrink: 0;
}

.patients-list-empty {
    padding: 1rem;
    text-align: center;
    color: var(--pico-muted-color);
    font-size: 0.8125rem;
}

/* Autocomplete dans la liste patients */
.patients-list-section .autocomplete-container {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

/* ==================== COLLAPSIBLE SECTIONS ==================== */

.collapsible {
    background: var(--pico-card-background-color);
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--transition-fast);
}

.collapsible:hover {
    box-shadow: var(--shadow-md);
}

.collapsible-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    cursor: pointer;
    user-select: none;
    background: rgba(0, 0, 0, 0.02);
    transition: background 150ms;
}

.collapsible-header:hover {
    background: rgba(0, 0, 0, 0.04);
}

.collapsible-header .chevron {
    font-size: 0.75rem;
    transition: transform 200ms ease;
    color: var(--pico-muted-color);
}

.collapsible.collapsed .collapsible-header .chevron {
    transform: rotate(-90deg);
}

.collapsible-header #patient-summary {
    flex: 1;
    font-weight: 600;
    font-size: 0.875rem;
}

.collapsible-header .btn-sm {
    margin-left: auto;
}

.collapsible-content {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 300ms ease, padding 300ms ease;
}

.collapsible.collapsed .collapsible-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

/* ==================== PRESCRIPTIONS HEADER ==================== */

.prescriptions-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.prescriptions-header #statut-ordonnance {
    margin-bottom: 0;
}

.prescriptions-header #prescriptions-count {
    font-size: 0.8125rem;
    color: var(--pico-muted-color);
}

/* ==================== MEDICATION STATUS BADGES ==================== */

.card-status .badge-active {
    background-color: var(--color-success-bg);
    color: #2e7d32;
}

.card-status .badge-ended {
    background-color: var(--color-danger-bg);
    color: #c62828;
}

.card-status .badge-lastday {
    background-color: var(--color-warning-bg);
    color: #b76a00;
}
