/* GaspoGate — feuille de style commune (portail et administration). Clair par défaut, sombre via prefers-color-scheme. */
:root {
  color-scheme: light dark;
  --bg: #f5f6f8; --surface: #fff; --surface-2: #eef0f4; --text: #1b2230; --muted: #5d6778; --border: #d9dde5;
  --primary: #1f5eff; --primary-text: #fff; --danger: #c62828; --ok: #1b7f4b; --warn: #946200;
  --ok-bg: #dff3e7; --warn-bg: #fff1cf; --bad-bg: #fbe0e0; --info-bg: #e3ebff; --shadow: 0 1px 2px rgba(20, 30, 50, .08);
  --radius: 8px; --side: 250px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --surface: #171d2b; --surface-2: #1f2637; --text: #e6e9f0; --muted: #98a2b5; --border: #2c3548;
    --primary: #6b93ff; --primary-text: #0b1020; --danger: #ff7b7b; --ok: #62d394; --warn: #f2c15c;
    --ok-bg: #123524; --warn-bg: #3a2e0e; --bad-bg: #3d1a1a; --info-bg: #1a2850; --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
a { color: var(--primary); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
p { margin: .5rem 0; }
small { color: var(--muted); }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Mise en page */
.layout { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 1.15rem; padding: .25rem .5rem 1rem; }
.brand span { color: var(--primary); }
.nav a { display: block; padding: .45rem .65rem; border-radius: 6px; color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--info-bg); color: var(--primary); font-weight: 600; }
.nav .nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1rem .65rem .25rem; }
.main { min-width: 0; }
.topbar { display: flex; gap: .75rem; align-items: center; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.topbar select { max-width: 240px; }
.menu-btn { display: none; }
.content { padding: 1.25rem; max-width: 1200px; }
.banner { background: var(--warn-bg); color: var(--text); border-bottom: 1px solid var(--border); padding: .5rem 1.25rem; font-size: .9rem; }
.banner strong { color: var(--warn); }

/* Cartes, grilles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.stat-label { color: var(--muted); font-size: .82rem; }
.stat-value { font-size: 1.7rem; font-weight: 700; }
.stat-sub { color: var(--muted); font-size: .82rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; flex: 1; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: .75rem; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td .btn { margin: 0 .25rem .25rem 0; }
td code { overflow-wrap: anywhere; }

/* Formulaires et boutons */
.form { display: grid; gap: .75rem; }
.field { display: grid; gap: .25rem; }
.field label { font-weight: 600; font-size: .88rem; }
.field-check label { font-weight: 400; display: flex; gap: .5rem; align-items: flex-start; }
.req { color: var(--danger); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; width: 100%; }
input[type="checkbox"] { width: auto; margin-top: .25rem; }
textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.form-error { color: var(--danger); font-size: .9rem; min-height: 0; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.btn { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; padding: .45rem .9rem; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { background: var(--primary); filter: brightness(1.1); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.1); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: .2rem .55rem; font-size: .82rem; }

/* États, badges, alertes */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--surface-2); white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); } .badge-warn { background: var(--warn-bg); color: var(--warn); } .badge-bad { background: var(--bad-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--primary); }
.state { padding: 1.25rem; text-align: center; color: var(--muted); display: flex; gap: .6rem; justify-content: center; align-items: center; flex-wrap: wrap; }
.state-error { color: var(--danger); background: var(--bad-bg); border-radius: var(--radius); }
.alert { padding: .7rem .9rem; border-radius: var(--radius); margin: .5rem 0 1rem; }
.alert-warn { background: var(--warn-bg); border: 1px solid var(--warn); }
.alert-info { background: var(--info-bg); }
.spin { width: 1rem; height: 1rem; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.disabled-item { opacity: .6; filter: grayscale(1); }

/* Onglets, code, secrets, modales, toasts */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tab { font: inherit; border: 0; background: none; color: var(--muted); padding: .5rem .9rem; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.code { margin: .5rem 0 1rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.code-label { background: var(--surface-2); padding: .25rem .75rem; font-size: .8rem; color: var(--muted); }
.code pre { margin: 0; padding: .75rem; overflow-x: auto; background: var(--surface); }
.secret { display: flex; gap: .5rem; align-items: center; background: var(--surface-2); padding: .5rem .75rem; border-radius: 6px; }
.secret code { flex: 1; overflow-wrap: anywhere; user-select: all; }
.pairing { font-size: 2rem; letter-spacing: .15em; font-weight: 700; text-align: center; padding: 1rem; background: var(--info-bg); border-radius: var(--radius); user-select: all; overflow-wrap: anywhere; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius); width: min(560px, 100%); max-height: 92vh; overflow-y: auto; border: 1px solid var(--border); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem 0; }
.modal-head h2 { margin: 0; }
.modal-body { padding: .75rem 1rem 1rem; display: grid; gap: .5rem; }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 60; max-width: min(420px, calc(100vw - 2rem)); }
.toast { padding: .65rem .9rem; border-radius: var(--radius); background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); }
.toast-error { background: var(--bad-bg); color: var(--danger); border-color: var(--danger); }
.option-list { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.option { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; background: var(--surface); }
.option.current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }

/* Authentification */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: min(430px, 100%); }
.link-btn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* Mobile */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; width: min(var(--side), 85vw); transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .4); }
  .menu-btn { display: inline-block; }
  .content { padding: .9rem; }
  /* tableaux en cartes empilées */
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; left: -9999px; }
  tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .6rem; padding: .25rem .4rem; }
  td { border: 0; padding: .25rem .4rem; }
  td::before { content: attr(data-label); display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; }
  .kv { grid-template-columns: 1fr; }
}
