:root {
  --bg: #f3f4f1;
  --surface: #ffffff;
  --surface-2: #eceee9;
  --border: #d9ddd4;
  --text: #1d2420;
  --muted: #66706a;
  --accent: #3f8f3a;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #2f8a3b;
  --log-bg: #15191c;
  --log-text: #d6dbd4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101316;
    --surface: #181c20;
    --surface-2: #20252a;
    --border: #2b3137;
    --text: #e6e9e4;
    --muted: #949c95;
    --accent: #5cb85c;
    --accent-ink: #0d140d;
    --danger: #e5604f;
    --warn: #e0a43a;
    --ok: #63c46b;
    --log-bg: #0b0d0f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .8rem; font-weight: 600; margin: 0 0 .25rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; }

/* ---- Marque ---- */
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; }
.block {
  width: 22px; height: 22px; border-radius: 3px; flex: none;
  background: linear-gradient(#4caf50 0 32%, #6b4a2b 32% 100%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .18);
}

/* ---- Connexion ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: .6rem; }
.login-card .brand { font-size: 1.15rem; margin-bottom: .5rem; }

/* ---- Barre du haut + onglets ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.top-right { display: flex; align-items: center; gap: .6rem; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.conn.on { background: var(--ok); }
.conn.off { background: var(--danger); }

.tabs {
  display: flex; gap: 4px; padding: 8px 16px 0; max-width: 1100px; margin: 0 auto;
}
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600;
  padding: .55rem .8rem; border-radius: 8px 8px 0 0; cursor: pointer; display: flex; gap: .4rem; align-items: center;
  border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs .ico { font-family: ui-monospace, monospace; font-size: .9em; opacity: .8; }

.tab { max-width: 1100px; margin: 0 auto; padding: 12px 16px 96px; display: flex; flex-direction: column; gap: 12px; }

/* Sur mobile : onglets en barre fixe en bas */
@media (max-width: 700px) {
  .tabs {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; margin: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); justify-content: space-around;
  }
  .tabs button { flex-direction: column; gap: 0; font-size: .7rem; padding: .35rem .2rem; border-radius: 8px; border-bottom: 0; flex: 1; }
  .tabs button[aria-selected="true"] { background: var(--surface-2); }
  .tabs .ico { font-size: 1.15rem; }
  .topbar .brand span:last-child { display: none; }
}

/* ---- Cartes ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .grid.two { grid-template-columns: 1fr; } }

.hero { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hero-main { display: flex; align-items: center; gap: 12px; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-flex; align-items: center; gap: .45rem; font-weight: 700; padding: .35rem .75rem;
  border-radius: 999px; background: var(--surface-2); white-space: nowrap;
}
.pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.pill.ok::before { background: var(--ok); }
.pill.warn::before { background: var(--warn); }
.pill.bad::before { background: var(--danger); }

.banner { padding: 10px 14px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.banner.bad { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

.stat-label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: .15rem 0 .35rem; }
.stat-value .good { color: var(--ok); }
.stat-value .mid { color: var(--warn); }
.stat-value .low { color: var(--danger); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar.big { height: 10px; margin: .6rem 0 .9rem; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s; }
.bar span.hot { background: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: .78rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); }

/* ---- Boutons / champs ---- */
.btn {
  font: inherit; font-weight: 600; border-radius: 9px; padding: .55rem .95rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.05); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: none; }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: .5rem .7rem; min-width: 0;
}
input:focus, select:focus, .btn:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: .5rem 0; }
.inline-form input { flex: 1 1 140px; }
.check { display: inline-flex; gap: .35rem; align-items: center; font-size: .85rem; color: var(--muted); white-space: nowrap; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: none; font: inherit; font-size: .82rem; font-weight: 600; color: var(--muted); padding: .25rem .65rem; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---- Listes de joueurs ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: .5rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.list li:first-child { border-top: 0; }
.list .who { display: flex; align-items: center; gap: .55rem; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.list .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.list .empty { color: var(--muted); justify-content: flex-start; }
.avatar {
  width: 26px; height: 26px; border-radius: 5px; display: grid; place-items: center; flex: none;
  font-size: .8rem; font-weight: 700; color: #fff;
}
.tag { font-size: .7rem; font-weight: 700; padding: .05rem .4rem; border-radius: 5px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tag.live { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.tag.op { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }

/* ---- Console ---- */
.console-card { display: flex; flex-direction: column; gap: 10px; }
.console-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.console-tools input { flex: 1 1 200px; }
.log {
  margin: 0; background: var(--log-bg); color: var(--log-text); border-radius: 10px; padding: 10px 12px;
  height: min(62dvh, 640px); overflow: auto; font: 12.5px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.log .w { color: #f0c05a; }
.log .e { color: #ff7b6b; }
.log .c { color: #8fd08b; }
.log .j { color: #7fb8ff; }
.cmd { display: flex; gap: 8px; align-items: center; }
.cmd .prompt { font-family: ui-monospace, monospace; font-weight: 700; color: var(--muted); }
.cmd input { flex: 1; font-family: ui-monospace, monospace; }

/* ---- Monde ---- */
.chunky { display: flex; gap: 16px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.chunky b { display: block; font-size: 1.15rem; }
.chunky-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; }
@media (max-width: 640px) { .fields { grid-template-columns: 1fr; } }
.field { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.field label { grid-column: 1 / -1; font-size: .85rem; font-weight: 600; display: flex; gap: .4rem; align-items: center; }
.field input, .field select { width: 100%; }
.settings .field:last-of-type { margin-top: 12px; max-width: 420px; }
.settings-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

/* ---- Graphiques ---- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 760px) { .charts { grid-template-columns: 1fr; } }
.chart { width: 100%; min-height: 160px; }
.uplot { font-family: inherit; }
.u-legend { font-size: .78rem; color: var(--muted); }
.u-legend .u-marker { border-radius: 3px; }

/* ---- Notifications ---- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); }
@media (max-width: 700px) { .toasts { bottom: 84px; left: 16px; right: 16px; max-width: none; } }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); white-space: pre-wrap; overflow-wrap: anywhere;
}
.toast.bad { border-left-color: var(--danger); }
