/* ===========================================================================
   GateLuks — feuille de style du dashboard
   Sombre d'abord, comme le logo. L'écran des téléphones garde ses propres
   couleurs : c'est un objet physique, pas une surface de l'interface.
   =========================================================================== */

:root {
  --ground:   #070C15;
  --panel:    #0E1826;
  --panel-2:  #131F30;
  --edge:     #1D2C40;
  --ink:      #E8F4F6;
  --ink-2:    #8DA3B8;
  --ink-3:    #5A6E82;
  --accent:   #2DD4BF;
  --accent-2: #22D3EE;
  --ok:       #34D399;
  --warn:     #F5B342;
  --crit:     #F26D78;
  --info:     #60A5FA;

  --phone-frame:  #04070C;
  --phone-edge:   #24313F;
  --screen:       #080E16;
  --screen-off:   #04070B;
  --screen-ink:   #EAF3F5;
  --screen-ink-2: #8FA6B8;
  --screen-ink-3: #55697B;
  --screen-line:  rgba(160,190,210,.14);

  --radius: 12px;
  --shadow: 0 18px 40px -22px rgba(0,0,0,.9);
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: Archivo, "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ground:  #EDF2F5;
    --panel:   #FFFFFF;
    --panel-2: #F5F8FA;
    --edge:    #D5E0E7;
    --ink:     #0B1620;
    --ink-2:   #4F6577;
    --ink-3:   #7A8FA0;
    --accent:  #0E9F8C;
    --accent-2:#0B8FAE;
    --ok:      #0F9D6E;
    --warn:    #B0730A;
    --crit:    #C93B4A;
    --info:    #2563EB;
    --shadow:  0 16px 34px -24px rgba(16,40,60,.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* --- Ossature ------------------------------------------------------------ */

.shell { display: flex; min-height: 100vh; }

.side {
  width: 216px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--edge);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -.015em; }
.brand-sub {
  font-family: var(--mono); font-size: 10px; color: var(--ink-3);
  letter-spacing: .07em; text-transform: uppercase;
}

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}
.nav a:hover { background: var(--panel-2); color: var(--ink); text-decoration: none; }
.nav a.on { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.nav a svg { flex-shrink: 0; opacity: .85; }

.side-foot { margin-top: auto; padding: 0 8px; font-size: 12px; color: var(--ink-3); }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.02em; }
.page-head p { margin: 3px 0 0; color: var(--ink-2); font-size: 13.5px; }

/* --- Bandeau de synthèse ------------------------------------------------- */

.summary { display: flex; gap: 28px; flex-wrap: wrap; align-items: center; }
.stat { display: flex; flex-direction: column; }
.stat-v {
  font-family: var(--mono); font-size: 20px; font-weight: 500;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.15;
}
.stat-v .unit { font-size: 13px; color: var(--ink-2); }
.stat-l { font-size: 11px; color: var(--ink-3); letter-spacing: .07em; text-transform: uppercase; }

.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  display: inline-block; margin-right: 7px; vertical-align: middle;
  animation: pulse 2.6s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  70%  { box-shadow: 0 0 0 7px color-mix(in srgb, var(--ok) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 0%, transparent); }
}

/* --- Le téléphone -------------------------------------------------------- */

.fleet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(224px, 1fr));
  gap: 26px 22px;
  align-items: start;
}

.device { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.device a.phone-link { display: block; width: 100%; max-width: 224px; }

.phone {
  position: relative; width: 100%; max-width: 224px;
  aspect-ratio: 71 / 148;
  background: var(--phone-frame);
  border: 1px solid var(--phone-edge);
  border-radius: 30px;
  padding: 7px;
  box-shadow: var(--shadow);
}

.device[data-state="online"] .phone::after {
  content: ""; position: absolute; inset: -1px;
  border-radius: 30px; padding: 1px;
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--accent) 55%, transparent), transparent 42%,
    color-mix(in srgb, var(--accent-2) 28%, transparent));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  pointer-events: none;
}
.device[data-alert="crit"] .phone::after {
  background: linear-gradient(160deg, color-mix(in srgb, var(--crit) 65%, transparent), transparent 45%);
}

.screen {
  position: relative; height: 100%; border-radius: 24px;
  background: var(--screen); overflow: hidden;
  display: flex; flex-direction: column;
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
  color: var(--screen-ink);
}
.device[data-state="offline"] .screen,
.device[data-state="disabled"] .screen { background: var(--screen-off); }

.screen::before {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: linear-gradient(148deg, rgba(255,255,255,.055) 0%, rgba(255,255,255,.012) 26%, transparent 48%);
}

.punch {
  position: absolute; top: 9px; left: 50%; transform: translateX(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: #010306; z-index: 4;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.07);
}

.statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 9px 13px 0; height: 26px;
  font-size: 9.5px; font-weight: 500; color: var(--screen-ink-2);
}
.carrier { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-right { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }

.bars { display: flex; align-items: flex-end; gap: 1.5px; height: 9px; }
.bars i { width: 2px; background: var(--screen-line); border-radius: .5px; display: block; }
.bars i:nth-child(1) { height: 3px; }
.bars i:nth-child(2) { height: 5px; }
.bars i:nth-child(3) { height: 7px; }
.bars i:nth-child(4) { height: 9px; }
.bars i.on { background: var(--screen-ink); }
.device[data-alert="warn"] .bars i.on { background: var(--warn); }

.net { font-size: 8.5px; font-weight: 700; letter-spacing: .04em; }
.batt-pct { font-size: 9px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

.batt { position: relative; width: 17px; height: 9px; border: 1px solid var(--screen-ink-2); border-radius: 2.5px; padding: 1px; }
.batt::after {
  content: ""; position: absolute; right: -3px; top: 50%; transform: translateY(-50%);
  width: 1.5px; height: 4px; background: var(--screen-ink-2); border-radius: 0 1px 1px 0;
}
.batt i { display: block; height: 100%; border-radius: 1px; background: var(--screen-ink); }
.batt.low i { background: var(--warn); }
.batt.crit i { background: var(--crit); }
.bolt { color: var(--accent); font-size: 9px; line-height: 1; }

.screen-body { flex: 1; display: flex; flex-direction: column; padding: 18px 15px 15px; gap: 3px; position: relative; z-index: 2; }
.dev-name { font-size: 17px; font-weight: 700; letter-spacing: -.015em; line-height: 1.2; }
.dev-num { font-family: var(--mono); font-size: 11px; color: var(--screen-ink-2); font-variant-numeric: tabular-nums; }
.sim-tag { font-family: var(--sans); font-size: 8.5px; font-weight: 600; letter-spacing: .05em; color: var(--screen-ink-3); margin-right: 5px; }

.state { display: flex; align-items: center; gap: 6px; margin-top: 14px; font-size: 12px; font-weight: 500; }
.dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot.ok { background: var(--ok); }
.dot.off { background: var(--screen-ink-3); }
.dot.wait { background: var(--accent-2); }
.seen { font-size: 10.5px; color: var(--screen-ink-3); font-family: var(--mono); margin-top: 1px; }

.spacer { flex: 1; min-height: 10px; }

.metrics { display: flex; gap: 14px; padding-top: 11px; border-top: 1px solid var(--screen-line); }
.metric { display: flex; flex-direction: column; }
.metric b { font-family: var(--mono); font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.metric span { font-size: 8.5px; font-family: var(--sans); color: var(--screen-ink-3); letter-spacing: .06em; text-transform: uppercase; }
.metric.good b { color: var(--ok); }
.metric.bad b { color: var(--crit); }

.alert { margin: 10px -15px -15px; padding: 8px 15px; font-size: 10px; font-weight: 500; line-height: 1.35; display: flex; gap: 7px; align-items: flex-start; }
.alert.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); border-top: 1px solid color-mix(in srgb, var(--warn) 32%, transparent); }
.alert.crit { background: color-mix(in srgb, var(--crit) 15%, transparent); color: var(--crit); border-top: 1px solid color-mix(in srgb, var(--crit) 32%, transparent); }

.off-screen, .pairing {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 20px; text-align: center;
}
.off-screen .n { font-size: 14px; font-weight: 600; color: var(--screen-ink-3); }
.off-screen .t { font-family: var(--mono); font-size: 10px; color: #3A4A59; }
.pairing .h { font-size: 12px; font-weight: 600; }
.pairing .code {
  font-family: var(--mono); font-size: 16px; font-weight: 600; letter-spacing: .16em;
  color: var(--accent); padding: 8px 10px;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 8px;
}
.pairing .p { font-size: 10px; color: var(--screen-ink-3); line-height: 1.4; max-width: 150px; }

.caption { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink-3); font-family: var(--mono); }
.caption .sep { opacity: .45; }

/* --- Panneaux, tableaux, formulaires ------------------------------------- */

.panel { background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius); }
.panel + .panel { margin-top: 20px; }
.panel-head { padding: 15px 18px; border-bottom: 1px solid var(--edge); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.panel-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.panel-body { padding: 18px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-wrap { overflow-x: auto; }
th {
  text-align: left; padding: 10px 14px; font-size: 10.5px; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3);
  border-bottom: 1px solid var(--edge); white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid color-mix(in srgb, var(--edge) 55%, transparent); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.queued     { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.pill.dispatched,
.pill.sending    { background: color-mix(in srgb, var(--accent-2) 15%, transparent); color: var(--accent-2); }
.pill.sent       { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.pill.delivered  { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.failed,
.pill.undelivered{ background: color-mix(in srgb, var(--crit) 15%, transparent); color: var(--crit); }
.pill.unknown,
.pill.canceled   { background: color-mix(in srgb, var(--ink-3) 18%, transparent); color: var(--ink-2); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: 8px; border: 1px solid var(--edge);
  background: var(--panel-2); color: var(--ink);
  font-family: var(--sans); font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); text-decoration: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #04141A;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); background: transparent; }
.btn.sm { padding: 5px 11px; font-size: 12.5px; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; letter-spacing: .02em; }

input[type=text], input[type=email], input[type=password], input[type=url], textarea, select {
  width: 100%; padding: 9px 12px;
  background: var(--ground); color: var(--ink);
  border: 1px solid var(--edge); border-radius: 8px;
  font-family: var(--sans); font-size: 14px;
}
textarea { font-family: var(--sans); resize: vertical; min-height: 88px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; }

.field + .field { margin-top: 15px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 180px; }

.hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--ink-3); }
.empty { padding: 42px 20px; text-align: center; color: var(--ink-3); font-size: 13.5px; }

.flash {
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px;
  font-size: 13.5px; border: 1px solid;
}
.flash.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ok); }
.flash.err { background: color-mix(in srgb, var(--crit) 12%, transparent); border-color: color-mix(in srgb, var(--crit) 35%, transparent); color: var(--crit); }

.secret-box {
  font-family: var(--mono); font-size: 13px; word-break: break-all;
  background: var(--ground); border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 8px; padding: 13px 15px; color: var(--accent);
}

/* --- Chronologie d'un message ------------------------------------------- */

.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: 14px; padding: 11px 0; position: relative; }
.tl-item:not(:last-child)::before {
  content: ""; position: absolute; left: 5px; top: 26px; bottom: -6px;
  width: 1px; background: var(--edge);
}
.tl-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; margin-top: 5px; border: 2px solid var(--panel); }
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-size: 13.5px; font-weight: 600; }
.tl-meta { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.tl-desc { font-size: 13px; color: var(--ink-2); margin-top: 2px; }

/* --- Connexion ----------------------------------------------------------- */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 372px; }
.login-card .panel-body { padding: 26px; }
.login-brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 24px; }

/* --- QR ------------------------------------------------------------------ */

.qr-box { background: #fff; padding: 14px; border-radius: 12px; display: inline-block; line-height: 0; }
.qr-box svg { display: block; width: 208px; height: 208px; }

.pair-code {
  font-family: var(--mono); font-size: 25px; font-weight: 600; letter-spacing: .2em;
  color: var(--accent); text-align: center;
}

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: auto; flex-direction: row; align-items: center; gap: 18px; padding: 12px 16px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--edge); }
  .nav { flex-direction: row; }
  .side-foot { margin-top: 0; }
  .main { padding: 20px 16px 48px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
