:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --text: #1b2433;
    --muted: #64708a;
    --line: #e3e8f0;
    --primary: #1f4fd8;
    --primary-dark: #173ca6;
    --ok: #15803d;
    --err: #b91c1c;
    --warn: #b45309;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 1rem; }
h3 { font-size: .95rem; margin: 1.2rem 0 .4rem; }
code.pw { font-size: 1.1rem; background: #fff; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); user-select: all; }

/* Barre supérieure */
.topbar {
    display: flex; align-items: center; gap: 24px;
    padding: 0 24px; height: 60px;
    background: #0f1b33; color: #fff;
    position: sticky; top: 0; z-index: 10;
}
.topbar a { color: #cdd6ea; }
.topbar a:hover, .topbar a.on { color: #fff; text-decoration: none; }
.brand { font-weight: 700; font-size: 1.15rem; color: #fff !important; white-space: nowrap; }
.brand i { color: #7aa2ff; }
.topnav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topnav a { padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-size: .92rem; }
.topnav a.on { background: rgba(255,255,255,.1); }
.topuser { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.topuser form { margin: 0; }
.icon-btn { background: none; border: 0; color: inherit; cursor: pointer; font-size: 1rem; padding: 6px 8px; border-radius: 8px; }
.topbar .icon-btn { color: #cdd6ea; }
.topbar .icon-btn:hover { color: #fff; background: rgba(255,255,255,.1); }

/* Mise en page */
.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 28px 24px; flex: 1; }
.container.wide { max-width: 1400px; }
.container.narrow { max-width: 640px; }
.page-title { font-size: 1.6rem; margin: 0 0 .3rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.c { text-align: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 20px; }
.card.center { text-align: center; padding: 40px 24px; }
.big-icon { font-size: 2.4rem; color: var(--muted); margin-bottom: .6rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px; }

/* Tuiles d'applis */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; margin-top: 1.4rem; }
.tile {
    display: flex; flex-direction: column; gap: 6px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
    padding: 22px; box-shadow: var(--shadow); color: var(--text);
    border-top: 4px solid var(--c);
    transition: transform .15s ease, box-shadow .15s ease;
}
.tile:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(16,24,40,.12); text-decoration: none; }
.tile-icon {
    width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center;
    background: color-mix(in srgb, var(--c) 14%, white); color: var(--c); font-size: 1.35rem; margin-bottom: 6px;
}
.tile-name { font-weight: 700; font-size: 1.15rem; }
.tile-desc { color: var(--muted); font-size: .9rem; }

/* Formulaires */
.form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input[type=text], input[type=password], input[type=email], input[type=search], select {
    font: inherit; padding: 9px 12px; border: 1px solid #cfd6e3; border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
input:disabled { background: #f1f4f9; }
.btn {
    display: inline-flex; align-items: center; gap: 8px; justify-content: center;
    font: inherit; font-weight: 600; padding: 9px 18px; border-radius: 8px; border: 1px solid var(--primary);
    background: var(--primary); color: #fff; cursor: pointer;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-light { background: #fff; color: var(--text); border-color: #cfd6e3; }
.btn-light:hover { background: #f1f4f9; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.span-2 { grid-column: 1 / -1; }
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input[type=search] { min-width: 260px; }

/* Messages */
.flash { max-width: 1100px; margin: 16px auto 0; padding: 12px 16px; border-radius: 10px; border: 1px solid; }
.flash.inline { margin: 0 0 16px; }
.flash-success { background: #ecfdf3; border-color: #a6e9c1; color: #166534; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: var(--err); }
.flash-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.flash-warn { background: #fffbeb; border-color: #fde68a; color: #78350f; }

/* Tableaux */
.table-card { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; white-space: nowrap; }
.table th.c, .table td.c { text-align: center; }
.table tbody tr:hover { background: #fafbfd; }
.table tr.inactive td { opacity: .55; }
.table form { margin: 0; }
.user-cell { display: flex; flex-direction: column; color: var(--text); }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #eef1f6; color: var(--muted); }
.badge-dark { background: #0f1b33; color: #fff; }
.badge-ok { background: #dcfce7; color: var(--ok); }
.badge-err { background: #fee2e2; color: var(--err); }
.app-dot {
    display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; font-size: .8rem;
    background: color-mix(in srgb, var(--c) 14%, white); color: var(--c); vertical-align: middle; margin-right: 4px;
}
.toggle {
    font: inherit; font-size: .78rem; min-width: 44px; min-height: 30px; padding: 3px 9px; border-radius: 8px; cursor: pointer;
    border: 1px dashed #cfd6e3; background: #fff; color: #b3bccb; display: inline-flex; gap: 6px; align-items: center; justify-content: center;
}
.toggle:hover { border-color: var(--c); color: var(--c); }
.toggle.on { border: 1px solid color-mix(in srgb, var(--c) 45%, white); background: color-mix(in srgb, var(--c) 12%, white); color: var(--c); font-weight: 600; }
.pager { display: flex; gap: 10px; justify-content: center; }

/* Accès appli (fiche utilisateur) */
.app-access { display: flex; flex-direction: column; gap: 10px; }
.app-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; border-left: 4px solid var(--c); }
.app-row select { min-width: 190px; }
.sub { margin: -4px 0 4px 16px; }

/* Connexion */
.login-wrap { flex: 1; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #1f3a8a 0, #0f1b33 55%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 18px; padding: 34px 30px; box-shadow: 0 20px 60px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; text-align: center; }
.login-card .muted { text-align: center; margin: -8px 0 6px; }
.login-logo { margin: 0 auto; width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; background: #e8efff; color: var(--primary); font-size: 1.7rem; }
body:has(.login-wrap) .foot { background: #0f1b33; color: #8793ad; }

@media (max-width: 800px) {
    .grid-2 { grid-template-columns: 1fr; }
    .topbar { padding: 0 12px; gap: 10px; }
    .topnav a span, .topuser a { font-size: 0; }
    .topuser a i { font-size: 1rem; }
    .container { padding: 20px 16px; }
    .filters input[type=search] { min-width: 0; flex: 1; }
}

/* ---------- Page de connexion ---------- */
.auth { flex: 1; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, .9fr); min-height: 100vh; }
.auth-intro {
    background: radial-gradient(circle at 15% 0%, #274a9e 0, #13254d 45%, #0b1630 100%);
    color: #dbe4f6; padding: 48px clamp(24px, 5vw, 72px); display: flex; flex-direction: column; gap: 26px;
}
.auth-brand { font-weight: 700; font-size: 1.3rem; color: #fff; }
.auth-brand i { color: #7aa2ff; }
.auth-intro h1 { color: #fff; font-size: clamp(1.6rem, 2.6vw, 2.3rem); margin: 0; letter-spacing: -.01em; }
.auth-lead { margin: 0; max-width: 62ch; font-size: 1.02rem; color: #c3cfe8; }
.auth-apps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.auth-apps li { display: flex; gap: 12px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.09); border-radius: 12px; padding: 12px 14px; }
.auth-apps strong { color: #fff; display: block; }
.auth-apps span { font-size: .86rem; color: #aebbd6; }
.auth-app-icon { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 30%, transparent); color: #fff; }
.auth-trust { border-top: 1px solid rgba(255,255,255,.12); padding-top: 20px; }
.auth-trust h2 { color: #fff; font-size: 1rem; margin: 0 0 12px; }
.auth-trust h2 i { color: #6ee7b7; }
.auth-trust ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; }
.auth-trust li { display: flex; gap: 10px; font-size: .86rem; color: #aebbd6; }
.auth-trust li i { color: #6ee7b7; margin-top: 3px; width: 16px; flex: none; }
.auth-trust strong { color: #e6ecf8; }
.auth-panel { background: var(--bg); display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 40px 24px; gap: 16px; }
.auth-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 32px 30px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.auth-card h2 { text-align: center; margin: 0; font-size: 1.4rem; }
.auth-card > .muted { text-align: center; margin: -6px 0 4px; }
.input-icon { position: relative; display: block; }
.input-icon > i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #9aa6bd; font-size: .9rem; }
.input-icon input { width: 100%; padding-left: 36px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: #9aa6bd; cursor: pointer; padding: 6px; }
.auth-help { font-size: .82rem; color: var(--muted); text-align: center; margin: 0; }
.auth-warn { font-size: .76rem; color: var(--muted); background: #f5f7fb; border-radius: 8px; padding: 8px 10px; margin: 0; }
.auth-links { font-size: .82rem; color: var(--muted); }
@media (max-width: 960px) {
    .auth { grid-template-columns: 1fr; }
    .auth-panel { order: -1; padding-top: 32px; }
    .auth-apps, .auth-trust ul { grid-template-columns: 1fr; }
}

/* ---------- Pages légales ---------- */
.legal h2 { margin-top: 1.6rem; }
.legal .todo { background: #fff7d6; padding: 0 4px; border-radius: 4px; }

/* Tuile d'une appli non attribuée : grisée, non cliquable */
.tile { position: relative; }
.tile-locked { cursor: not-allowed; filter: grayscale(1); opacity: .55; border-top-color: #c3cad6; box-shadow: none; user-select: none; }
.tile-locked:hover { transform: none; box-shadow: none; }
.tile-lock { position: absolute; top: 14px; right: 14px; font-size: .75rem; font-weight: 600; color: var(--muted); background: #eef1f6; padding: 3px 8px; border-radius: 999px; }

/* Mot de passe oublié */
.auth-simple { flex: 1; display: grid; place-items: center; padding: 24px; min-height: 100vh; background: radial-gradient(circle at 15% 0%, #274a9e 0, #13254d 45%, #0b1630 100%); }
.auth-forgot { text-align: right; margin: -6px 0 0; font-size: .85rem; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* Nom de l'établissement */
.brand-tenant { font-weight: 500; font-size: .85rem; color: #9fb4e6; margin-left: 6px; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.25); }
.auth-tenant { display: inline-block; margin-left: 10px; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.12); font-size: .85rem; font-weight: 600; color: #dbe4f6; vertical-align: middle; }
