/* ── Variables ──────────────────────────────────────────────── */
:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --primary-light: #e0e7ff;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --info: #0891b2;
    --info-light: #cffafe;
    --orange: #ea580c;
    --orange-light: #ffedd5;
    --purple: #7c3aed;
    --purple-light: #ede9fe;
    --pink: #db2777;
    --pink-light: #fce7f3;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
    --radius: 8px;
    --radius-lg: 12px;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ─────────────────────────────────────────────────── */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    white-space: nowrap;
    flex-shrink: 0;
}
.nav-brand i { font-size: 1.3rem; }
.nav-links {
    display: flex;
    gap: .25rem;
    flex-wrap: wrap;
    min-width: 0;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .8rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: .875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all .15s;
}
.nav-link:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-shrink: 0;
}
.user-info {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .875rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.user-info .badge { flex-shrink: 0; }

/* ── Main content ───────────────────────────────────────────── */
.main-content { padding: 1.5rem; }
.container { max-width: 1400px; margin: 0 auto; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.page-actions { display: flex; gap: .5rem; align-items: center; }

/* When a row is selected from the quick autocomplete */
.row-highlight {
    animation: rowFlash 1.6s ease-out;
}
@keyframes rowFlash {
    0%   { background: rgba(79, 70, 229, 0.18); }
    100% { background: transparent; }
}

/* Stat cards behave as links cleanly */
a.stat-card { text-decoration: none; color: inherit; cursor: pointer; }
a.stat-card:hover { text-decoration: none; }

.text-muted   { color: var(--text-muted); }
.text-warning { color: var(--warning); }
.form-help    { display: inline-block; margin-top: .35rem; font-size: .8rem; }

/* Quick-search bar label */
.form-label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: .35rem;
}

/* ── Stats Grid ─────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    border-left: 4px solid transparent;
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-blue  { border-color: var(--primary); }
.stat-green { border-color: var(--success); }
.stat-red   { border-color: var(--danger); }
.stat-orange{ border-color: var(--orange); }
.stat-purple{ border-color: var(--purple); }

.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; flex-shrink: 0;
}
.stat-blue  .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-green .stat-icon { background: var(--success-light); color: var(--success); }
.stat-red   .stat-icon { background: var(--danger-light);  color: var(--danger); }
.stat-orange .stat-icon { background: var(--orange-light);  color: var(--orange); }
.stat-purple .stat-icon { background: var(--purple-light);  color: var(--purple); }

.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .78rem; color: var(--text-muted); }

/* ── Card ───────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    overflow: hidden;
}
.card-header {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fafafa;
}
.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.card-body { padding: 1.25rem; }
.card-body.p-0 { padding: 0; }

/* ── Filters Grid ───────────────────────────────────────────── */
.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: .75rem;
    margin-bottom: .75rem;
}
.filter-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

/* ── Table ──────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
    padding: .625rem 1rem;
    background: #f8fafc;
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: .625rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8fafc; }
.actions-cell { white-space: nowrap; display: flex; gap: .25rem; align-items: center; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-control {
    padding: .45rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .875rem;
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
    background: var(--surface);
    color: var(--text);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; }
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius) 0 0 var(--radius); }
.input-addon {
    padding: .45rem .75rem;
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    background: #f8fafc;
    cursor: pointer;
    color: var(--text-muted);
    transition: background .15s;
}
.input-addon:hover { background: var(--border); }

.autocomplete { position: relative; }
.autocomplete-list {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    z-index: 20;
    margin: 0;
    padding: .25rem 0;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
    max-height: 220px;
    overflow-y: auto;
    display: none;
}
.autocomplete-item {
    padding: .45rem .75rem;
    font-size: .875rem;
    cursor: pointer;
    color: var(--text);
}
.autocomplete-item:hover,
.autocomplete-item.is-active {
    background: var(--bg);
}
.autocomplete-meta {
    color: var(--text-muted);
    font-size: .8rem;
}
.autocomplete-empty {
    padding: .45rem .75rem;
    font-size: .875rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all .15s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); color: #fff; }
.btn-success  { background: var(--success);  color: #fff; }
.btn-success:hover  { background: #15803d; color: #fff; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover   { background: #b91c1c; color: #fff; }
.btn-warning  { background: var(--warning);  color: #fff; }
.btn-warning:hover  { background: #b45309; color: #fff; }
.btn-outline  {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }

/* Icon-only buttons inside an actions cell: square, centered.
   Restricted to .actions-cell so buttons that mix an icon with a text label
   (e.g. "Nouveau RDV") are not collapsed into a 2 rem square. */
.actions-cell .btn-sm {
    width: 2rem;
    height: 2rem;
    padding: 0;
    justify-content: center;
    gap: 0;
}
.actions-cell .btn-sm i { font-size: .85rem; line-height: 1; }
.actions-cell form { display: inline-flex; margin: 0; }

/* ── Agenda KPI strip ───────────────────────────────────────── */
.agenda-kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
}
.agenda-kpi {
    background: var(--surface);
    padding: .9rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .15rem;
    border-bottom: 3px solid transparent;
}
.agenda-kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}
.agenda-kpi-label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}
.agenda-kpi-green  { border-bottom-color: var(--success); }
.agenda-kpi-green  .agenda-kpi-value { color: var(--success); }
.agenda-kpi-orange { border-bottom-color: var(--warning); }
.agenda-kpi-orange .agenda-kpi-value { color: var(--warning); }
.agenda-kpi-red    { border-bottom-color: var(--danger); }
.agenda-kpi-red    .agenda-kpi-value { color: var(--danger); }
@media (max-width: 640px) {
    .agenda-kpi-strip { grid-template-columns: repeat(2, 1fr); }
}

/* ── Report cards ──────────────────────────────────────────── */
.report-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}
.report-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    text-decoration: none;
    color: inherit;
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.report-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    text-decoration: none;
}
.report-card h3 { font-size: 1rem; font-weight: 600; margin: 0 0 .25rem 0; }
.report-card p { font-size: .85rem; color: var(--text-muted); margin: 0; }
.report-card-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}
.report-icon-blue   { background: var(--primary-light); color: var(--primary); }
.report-icon-orange { background: var(--orange-light);  color: var(--orange); }
.report-icon-green  { background: var(--success-light); color: var(--success); }

/* Inline rate bar (presence %) */
.rate-bar {
    position: relative;
    height: 1.4rem;
    background: var(--bg);
    border-radius: var(--radius);
    overflow: hidden;
    min-width: 8rem;
}
.rate-bar-fill {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--success-light);
    border-right: 2px solid var(--success);
    transition: width .3s;
}
.rate-bar-label {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text);
}

th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Charts ─────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 320px; }
.chart-wrap-sm { height: 200px; }
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
@media (max-width: 900px) {
    .chart-grid { grid-template-columns: 1fr; }
}

/* Fulfilled appointment row */
.rdv-fulfilled td { background: var(--success-light); }
.rdv-fulfilled td:first-child,
.rdv-fulfilled td:nth-child(3),
.rdv-fulfilled td:nth-child(4) {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* Cancelled appointment row */
.rdv-cancelled td { background: var(--danger-light); opacity: .8; }
.rdv-cancelled td:first-child,
.rdv-cancelled td:nth-child(2),
.rdv-cancelled td:nth-child(3),
.rdv-cancelled td:nth-child(4) {
    text-decoration: line-through;
    color: var(--text-muted);
}
.rdv-cancelled .badge { text-decoration: none; }
.btn-block { width: 100%; justify-content: center; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-green  { background: var(--success-light); color: var(--success); }
.badge-red    { background: var(--danger-light);  color: var(--danger); }
.badge-yellow { background: var(--warning-light); color: var(--warning); }
.badge-blue   { background: var(--primary-light); color: var(--primary); }
.badge-orange { background: var(--orange-light);  color: var(--orange); }
.badge-purple { background: var(--purple-light);  color: var(--purple); }
.badge-pink   { background: var(--pink-light);    color: var(--pink); }
.badge-role-admin     { background: #fef9c3; color: #a16207; }
.badge-role-medecin   { background: var(--primary-light); color: var(--primary); }
.badge-role-secretaire{ background: var(--success-light); color: var(--success); }

/* ── Alerts ─────────────────────────────────────────────────── */
.flash-container { margin-bottom: 1rem; }
.alert {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: .5rem;
    font-size: .875rem;
    position: relative;
}
.alert-success { background: var(--success-light); color: var(--success); }
.alert-danger  { background: var(--danger-light);  color: var(--danger); }
.alert-info    { background: var(--info-light);    color: var(--info); }
.alert-warning { background: var(--warning-light); color: var(--warning); }
.alert-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: inherit;
    opacity: .6;
    line-height: 1;
}
.alert-close:hover { opacity: 1; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-dialog {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-dialog.modal-sm { max-width: 480px; }
.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.modal-header h4 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: .25rem;
    line-height: 1;
    border-radius: var(--radius);
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.modal-footer {
    padding: .875rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* ── Login ──────────────────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    padding: 1rem;
}
.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
}
.login-logo {
    text-align: center;
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: .75rem;
}
.login-title {
    text-align: center;
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: .25rem;
}
.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: .875rem;
    margin-bottom: 1.75rem;
}
.login-form { display: flex; flex-direction: column; gap: 1rem; }

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: .75rem; display: block; opacity: .4; }

/* ── Error page ─────────────────────────────────────────────── */
.error-page {
    text-align: center;
    padding: 4rem 1rem;
}
.error-icon { font-size: 4rem; color: var(--danger); margin-bottom: 1rem; }
.error-page h1 { font-size: 1.8rem; margin-bottom: .75rem; }
.error-page p { color: var(--text-muted); margin-bottom: 1.5rem; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    .navbar { gap: .75rem; flex-wrap: wrap; height: auto; padding: .5rem 1rem; }
    .nav-user { flex-wrap: wrap; gap: .5rem; }
    .form-row { grid-template-columns: 1fr; }
    .filters-grid { grid-template-columns: 1fr 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .main-content { padding: 1rem; }
}
@media (max-width: 480px) {
    .filters-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
}
