:root {
  --bg: #0a0e16;
  --card: #121a29;
  --card2: #0f1626;
  --line: #1f2a3d;
  --text: #e6ebf4;
  --muted: #8a96ab;
  --brand: #22d3ee;
  --brand2: #8b5cf6;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --lock: #94a3b8;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(139, 92, 246, .18), transparent 60%),
    radial-gradient(800px 480px at -10% 0%, rgba(34, 211, 238, .14), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.noscript { padding: 24px; text-align: center; }

svg.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 14px; border-radius: 12px; cursor: pointer; font-weight: 600; min-height: 42px;
  transition: transform .06s ease, border-color .15s, background .15s, opacity .15s;
}
.btn:hover { border-color: #33445f; background: #162033; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; cursor: wait; }
.btn.primary { border: 0; color: #04141a; background: linear-gradient(135deg, var(--brand), #60a5fa 55%, var(--brand2)); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: #fff; border: 0; background: linear-gradient(135deg, #f43f5e, #be123c); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 13px; border-radius: 10px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card2); color: var(--muted); cursor: pointer;
  transition: color .15s, border-color .15s, background .15s, transform .06s;
}
.icon-btn:hover { color: var(--text); border-color: #33445f; background: #162033; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.warn:hover { color: var(--warn); }
.icon-btn.bad:hover { color: var(--bad); border-color: rgba(251, 113, 133, .5); }
.icon-btn.ok:hover { color: var(--ok); }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 13px; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; min-height: 44px; outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card2); color: var(--muted);
  padding: 7px 12px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 13px;
  transition: all .15s;
}
.chip:hover { color: var(--text); border-color: #33445f; }
.chip.on { color: #04141a; border-color: transparent; background: linear-gradient(135deg, var(--brand), #60a5fa); }

/* ---------- connexion ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, .035), rgba(255, 255, 255, .01)), var(--card);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .4);
}
.login { width: min(400px, 100%); padding: 28px 24px; }
.logo {
  width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; margin: 0 auto 14px;
  background: linear-gradient(135deg, rgba(34, 211, 238, .18), rgba(139, 92, 246, .22)); border: 1px solid #2b3a55; color: var(--brand);
}
.logo svg.ico { width: 30px; height: 30px; }
.login h1 { text-align: center; font-size: 24px; letter-spacing: .3px; }
.login .sub { text-align: center; margin: 4px 0 22px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(14px);
  background: rgba(10, 14, 22, .78); border-bottom: 1px solid var(--line);
}
.topbar-in { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .3px; }
.brand .logo { width: 36px; height: 36px; margin: 0; border-radius: 11px; }
.brand .logo svg.ico { width: 20px; height: 20px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; letter-spacing: 0; margin-top: -2px; }
.spacer { flex: 1; }
.sys { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card2); font-size: 12px; color: var(--muted); white-space: nowrap;
}
.pill b { color: var(--text); font-weight: 700; }
.pill.warn b { color: var(--warn); }
.pill.bad b { color: var(--bad); }

/* ---------- page ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: 18px 16px 90px; }

.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 18px; }
.kpi {
  text-align: left; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card);
  cursor: pointer; position: relative; overflow: hidden; transition: border-color .15s, transform .06s;
}
.kpi:hover { border-color: #33445f; }
.kpi:active { transform: scale(.98); }
.kpi.on { border-color: var(--c, var(--brand)); box-shadow: 0 0 0 1px var(--c, var(--brand)) inset; }
.kpi::after { content: ""; position: absolute; inset: auto -20px -30px auto; width: 80px; height: 80px; border-radius: 50%; background: var(--c, var(--brand)); opacity: .09; }
.kpi .lbl { color: var(--muted); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .num { font-size: 28px; font-weight: 800; margin-top: 6px; line-height: 1; color: var(--c, var(--text)); }
.k-all { --c: var(--brand); } .k-active { --c: var(--ok); } .k-expiring { --c: var(--warn); }
.k-expired { --c: var(--bad); } .k-locked { --c: var(--lock); } .k-online { --c: var(--brand2); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search { position: relative; flex: 1 1 240px; }
.search svg.ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 38px; }
.toolbar select.input { width: auto; min-width: 150px; }

/* ---------- liste ---------- */
.list { display: grid; gap: 10px; }
.row {
  display: grid; grid-template-columns: 1.5fr .9fr 1.3fr auto; gap: 14px; align-items: center;
  padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card);
  border-left: 4px solid var(--c, var(--line)); transition: border-color .15s, background .15s;
}
.row:hover { background: #141d2e; }
.row.s-active { --c: var(--ok); } .row.s-expiring { --c: var(--warn); }
.row.s-expired { --c: var(--bad); } .row.s-locked { --c: var(--lock); }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; flex: none; text-transform: uppercase;
  color: var(--c, var(--text)); background: color-mix(in srgb, var(--c, #fff) 14%, transparent); border: 1px solid color-mix(in srgb, var(--c, #fff) 30%, transparent);
}
.name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--c);
  background: color-mix(in srgb, var(--c) 15%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.b-active { --c: var(--ok); } .b-expiring { --c: var(--warn); } .b-expired { --c: var(--bad); } .b-locked { --c: var(--lock); }
.conn { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #3b475c; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 211, 153, .18); }
.exp-top { font-size: 13px; display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.exp-top b { font-weight: 700; }
.bar { height: 6px; border-radius: 999px; background: #1a2436; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--c, var(--ok)); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.empty { text-align: center; padding: 50px 20px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

/* ---------- fenêtres ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(4, 7, 12, .7); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px; overflow-y: auto; animation: fade .15s ease;
}
.modal {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; border-radius: 20px;
  background: var(--card); border: 1px solid #2a3850; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); animation: pop .18s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.result {
  background: #0a111d; border: 1px solid #22314a; border-radius: 14px; padding: 14px; white-space: pre-wrap; word-break: break-word;
  font: 13.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 46vh; overflow-y: auto; margin-bottom: 14px;
}
.warnbox { background: rgba(251, 191, 36, .09); border: 1px solid rgba(251, 191, 36, .3); color: #fde68a; border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }

/* ---------- notifications ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast {
  background: #0f1828; border: 1px solid #2a3850; border-left: 4px solid var(--ok); border-radius: 12px; padding: 11px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5); animation: rise .2s ease; transition: opacity .35s, transform .35s;
}
.toast.err { border-left-color: var(--bad); }
.toast.out { opacity: 0; transform: translateY(8px); }

.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .25); border-top-color: currentColor; animation: spin .7s linear infinite; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- téléphone ---------- */
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .row { grid-template-columns: 1fr 1fr; gap: 12px; }
  .who { grid-column: 1 / -1; }
  .actions { grid-column: 1 / -1; justify-content: flex-start; padding-top: 4px; border-top: 1px solid var(--line); }
  .note { max-width: 70vw; }
  .sys { display: none; }
}
@media (max-width: 480px) {
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi .num { font-size: 24px; }
  .row2 { grid-template-columns: 1fr; }
  .toolbar .btn { flex: 1 1 auto; }
  .toolbar select.input { flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.on-txt { color: var(--ok); } .off-txt { color: var(--muted, #8a97ad); }
.grp { margin: 18px 0 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted, #8a97ad); }
textarea.input { resize: vertical; min-height: 70px; font-family: ui-monospace, monospace; }
