/* Main Courante v2 — design system (aucune dépendance externe) */

:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --border: #dde3ec;
    --text: #1a2433;
    --text-muted: #64748b;
    --primary: #2456d6;
    --primary-strong: #1a43ab;
    --primary-soft: #e3ebfd;
    --success: #157347;
    --success-soft: #d9f2e5;
    --danger: #c22f3d;
    --danger-soft: #fbe0e3;
    --warning: #9a6700;
    --warning-soft: #fff1cc;
    --info: #0b6e83;
    --info-soft: #d8f0f5;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .08);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 240px;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #0e1420;
    --surface: #171f2e;
    --surface-2: #1f2a3d;
    --border: #2b3850;
    --text: #e6ecf5;
    --text-muted: #93a1b7;
    --primary: #6d94ff;
    --primary-strong: #8fadff;
    --primary-soft: #22335c;
    --success: #4ade80;
    --success-soft: #143526;
    --danger: #f87181;
    --danger-soft: #432026;
    --warning: #fbbf24;
    --warning-soft: #3d3014;
    --info: #38bdf8;
    --info-soft: #12303d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 30;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 16px;
}

.brand-badge {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: #fff;
    border-radius: 9px;
    font-size: 16px;
    flex-shrink: 0;
}

.nav { padding: 12px; flex: 1; overflow-y: auto; }

.nav-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    padding: 14px 10px 6px;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 500;
    margin-bottom: 2px;
}

.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a .ico { width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}

/* Boutons du pied : s'adaptent à la largeur, ne débordent jamais */
.footer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.footer-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    padding-left: 8px;
    padding-right: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.footer-actions .btn.icon {
    flex: 0 0 auto;
    padding-left: 10px;
    padding-right: 10px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: grid; place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
    flex-shrink: 0;
    text-transform: uppercase;
}

.license-line {
    font-size: 11.5px;
    color: var(--text-muted);
    padding-top: 2px;
}

.license-line.expiring { color: var(--warning); font-weight: 600; }

.user-chip .meta { min-width: 0; }
.user-chip .meta .name { font-weight: 600; }
.user-chip .meta .role { color: var(--text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main {
    flex: 1;
    min-width: 0;
    padding: 24px clamp(16px, 3vw, 40px) 60px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.topbar h1 { font-size: 22px; }
.topbar .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Composants ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}

.stat .label { color: var(--text-muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 2px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-strong); }
[data-theme="dark"] .btn.primary { color: #0e1420; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 13px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field .hint { color: var(--text-muted); font-weight: 400; }

input[type="text"], input[type="password"], input[type="email"], input[type="date"],
input[type="time"], input[type="datetime-local"], input[type="number"], input[type="file"],
select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

textarea { resize: vertical; min-height: 90px; }

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
    border-color: var(--primary);
}

.field .error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }

.checks { display: flex; flex-wrap: wrap; gap: 8px; }

.check-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    font-size: 13.5px;
    user-select: none;
    background: var(--surface);
}

.check-pill input { accent-color: var(--primary); margin: 0; }
.check-pill:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    white-space: nowrap;
}

.badge.note { background: var(--surface-2); color: var(--text-muted); }
.badge.action { background: var(--primary-soft); color: var(--primary); }
.badge.event { background: var(--warning-soft); color: var(--warning); }
.badge.fire { background: var(--danger-soft); color: var(--danger); }
.badge.camera { background: var(--info-soft); color: var(--info); }
.badge.callduty { background: var(--danger-soft); color: var(--danger); }
.badge.gray { background: var(--surface-2); color: var(--text-muted); }
.badge.green { background: var(--success-soft); color: var(--success); }

/* ---------- Timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }

.timeline li {
    display: flex;
    gap: 14px;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
}

.timeline li:last-child { border-bottom: none; }

.timeline .dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: 7px;
    flex-shrink: 0;
}

.timeline .dot.event { background: var(--warning); }
.timeline .dot.fire, .timeline .dot.callduty { background: var(--danger); }
.timeline .dot.camera { background: var(--info); }
.timeline .dot.note { background: var(--text-muted); }

.timeline .body { flex: 1; min-width: 0; }
.timeline .msg { white-space: pre-wrap; word-wrap: break-word; }
.timeline .meta { display: flex; gap: 10px; align-items: center; color: var(--text-muted); font-size: 12.5px; margin-top: 3px; flex-wrap: wrap; }

/* ---------- Actions rapides (barre compacte) ---------- */

.actions-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.action-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
    transition: border-color .15s, background .15s, transform .05s;
}

.action-chip:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.action-chip:active { transform: scale(.97); }

/* ---------- Bandeaux d'information ---------- */

.banner {
    display: block;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    margin-bottom: 12px;
    font-size: 13.5px;
    color: var(--text);
    text-decoration: none;
}

a.banner:hover { border-color: var(--primary); text-decoration: none; }
.banner.warn { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.banner.notice { border-color: var(--warning); background: var(--warning-soft); color: var(--warning); }

.card-body.compact { padding: 12px 14px; }
.card-body.compact .filters .field { min-width: 120px; }

/* ---------- Tableaux ---------- */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table.data th, table.data td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

table.data th { color: var(--text-muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
table.data tr:last-child td { border-bottom: none; }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 15, 25, .55);
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 100;
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: min(560px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 16px;
}

.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- Toasts ---------- */

.toasts {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 200;
    max-width: min(380px, calc(100vw - 40px));
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow);
    animation: slide-in .2s ease-out;
    font-size: 14px;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@keyframes slide-in {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ---------- Rappels ---------- */

.reminder {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
}

.reminder:last-child { border-bottom: none; }
.reminder.overdue { background: var(--danger-soft); }
.reminder .when { font-size: 12.5px; color: var(--text-muted); }
.reminder.overdue .when { color: var(--danger); font-weight: 700; }
.reminder .content { flex: 1; min-width: 0; }

/* ---------- Calendrier ---------- */

.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.cal-head .title { font-weight: 700; font-size: 17px; text-transform: capitalize; }

.calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.calendar .dow { text-align: center; font-size: 12px; color: var(--text-muted); font-weight: 600; padding: 4px 0; text-transform: uppercase; }

.cal-day {
    min-height: 86px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    background: var(--surface);
    font-size: 12px;
    overflow: hidden;
}

.cal-day.out { opacity: .4; }
.cal-day.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal-day .num { font-weight: 700; font-size: 13px; margin-bottom: 3px; }

.cal-evt {
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: 5px;
    padding: 1px 6px;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    cursor: default;
}

/* ---------- Login ---------- */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background:
        radial-gradient(1000px 500px at 10% -10%, var(--primary-soft), transparent),
        radial-gradient(800px 400px at 110% 110%, var(--primary-soft), transparent),
        var(--bg);
}

.login-card { width: min(400px, 100%); }
.login-card .brand { justify-content: center; display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 800; margin-bottom: 20px; }

/* ---------- Divers ---------- */

.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 34px 20px;
}
.empty .emoji { font-size: 30px; display: block; margin-bottom: 8px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; }
.pager .info { color: var(--text-muted); font-size: 13px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; min-width: 140px; flex: 1; }
.filters .field.grow { flex: 2; min-width: 200px; }

.thumb { max-width: 220px; max-height: 160px; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; margin-top: 8px; }

/* Lightbox photo */
.photo-viewer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(90vw, 900px);
    max-height: 90vh;
}
.photo-viewer img {
    max-width: 100%;
    max-height: 78vh;
    object-fit: contain;
    border-radius: var(--radius);
    background: #000;
}
.photo-actions { display: flex; gap: 10px; justify-content: center; }

.mobile-nav-toggle { display: none; }

/* ---------- Page confidentialité ---------- */

.privacy { max-width: 860px; font-size: 14.5px; }
.privacy .lead { color: var(--text-muted); margin-top: 0; }
.privacy h3 { font-size: 16px; margin: 22px 0 8px; }
.privacy ul { margin: 8px 0; padding-left: 22px; }
.privacy li { margin-bottom: 5px; }
.privacy table.data { margin: 10px 0; }
.privacy table.data th, .privacy table.data td { padding: 8px 10px; }

.skeleton {
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
    margin: 10px 18px;
}

@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
    .mobile-nav-toggle { display: inline-flex; }
    .main { padding: 16px 14px 60px; }
    .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }
}
