/* =============================================================================
   Cab_Beynost — Feuille de style principale
   Design : sobre, médical. Bleu #3B82F6, vert #10B981. Mobile-first.
   ============================================================================= */

:root {
    /* Couleurs */
    --c-bg: #F8FAFC;
    --c-surface: #FFFFFF;
    --c-border: #E5E7EB;
    --c-border-strong: #D1D5DB;
    --c-text: #1F2937;
    --c-text-muted: #6B7280;
    --c-text-light: #9CA3AF;

    --c-primary: #3B82F6;
    --c-primary-dark: #2563EB;
    --c-primary-light: #DBEAFE;
    --c-primary-fade: #EFF6FF;

    --c-success: #10B981;
    --c-success-dark: #059669;
    --c-success-light: #D1FAE5;

    --c-warning: #F59E0B;
    --c-warning-light: #FEF3C7;

    --c-danger: #EF4444;
    --c-danger-dark: #DC2626;
    --c-danger-light: #FEE2E2;

    --c-info: #06B6D4;
    --c-purple: #A855F7;

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

    /* Layout */
    --sidebar-w: 240px;
    --topbar-h: 60px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
    --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, .1), 0 4px 10px rgba(0, 0, 0, .05);

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: var(--font-sans);
    color: var(--c-text);
    background: var(--c-bg);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; font-size: inherit; cursor: pointer; }

input, select, textarea {
    font-family: inherit; font-size: inherit;
    color: var(--c-text);
    background: var(--c-surface);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    padding: 8px 12px;
    width: 100%;
    transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px var(--c-primary-light);
}
input:disabled, textarea:disabled { background: var(--c-bg); color: var(--c-text-muted); }
textarea { resize: vertical; min-height: 80px; }

label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    color: var(--c-text);
    margin-bottom: var(--s-1);
}
.field { margin-bottom: var(--s-4); }
.field-hint { font-size: 12px; color: var(--c-text-muted); margin-top: var(--s-1); }
.field-error { font-size: 12px; color: var(--c-danger); margin-top: var(--s-1); }

.required::after { content: " *"; color: var(--c-danger); }

/* ========== Spinner ========== */
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--c-border);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto;
}
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-loading {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: 100vh; gap: var(--s-3);
    color: var(--c-text-muted);
}

/* ========== Boutons ========== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border: 1px solid transparent; border-radius: var(--radius);
    background: var(--c-surface); color: var(--c-text);
    font-weight: 500; font-size: 14px; line-height: 1.2;
    transition: background .15s, border-color .15s, color .15s, opacity .15s;
    user-select: none; white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-dark); border-color: var(--c-primary-dark); }

.btn-success { background: var(--c-success); color: #fff; border-color: var(--c-success); }
.btn-success:hover:not(:disabled) { background: var(--c-success-dark); border-color: var(--c-success-dark); }

.btn-danger { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.btn-danger:hover:not(:disabled) { background: var(--c-danger-dark); border-color: var(--c-danger-dark); }

.btn-secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--c-bg); border-color: var(--c-text-muted); }

.btn-ghost { background: transparent; color: var(--c-text); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--c-bg); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 20px; font-size: 16px; }
.btn-icon { padding: 6px; width: 32px; height: 32px; }
.btn-block { width: 100%; }

/* ========== Layout ========== */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "sidebar topbar" "sidebar main";
    min-height: 100vh;
}

.sidebar {
    grid-area: sidebar;
    background: #1F2937;
    color: #fff;
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.sidebar-logo {
    padding: 16px 20px; font-weight: 700; font-size: 16px;
    color: #fff; border-bottom: 1px solid rgba(255, 255, 255, .1);
    display: flex; align-items: center; gap: var(--s-2);
}
.sidebar-logo .dot { width: 24px; height: 24px; border-radius: 6px; background: var(--c-primary); display: inline-block; }

.sidebar-nav { flex: 1; padding: var(--s-2) 0; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px; color: #D1D5DB;
    border-left: 3px solid transparent;
    font-size: 14px;
}
.sidebar-nav a:hover { background: rgba(255, 255, 255, .05); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: rgba(59, 130, 246, .15); color: #fff; border-left-color: var(--c-primary); }
.sidebar-nav .icon { width: 18px; flex-shrink: 0; }

.sidebar-footer {
    padding: var(--s-3) var(--s-5); border-top: 1px solid rgba(255, 255, 255, .1);
    display: flex; align-items: center; gap: var(--s-2);
}
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--c-primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; }

.topbar {
    grid-area: topbar;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    padding: 0 var(--s-5);
    display: flex; align-items: center;
    justify-content: space-between;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; gap: var(--s-2); align-items: center; }

.main {
    grid-area: main;
    padding: var(--s-6);
    overflow-y: auto;
}

@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: var(--topbar-h) 1fr;
        grid-template-areas: "topbar" "main";
    }
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; width: 80%; max-width: 280px;
        z-index: 100; transform: translateX(-100%); transition: transform .25s;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay {
        position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90;
        opacity: 0; pointer-events: none; transition: opacity .25s;
    }
    .sidebar-overlay.open { opacity: 1; pointer-events: auto; }
    .topbar .menu-toggle { display: inline-flex; }
    .main { padding: var(--s-4); }
}
.menu-toggle { display: none; }

/* ========== Cards ========== */
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: var(--s-5);
    box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s-4); }
.card-header h2 { font-size: 16px; font-weight: 600; }

.card-grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* ========== Tableau ========== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--c-border); font-size: 14px; }
.table th { background: var(--c-bg); font-weight: 600; color: var(--c-text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:hover { background: var(--c-bg); cursor: pointer; }
.table .actions { white-space: nowrap; }
.table .empty { text-align: center; color: var(--c-text-muted); padding: var(--s-8); }

/* ========== Badges ========== */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 500;
    background: var(--c-primary-light); color: var(--c-primary-dark);
    white-space: nowrap;
}
.badge-success { background: var(--c-success-light); color: var(--c-success-dark); }
.badge-warning { background: var(--c-warning-light); color: #92400E; }
.badge-danger  { background: var(--c-danger-light); color: var(--c-danger-dark); }
.badge-muted   { background: var(--c-bg); color: var(--c-text-muted); }
.badge-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ========== Toasts ========== */
#toasts {
    position: fixed; bottom: 20px; right: 20px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 200; max-width: 360px;
}
.toast {
    background: var(--c-surface); border: 1px solid var(--c-border);
    border-left: 4px solid var(--c-primary);
    padding: var(--s-3) var(--s-4); border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex; gap: var(--s-3); align-items: flex-start;
    animation: toast-in .25s ease-out;
}
.toast.success { border-left-color: var(--c-success); }
.toast.error   { border-left-color: var(--c-danger); }
.toast.warning { border-left-color: var(--c-warning); }
.toast-content { flex: 1; }
.toast-title { font-weight: 600; font-size: 14px; }
.toast-msg { font-size: 13px; color: var(--c-text-muted); margin-top: 2px; }
.toast-close { background: none; border: none; color: var(--c-text-muted); padding: 0; }
.toast-undo { font-size: 12px; color: var(--c-primary); padding: 4px 8px; background: none; border: 1px solid var(--c-primary); border-radius: 4px; }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } }

/* ========== Modal ========== */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .6);
    display: flex; align-items: center; justify-content: center;
    z-index: 150; padding: var(--s-4);
    animation: fade-in .15s;
}
.modal {
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 720px; width: 100%; max-height: 90vh;
    display: flex; flex-direction: column;
    animation: pop-in .2s;
}
.modal.large { max-width: 1024px; }
.modal-header { padding: var(--s-5); border-bottom: 1px solid var(--c-border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-body { padding: var(--s-5); overflow-y: auto; }
.modal-footer { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: var(--s-2); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { transform: scale(.96); opacity: 0; } }

/* ========== Alertes ========== */
.alert {
    padding: var(--s-3) var(--s-4);
    border-radius: var(--radius);
    font-size: 14px;
    border-left: 4px solid;
    margin-bottom: var(--s-3);
}
.alert-info    { background: var(--c-primary-fade); border-color: var(--c-primary); color: #1E40AF; }
.alert-success { background: var(--c-success-light); border-color: var(--c-success); color: #065F46; }
.alert-warning { background: var(--c-warning-light); border-color: var(--c-warning); color: #92400E; }
.alert-danger  { background: var(--c-danger-light); border-color: var(--c-danger); color: #991B1B; }

/* ========== Layouts utilitaires ========== */
.row { display: flex; gap: var(--s-3); flex-wrap: wrap; }
.row-tight { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.col { flex: 1; min-width: 200px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); }
@media (max-width: 640px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.text-muted { color: var(--c-text-muted); }
.text-sm { font-size: 12px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 20px; font-weight: 600; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-bold { font-weight: 600; }
.text-success { color: var(--c-success-dark); }
.text-danger { color: var(--c-danger-dark); }
.text-warning { color: #92400E; }

.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); } .mb-4 { margin-bottom: var(--s-4); }
.mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }

.gap-2 { gap: var(--s-2); } .gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); }

.flex { display: flex; }
.flex-1 { flex: 1; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-end { display: flex; justify-content: flex-end; }
.items-center { align-items: center; }

.hidden { display: none !important; }

/* ========== Login ========== */
.login-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--c-primary-fade), var(--c-success-light));
    padding: var(--s-4);
}
.login-card {
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--s-8);
    width: 100%;
    max-width: 400px;
}
.login-card h1 { color: var(--c-primary); font-size: 24px; margin-bottom: var(--s-2); }
.login-card .lead { color: var(--c-text-muted); margin-bottom: var(--s-6); }

/* ========== Tooltip / aide ========== */
.help-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--c-border); color: var(--c-text-muted);
    font-size: 11px; font-weight: 600; cursor: help;
    margin-left: 4px; vertical-align: middle;
}
.help-icon:hover { background: var(--c-primary); color: #fff; }

/* ========== Schéma dentaire ========== */
.dental-chart { width: 100%; max-width: 600px; margin: 0 auto; }
.tooth { cursor: pointer; transition: opacity .1s; }
.tooth:hover { opacity: 0.7; }
.tooth-label { font-size: 10px; fill: var(--c-text-muted); pointer-events: none; }

/* ========== Kanban ========== */
.kanban {
    display: flex; gap: var(--s-3);
    overflow-x: auto; padding-bottom: var(--s-3);
    min-height: 400px;
}
.kanban-col {
    flex: 0 0 280px;
    background: var(--c-bg);
    border-radius: var(--radius-lg);
    padding: var(--s-3);
    display: flex; flex-direction: column;
}
.kanban-col-header { font-size: 13px; font-weight: 600; padding: 4px 8px; border-radius: 999px; display: inline-block; margin-bottom: var(--s-3); }
.kanban-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    padding: var(--s-3);
    margin-bottom: var(--s-2);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    border-left: 3px solid var(--c-primary);
}
.kanban-card.priority-urgente { border-left-color: var(--c-danger); }
.kanban-card.priority-haute { border-left-color: var(--c-warning); }
.kanban-card.priority-basse { border-left-color: var(--c-text-muted); }
.kanban-card.dragging { opacity: 0.5; }
.kanban-col.dropping { background: var(--c-primary-light); }

/* ========== Agenda ========== */
.agenda {
    display: grid;
    grid-template-columns: 60px repeat(var(--days, 5), 1fr);
    gap: 1px;
    background: var(--c-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.agenda-cell { background: var(--c-surface); padding: 4px 6px; font-size: 12px; min-height: 30px; position: relative; }
.agenda-time { background: var(--c-bg); color: var(--c-text-muted); text-align: right; padding: 4px 8px; }
.agenda-day-header { background: var(--c-bg); padding: 8px; text-align: center; font-weight: 600; font-size: 13px; }
.agenda-event {
    position: absolute; left: 2px; right: 2px;
    background: var(--c-primary-light);
    border-left: 3px solid var(--c-primary);
    padding: 4px 6px; border-radius: 4px;
    font-size: 11px; line-height: 1.3;
    overflow: hidden; cursor: pointer;
    z-index: 1;
}
.agenda-event:hover { z-index: 2; box-shadow: var(--shadow); }
.agenda-event .event-time { font-weight: 600; }
.agenda-event .event-name { color: var(--c-text); }

/* ========== Wiki ========== */
.wiki-layout { display: grid; grid-template-columns: 280px 1fr; gap: var(--s-4); align-items: start; }
@media (max-width: 768px) { .wiki-layout { grid-template-columns: 1fr; } }
.wiki-tree ul { list-style: none; }
.wiki-tree li { padding: 4px 0; }
.wiki-tree .folder { font-weight: 600; cursor: pointer; }
.wiki-tree .article { display: block; padding: 4px 8px; border-radius: 4px; cursor: pointer; }
.wiki-tree .article:hover { background: var(--c-primary-fade); }
.wiki-tree .article.active { background: var(--c-primary-light); color: var(--c-primary-dark); }
.wiki-content {
    line-height: 1.7; max-width: 800px;
}
.wiki-content h1, .wiki-content h2, .wiki-content h3 { margin: 1.4em 0 .6em; line-height: 1.3; }
.wiki-content h1 { font-size: 24px; }
.wiki-content h2 { font-size: 20px; color: var(--c-primary-dark); }
.wiki-content h3 { font-size: 16px; }
.wiki-content p, .wiki-content ul, .wiki-content ol { margin: .8em 0; }
.wiki-content ul, .wiki-content ol { padding-left: 1.6em; }
.wiki-content code { background: var(--c-bg); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 13px; }
.wiki-content pre { background: var(--c-text); color: #fff; padding: var(--s-3); border-radius: var(--radius); overflow-x: auto; }
.wiki-content table { border-collapse: collapse; margin: 1em 0; }
.wiki-content table td, .wiki-content table th { border: 1px solid var(--c-border); padding: 6px 10px; }
.wiki-content blockquote { border-left: 3px solid var(--c-primary); padding-left: var(--s-3); color: var(--c-text-muted); }

/* ========== Rich-text editor (très simple) ========== */
.rte-toolbar {
    display: flex; gap: 4px; flex-wrap: wrap;
    padding: 6px; background: var(--c-bg); border-radius: var(--radius) var(--radius) 0 0;
    border: 1px solid var(--c-border-strong); border-bottom: none;
}
.rte-toolbar button {
    background: var(--c-surface); border: 1px solid var(--c-border);
    padding: 4px 10px; border-radius: 4px; font-weight: 600; font-size: 13px;
}
.rte-toolbar button:hover { background: var(--c-primary-fade); border-color: var(--c-primary); }
.rte-content {
    min-height: 300px; max-height: 500px; overflow-y: auto;
    padding: var(--s-4); background: var(--c-surface);
    border: 1px solid var(--c-border-strong); border-radius: 0 0 var(--radius) var(--radius);
    line-height: 1.6;
}
.rte-content:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-light); }

/* ========== Statut visuels ========== */
.status-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

/* ========== Filtres / search bar ========== */
.toolbar {
    display: flex; gap: var(--s-3);
    flex-wrap: wrap; align-items: center;
    margin-bottom: var(--s-4);
}
.toolbar input[type=search], .toolbar input[type=text] { max-width: 320px; }
.toolbar select { width: auto; }

/* ========== Pagination ========== */
.pagination { display: flex; gap: var(--s-2); justify-content: center; align-items: center; margin-top: var(--s-4); }

/* ========== Print ========== */
@media print {
    .sidebar, .topbar, .toolbar, .btn { display: none !important; }
    .main { padding: 0; }
    body { background: #fff; }
}

/* ========== Onboarding ========== */
.onboarding { max-width: 720px; margin: 0 auto; padding: var(--s-6); }
.onboarding-steps { display: flex; gap: var(--s-2); margin-bottom: var(--s-6); }
.onboarding-step {
    flex: 1; height: 6px; border-radius: 3px;
    background: var(--c-border); transition: background .25s;
}
.onboarding-step.active { background: var(--c-primary); }
.onboarding-step.completed { background: var(--c-success); }

/* ========== Détail patient ========== */
.patient-header {
    display: grid; grid-template-columns: auto 1fr auto;
    gap: var(--s-4); align-items: center;
    padding: var(--s-4); background: var(--c-surface);
    border-radius: var(--radius-lg); border: 1px solid var(--c-border);
    margin-bottom: var(--s-4);
}
.patient-avatar {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--c-primary-light); color: var(--c-primary-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 18px;
}
.patient-tabs {
    display: flex; gap: 0; border-bottom: 1px solid var(--c-border);
    margin-bottom: var(--s-4); overflow-x: auto;
}
.patient-tabs button {
    background: none; border: none; border-bottom: 2px solid transparent;
    padding: 10px 16px; font-weight: 500; color: var(--c-text-muted);
    white-space: nowrap;
}
.patient-tabs button.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.patient-tabs button:hover { color: var(--c-text); }

/* ========== Color picker swatch ========== */
.color-swatch {
    display: inline-block; width: 16px; height: 16px;
    border-radius: 3px; vertical-align: middle;
    margin-right: 4px; border: 1px solid var(--c-border);
}

/* ========== Drag handle ========== */
.drag-handle {
    cursor: grab; color: var(--c-text-light);
    padding: 4px;
}
.drag-handle:active { cursor: grabbing; }
.dragging-row { opacity: 0.5; }
