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

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
    --gold: #D5B654;
    --gold-light: #E8CC72;
    --gold-dark: #A8912D;
    --gold-glow: rgba(213, 182, 84, 0.18);
    --gold-subtle: rgba(213, 182, 84, 0.08);

    --bg-void: #080808;
    --bg-base: #0e0e0e;
    --bg-surface: #161616;
    --bg-raised: #1e1e1e;
    --bg-overlay: #252525;
    --bg-hover: #2d2d2d;

    --text-primary: #f0f0f0;
    --text-secondary: #c0c0c0;
    --text-muted: #808080;
    --text-faint: #505050;

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-mid: rgba(255, 255, 255, 0.12);
    --border-gold: rgba(213, 182, 84, 0.4);

    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;

    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.25rem;
    --sp-6: 1.5rem;
    --sp-8: 2rem;
    --sp-10: 2.5rem;
    --sp-12: 3rem;

    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 20px;
    --r-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-gold: 0 0 20px var(--gold-glow);

    --ease: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --ease-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    --font-body: 'Inter', system-ui, sans-serif;
    --font-display: 'Rajdhani', system-ui, sans-serif;
}

/* ── Light theme override ──────────────────────────────────── */
[data-theme="light"] {
    --bg-void: #eceef1;
    --bg-base: #f7f8f9;
    --bg-surface: #ffffff;
    --bg-raised: #ffffff;
    --bg-overlay: #ffffff;
    --bg-hover: #eef1f4;

    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --text-faint: #94a3b8;

    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-mid: rgba(0, 0, 0, 0.14);
    --border-gold: rgba(213, 182, 84, 0.5);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
}

/* ── Base ──────────────────────────────────────────────────── */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-void);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    position: relative;
    transition: background-color var(--ease), color var(--ease);
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(213, 182, 84, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(213, 182, 84, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    pointer-events: none;
    z-index: 0;
}

a {
    color: var(--gold);
    text-decoration: none;
    transition: color var(--ease);
}

a:hover {
    color: var(--gold-light);
}

/* ── SVG Icons (icons.js) ──────────────────────────────────── */
.pr-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    flex-shrink: 0;
}

[data-icon] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Entrées slottées dans l'engrenage du <pr-site-header>. Le shadow DOM ne peut
   pas styler les enfants d'un élément slotté (::slotted ne descend pas), donc
   la boîte d'icône de 16px — celle qui aligne « Compte »/« Pays » sur
   « Jour / Nuit » et « Déconnexion » — se pose ici, côté light DOM. */
pr-site-header > [slot="menu"] > [data-icon] {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
}

pr-site-header > [slot="menu"] > [data-icon] .pr-icon {
    width: 16px;
    height: 16px;
}

.card-icon .pr-icon {
    width: 16px;
    height: 16px;
}

.empty-state-icon .pr-icon,
.empty-icon .pr-icon {
    width: 40px;
    height: 40px;
    opacity: 0.6;
}

.gear-logout {
    color: var(--danger);
}

.gear-logout:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* ── Header ────────────────────────────────────────────────── */
/* .site-header / .brand / .header-actions now live inside <pr-site-header>'s
   Shadow DOM (static/site-header.js) — see base.html. */
.settings-link-btn {
    gap: var(--sp-2);
    text-decoration: none;
    white-space: nowrap;
}

.settings-link-btn svg {
    width: 14px;
    height: 14px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--r-full);
    border: 1px solid var(--border-mid);
    background: var(--bg-surface);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--ease);
    font-size: 1rem;
}

.icon-btn:hover {
    border-color: var(--border-gold);
    color: var(--gold);
    background: var(--bg-hover);
}

/* ── Main ──────────────────────────────────────────────────── */
.main-content {
    /* No z-index here on purpose: it would create a stacking context
       that traps every descendant — including fixed, high-z-index
       modals like #treaty-modal — below .site-footer (which is a
       sibling, not a descendant, and would otherwise win the tie). */
    position: relative;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--sp-6);
}

/* ── Footer ────────────────────────────────────────────────── */
.site-footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: var(--sp-6);
    color: var(--text-faint);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-subtle);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4);
    border: 1px solid var(--border-mid);
    border-radius: var(--r-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--ease);
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-gold);
}

.btn:disabled,
.btn.is-loading {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--gold);
    color: var(--bg-void);
    border-color: var(--gold);
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--gold-light);
}

/* Le bouton d'une action qu'on ne peut pas défaire soi-même. Contour et non
   aplat : un bouton rouge plein attire le clic autant qu'un bouton primaire,
   alors qu'on veut exactement l'inverse. */
.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
    font-weight: 600;
}
.btn-danger:hover {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-discord {
    background: #5865F2;
    color: #fff;
    border-color: #5865F2;
}

.btn-discord:hover {
    background: #4752C4;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-overlay);
}

.btn-sm {
    padding: var(--sp-1) var(--sp-3);
    font-size: 0.8rem;
}

.btn-lg {
    padding: var(--sp-3) var(--sp-6);
    font-size: 1rem;
}

/* Touch devices get a guaranteed 44px tap area without bloating mouse-driven desktop density */
@media (pointer: coarse) {
    .btn-sm {
        min-height: 44px;
    }
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    overflow: hidden;
    transition: border-color var(--ease), box-shadow var(--ease);
}

.card:hover {
    border-color: var(--border-mid);
}

.card-header {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.card-header h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--r-sm);
    background: var(--gold-subtle);
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.card-body {
    padding: var(--sp-5);
}

/* ── Badges ────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    /* Une pastille tient sur une ligne, sinon ce n'est plus une pastille : sans
       nowrap, « En validation » se coupait en deux dans une carte étroite et le
       texte passait sous l'icône. `gap` parce que l'icône collait au mot, et
       `width: fit-content` pour qu'elle ne s'étire pas à la largeur du parent
       quand elle est posée dans une colonne flex. */
    gap: 4px;
    white-space: nowrap;
    width: fit-content;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 8px;
    border-radius: var(--r-full);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-gold {
    background: var(--gold-subtle);
    color: var(--gold);
}

.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.badge-info {
    background: rgba(59, 130, 246, 0.15);
    color: var(--info);
}

.badge-muted {
    background: var(--bg-overlay);
    color: var(--text-muted);
}

/* ── Stat Grid ─────────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-4);
}

.stat-card {
    background: var(--bg-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    padding: var(--sp-4);
    text-align: center;
    transition: all var(--ease);
    /* Un élément de grille a `min-width: auto`, c'est-à-dire la largeur de son
       propre contenu : sans ce 0, une valeur longue ne rétrécit jamais et
       pousse la carte hors de sa colonne. */
    min-width: 0;
}

.stat-card:hover {
    border-color: var(--border-gold);
    box-shadow: var(--shadow-gold);
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--gold);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    /* « 1 234 567 890 ¤ » n'a aucun point de coupure naturel : sans ceci sa
       largeur min-content devient le plancher de la colonne. */
    min-width: 0;
    overflow-wrap: anywhere;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: var(--sp-1);
}

/* ── Table ─────────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    text-align: left;
    padding: var(--sp-3) var(--sp-4);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-mid);
}

.data-table td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

/* ── Login Section ─────────────────────────────────────────── */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70vh;
}

.login-card {
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-card .card-body {
    padding: var(--sp-8) var(--sp-6);
}

.login-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: var(--sp-2);
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: var(--sp-6);
}

/* ── Dashboard Layout ──────────────────────────────────────── */
.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-6);
    flex-wrap: wrap;
    gap: var(--sp-4);
}

.country-name {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--gold);
}

.country-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.country-flag-icon {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: var(--r-sm);
    border: 1px solid var(--border-mid);
}

.country-flag-icon-sm {
    width: 18px;
    height: 18px;
    object-fit: cover;
    border-radius: 3px;
    vertical-align: middle;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--sp-5);
}

.dashboard-grid .full-width {
    grid-column: 1 / -1;
}

/* ── Map Embed ─────────────────────────────────────────────── */
.map-embed {
    width: 100%;
    height: 450px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    overflow: hidden;
}



/* ── Tab panels (content, not nav) ─────────────────────────── */
.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: var(--sp-4);
    right: var(--sp-4);
    left: var(--sp-4);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--sp-2);
    /* Le conteneur est une bande invisible sur toute la largeur, au z-index le
       plus haut, présente en permanence et vide la plupart du temps. Sans ceci
       elle intercepte les clics de tout ce qui passe dessous — mesuré : le
       CENTRE des onglets à menu de la barre de navigation était inerte, ce qui
       obligeait à viser le haut du bouton pour ouvrir un menu.
       Les messages, eux, redeviennent cliquables : ils portent une croix. */
    pointer-events: none;
}

.toast-container > * { pointer-events: auto; }

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-5);
    border-radius: var(--r-md);
    background: var(--bg-raised);
    border: 1px solid var(--border-mid);
    color: var(--text-primary);
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    width: min(360px, 100%);
    touch-action: pan-y;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.toast-message {
    flex: 1;
    min-width: 0;
}

.toast-close {
    display: grid;
    place-items: center;
    flex: 0 0 2rem;
    width: 2rem;
    height: 2rem;
    margin: -0.35rem -0.35rem -0.35rem 0;
    padding: 0;
    border: 0;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font: inherit;
    font-size: 1.35rem;
    line-height: 1;
}

.toast-close:hover,
.toast-close:focus-visible {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.toast-swiping {
    transition: none;
}

.toast-dismissing {
    opacity: 0;
    transform: translateX(var(--toast-dismiss-x, 120%));
}

.toast-error {
    border-left: 3px solid var(--danger);
}

.toast-success {
    border-left: 3px solid var(--success);
}

.toast-info {
    border-left: 3px solid var(--info);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ── Loading ───────────────────────────────────────────────── */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-12);
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-mid);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: var(--sp-10);
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: var(--sp-3);
    opacity: 0.5;
}

/* ── User Badge ────────────────────────────────────────────── */
.user-badge {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-1) var(--sp-3);
    border-radius: var(--r-full);
    background: var(--bg-overlay);
    border: 1px solid var(--border-subtle);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.user-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

/* ── Settings Panel ────────────────────────────────────────── */
.settings-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9000;
    display: none;
}

.settings-panel-overlay.open {
    display: block;
}

.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: min(560px, 100vw);
    height: 100vh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-mid);
    box-shadow: var(--shadow-lg);
    z-index: 9100;
    transform: translateX(100%);
    transition: transform var(--ease-slow);
    display: flex;
    flex-direction: column;
}

.settings-panel.open {
    transform: translateX(0);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border-subtle);
}

.settings-title {
    font-family: var(--font-display);
    color: var(--gold);
    font-size: 1.3rem;
    letter-spacing: 0.03em;
}

.settings-body {
    padding: var(--sp-5);
    overflow-y: auto;
    display: grid;
    gap: var(--sp-4);
}

.settings-card {
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    background: var(--bg-raised);
    padding: var(--sp-4);
}

.settings-card h4 {
    color: var(--gold);
    font-size: 1rem;
    margin-bottom: var(--sp-3);
    font-family: var(--font-display);
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-2) var(--sp-4);
    font-size: 0.9rem;
}

.settings-label {
    color: var(--text-muted);
}

.settings-value {
    color: var(--text-primary);
    text-align: right;
}

.settings-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: var(--sp-2);
}

.settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-top: var(--sp-4);
}

.settings-form {
    margin-top: var(--sp-4);
    display: grid;
    gap: var(--sp-3);
}

.settings-field {
    display: grid;
    gap: var(--sp-1);
}

.settings-field label {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.settings-field input {
    background: var(--bg-base);
    border: 1px solid var(--border-mid);
    border-radius: var(--r-sm);
    color: var(--text-primary);
    padding: var(--sp-2) var(--sp-3);
    font-size: 0.9rem;
}

.settings-field input:focus {
    outline: none;
    border-color: var(--border-gold);
}

.code-box {
    margin-top: var(--sp-3);
    padding: var(--sp-3);
    border: 1px dashed var(--border-gold);
    border-radius: var(--r-sm);
    color: var(--gold-light);
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 0.04em;
    word-break: break-word;
    display: none;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .main-content {
        padding: var(--sp-5);
    }

    .stat-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: var(--sp-3);
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .overview-grid {
        grid-template-columns: 1fr;
    }

    /* `minmax(0, …)` et pas `1fr` : la borne basse implicite d'un `1fr` est
       `auto` = min-content, donc une carte au contenu large agrandit sa piste
       et la grille déborde de SON PROPRE conteneur — 373 px de contenu dans
       344 px de large sur /finances, soit 13 px de défilement horizontal sur
       toute la page. */
    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .country-name {
        font-size: 1.5rem;
    }

    .map-embed {
        height: 280px;
    }

    .unit-row {
        grid-template-columns: 30px 1fr 60px 60px 60px 60px;
        gap: var(--sp-2);
        padding: var(--sp-2) var(--sp-3);
    }

    .unit-list-header {
        grid-template-columns: 30px 1fr 60px 60px 60px 60px;
        gap: var(--sp-2);
        padding: var(--sp-2) var(--sp-3);
    }

    .unit-row-value {
        font-size: 0.9rem;
    }

    .tech-inventory-grid {
        grid-template-columns: 1fr;
    }

    .region-struct-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .structures-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }

    .lb-row {
        font-size: 0.8rem;
    }

    .treaty-modal.open {
        padding: var(--sp-3);
    }

    .treaty-modal-content {
        top: var(--sp-4);
    }

    .item-summary-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .treaty-lifecycle {
        overflow-x: auto;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--sp-2);
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .card-header {
        padding: var(--sp-3) var(--sp-4);
    }

    .card-body {
        padding: var(--sp-4);
    }

    .map-embed {
        height: 220px;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-chart {
        height: 180px;
    }

    .military-totals {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--sp-2);
    }

    .mil-total-value {
        font-size: 1.2rem;
    }

    .unit-list-header {
        display: none;
    }

    .unit-row {
        grid-template-columns: 24px 1fr 50px 50px 50px;
    }

    .unit-row>div:last-child {
        display: none;
    }

    .treaty-modal.open {
        padding: 0;
        align-items: stretch;
    }

    .treaty-modal-content {
        max-width: 100%;
        min-height: 100%;
        top: 0;
        border-radius: 0;
    }

    .lifecycle-step {
        font-size: 0.7rem;
    }

    .lifecycle-connector {
        width: 14px;
    }
}


/* ── Bouton actualiser (header, révélé par les pages qui définissent
   window.pageRefresh) ────────────────────────────────────────── */
#refresh-btn .pr-icon {
    transition: transform 0.4s;
}

#refresh-btn.spinning .pr-icon {
    animation: spin 0.8s linear infinite;
}
/* ── Sélecteur de pays (autocomplétion) ─────────────────────────────────────
   Remplace partout la selectbox native : plusieurs centaines d'entrées y sont
   impraticables, et sur mobile la liste occupe tout l'écran sans recherche.
   Défini dans base.css parce que le composant vit dans base.js — donc sur
   toutes les pages, dashboard comme staff. */
.pr-country-picker { position: relative; }
.pr-country-dropdown {
    position: absolute;
    top: 100%; left: 0; right: 0;
    z-index: 60;
    max-height: 260px;
    overflow-y: auto;
    background: var(--bg-surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--r-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.pr-country-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: var(--sp-2) var(--sp-3);
    background: none;
    border: 0;
    color: var(--text-primary);
    font: inherit;
    cursor: pointer;
}
.pr-country-option:hover,
.pr-country-option.active { background: var(--bg-raised); color: var(--gold); }
.pr-country-none { padding: var(--sp-2) var(--sp-3); color: var(--text-muted); font-size: .85rem; }

/* ── Bandeau « voir comme ce pays » ─────────────────────────────────────────
   Collé en haut et impossible à manquer : la seule façon de se tromper avec
   cette bascule est de lire les chiffres d'un autre pays en croyant lire les
   siens. Le serveur refuse déjà toute écriture dans ce mode ; le bandeau est
   là pour la lecture. */
.view-as-bar {
    position: sticky;
    top: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-4);
    background: var(--gold-subtle, rgba(213, 182, 84, 0.12));
    border-bottom: 1px solid var(--border-gold, #a8912d);
    color: var(--text-primary);
    font-size: 0.85rem;
}
.view-as-bar span[data-icon] { flex: none; }
.view-as-bar > span:nth-child(2) { flex: 1; min-width: 0; }
.view-as-bar .btn { flex: none; }


/* ── Tiroir « Règles » ──────────────────────────────────────────────────
   Le règlement à côté du formulaire qu'on remplit. Le tiroir n'affiche que
   l'index : les corps sont du markdown dont content_markdown.py est le seul
   rendu autorisé (règle 6b), donc chaque entrée ouvre le site public. */

.rules-drawer {
    position: fixed;
    z-index: 900;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(92vw, 340px);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    padding: var(--sp-4);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg-surface);
    border-left: 1px solid var(--gold-dark);
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.45);
}

/* `RulesDrawer.close()` pose `el.hidden = true`, et le `display: none` du
   navigateur pour [hidden] vient de SA feuille de style — donc la règle
   auteur ci-dessus le bat, quelle que soit sa spécificité. Sans cette ligne
   le tiroir s'ouvre et ne se referme plus : ni la croix, ni Échap, ni le
   bouton qui l'a ouvert n'ont d'effet visible. Même piège que .nav-count,
   .qm-panel et .tech-guide, qui portent chacune la leur. */
.rules-drawer[hidden] { display: none; }

.rules-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.rules-drawer-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
}
.rules-drawer-close:hover { color: var(--text-primary); }

.rules-drawer-tabs { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

.rules-drawer-body { flex: 1; min-height: 0; }

.rules-chapter { margin-bottom: var(--sp-4); }

.rules-chapter-title {
    display: block;
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--gold);
    text-decoration: none;
}
.rules-chapter-title:hover { text-decoration: underline; }

.rules-section {
    display: block;
    padding: 3px 0 3px var(--sp-3);
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 1px solid var(--bg-raised);
}
.rules-section:hover { color: var(--text-primary); border-left-color: var(--gold-dark); }


/* ── Fiche de création de pays ──────────────────────────────────────────
   Elle vivait dans une `.login-card` large de quelques centaines de pixels :
   onze champs dont quatre rédactionnels, empilés dans une colonne prévue pour
   un bouton de connexion. Deux colonnes, et la largeur de l'écran. */

.cc-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: var(--sp-4);
    border: 0;
    padding: 0;
    margin: 0;
}
.cc-form[disabled] { opacity: 0.7; }

.cc-col { min-width: 0; }

/* Le sélecteur de région. Le libellé s'affiche, l'identifiant part au serveur —
   les deux vivent séparément pour que l'un ne puisse pas passer pour l'autre. */
.cc-picker { position: relative; }

.cc-picker-list {
    position: absolute;
    z-index: 40;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    padding: var(--sp-1);
    background: var(--bg-raised);
    border: 1px solid var(--gold-dark);
    border-radius: var(--r-md);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.cc-picker-item {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-3);
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}
.cc-picker-item:hover { background: var(--bg-surface); }
.cc-picker-name { font-weight: 600; font-size: 0.92rem; }
.cc-picker-meta { flex-shrink: 0; font-size: 0.78rem; color: var(--text-muted); font-family: var(--font-mono, monospace); }

.cc-flag { display: flex; align-items: center; gap: var(--sp-3); }

.cc-flag-preview {
    width: 96px;
    height: 64px;
    object-fit: cover;
    border: 1px solid var(--bg-raised);
    border-radius: var(--r-sm);
}
.cc-flag-preview.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-faint);
    background: var(--bg-raised);
}


/* Une ligne d'arme de départ. Elle porte soit une technologie administrative
   existante, soit une demande d'en créer une — les deux partent dans la même
   liste, et c'est l'arbitre qui tranche. La catégorie a sa propre colonne parce
   que c'est elle qui déclenche l'avertissement « une seule par catégorie »,
   plutôt que d'être devinée depuis le nom. */
.pv-weapon-row {
    margin-bottom: var(--sp-3);
    padding: var(--sp-3);
    background: var(--bg-surface);
    border-radius: var(--r-md);
}
.pv-weapon-mode {
    display: flex;
    gap: var(--sp-2);
    margin-bottom: var(--sp-2);
}
.pv-weapon-mode .btn-ghost { margin-left: auto; }

.pv-weapon {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
    margin-bottom: var(--sp-2);
}
@media (max-width: 560px) {
    .pv-weapon { grid-template-columns: 1fr; }
}

.pv-picker { position: relative; }
.pv-picker-list {
    position: absolute;
    z-index: 40;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    padding: var(--sp-1);
    background: var(--bg-raised);
    border: 1px solid var(--gold-dark);
    border-radius: var(--r-md);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.pv-picker-item {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-3);
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}
.pv-picker-item:hover { background: var(--bg-surface); }
.pv-picker-name { font-weight: 600; font-size: 0.92rem; }
.pv-picker-meta { flex-shrink: 0; font-size: 0.78rem; color: var(--text-muted); }


/* Un champ que l'arbitre a signalé. Il doit se repérer d'un coup d'œil dans une
   fiche de onze champs : c'est tout l'intérêt de commenter le champ plutôt que
   la fiche. */
.cc-field-flagged {
    padding-left: var(--sp-3);
    border-left: 2px solid var(--gold);
}
.cc-note { color: var(--gold-light); }


/* Les points de dotation : un incrémenteur, pas un curseur. Le `input[range]`
   natif offre une zone de saisie de quelques pixels de haut — difficile à viser
   à la souris, pire au doigt — et pour cinq crans au maximum, glisser n'apporte
   rien qu'un clic ne fasse. Les cibles font ici 44px, le minimum tactile. */
.pv-stepper {
    display: flex;
    align-items: stretch;
    gap: var(--sp-2);
    max-width: 260px;
}

.pv-step {
    flex: 0 0 auto;
    width: 48px;
    min-height: 44px;
    font-size: 1.3rem;
    line-height: 1;
    color: var(--text-primary);
    background: var(--bg-raised);
    border: 1px solid var(--gold-dark);
    border-radius: var(--r-sm);
    cursor: pointer;
}
.pv-step:hover:not(:disabled) { background: var(--bg-surface); border-color: var(--gold); }
.pv-step:disabled { opacity: 0.35; cursor: default; }

.pv-step-value {
    flex: 1;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 var(--sp-2);
    font-size: 1.15rem;
    line-height: 44px;
    background: var(--bg-surface);
    border-radius: var(--r-sm);
}
.pv-step-unit { font-size: 0.8rem; color: var(--text-muted); }

/* Le « ? » porte l'explication en survol ; le texte reste écrit en dessous pour
   qui navigue au doigt ou au clavier, où un survol n'existe pas. */
.pv-help {
    width: 20px;
    height: 20px;
    margin-left: 6px;
    padding: 0;
    font-size: 0.75rem;
    color: var(--bg-base);
    background: var(--gold-dark);
    border: 0;
    border-radius: 50%;
    cursor: help;
}
.pv-help-text {
    margin-top: 4px;
    font-style: italic;
    color: var(--text-muted);
}


/* L'appel à remplir sa dotation, en tête de la Vue d'ensemble. Tant qu'elle
   n'est pas réglée, c'est la seule chose à faire du pays — la ranger dans un
   menu déroulant revenait à la cacher à qui vient de le créer. */
.prov-cta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    margin-bottom: var(--sp-4);
    padding: var(--sp-4);
    background: var(--gold-wash, var(--bg-surface));
    border: 1px solid var(--gold-dark);
    border-radius: var(--r-lg);
}
.prov-cta-title {
    font-family: var(--font-display);
    font-size: 1.05rem;
    color: var(--gold);
}
.prov-cta-text { margin: 4px 0 0; font-size: 0.88rem; color: var(--text-secondary); }


/* Le fil d'une demande. Même rendu des deux côtés : le joueur et l'arbitre
   lisent la même conversation, et deux mises en forme laisseraient croire à
   deux fils différents. */
.rt-thread {
    display: flex;
    flex-direction: column;
    margin-top: var(--sp-4);
    border: 1px solid var(--bg-raised);
    border-radius: var(--r-md);
    overflow: hidden;
}
.rt-head {
    padding: var(--sp-2) var(--sp-3);
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--gold);
    background: var(--bg-surface);
}
.rt-messages {
    max-height: 320px;
    overflow-y: auto;
    padding: var(--sp-3);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}
.rt-msg {
    max-width: 85%;
    padding: var(--sp-2) var(--sp-3);
    background: var(--bg-surface);
    border-radius: var(--r-md);
}
/* Ses propres messages d'un côté : sans cette distinction, relire un fil de
   quinze lignes demande de lire chaque nom. */
.rt-msg--mine {
    align-self: flex-end;
    background: var(--gold-wash, var(--bg-raised));
}
.rt-msg-head {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    font-size: 0.75rem;
    color: var(--text-muted);
}
.rt-msg-body {
    margin-top: 2px;
    font-size: 0.88rem;
    white-space: pre-wrap;
    word-break: break-word;
}
.rt-compose {
    display: flex;
    gap: var(--sp-2);
    padding: var(--sp-3);
    border-top: 1px solid var(--bg-raised);
}
.rt-compose .form-control { flex: 1; }
/* `display: flex` ci-dessus l'emporte sur la valeur par défaut de l'attribut
   `hidden`, qui vient de la feuille du navigateur. Sans cette ligne, un fil
   archivé garde son champ de saisie — et le joueur écrit dans un canal que
   plus personne ne lit. Même piège que les pastilles de la barre. */
.rt-compose[hidden] { display: none; }


/* La bulle de discussion, présente sur toutes les pages. Le fil vivait au bas
   de la fiche de création : accessible seulement en ouvrant la bonne page, et
   invisible partout ailleurs — alors qu'un joueur qui attend un arbitrage passe
   justement son temps sur les autres pages. */
.rt-bubble {
    position: fixed;
    z-index: 800;
    right: var(--sp-4);
    bottom: var(--sp-4);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--sp-2);
}

.rt-bubble-btn {
    position: relative;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg-base);
    background: var(--gold);
    border: 0;
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    cursor: pointer;
}
.rt-bubble-btn:hover { background: var(--gold-light); }

/* Un message non lu doit se voir sans ouvrir le fil : sinon il faut l'ouvrir
   pour savoir s'il a bougé, ce qui revient à ne pas être prévenu. */
.rt-bubble--unread { animation: rt-pulse 2s ease-in-out infinite; }
@keyframes rt-pulse {
    0%, 100% { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); }
    50% { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 0 8px rgba(213, 182, 84, 0.25); }
}
@media (prefers-reduced-motion: reduce) {
    .rt-bubble--unread { animation: none; border: 2px solid var(--text-primary); }
}

.rt-bubble-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    font-size: 0.7rem;
    line-height: 20px;
    color: #fff;
    background: var(--danger, #ef4444);
    border-radius: 10px;
}

.rt-bubble-panel {
    width: min(92vw, 380px);
    background: var(--bg-surface);
    border: 1px solid var(--gold-dark);
    border-radius: var(--r-lg);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}
.rt-bubble-panel .rt-thread { margin-top: 0; border: 0; }

/* ── Signaler un problème (GD-21) ──────────────────────────────────────────
   La boîte se construit elle-même dans `report-problem.js` et n'emprunte le
   squelette d'aucune page : le bouton doit marcher depuis celle qui vient de
   casser, y compris quand c'est le module de la page qui a échoué à se
   charger. */
.pr-report-overlay {
    position: fixed;
    inset: 0;
    z-index: 4000;   /* au-dessus de la palette (3000) et du tiroir (2500) */
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh var(--sp-4) var(--sp-4);
    background: rgba(0, 0, 0, 0.62);
}

.pr-report-box {
    width: min(560px, 100%);
    max-height: 84vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-raised);
    border: 1px solid var(--border-gold);
    border-radius: var(--r-lg);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.pr-report-head {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-subtle);
}
.pr-report-head h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    color: var(--text-primary);
}
.pr-report-close {
    margin-left: auto;
    min-width: var(--pr-touch-target);
    min-height: var(--pr-touch-target);
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.pr-report-body {
    padding: var(--sp-4);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}
.pr-report-body label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.pr-report-body textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--r-md);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: vertical;
}
.pr-report-body textarea:focus {
    outline: none;
    border-color: var(--border-gold);
}

.pr-report-hint {
    margin: 0;
    font-size: 0.76rem;
    color: var(--text-faint);
}

/* Le contexte est montré, pas caché : le joueur envoie son agent utilisateur
   et sa dernière erreur, il doit pouvoir les lire avant de cliquer. */
.pr-report-ctx {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    font-size: 0.75rem;
}
.pr-report-ctx-row { display: flex; gap: 10px; align-items: baseline; }
.pr-report-ctx-key {
    flex: none;
    width: 105px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.66rem;
}
.pr-report-ctx-val {
    color: var(--text-secondary);
    font-family: ui-monospace, Menlo, monospace;
    word-break: break-word;
    min-width: 0;
}

.pr-report-foot {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-surface);
}

@media (max-width: 768px) {
    .pr-report-overlay { padding: 0; align-items: stretch; }
    .pr-report-box { width: 100%; max-height: 100vh; border-radius: 0; border: 0; }
    .pr-report-ctx-key { width: 82px; }
}
