/* ── 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;
}
.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); }
.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;
    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);
}
.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;
}
.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);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}
.toast {
    padding: 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;
    max-width: 360px;
}
.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 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; }
    .stat-grid { grid-template-columns: repeat(2, 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: 1fr 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; }
