/* ============================================
   CPA Design System v2.0
   Pré-Consultation Anesthésie
   ============================================ */

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Colors */
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --primary-300: #93c5fd;
    --primary-400: #60a5fa;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-700: #1d4ed8;
    --primary-800: #1e40af;
    --primary-900: #1e3a8a;

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    --green-50: #f0fdf4;
    --green-100: #dcfce7;
    --green-500: #22c55e;
    --green-600: #16a34a;
    --green-700: #15803d;

    --red-50: #fef2f2;
    --red-100: #fee2e2;
    --red-500: #ef4444;
    --red-600: #dc2626;
    --red-700: #b91c1c;

    --amber-50: #fffbeb;
    --amber-100: #fef3c7;
    --amber-500: #f59e0b;
    --amber-600: #d97706;
    --amber-700: #b45309;

    --purple-50: #faf5ff;
    --purple-500: #a855f7;
    --purple-600: #9333ea;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);

    /* Radius */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-2xl: 24px;
    --radius-full: 9999px;

    /* Transitions */
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    /* Typography */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', monospace;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;
}

html {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    color: var(--gray-800);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--gray-50);
}

/* === Typography === */
h1 { font-size: 1.875rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.025em; }
h2 { font-size: 1.5rem; font-weight: 600; line-height: 1.25; letter-spacing: -0.015em; }
h3 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
h4 { font-size: 1.1rem; font-weight: 600; line-height: 1.4; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.125rem; }
.text-muted { color: var(--gray-500); }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* === Links === */
a { color: var(--primary-600); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-700); }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-family: var(--font);
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.4;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
    color: white;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}
.btn-primary:hover { box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4); transform: translateY(-1px); }

.btn-success {
    background: linear-gradient(135deg, var(--green-500), var(--green-600));
    color: white;
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.3);
}
.btn-success:hover { box-shadow: 0 4px 16px rgba(22, 163, 74, 0.4); transform: translateY(-1px); }

.btn-danger {
    background: linear-gradient(135deg, var(--red-500), var(--red-600));
    color: white;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}
.btn-danger:hover { box-shadow: 0 4px 16px rgba(220, 38, 38, 0.4); }

.btn-outline {
    background: white;
    color: var(--gray-700);
    border: 1.5px solid var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
    padding: var(--space-2) var(--space-3);
    min-height: 40px;
}
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-800); }

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: 1.0625rem;
    min-height: 56px;
    border-radius: var(--radius-lg);
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: 0.8125rem;
    min-height: 36px;
    border-radius: var(--radius-sm);
}

.btn-icon {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: var(--radius);
}

.btn-full { width: 100%; }

/* === Cards === */
.card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-100);
    overflow: hidden;
    transition: all var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-body { padding: var(--space-6); }
.card-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--gray-100);
    background: var(--gray-50);
}

/* Glass card */
.card-glass {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* === Forms === */
.form-group { margin-bottom: var(--space-5); }
.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: var(--space-2);
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-family: var(--font);
    font-size: 1rem;
    color: var(--gray-800);
    background: white;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius);
    transition: all var(--transition);
    min-height: 48px;
    -webkit-appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.form-input::placeholder { color: var(--gray-400); }
.form-textarea { min-height: 100px; resize: vertical; line-height: 1.5; }
.form-hint { font-size: 0.8125rem; color: var(--gray-500); margin-top: var(--space-1); }

/* Input group */
.input-group {
    display: flex;
    gap: var(--space-3);
}
.input-group .form-input { flex: 1; }

/* === Badges === */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.badge-waiting { background: var(--amber-100); color: var(--amber-700); }
.badge-active { background: var(--primary-100); color: var(--primary-700); }
.badge-done { background: var(--green-100); color: var(--green-700); }
.badge-critical { background: var(--red-100); color: var(--red-700); }
.badge-warning { background: var(--amber-100); color: var(--amber-700); }

.badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}
.badge-waiting .badge-dot { background: var(--amber-500); }
.badge-active .badge-dot { background: var(--primary-500); animation: pulse-dot 2s infinite; }
.badge-done .badge-dot { background: var(--green-500); }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* === Alerts === */
.alert {
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    font-size: 0.9375rem;
    line-height: 1.5;
}
.alert-icon { flex-shrink: 0; margin-top: 1px; }
.alert-info { background: var(--primary-50); color: var(--primary-800); border: 1px solid var(--primary-200); }
.alert-success { background: var(--green-50); color: var(--green-700); border: 1px solid var(--green-100); }
.alert-warning { background: var(--amber-50); color: var(--amber-700); border: 1px solid var(--amber-100); }
.alert-danger { background: var(--red-50); color: var(--red-700); border: 1px solid var(--red-100); }

/* === Tables === */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}
thead th {
    padding: var(--space-3) var(--space-4);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
    text-align: left;
    white-space: nowrap;
}
tbody td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--gray-50); }

/* === Layout helpers === */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: 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); }
.gap-8 { gap: var(--space-8); }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.w-full { width: 100%; }
.mx-auto { margin-left: auto; margin-right: auto; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }

.hidden { display: none !important; }
.relative { position: relative; }
.overflow-hidden { overflow: hidden; }

/* === Dividers === */
.divider {
    height: 1px;
    background: var(--gray-200);
    margin: var(--space-6) 0;
}

/* === Animations === */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.animate-fade-in { animation: fadeIn 0.3s ease-out; }
.animate-fade-in-up { animation: fadeInUp 0.4s ease-out; }
.animate-slide-right { animation: slideInRight 0.4s ease-out; }
.animate-scale-in { animation: scaleIn 0.3s ease-out; }

/* === Spinner === */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-4);
    animation: fadeIn 0.2s ease-out;
}
.modal {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: scaleIn 0.3s ease-out;
}
.modal-header {
    padding: var(--space-6) var(--space-6) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-body { padding: 0 var(--space-6) var(--space-6); }
.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--gray-100);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

/* === Toast / Notification === */
.toast-container {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}
.toast {
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius);
    background: white;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary-500);
    animation: slideInRight 0.3s ease-out;
    max-width: 380px;
    font-size: 0.9375rem;
}
.toast-success { border-left-color: var(--green-500); }
.toast-error { border-left-color: var(--red-500); }

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--gray-500);
}
.empty-state svg { margin-bottom: var(--space-4); opacity: 0.4; }

/* === Stat cards === */
.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    border: 1px solid var(--gray-100);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: var(--space-1);
}
.stat-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* === Toggle buttons (Yes/No) === */
.toggle-group {
    display: flex;
    gap: var(--space-2);
}
.toggle-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    min-height: 52px;
    font-size: 1rem;
    font-weight: 500;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.toggle-btn:active { transform: scale(0.97); }
.toggle-btn.active-yes {
    border-color: var(--green-500);
    background: var(--green-50);
    color: var(--green-700);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}
.toggle-btn.active-no {
    border-color: var(--red-500);
    background: var(--red-50);
    color: var(--red-700);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* === Progress === */
.progress-bar {
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-500), var(--primary-600));
    border-radius: 3px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === Print === */
@media print {
    body { background: white !important; }
    .no-print { display: none !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    .btn { display: none !important; }
}

/* === Responsive === */
@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    .card-body { padding: var(--space-4); }
    .modal { max-width: 100%; margin: var(--space-2); }
}

/* === Safe area (notched devices) === */
@supports (padding: env(safe-area-inset-bottom)) {
    .safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
}

/* === Inter font import === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
