body {
    font-family: var(--mm-font-ui, "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    font-feature-settings: "ss01", "cv11";
    background: #f0f2f5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(102, 126, 234, 0.3); border-radius: 3px; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
    animation: fadeIn 0.4s ease;
}

/* ===== BOUTONS ===== */
.btn {
    padding: 0.55rem 1.15rem;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-family: inherit;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary {
    background: var(--mm-indigo-600, #5b6cf0);
    color: white;
    box-shadow:
        0 1px 0 0 var(--mm-indigo-700, #4a59cf) inset,
        0 6px 20px -8px var(--mm-indigo-500, #6478f3);
}
.btn-primary:hover { background: var(--mm-indigo-700, #4a59cf); }
.btn-secondary {
    background: transparent;
    color: var(--mm-ink, #1a202c);
    border-color: var(--mm-hairline, #e2e8f0);
}
.btn-secondary:hover { background: var(--mm-surface-3, #eef2f7); }
.btn-danger {
    background: transparent;
    color: oklch(60% 0.22 25);
    border-color: color-mix(in oklab, oklch(60% 0.22 25), transparent 80%);
}
.btn-danger:hover {
    background: color-mix(in oklab, oklch(60% 0.22 25), transparent 92%);
    color: oklch(50% 0.22 25);
}
.btn-small { padding: 0.4rem 0.85rem; font-size: 0.8rem; border-radius: 8px; }

/* ===== PAGE HEAD ===== */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.page-head h1 {
    font-family: var(--mm-font-display, inherit);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: #1a202c;
    line-height: 1.05;
    margin: 0;
}
.page-head h1 .accent {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-style: italic;
    font-weight: 600;
    display: inline-block;
    padding-right: 0.12em;
    margin-right: -0.06em;
}
.page-sub {
    color: #a0aec0;
    margin-top: 0.35rem;
    font-size: 0.92rem;
}
.page-head-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ===== STATS STRIP ===== */
.cat-stats {
    display: flex;
    align-items: center;
    background: white;
    border-radius: 16px;
    padding: 1rem 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    margin-bottom: 1.25rem;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.cat-stat {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 90px;
}
.cat-stat .num {
    font-family: var(--mm-font-display, inherit);
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a202c;
    letter-spacing: -0.02em;
    line-height: 1.1;
}
.cat-stat .lbl {
    color: var(--mm-muted, #94a3b8);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cat-stats .divider {
    width: 1px;
    align-self: stretch;
    background: var(--mm-hairline, #e2e8f0);
}

/* ===== TOOLBAR ===== */
.coll-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.search {
    position: relative;
    flex: 1;
    min-width: 240px;
}
.search input {
    width: 100%;
    padding: 0.7rem 0.9rem 0.7rem 2.4rem;
    font-size: 0.92rem;
    color: #1a202c;
    background: white;
    border: 1px solid transparent;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    outline: none;
    transition: box-shadow 0.15s, border-color 0.15s;
    font-family: inherit;
}
.search input::placeholder { color: #a0aec0; }
.search input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.12);
}
.search-icon {
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--mm-muted, #a0aec0);
    display: grid;
    place-items: center;
    pointer-events: none;
}
.sort-select {
    padding: 0.7rem 2.4rem 0.7rem 0.95rem;
    background: white url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.85rem center;
    border: 1px solid transparent;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    color: #1a202c;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    appearance: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.sort-select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.12);
}

/* ===== TOPS GRID ===== */
.tops-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 1.25rem;
}
.top-card {
    background: white;
    border-radius: 18px;
    padding: 1.25rem 1.35rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    cursor: pointer;
    transition: transform 0.25s, box-shadow 0.25s;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    text-decoration: none;
    color: inherit;
    border: 0;
    text-align: left;
    font-family: inherit;
}
.top-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 28px rgba(0,0,0,0.09);
}
.top-card .head {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.top-card .icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    display: grid;
    place-items: center;
    font-size: 24px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px -4px rgba(245, 158, 11, 0.4);
}
.top-card .head-body {
    flex: 1;
    min-width: 0;
}
.top-card .head h3 {
    font-family: var(--mm-font-display, inherit);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    margin: 0;
    color: #1a202c;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.top-card .head-meta {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.4rem;
    flex-wrap: wrap;
}
.pill {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    background: var(--mm-surface-3, #eef2f7);
    color: var(--mm-ink-2, #4a5568);
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 999px;
    line-height: 1.4;
}
.pill-indigo { background: #eef2ff; color: #4338ca; }
.pill-gold { background: #fef3c7; color: #92400e; }

.top-card .desc {
    color: var(--mm-muted, #94a3b8);
    font-size: 0.85rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
}

.top-card .foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.85rem;
    border-top: 1px solid var(--mm-hairline, #e2e8f0);
    color: var(--mm-muted, #94a3b8);
    font-size: 0.78rem;
    margin-top: auto;
}
.top-card .stats {
    display: flex;
    gap: 0.65rem;
}
.top-card .stat-pair {
    font-weight: 600;
}

.top-card .actions {
    display: flex;
    gap: 0.4rem;
    padding-top: 0.5rem;
}
.top-card .actions .btn { flex: 1; }

/* Tuile « créer » en pointillés */
.top-card-add {
    background: transparent;
    border: 2px dashed #cbd5e0;
    border-radius: 18px;
    min-height: 220px;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    padding: 1.5rem;
    font-family: inherit;
    color: #a0aec0;
}
.top-card-add:hover {
    border-color: #667eea;
    color: #667eea;
    background: rgba(102, 126, 234, 0.03);
}
.top-card-add .add-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: white;
    margin: 0 auto 0.75rem;
    display: grid;
    place-items: center;
    font-size: 1.6rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    color: #667eea;
}
.top-card-add .add-title {
    font-family: var(--mm-font-display, inherit);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #4a5568;
    margin-bottom: 0.2rem;
}
.top-card-add:hover .add-title { color: #1a202c; }
.top-card-add .add-sub { font-size: 0.8rem; }

/* ===== EMPTY / LOADING ===== */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--mm-muted, #94a3b8);
}
.empty-state {
    background: white;
    border-radius: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    padding: 3rem 2rem;
    text-align: center;
    color: var(--mm-muted, #94a3b8);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state h3 {
    font-family: var(--mm-font-display, inherit);
    color: #4a5568;
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}
.empty-state p { font-size: 0.92rem; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: white;
    border-radius: 18px;
    padding: 1.75rem;
    max-width: 640px;
    width: 90%;
    /* % du parent (overlay plein écran) plutôt que vh : les unités vh sur
       max-height se calculent parfois à 0 en WebView Android, ce qui écrase
       la modale (contenu masqué). On garde la ligne dvh en fallback. */
    max-height: 90%;
    max-height: 90dvh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: fadeIn 0.25s ease;
}
@media (max-width: 600px) {
    .modal-overlay { align-items: flex-start; padding-top: 1rem; }
    .modal { width: 95%; padding: 1.25rem; max-height: 95dvh; }
}
.modal h3 {
    font-family: var(--mm-font-display, inherit);
    color: #1a202c;
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0 0 1.25rem;
    letter-spacing: -0.015em;
}

.form-group {
    margin-bottom: 1.1rem;
}
.form-group label {
    display: block;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 0.4rem;
    font-size: 0.88rem;
}
.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.7rem 0.95rem;
    border: 1px solid var(--mm-hairline, #e2e8f0);
    border-radius: 12px;
    font-size: 0.92rem;
    color: #1a202c;
    background: #fafbfc;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    font-family: inherit;
    outline: none;
}
.form-group input:focus,
.form-group textarea:focus {
    border-color: #5b6cf0;
    background: white;
    box-shadow: 0 0 0 3px rgba(91, 108, 240, 0.15);
}
.form-group textarea { resize: vertical; min-height: 60px; }

.items-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.6rem;
}
.item-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--mm-surface-2, #f6f7f9);
    border-radius: 10px;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--mm-hairline, #e2e8f0);
    cursor: grab;
}
.item-row:active { cursor: grabbing; }
.item-row .rank {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
    font-family: var(--mm-font-mono, inherit);
}
.item-row .item-name {
    flex: 1;
    font-size: 0.9rem;
    color: #1a202c;
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.item-row .btn-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--mm-muted, #94a3b8);
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    transition: all 0.15s;
}
.item-row .btn-remove:hover {
    color: #b91c1c;
    background: #fee2e2;
}
.items-empty {
    color: var(--mm-muted, #94a3b8);
    font-size: 0.85rem;
    padding: 0.65rem 0.85rem;
    background: var(--mm-surface-2, #f6f7f9);
    border-radius: 10px;
    text-align: center;
}

.search-ref { position: relative; }
.search-ref-results {
    position: fixed;
    background: white;
    border: 1px solid var(--mm-hairline, #e2e8f0);
    border-radius: 12px;
    max-height: 60vh;
    overflow-y: auto;
    z-index: 1100;
    box-shadow: 0 12px 32px rgba(0,0,0,0.15);
    display: none;
}
.search-ref-results.active { display: block; }
.search-ref-item {
    padding: 0.65rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: #1a202c;
    border-bottom: 1px solid var(--mm-hairline, #e2e8f0);
    transition: background 0.12s;
}
.search-ref-item:hover { background: var(--mm-surface-2, #f6f7f9); }
.search-ref-item:last-child { border-bottom: 0; }
.search-ref-item small {
    color: var(--mm-muted, #94a3b8);
    margin-left: 0.5rem;
    font-size: 0.78rem;
}
.search-ref-item-meta {
    margin-top: 0.3rem;
    color: var(--mm-muted, #94a3b8);
    font-size: 0.78rem;
    line-height: 1.45;
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 0.45rem;
}
.search-ref-item-meta > span { display: inline-block; }
.search-ref-item-meta .meta-sep { color: #cbd5e0; }
@media (max-width: 600px) {
    .search-ref-item-meta { flex-direction: column; gap: 0.1rem; }
    .search-ref-item-meta .meta-sep { display: none; }
}
@media (max-width: 600px) {
    .search-ref-results {
        position: relative;
        top: auto !important;
        left: auto !important;
        right: auto;
        width: auto !important;
        max-height: none;
        box-shadow: none;
        margin-top: 0.4rem;
        z-index: auto;
    }
}

.search-ref-popover {
    position: fixed;
    background: white;
    border: 1px solid var(--mm-hairline, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.15);
    padding: 0.85rem 1rem;
    font-size: 0.85rem;
    color: var(--mm-ink-2, #4a5568);
    line-height: 1.5;
    z-index: 1000;
    max-width: 320px;
    min-width: 220px;
    pointer-events: none;
}
.search-ref-popover .pop-title {
    font-family: var(--mm-font-display, inherit);
    font-weight: 700;
    color: #1a202c;
    margin-bottom: 0.35rem;
    word-wrap: break-word;
}
.search-ref-popover .pop-row {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.15rem;
}
.search-ref-popover .pop-key {
    color: var(--mm-muted, #94a3b8);
    min-width: 90px;
}
.search-ref-popover .pop-val {
    color: var(--mm-ink, #1a202c);
    word-break: break-word;
}

.modal-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 1.5rem;
    justify-content: flex-end;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .container { padding: 1rem 0.75rem 2rem; }
    .page-head h1 { font-size: 1.6rem; }
    .page-head-actions { width: 100%; }
    .page-head-actions .btn { flex: 1; justify-content: center; }
    .cat-stats { gap: 0.75rem; padding: 0.85rem 1rem; }
    .cat-stat .num { font-size: 1.2rem; }
    .cat-stats .divider { display: none; }
    .tops-grid { grid-template-columns: 1fr; }
}
