:root {
    --bg: #0b0c14;
    --bg2: #10121e;
    --bg3: #161828;
    --border: rgba(255, 255, 255, 0.07);
    --gold: #c9a84c;
    --gold-glow: rgba(201, 168, 76, 0.25);
    --text: #d4cfc7;
    --text-dim: #7a7590;
    --commun: #a0a0b0;
    --rare: #4fc3f7;
    --epique: #ce93d8;
    --legendaire: #ffd54f;
    --onirique: #f48fb1;
    --radius: 10px;
    --card-w: 200px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Crimson Text', Georgia, serif;
    font-size: 16px;
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    opacity: 0.5;
}

/* ── LAYOUT ─────────────────────────────────────────── */
.app {
    display: flex;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

.sidebar {
    width: 230px;
    min-width: 230px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 28px 24px 20px;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.sidebar-logo .logo-symbol {
    font-size: 2.2rem;
    display: block;
    margin-bottom: 6px;
    filter: drop-shadow(0 0 12px var(--gold));
    animation: floatSymbol 4s ease-in-out infinite;
}

@keyframes floatSymbol {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

.sidebar-logo h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--gold);
    text-shadow: 0 0 20px var(--gold-glow);
}

.sidebar-logo p {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-top: 2px;
    letter-spacing: 0.08em;
}

nav {
    padding: 16px 0;
    flex: 1;
}

.nav-section {
    padding: 8px 20px 4px;
    font-size: 0.65rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-dim);
    font-family: 'Cinzel', serif;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    font-size: 0.95rem;
    color: var(--text-dim);
    border-left: 3px solid transparent;
    user-select: none;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.nav-item.active {
    background: rgba(201, 168, 76, 0.08);
    color: var(--gold);
    border-left-color: var(--gold);
}

.nav-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.rarity-pills {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rarity-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s;
}

.rarity-pill:hover {
    background: rgba(255, 255, 255, 0.07);
}

.rarity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pill-color);
    flex-shrink: 0;
}

.rarity-name {
    flex: 1;
    padding: 0 8px;
}

.rarity-count {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 1px 7px;
    font-size: 0.72rem;
    color: var(--text-dim);
}

main {
    flex: 1;
    overflow-y: auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px;
    border-bottom: 1px solid var(--border);
    background: rgba(16, 18, 30, 0.8);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h2 {
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.1em;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* ── BOUTONS ─────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 7px;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: 'Crimson Text', serif;
    font-size: 0.9rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #b8922e, #d4a84b);
    color: #0b0c14;
    font-weight: 600;
    border-color: #c9a84c;
    box-shadow: 0 0 12px rgba(201, 168, 76, 0.2);
}

.btn-primary:hover {
    box-shadow: 0 0 22px rgba(201, 168, 76, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.09);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.82rem;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 12px;
}

.search-bar input {
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    width: 200px;
}

.search-bar input::placeholder {
    color: var(--text-dim);
}

/* ── PAGES ──────────────────────────────────────────── */
.page {
    display: none;
    padding: 28px 32px;
}

.page.active {
    display: block;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
    transition: border-color 0.2s;
}

.stat-card:hover {
    border-color: rgba(201, 168, 76, 0.3);
}

.stat-number {
    font-family: 'Cinzel', serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--gold);
    display: block;
    text-shadow: 0 0 16px var(--gold-glow);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 4px;
}

.stat-card.rarity-stat .stat-number {
    color: var(--rc);
    text-shadow: 0 0 16px var(--rg);
}

.section-title {
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── GALERIE ─────────────────────────────────────────── */
.gallery-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 5px 13px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-dim);
    cursor: pointer;
    font-family: 'Crimson Text', serif;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.filter-btn:hover {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.15);
}

.filter-btn.active {
    background: rgba(201, 168, 76, 0.12);
    color: var(--gold);
    border-color: var(--gold);
}

.filter-btn[data-rarity="commun"].active {
    background: rgba(160, 160, 176, 0.12);
    color: var(--commun);
    border-color: var(--commun);
}

.filter-btn[data-rarity="rare"].active {
    background: rgba(79, 195, 247, 0.12);
    color: var(--rare);
    border-color: var(--rare);
}

.filter-btn[data-rarity="epique"].active {
    background: rgba(206, 147, 216, 0.12);
    color: var(--epique);
    border-color: var(--epique);
}

.filter-btn[data-rarity="legendaire"].active {
    background: rgba(255, 213, 79, 0.12);
    color: var(--legendaire);
    border-color: var(--legendaire);
}

.filter-btn[data-rarity="onirique"].active {
    background: rgba(244, 143, 177, 0.12);
    color: var(--onirique);
    border-color: var(--onirique);
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr));
    gap: 18px;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}

.empty-state .es-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
    opacity: 0.4;
}

.card-item {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
    position: relative;
}

.card-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.card-item[data-rarity="commun"]:hover {
    border-color: var(--commun);
    box-shadow: 0 8px 28px rgba(160, 160, 176, 0.2);
}

.card-item[data-rarity="rare"]:hover {
    border-color: var(--rare);
    box-shadow: 0 8px 28px rgba(79, 195, 247, 0.2);
}

.card-item[data-rarity="epique"]:hover {
    border-color: var(--epique);
    box-shadow: 0 8px 28px rgba(206, 147, 216, 0.2);
}

.card-item[data-rarity="legendaire"]:hover {
    border-color: var(--legendaire);
    box-shadow: 0 8px 28px rgba(255, 213, 79, 0.3);
}

.card-item[data-rarity="onirique"]:hover {
    border-color: var(--onirique);
    box-shadow: 0 8px 28px rgba(244, 143, 177, 0.3);
}

.card-img-wrap {
    aspect-ratio: 3/4;
    overflow: hidden;
    background: var(--bg3);
    position: relative;
}

.card-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s;
}

.card-item:hover .card-img-wrap img {
    transform: scale(1.05);
}

.card-img-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    opacity: 0.2;
    background: linear-gradient(135deg, var(--bg3), var(--bg2));
}

.card-rarity-stripe {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.card-info {
    padding: 12px;
}

.card-name {
    font-family: 'Cinzel', serif;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.rarity-badge {
    font-size: 0.68rem;
    padding: 2px 7px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.card-owner {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.card-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    opacity: 0;
    transition: opacity 0.2s;
    background: linear-gradient(to top, rgba(11, 12, 20, 0.95) 60%, transparent);
    padding: 20px 10px 10px;
}

.card-item:hover .card-actions {
    opacity: 1;
}

.card-actions .btn {
    flex: 1;
    justify-content: center;
}


/* ── FORMULAIRES ─────────────────────────────────────── */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.form-group:last-child {
    margin-bottom: 0;
}

label {
    font-size: 0.82rem;
    color: var(--text-dim);
    letter-spacing: 0.05em;
}

input[type="text"], input[type="number"], textarea, select {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: 'Crimson Text', serif;
    font-size: 0.95rem;
    padding: 8px 11px;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}

input:focus, textarea:focus, select:focus {
    border-color: rgba(201, 168, 76, 0.5);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.08);
}

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

select option {
    background: var(--bg2);
}

/* ── MODAL ───────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg2);
    border: 1px solid rgba(201, 168, 76, 0.2);
    border-radius: 14px;
    width: 100%;
    max-width: 560px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(201, 168, 76, 0.05);
    animation: modalIn 0.25s ease;
    overflow: hidden;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--gold);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 2px 6px;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 22px 24px;
}

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

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 22px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--gold);
    background: rgba(201, 168, 76, 0.05);
}

.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
}

.upload-preview {
    width: 100%;
    max-height: 160px;
    object-fit: cover;
    border-radius: 6px;
    margin-top: 8px;
    display: none;
}

.upload-preview.visible {
    display: block;
}

/* ── TOAST ───────────────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 11px 16px;
    font-size: 0.88rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
    animation: toastIn 0.3s ease;
    max-width: 300px;
}

.toast.success {
    border-color: rgba(74, 222, 128, 0.3);
    color: #4ade80;
}

.toast.error {
    border-color: rgba(239, 68, 68, 0.3);
    color: #f87171;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.confirm-dialog .modal {
    max-width: 380px;
}

.confirm-dialog .modal-body {
    padding: 24px;
    text-align: center;
}

.confirm-dialog .confirm-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 10px;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .page {
        padding: 16px;
    }

    .topbar {
        padding: 14px 16px;
    }

    .form-row {
        grid-template-columns:1fr;
    }
}