:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #5d6b7a;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --ok: #2b8a3e;
  --ok-bg: #e6f4ea;
  --warn: #a35b00;
  --warn-bg: #fff3e0;
  --danger: #c92a2a;
  --danger-bg: #fdecec;
  --info: #1864ab;
  --info-bg: #e7f1fb;
  --neutral-bg: #eceff3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #181e26;
    --surface-2: #1f2630;
    --border: #2c3542;
    --text: #e6eaef;
    --muted: #9aa7b5;
    --accent: #7c95ff;
    --accent-text: #0d1220;
    --ok: #69db7c;
    --ok-bg: #16301f;
    --warn: #ffc078;
    --warn-bg: #3a2a12;
    --danger: #ff8787;
    --danger-bg: #3b1a1a;
    --info: #74c0fc;
    --info-bg: #13283d;
    --neutral-bg: #262e39;
    --shadow: none;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.6rem;
}

h1 {
  font-size: 1.45rem;
}

h2 {
  font-size: 1.15rem;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.center {
  text-align: center;
}

/* ------------------------------------------------------------------ en-tête */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 650;
}

.brand small {
  display: block;
  font-weight: 450;
  color: var(--muted);
  font-size: 0.78rem;
}

.brand-mark {
  font-size: 1.5rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.tab {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
}

.tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tab[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

.who {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------------ mise en page */

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.auth-card {
  max-width: 400px;
  margin: 8vh auto 0;
}

.auth-card .brand {
  justify-content: center;
  margin-bottom: 1.25rem;
}

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

.page-head h1 {
  margin: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}

.stat .value {
  font-size: 1.5rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.stat .label {
  color: var(--muted);
  font-size: 0.85rem;
}

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.75rem;
}

.toolbar .grow {
  flex: 1;
  min-width: 200px;
}

/* ------------------------------------------------------------------ formulaires */

label {
  display: block;
  font-weight: 550;
  margin: 0.75rem 0 0.3rem;
}

input,
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toolbar input,
.toolbar select {
  width: auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  filter: brightness(1.07);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border);
}

.button.small {
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
  font-weight: 550;
}

.button.wide {
  width: 100%;
  margin-top: 1.1rem;
}

.link {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.error {
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin-top: 0.9rem;
}

.warning {
  color: var(--warn);
  background: var(--warn-bg);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}

.rules {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
}

/* ------------------------------------------------------------------ tableaux */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

th,
td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: var(--surface-2);
  font-weight: 600;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.nowrap {
  white-space: nowrap;
}

.channel-name {
  font-weight: 600;
}

.channel-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ------------------------------------------------------------------ pastilles */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--neutral-bg);
  color: var(--muted);
}

.badge::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge.info {
  background: var(--info-bg);
  color: var(--info);
}

.badge.info::before {
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

.banner {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  background: var(--info-bg);
  color: var(--info);
}

.banner.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.banner.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ------------------------------------------------------------------ divers */

details.history summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0.6rem;
}

.qr {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.qr img {
  width: 180px;
  height: 180px;
  background: #fff;
  border-radius: 8px;
  padding: 6px;
}

.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.04em;
  word-break: break-all;
}

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  max-width: 460px;
  width: calc(100% - 2rem);
  padding: 1.5rem;
}

.dialog::backdrop {
  background: rgba(10, 14, 20, 0.55);
}

.secret-box {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin: 1rem 0;
}

.secret-box code {
  flex: 1;
  font-size: 1.15rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: var(--surface-2);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  user-select: all;
}

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  max-width: 360px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

@media (max-width: 720px) {
  .topbar {
    gap: 0.6rem;
  }

  .tabs {
    order: 3;
    flex-basis: 100%;
    overflow-x: auto;
  }

  .app {
    padding: 1rem 0.75rem 2rem;
  }

  .hide-mobile {
    display: none;
  }
}
