:root {
    color-scheme: light;
    --bg: #f3f6fb;
    --card: #ffffff;
    --card-2: #eef3fb;
    --text: #0f172a;
    --muted: #51607a;
    --border: #d6e0ee;
    --primary: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
    color: var(--text);
}

/* Barre debug (tag clan, refresh, cache) : visible uniquement avec ?debug=1 */
body:not(.debug-ui) .topbar .actions {
    display: none !important;
}

a {
    color: inherit;
    text-decoration: none;
}

.layout {
    min-height: 100vh;
}

.sidebar {
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    padding: 14px 12px 12px;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.brand {
    font-size: 16px;
    font-weight: 700;
    margin: 0 4px 10px;
}

.nav-toggle {
    width: auto;
    min-width: 40px;
    height: 36px;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #f3f7ff;
    color: #1e3a8a;
    font-size: 18px;
    line-height: 1;
}

.nav {
    display: none;
    gap: 8px;
    padding-top: 6px;
}

body.nav-open .nav {
    display: grid;
}

.nav a {
    padding: 9px 11px;
    border-radius: 10px;
    color: var(--muted);
    border: 1px solid transparent;
    white-space: nowrap;
    flex: 0 0 auto;
}

.nav a:hover,
.nav a.active {
    color: var(--text);
    border-color: var(--border);
    background: #e9f1ff;
}

.content {
    padding: 14px;
}

.topbar {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.title h1 {
    margin: 0;
    font-size: 24px;
}

.subtitle {
    color: var(--muted);
    margin-top: 6px;
    font-size: 14px;
}

.actions {
    display: grid;
    gap: 8px;
    width: 100%;
}

input[type="text"],
select,
button {
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card-2);
    color: var(--text);
    padding: 10px 12px;
    font-size: 14px;
    width: 100%;
}

button {
    background: var(--primary);
    border-color: #1d4ed8;
    color: #ffffff;
    cursor: pointer;
}

button.secondary {
    background: #e8eef8;
    color: #1e293b;
    border-color: #cad7ea;
}

button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.status {
    margin-bottom: 14px;
    color: #1d4ed8;
}

.status.error {
    color: #b91c1c;
}

.grid {
    display: grid;
    gap: 12px;
}

.grid.kpi {
    grid-template-columns: 1fr;
    margin-bottom: 12px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.label {
    color: #334155;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
}

.value {
    margin: 0;
    font-size: 25px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: 0.01em;
}

.small {
    color: var(--muted);
    font-size: 13px;
    margin-top: 6px;
}

.section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    margin-top: 12px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.section h2 {
    margin: 0 0 12px;
    font-size: 17px;
    color: #0f172a;
}

.war-chart {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.war-chart-row {
    display: grid;
    grid-template-columns: minmax(88px, auto) minmax(120px, 1fr) 40px;
    align-items: center;
    gap: 10px;
}

.war-chart-label {
    color: #1e3a8a;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.war-chart-track {
    height: 12px;
    border-radius: 999px;
    background: #e2ecff;
    border: 1px solid #c8dbfb;
    overflow: hidden;
}

.war-chart-bar {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #3b82f6 0%, #2563eb 100%);
}

.war-chart-count {
    text-align: right;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
}

.table-wrap {
    overflow: visible;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.responsive-table thead {
    display: none;
}

.responsive-table,
.responsive-table tbody,
.responsive-table tr,
.responsive-table td {
    display: block;
    width: 100%;
}

.responsive-table tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    background: #f7faff;
    padding: 8px 10px;
}

.responsive-table td {
    border: 0;
    padding: 6px 0;
    text-align: left;
    display: grid;
    grid-template-columns: minmax(95px, 40%) 1fr;
    gap: 10px;
    font-size: 13px;
    align-items: center;
}

.responsive-table td::before {
    content: attr(data-label);
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.responsive-table tr:last-child {
    margin-bottom: 0;
}

.responsive-table tr.member-inactive-24h {
    border-color: #7f1d1d;
    background: rgba(127, 29, 29, 0.18);
}

.responsive-table tr.war-low-combats-day {
    border-color: #dc2626;
    background: rgba(220, 38, 38, 0.14);
}

.responsive-table .col-detailed {
    display: none;
}

#riverLogTable.detailed .col-detailed {
    display: grid;
}

#riverLogTable tfoot .col-detailed {
    display: none;
}

#riverLogTable.detailed tfoot .col-detailed {
    display: grid;
}

#riverLogTable tfoot .river-log-summary td {
    border-top: 2px solid var(--primary);
    background: rgba(37, 99, 235, 0.1);
    font-weight: 600;
    color: #0f172a;
}

.responsive-table td.empty {
    display: block;
    padding: 8px 2px;
}

.responsive-table td.empty::before {
    content: "";
}

.pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    border: 1px solid var(--border);
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    background: #f8fafc;
}

.pill.success {
    color: #166534;
    border-color: #86efac;
    background: #dcfce7;
}

.pill.warning {
    color: #92400e;
    border-color: #fcd34d;
    background: #fef3c7;
}

.pill.info {
    color: #1d4ed8;
    border-color: #93c5fd;
    background: #dbeafe;
}

.pill.danger {
    color: #991b1b;
    border-color: #fca5a5;
    background: #fee2e2;
}

td.gdc-combat-low {
    background: rgba(245, 158, 11, 0.2);
}

.section-actions {
    margin-top: 10px;
    margin-bottom: 10px;
}

.empty {
    color: var(--muted);
    padding: 8px;
}

@media (min-width: 760px) {
    .actions {
        grid-template-columns: repeat(3, minmax(150px, auto));
        width: auto;
    }

    input[type="text"],
    select,
    button {
        width: auto;
    }

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

@media (min-width: 1000px) {
    .layout {
        display: grid;
        grid-template-columns: 260px minmax(0, 1fr);
    }

    .sidebar {
        border-bottom: 0;
        border-right: 1px solid var(--border);
        position: sticky;
        top: 0;
        height: 100vh;
        padding: 20px 14px;
    }

    .brand {
        margin: 6px 10px 18px;
        font-size: 18px;
    }

    .nav-toggle {
        display: none;
    }

    .nav {
        display: grid;
        gap: 6px;
        overflow-x: visible;
        padding-bottom: 0;
    }

    .nav a {
        white-space: normal;
    }

    .content {
        padding: 24px 26px;
    }

    .topbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 18px;
    }

    .title h1 {
        font-size: 28px;
    }

    .subtitle {
        max-width: 72ch;
    }

    .actions {
        display: flex;
        flex-wrap: wrap;
        width: auto;
        justify-content: flex-end;
        align-items: center;
        gap: 8px;
    }

    .actions input[type="text"] {
        min-width: 180px;
    }

    .actions button,
    .actions select {
        min-width: 140px;
    }

    .card {
        border-radius: 16px;
        padding: 16px;
    }

    .section {
        border-radius: 16px;
        padding: 16px;
    }

    .value {
        font-size: 28px;
    }
}

@media (min-width: 900px) {
    .table-wrap {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        padding-right: 8px;
    }

    .responsive-table {
        display: table;
        table-layout: auto;
        width: 100%;
        max-width: 100%;
    }

    .responsive-table.col-first-narrow th:first-child,
    .responsive-table.col-first-narrow td:first-child {
        width: 3rem;
        max-width: 3.5rem;
        min-width: 0;
        white-space: nowrap;
        text-align: center;
        box-sizing: border-box;
    }

    /* Members + War: colonnes auto avec plafond de largeur */
    #membersTable td,
    #membersTable th,
    body[data-page="war"] .responsive-table td,
    body[data-page="war"] .responsive-table th,
    body[data-page="dashboard"] .responsive-table td,
    body[data-page="dashboard"] .responsive-table th,
    body[data-page="alerts"] .responsive-table td,
    body[data-page="alerts"] .responsive-table th,
    body[data-page="performance"] .responsive-table td,
    body[data-page="performance"] .responsive-table th {
        width: auto;
        max-width: 70px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .responsive-table.col-first-narrow th:not(:first-child),
    .responsive-table.col-first-narrow td:not(:first-child) {
        overflow-wrap: break-word;
        word-break: normal;
    }

    .responsive-table thead {
        display: table-header-group;
    }

    .responsive-table tbody {
        display: table-row-group;
    }

    .responsive-table tr {
        display: table-row;
        border: 0;
        background: transparent;
        padding: 0;
        margin: 0;
    }

    .responsive-table td,
    .responsive-table th {
        display: table-cell;
        text-align: left;
        padding: 10px 14px 10px 8px;
        border-bottom: 1px solid var(--border);
        font-size: 14px;
    }

    .responsive-table td:last-child,
    .responsive-table th:last-child {
        padding-right: 18px;
    }

    .responsive-table th {
        color: #1e3a8a;
        position: sticky;
        top: 0;
        background: #eaf2ff;
        z-index: 1;
    }

    .responsive-table td::before {
        content: none;
    }

    .responsive-table tr:last-child td {
        border-bottom: none;
    }

    .responsive-table tbody tr:nth-child(even) td {
        background: #f3f7ff;
    }

    .responsive-table tbody tr:hover td {
        background: #e4eeff;
        transition: background 120ms ease-in-out;
    }

    .responsive-table tr.member-inactive-24h td {
        background: rgba(220, 38, 38, 0.1);
    }

    .responsive-table tr.war-low-combats-day td {
        background: rgba(220, 38, 38, 0.16) !important;
    }

    #riverLogTable .col-detailed {
        display: none;
    }

    #riverLogTable.detailed .col-detailed {
        display: table-cell;
    }

    #riverLogTable tfoot .col-detailed {
        display: none;
    }

    #riverLogTable.detailed tfoot .col-detailed {
        display: table-cell;
    }

    #riverLogTable tfoot .river-log-summary td {
        border-top: 2px solid var(--primary);
        background: rgba(37, 99, 235, 0.12);
        font-weight: 600;
        color: #0f172a;
        border-bottom: none;
    }

    th.sortable {
        cursor: pointer;
        user-select: none;
        white-space: nowrap;
    }

    th.sortable::after {
        content: " ↕";
        color: #64748b;
        font-size: 12px;
    }

    th.sortable.sorted-asc::after {
        content: " ↑";
        color: #1d4ed8;
    }

    th.sortable.sorted-desc::after {
        content: " ↓";
        color: #1d4ed8;
    }
}

.th-actions,
.td-actions {
    width: 1%;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #eff5ff;
    color: #1d4ed8;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn-icon:hover {
    background: #dbeafe;
    border-color: #60a5fa;
    color: #1e3a8a;
}

.btn-icon:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

body.modal-open {
    overflow: hidden;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 80;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

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

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.28);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: min(960px, 100vw);
    max-height: 88vh;
    overflow: auto;
    margin: 0;
    padding: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.modal-title {
    margin: 0;
    font-size: 18px;
}

.modal-subtitle {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.modal-close {
    flex: 0 0 auto;
    width: 40px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #eff5ff;
    color: var(--text);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    border-color: #60a5fa;
}

.modal-table-wrap {
    margin-top: 4px;
}

@media (min-width: 760px) {
    .modal {
        align-items: center;
        padding: 16px;
    }

    .modal-panel {
        border-radius: 16px;
    }
}
