/* Pêle-Mêle — feuille de style globale.
   Mode sombre auto via prefers-color-scheme, grilles type "Audible". */

:root {
    --bg: #f7f5f1;
    --bg-elevated: #ffffff;
    --text: #1c1b18;
    --text-muted: #5e5b54;
    --border: #d8d3c8;
    --accent: #8b3a2a;
    --accent-soft: #d8a99a;
    --danger: #b3261e;
    --success: #1a6b3f;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 12px rgba(0,0,0,.08);
    --radius: 8px;
    --gap: 1rem;
    --maxw: 1400px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14110d;
        --bg-elevated: #1f1c17;
        --text: #f1ede4;
        --text-muted: #a39d8e;
        --border: #2f2b25;
        --accent: #d8a99a;
        --accent-soft: #8b3a2a;
        --shadow: 0 2px 6px rgba(0,0,0,.4);
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar__inner {
    display: flex;
    align-items: center;
    gap: var(--gap);
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 0.75rem 1rem;
    /* Structure 4 zones [brand · nav · search · profile] sur 1 ligne.
       Pas de wrap : si trop étroit, la primary-nav scrollera horizontalement
       (rare en desktop ≥1281px). */
    flex-wrap: nowrap;
}
.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}
.brand__wordmark {
    height: 36px;
    width: auto;
    display: block;
}
.brand:hover { text-decoration: none; }
.primary-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: nowrap;
    flex: 1 1 auto;
    min-width: 0;
    /* Justify-content: center pour aérer les 6 items au centre de la topbar
       quand il y a de la place. */
    justify-content: center;
}
.topbar-search { flex: 0 1 240px; }
.topbar-profile { flex: 0 0 auto; }
.primary-nav a { color: var(--text); }
.primary-nav .cta {
    background: var(--accent);
    color: white;
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius);
}
.primary-nav .cta:hover { text-decoration: none; opacity: 0.9; }
.primary-nav .logout { color: var(--text-muted); font-size: 0.9rem; }
.user-chip {
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
}

.layout {
    flex: 1;
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.footer {
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    text-align: center;
    padding: 1.25rem 1rem;
}

.flash {
    max-width: var(--maxw);
    margin: 0.75rem auto;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
}
.flash--success { border-left: 4px solid var(--success); }
.flash--error { border-left: 4px solid var(--danger); }

.page-title {
    margin: 0 0 1.25rem;
    font-size: 1.6rem;
    letter-spacing: -0.01em;
}

.toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
}
.toolbar .spacer { flex: 1; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
    font: inherit;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn--primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.btn--primary:hover { opacity: 0.9; }
.btn--danger { color: white; background: var(--danger); border-color: var(--danger); }

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 1.2rem;
}

.tile {
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
    color: var(--text);
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
.tile__cover {
    aspect-ratio: 5 / 7;
    background: var(--accent-soft) center / cover no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.4rem;
}
.tile__cover img { width: 100%; height: 100%; object-fit: cover; }
.tile__body {
    padding: 0.6rem 0.75rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.tile__title {
    font-weight: 600;
    font-size: 0.95rem;
    margin: 0;
    color: var(--text);
}
.tile__sub {
    color: var(--text-muted);
    font-size: 0.85rem;
}
/* V3-Inc 3.7 — badge mini genre Deezer sous le sous-titre d'une vignette
   musique. Reste discret pour ne pas dominer le titre. */
.tile__genre {
    align-self: flex-start;
    margin-top: 0.15rem;
    background: rgba(245, 158, 11, 0.14);
    color: #b45309;
    border: 1px solid rgba(245, 158, 11, 0.30);
    padding: 0 0.45rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.4;
}

.tile--ghost { opacity: 0.55; border-style: dashed; }
.tile--ghost .tile__cover {
    background: repeating-linear-gradient(
        45deg,
        var(--border),
        var(--border) 8px,
        transparent 8px,
        transparent 16px
    );
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.form-grid label { display: block; font-weight: 500; margin-bottom: 0.25rem; }
.form-grid input, .form-grid select, .form-grid textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.6rem;
    color: var(--text);
    font: inherit;
}
.form-grid textarea { min-height: 5rem; }
.form-grid .form-row--full { grid-column: 1 / -1; }
.form-grid .help { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; }
.form-grid .form-errors { color: var(--danger); margin-top: 0.25rem; }

.item-show {
    display: grid;
    grid-template-columns: minmax(220px, 320px) 1fr;
    gap: 2rem;
}
@media (max-width: 720px) { .item-show { grid-template-columns: 1fr; } }
.item-show__cover {
    aspect-ratio: 5 / 7;
    background: var(--accent-soft);
    border-radius: var(--radius);
    overflow: hidden;
}
.item-show__cover img { width: 100%; height: 100%; object-fit: cover; }
.item-show h1 { margin-top: 0; }
.item-meta { color: var(--text-muted); margin: 0.25rem 0 1rem; }
.field-list { list-style: none; padding: 0; margin: 1rem 0; }
.field-list li { padding: 0.35rem 0; border-bottom: 1px dashed var(--border); }
.field-list li strong { color: var(--text); margin-right: 0.5rem; }

.series-header { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 1rem; }
.series-summary { color: var(--text-muted); }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state .btn { margin-top: 1rem; }

/* Skeleton couverture en attente d'enrichissement.
   Utilise --cover-bg posée en inline depuis CoverImage.dominantColor
   (sinon retombe sur --accent-soft via la règle générique). */
.item-show__cover-skeleton,
.tile__cover-skeleton {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.85);
    font-size: 1.4rem;
    background:
        linear-gradient(110deg, transparent 30%, rgba(255,255,255,.18) 50%, transparent 70%) 0 0 / 200% 100% no-repeat,
        var(--cover-bg, var(--accent-soft));
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.item-show__cover-skeleton[aria-busy="false"],
.tile__cover-skeleton[aria-busy="false"] {
    animation: none;
    background: var(--cover-bg, var(--accent-soft));
}
@keyframes skeleton-shimmer {
    from { background-position: 100% 0, 0 0; }
    to   { background-position: -100% 0, 0 0; }
}

.enrich-status {
    background: var(--bg-elevated);
    border-left: 3px solid var(--accent);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* Barre de recherche dans le header et page /recherche. */
.topbar-search {
    margin: 0;
    flex: 0 1 240px;
}
.topbar-search input {
    width: 100%;
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.search-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    background: var(--bg-elevated);
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.search-bar input[type="search"], .search-bar input[type="text"], .search-bar select {
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
.search-bar input[type="search"] { flex: 1 1 240px; }

/* Tracklist sur la fiche album musical. */
.tracklist {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 1rem;
    counter-reset: track;
}
.tracklist li {
    display: grid;
    grid-template-columns: 2.4em 1fr auto;
    gap: 0.5rem;
    align-items: baseline;
    padding: 0.35rem 0;
    border-bottom: 1px dashed var(--border);
}
.tracklist__pos { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tracklist__title { font-weight: 500; }
.tracklist__performer { color: var(--text-muted); font-size: 0.9rem; grid-column: 2 / -1; }
.tracklist__duration { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Variante "fantôme" cliquable des tomes manquants pour wishlist 1-clic. */
.tile-ghost-form {
    margin: 0;
    padding: 0;
    display: contents;
}
.tile--ghost-button {
    background: transparent;
    border: 1px dashed var(--border);
    cursor: pointer;
    color: inherit;
    text-align: left;
    font: inherit;
    padding: 0;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s, transform 0.15s;
}
.tile--ghost-button:hover {
    border-color: var(--accent);
    border-style: solid;
    transform: translateY(-2px);
}

/* ===== Prêts famille (Inc 7) ===== */
.tile__loan-badge {
    display: inline-block;
    margin-top: 0.25rem;
    padding: 0.1rem 0.4rem;
    background: #e0f2fe;
    color: #075985;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
}
.tile__loan-badge--overdue {
    background: #fee2e2;
    color: #991b1b;
}
.badge {
    display: inline-block;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: var(--accent, #2563eb);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    vertical-align: middle;
}
.badge--overdue {
    background: #dc2626;
}
.loan-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}
.loan-table th, .loan-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border, #e5e7eb);
    text-align: left;
    vertical-align: middle;
}
.loan-table th { font-weight: 600; }
.loan-row--overdue { background: #fef2f2; }

.member-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}
.member-actions form { margin: 0; }

.pwa-install {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: inherit;
    cursor: pointer;
    font: inherit;
    padding: 0.35rem 0.75rem;
    border-radius: 0.5rem;
}
.pwa-install[hidden] { display: none; }

/* Profil famille actif (Inc 10) */
.profile-switch { position: relative; }
.profile-switch summary {
    list-style: none;
    cursor: pointer;
    padding: 0.35rem 0.75rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.5rem;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.profile-switch__sep { opacity: 0.4; }
.profile-switch__me { font-weight: 600; }
.profile-switch__active { opacity: 0.85; }
.profile-switch summary::-webkit-details-marker { display: none; }
.profile-switch[open] summary { background: rgba(99, 102, 241, 0.3); }
.profile-switch__menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.25rem);
    z-index: 50;
    min-width: 14rem;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.5rem;
    padding: 0.5rem;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.profile-switch__user {
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
    opacity: 0.7;
}
.profile-switch__menu form { margin: 0; }
.profile-switch__option {
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    color: inherit;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border-radius: 0.35rem;
    font: inherit;
}
.profile-switch__option:hover { background: rgba(255, 255, 255, 0.08); }
.profile-switch__option.is-active {
    background: rgba(99, 102, 241, 0.3);
    font-weight: 600;
}
.profile-switch__logout {
    margin-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 0.65rem;
    color: #fca5a5;
    text-decoration: none;
    text-align: center;
    font-weight: 600;
    transition: background 120ms ease;
    font-size: 0.85rem;
}
.profile-switch__logout:hover {
    background: rgba(248, 113, 113, 0.15);
    border-radius: 0.35rem;
    text-decoration: none;
}

.tile--ghost-button:hover .tile__sub { color: var(--accent); }

/* ============================================================
   Topbar redesign 2026-05-17 — dropdown Audio + profil compact
   ============================================================ */

/* Wrapper inline-block pour positionner le menu en absolute. */
.topbar-dropdown { position: relative; display: inline-block; }
.topbar-dropdown__trigger {
    list-style: none;
    cursor: pointer;
    user-select: none;
    padding: 0.35rem 0.5rem;
    color: var(--text, #e2e8f0);
    border-radius: 0.4rem;
    transition: background 120ms ease;
}
.topbar-dropdown__trigger::-webkit-details-marker { display: none; }
.topbar-dropdown__trigger::after {
    content: " ▾";
    font-size: 0.7em;
    margin-left: 0.2rem;
    opacity: 0.7;
}
.topbar-dropdown[open] .topbar-dropdown__trigger { background: rgba(99, 102, 241, 0.25); }
.topbar-dropdown[open] .topbar-dropdown__trigger::after { content: " ▴"; }
.topbar-dropdown__menu {
    position: absolute;
    top: calc(100% + 0.3rem);
    left: 0;
    z-index: 60;
    min-width: 12rem;
    padding: 0.4rem;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.5rem;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.topbar-dropdown__menu a {
    display: block;
    padding: 0.5rem 0.6rem;
    color: var(--text, #e2e8f0);
    text-decoration: none;
    border-radius: 0.35rem;
    transition: background 120ms ease;
}
.topbar-dropdown__menu a:hover {
    background: rgba(99, 102, 241, 0.18);
    text-decoration: none;
}

/* Profil compact (remplace .profile-switch) — avatar 36 px + caret.
   Le menu reprend les options switch profil + admin famille + PWA install + déco.
   `flex: 0 0 auto` est défini plus haut dans .topbar__inner siblings. */
.topbar-profile { position: relative; }
.topbar-profile__trigger {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem 0.2rem 0.2rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    transition: background 120ms ease;
}
.topbar-profile__trigger::-webkit-details-marker { display: none; }
.topbar-profile[open] .topbar-profile__trigger { background: rgba(99, 102, 241, 0.3); }
.topbar-profile__avatar {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: linear-gradient(135deg, #7c3aed, #f59e0b);
    color: white;
    font-size: 1.1rem;
    flex: 0 0 auto;
}
.topbar-profile__caret { opacity: 0.65; font-size: 0.75rem; }
.topbar-profile__menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.3rem);
    z-index: 60;
    min-width: 15rem;
    padding: 0.5rem;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.5rem;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.topbar-profile__user {
    margin: 0 0 0.4rem;
    padding: 0 0.5rem;
    font-size: 0.8rem;
    opacity: 0.75;
}
.topbar-profile__section-title {
    margin: 0.3rem 0 0.2rem;
    padding: 0 0.5rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(199, 210, 254, 0.7);
    font-weight: 700;
}
.topbar-profile__menu form { margin: 0; }
.topbar-profile__option {
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    color: inherit;
    cursor: pointer;
    padding: 0.45rem 0.6rem;
    border-radius: 0.35rem;
    font: inherit;
    text-decoration: none;
    display: block;
    transition: background 120ms ease;
}
.topbar-profile__option:hover {
    background: rgba(99, 102, 241, 0.18);
    text-decoration: none;
}
.topbar-profile__option.is-active {
    background: rgba(99, 102, 241, 0.3);
    font-weight: 600;
}
.topbar-profile__sep {
    margin: 0.4rem 0;
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.topbar-profile__logout {
    color: #fca5a5;
}
.topbar-profile__logout:hover {
    background: rgba(248, 113, 113, 0.15);
}
