:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e3e6ea;
    --text: #1c2024;
    --muted: #6b7280;
    --primary: #2f6fed;
    --primary-dark: #2459c4;
    --danger: #e5484d;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); }

/* ---- Top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; font-size: 18px; }
.brand-link { color: inherit; text-decoration: none; }
.brand-mark {
    display: inline-grid; place-items: center;
    width: 30px; height: 30px; margin-right: 6px;
    background: var(--primary); color: #fff;
    border-radius: 8px; font-size: 13px; font-weight: 700;
    vertical-align: middle;
}
.topbar nav { display: flex; gap: 10px; }

/* ---- Layout ---- */
.container { max-width: 1080px; margin: 28px auto; padding: 0 24px; }
.info-band { margin-top: 0; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 9px 16px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text);
    border-radius: 9px; font-size: 14px; font-weight: 500;
    cursor: pointer; text-decoration: none; transition: .15s;
}
.btn:hover { border-color: #cfd4da; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #f3c6c7; }
.btn-danger:hover { background: #fdeced; border-color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---- Cards grid ---- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex; flex-direction: column;
}
.qr-holder {
    display: grid; place-items: center;
    padding: 18px; background: #fafbfc;
    border-bottom: 1px solid var(--border);
}
.qr-holder canvas, .qr-holder svg { max-width: 100%; height: auto; }
.card-body { padding: 14px 16px; flex: 1; }
.card-title { margin: 0 0 4px; font-size: 16px; }
.card-url {
    display: block; font-size: 13px; color: var(--muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    text-decoration: none;
}
.card-url:hover { color: var(--primary); }
.card-meta {
    display: flex; justify-content: space-between;
    margin-top: 10px; font-size: 12px; color: var(--muted);
}
.card-actions {
    display: flex; gap: 8px; padding: 12px 16px;
    border-top: 1px solid var(--border); flex-wrap: wrap; align-items: center;
}
.inline-form { display: inline; margin: 0; }

/* ---- Empty state ---- */
.empty {
    text-align: center; padding: 60px 20px;
    background: var(--surface); border: 1px dashed var(--border);
    border-radius: var(--radius);
}
.empty p { color: var(--muted); margin-bottom: 16px; }

/* ---- Editor ---- */
.editor-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 22px;
    align-items: start;
}
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}
.panel h2 { margin: 0 0 18px; font-size: 18px; }
.preview-panel { position: sticky; top: 20px; text-align: center; }
.preview-box {
    display: grid; place-items: center;
    min-height: 280px; margin-bottom: 16px;
    background: #fafbfc; border: 1px solid var(--border); border-radius: 10px;
}

label { display: block; font-size: 13px; font-weight: 500; margin: 14px 0 6px; }
input[type="text"], input[type="url"], input[type="password"], input[type="file"], select {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 9px;
    font-size: 14px; font-family: inherit; background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,111,237,.12); }
input[type="color"] { width: 100%; height: 42px; padding: 4px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > div { flex: 0 0 90px; }
.row > .grow { flex: 1 1 140px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.checkbox input { width: auto; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.hint.center { text-align: center; }
.form-buttons { display: flex; gap: 10px; margin-top: 22px; }

/* ---- Alerts ---- */
.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; font-size: 14px; }
.alert.success { background: #e9f7ef; color: #1d7a46; border: 1px solid #bce5cd; }
.alert.error { background: #fdeced; color: #b42318; border: 1px solid #f3c6c7; }

/* ---- Login ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
    width: 100%; max-width: 360px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 32px; text-align: center;
}
.login-logo {
    width: 52px; height: 52px; margin: 0 auto 16px;
    display: grid; place-items: center;
    background: var(--primary); color: #fff;
    border-radius: 12px; font-weight: 700; font-size: 18px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card form { margin-top: 20px; text-align: left; }
.login-card .btn-block { margin-top: 16px; }
.muted { color: var(--muted); }

@media (max-width: 720px) {
    .editor-grid { grid-template-columns: 1fr; }
    .preview-panel { position: static; }
}

/* ---- Bibliothèque de logos (sélecteur) ---- */
.logo-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 10px;
    margin-top: 4px;
}
.logo-tile {
    position: relative;
    aspect-ratio: 1 / 1;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fafbfc;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; padding: 6px; overflow: hidden;
    font-size: 12px; color: var(--muted);
    transition: .12s;
}
.logo-tile:hover { border-color: #cfd4da; }
.logo-tile.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(47,111,237,.18); }
.logo-tile img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-none span, .logo-add span { text-align: center; line-height: 1.2; }
.logo-add { border-style: dashed; color: var(--primary); font-weight: 500; }
.logo-del {
    position: absolute; top: 2px; right: 2px;
    width: 18px; height: 18px; line-height: 16px; text-align: center;
    border: none; border-radius: 50%;
    background: rgba(0,0,0,.55); color: #fff;
    font-size: 14px; cursor: pointer; padding: 0;
    opacity: 0; transition: opacity .12s;
}
.logo-tile:hover .logo-del { opacity: 1; }
.logo-del:hover { background: var(--danger); }

/* ---- Sélection de logo (étape amont) ---- */
.logo-control { display: flex; align-items: center; gap: 14px; margin-top: 4px; flex-wrap: wrap; }
.logo-current {
    width: 64px; height: 64px; flex: 0 0 auto;
    border: 1px solid var(--border); border-radius: 10px; background: #fafbfc;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; color: var(--muted); text-align: center; padding: 6px; overflow: hidden;
}
.logo-current.has-logo { background: #fff; }
.logo-current img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Modal bibliothèque ---- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(15, 23, 42, .5);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--surface); border-radius: 14px;
    width: 100%; max-width: 640px; max-height: 80vh;
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close {
    border: none; background: none; font-size: 24px; line-height: 1;
    color: var(--muted); cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px 20px; overflow-y: auto; }

/* ---- Grille de miniatures de taille égale ---- */
.logo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 12px;
}
.logo-thumb {
    position: relative; aspect-ratio: 1 / 1;
    border: 1px solid var(--border); border-radius: 10px; background: #fff;
    display: flex; align-items: center; justify-content: center;
    padding: 8px; cursor: pointer; overflow: hidden; transition: .12s;
}
.logo-thumb:hover { border-color: #cfd4da; }
.logo-thumb.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(47,111,237,.18); }
.logo-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-thumb:hover .logo-del { opacity: 1; }

/* ============================================================
   URL courtes : filtres, badges, blocs de l'éditeur
   ============================================================ */

/* ---- Filtres du tableau de bord ---- */
.filters { display: flex; gap: 8px; margin: 0 0 18px; flex-wrap: wrap; }
.chip {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 14px; border: 1px solid var(--border);
    background: var(--surface); color: var(--muted);
    border-radius: 999px; font-size: 13px; font-weight: 500;
    cursor: pointer; transition: .15s;
}
.chip:hover { border-color: #cfd4da; color: var(--text); }
.chip.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-n {
    display: inline-grid; place-items: center; min-width: 20px; height: 20px;
    padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: 700;
    background: rgba(0, 0, 0, .06);
}
.chip.is-active .chip-n { background: rgba(255, 255, 255, .22); }

/* ---- Vignette des entrées sans QR code ---- */
.link-holder {
    display: grid; place-items: center; gap: 6px;
    padding: 30px 18px; background: #fafbfc;
    border-bottom: 1px solid var(--border);
    min-height: 152px;
}
.link-glyph { font-size: 30px; line-height: 1; opacity: .5; }
.link-slug {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 17px; font-weight: 600; color: var(--text);
    word-break: break-all; text-align: center;
}

/* ---- Lien court sur les cartes ---- */
.short-row {
    display: flex; align-items: center; gap: 8px;
    margin-top: 10px; padding: 7px 9px;
    background: #f1f5fd; border: 1px solid #dde6fa; border-radius: 8px;
}
.short-link {
    flex: 1; min-width: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px; color: var(--primary); text-decoration: none;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.short-link:hover { text-decoration: underline; }
.btn-xs { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.copy-btn.copied { color: #067647; border-color: #a9dfc0; background: #ecfdf3; }

/* ---- Badges QR / URL ---- */
.badges { display: inline-flex; gap: 5px; }
.badge {
    display: inline-block; padding: 2px 7px;
    border-radius: 5px; font-size: 10.5px; font-weight: 700; letter-spacing: .03em;
}
.badge-qr    { background: #eef2ff; color: #3538cd; }
.badge-short { background: #ecfdf3; color: #067647; }

/* ---- Éditeur : choix QR / URL courte ---- */
.choice-box {
    margin: 20px 0 4px; padding: 14px 16px 6px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: #fbfcfd;
}
.choice-box legend {
    padding: 0 7px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.choice {
    display: flex; align-items: flex-start; gap: 11px;
    padding: 10px 11px; margin-bottom: 8px;
    border: 1px solid var(--border); border-radius: 9px;
    background: var(--surface); cursor: pointer; transition: .15s;
}
.choice:hover { border-color: #cfd4da; }
.choice input[type="checkbox"] { margin-top: 3px; width: 17px; height: 17px; flex: none; cursor: pointer; }
.choice strong { display: block; font-size: 14px; font-weight: 600; }
.choice em { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.choice:has(input:checked) { border-color: var(--primary); background: #f5f8ff; }

/* ---- Éditeur : champ slug ---- */
.section-block { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.section-block[hidden] { display: none; }
.slug-field {
    display: flex; align-items: stretch;
    border: 1px solid var(--border); border-radius: 9px;
    background: var(--surface); overflow: hidden;
}
.slug-prefix {
    display: flex; align-items: center; padding: 0 3px 0 11px;
    background: #f4f5f7; border-right: 1px solid var(--border);
    color: var(--muted); font-size: 13px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: nowrap;
}
.slug-field input {
    flex: 1; min-width: 0; border: 0; outline: 0; padding: 10px 11px;
    font-size: 14px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: transparent;
}
.slug-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 111, 237, .12); }
.linklike {
    border: 0; background: none; padding: 0; color: var(--primary);
    font-size: inherit; font-family: inherit; cursor: pointer; text-decoration: underline;
}

/* ---- Éditeur : aperçu de l'URL courte ---- */
.short-preview[hidden], .qr-only[hidden] { display: none; }
.short-preview { margin-top: 14px; }
.short-preview-url {
    padding: 13px 12px; margin-bottom: 10px;
    background: #f1f5fd; border: 1px solid #dde6fa; border-radius: 9px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 14px; color: var(--primary);
    text-align: center; word-break: break-all;
}

/* ---- Écran vide ---- */
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

@media (max-width: 640px) {
    .topbar { flex-wrap: wrap; gap: 10px; }
    .topbar nav { width: 100%; flex-wrap: wrap; }
}

/* ============================================================
   Dossiers par collaborateur
   ============================================================ */
.badge-owner { background: #fff4e5; color: #b54708; }

.whoami-card { max-width: 420px; }
.whoami-label {
    margin: 18px 0 8px; font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
.whoami-list { display: flex; flex-wrap: wrap; gap: 8px; }
.whoami-list .inline-form { display: inline; }
.whoami-btn { display: inline-flex; align-items: center; gap: 7px; }
.whoami-n {
    display: inline-grid; place-items: center; min-width: 19px; height: 19px;
    padding: 0 5px; border-radius: 999px; font-size: 11px; font-weight: 700;
    background: rgba(0, 0, 0, .06); color: var(--muted);
}
.filters + .filters { margin-top: -8px; }

/* ---- Choix de la destination : lien externe / fichier hébergé ---- */
.target-type { display: flex; gap: 18px; margin: 4px 0 10px; flex-wrap: wrap; }
.radio-inline { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 14px; margin: 0; }
.radio-inline input { width: auto; }
.target-block[hidden] { display: none; }
