.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 1.6rem 1.2rem;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .brand { font-family: var(--font-title); color: var(--gold-bright); font-size: 1.25rem; margin-bottom: 0.2rem; }
.sidebar .brand small { display: block; font-family: var(--font-body); color: var(--text-dim); font-size: 0.72rem; font-weight: 400; margin-top: 0.2rem; }
.sidebar nav { margin-top: 2rem; display: flex; flex-direction: column; gap: 0.3rem; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 0.6em;
    padding: 0.6em 0.8em;
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 0.92rem;
    font-weight: 500;
}
.sidebar nav a:hover { background: var(--bg-panel-alt); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--bg-panel-alt); color: var(--gold-bright); }
.sidebar .sidebar-foot { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }

.main { flex: 1; padding: 2rem 2.5rem 4rem; max-width: 1100px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.8rem; flex-wrap: wrap; gap: 1rem; }
.topbar h1 { margin-bottom: 0.2rem; font-size: 1.7rem; }
.topbar .subtitle { color: var(--text-dim); font-size: 0.9rem; }
.topbar > div:last-child { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.grid { display: grid; gap: 1.2rem; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.4rem 1.5rem;
}
.card h3 { font-size: 1.05rem; margin-bottom: 0.6rem; }
.card .stat-value { font-size: 2rem; font-family: var(--font-title); color: var(--gold-bright); }
.card .stat-label { color: var(--text-dim); font-size: 0.82rem; }

.class-card { display: flex; flex-direction: column; gap: 0.6rem; }
.class-card .meta { color: var(--text-dim); font-size: 0.85rem; display: flex; gap: 1rem; }
.join-code {
    font-family: monospace;
    font-size: 1.1rem;
    letter-spacing: 0.15em;
    background: var(--bg-void);
    padding: 0.3em 0.6em;
    border-radius: 6px;
    border: 1px dashed var(--gold);
    color: var(--gold-bright);
    cursor: pointer;
}

table { width: 100%; border-collapse: collapse; }
table th, table td { text-align: left; padding: 0.7em 0.6em; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
table th { color: var(--text-dim); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
table tr:last-child td { border-bottom: none; }

.xp-bar { height: 10px; border-radius: 999px; background: var(--bg-void); overflow: hidden; border: 1px solid var(--border); box-shadow: inset 0 1px 2px rgba(0,0,0,0.4); }
.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold) 0%, var(--gold-bright) 60%, #fff2c9 100%);
    box-shadow: 0 0 8px rgba(241, 201, 121, 0.55);
    transition: width 0.4s ease;
}
.level-pill {
    font-family: var(--font-title);
    font-size: 0.75rem;
    color: var(--gold-bright);
    background: var(--bg-panel-alt);
    border: 1px solid var(--gold);
    border-radius: 999px;
    padding: 0.15em 0.6em;
    white-space: nowrap;
}

/* ---------- Liste des élèves (roster) ---------- */
.roster-list { display: flex; flex-direction: column; gap: 0.8rem; }
.roster-row {
    display: flex;
    align-items: center;
    gap: 1.4rem;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.9rem 1.2rem;
    flex-wrap: wrap;
}
.roster-identity { display: flex; align-items: center; gap: 0.7rem; min-width: 220px; flex: 1 1 220px; }
.roster-identity > div { min-width: 0; overflow-wrap: anywhere; }
.roster-remove { margin-left: auto; }

.avatar-icon { font-size: 1.4rem; line-height: 1; }
.avatar-icon-lg { font-size: 1.8rem; margin-right: 0.3rem; vertical-align: middle; }

/* ---------- Formulaire d'attribution de points (PV / XP) ---------- */
.points-form { display: flex; gap: 1.6rem; flex-wrap: wrap; align-items: flex-start; }
.gauge-block { display: flex; flex-direction: column; gap: 0.3rem; min-width: 220px; }
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; row-gap: 0.15rem; column-gap: 0.5rem; font-size: 0.78rem; color: var(--text-dim); }
.gauge-head > * { flex-shrink: 0; }
.gauge-head span { font-weight: 700; color: var(--text); letter-spacing: 0.04em; }
.gauge-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.15rem; flex-wrap: wrap; }
.gauge-action-label { color: var(--text-dim); font-size: 0.75rem; margin-right: 0.3rem; }

.pv-bar { height: 10px; border-radius: 999px; background: var(--bg-void); overflow: hidden; border: 1px solid var(--border); box-shadow: inset 0 1px 2px rgba(0,0,0,0.4); }
.pv-bar-fill { height: 100%; background: linear-gradient(90deg, var(--danger), var(--success)); transition: width 0.4s ease; }

.manual-adjust { display: inline-flex; gap: 0.35rem; align-items: center; }
.manual-adjust input[type="number"] {
    width: 68px;
    padding: 0.35em 0.5em;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-void);
    color: var(--text);
}

.point-popover { position: relative; }
.point-popover summary { list-style: none; }
.point-popover summary::-webkit-details-marker { display: none; }
.popover-panel {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    left: 0;
    width: 300px;
    max-height: 360px;
    overflow-y: auto;
    background: var(--bg-panel-alt);
    border: 1px solid var(--gold);
    border-radius: 10px;
    padding: 0.9rem;
    box-shadow: 0 12px 32px rgba(0,0,0,0.45);
}
.popover-panel .hint { margin: 0.6rem 0 0.3rem; color: var(--gold-bright); font-weight: 600; }
.popover-panel .hint:first-child { margin-top: 0; }
.popover-panel .hint-grade { margin-bottom: 0.25rem; color: var(--text-dim); font-weight: 400; }
.motif-list { display: flex; flex-direction: column; gap: 0.35rem; }
.branch-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.3rem; margin-bottom: 0.5rem; }
.branch-grid .btn { font-size: 0.75rem; padding: 0.35em 0.4em; }

/* ---------- Bandeau passage de niveau ---------- */
.levelup-banner { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }

/* ---------- Édition rapide d'une classe ---------- */
.class-edit { position: relative; }
.class-edit summary { list-style: none; }
.class-edit summary::-webkit-details-marker { display: none; }
.class-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.class-edit-panel {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    right: 0;
    width: 260px;
    background: var(--bg-panel-alt);
    border: 1px solid var(--gold);
    border-radius: 10px;
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    box-shadow: 0 12px 32px rgba(0,0,0,0.45);
}

/* ---------- Inventaire ---------- */
.item-card-button {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    color: inherit;
    padding: 0;
}
.item-used { position: relative; opacity: 0.55; }
.used-cross {
    display: inline-block;
    margin-top: 0.4rem;
    font-size: 0.72rem;
    color: var(--danger);
    font-weight: 700;
    text-transform: uppercase;
}
.item-add summary {
    list-style: none;
    cursor: pointer;
    font-size: 1.6rem;
    color: var(--text-dim);
}
.item-add summary::-webkit-details-marker { display: none; }

/* ---------- Arbre des talents (version simple) ---------- */
.talent-tree { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.talent-branch { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.9rem 1.1rem; }
.talent-branch-head { display: flex; justify-content: space-between; font-size: 0.88rem; margin-bottom: 0.5rem; }
.talent-branch-head span { font-family: var(--font-title); color: var(--gold-bright); }
.talent-branch-bar { height: 10px; border-radius: 999px; background: var(--bg-void); overflow: hidden; border: 1px solid var(--border); }
.talent-branch-fill { height: 100%; background: linear-gradient(90deg, #2f6b45, var(--success)); transition: width 0.4s ease; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-dim); }
.empty-state .icon { font-size: 2.4rem; display: block; margin-bottom: 0.8rem; }

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; }
.item-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem; text-align: center; }
.item-card .icon { font-size: 2rem; display: block; margin-bottom: 0.4rem; }
.item-card h4 { margin: 0 0 0.2rem; font-size: 0.95rem; }
.item-card p { color: var(--text-dim); font-size: 0.78rem; line-height: 1.4; min-height: 2.6em; }

.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: 0.6rem; z-index: 50; }
.toast {
    background: var(--bg-panel-alt);
    border: 1px solid var(--gold);
    color: var(--text);
    padding: 0.8em 1.2em;
    border-radius: 10px;
    font-size: 0.88rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.section { margin-bottom: 2.4rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.6rem; }

@media (max-width: 780px) {
    .app { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: sticky;
        top: 0;
        z-index: 30;
        padding: 0.8rem 1rem;
        display: flex;
        align-items: center;
        gap: 0.9rem;
    }
    .sidebar .brand { font-size: 1.05rem; margin-bottom: 0; white-space: nowrap; }
    .sidebar .brand small { display: none; }
    .sidebar nav {
        margin-top: 0;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 0.3rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-width: 0;
    }
    .sidebar nav a { flex-shrink: 0; padding: 0.5em 0.75em; font-size: 0.85rem; }
    .sidebar nav a span { font-size: 1rem; }
    .sidebar .sidebar-foot { display: none; }

    .main { padding: 1.1rem; }

    .grid-2, .grid-3, .item-grid, .talent-tree { grid-template-columns: 1fr; }

    .roster-row { flex-direction: column; align-items: stretch; gap: 0.8rem; padding: 0.9rem; }
    .roster-identity { flex: 0 0 auto; min-width: 0; }
    .points-form { flex-direction: column; gap: 0.8rem; width: 100%; }
    .gauge-block { min-width: 0; width: 100%; }
    .gauge-actions { gap: 0.6rem; }
    .manual-adjust { flex-wrap: wrap; }
    .manual-adjust input[type="number"] { flex: 1; min-width: 70px; }
    .roster-remove { margin-left: 0; }
    .roster-remove .btn { width: 100%; }

    .popover-panel {
        position: fixed;
        left: 3vw;
        right: 3vw;
        top: auto;
        bottom: 3vh;
        width: auto;
        max-height: 70vh;
    }
    .class-edit-panel { width: min(260px, 88vw); }

    .branch-grid { grid-template-columns: repeat(2, 1fr); }

    .table-scroll table { min-width: 480px; }
}
