:root {
  --bg: #0b0e14;
  --panel: #141925;
  --panel-2: #1b2230;
  --line: #232b3a;
  --ink: #e6e9ef;
  --muted: #8b95a7;
  --accent: #5b8cff;
  --accent-2: #36d399;
  --warn: #f0a93b;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-weight: 400; font-size: 11px; text-transform: none; letter-spacing: 0; }

/* ---- gate ---- */
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; padding: 16px; }
.gate form {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px; width: min(360px, 92vw);
  display: flex; flex-direction: column; gap: 14px;
}
.gate h1 { margin: 0; font-size: 18px; }
.gate p { margin: 0; color: var(--muted); font-size: 13px; }

input, select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 9px 11px; outline: none; font: inherit; max-width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 14px; font-weight: 600; }
.btn.ghost { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }

/* ---- shell (mobile-first: wraps, sticky) ---- */
header.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(11,14,20,.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 15px; margin: 0; letter-spacing: .02em; }
.bar .spacer { flex: 1 1 100%; height: 0; }
.bar select { flex: 1 1 auto; min-width: 0; }
.live { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2);
  box-shadow: 0 0 0 0 rgba(54,211,153,.6); animation: pulse 2s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(54,211,153,.5)} 70%{box-shadow:0 0 0 8px rgba(54,211,153,0)} }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel); color: var(--muted); border: 0; padding: 7px 12px; font-size: 13px; }
.seg button.on { background: var(--accent); color: #fff; }

main { padding: 14px; max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

.grid2 { display: grid; grid-template-columns: 1fr; gap: 14px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card > h2 { font-size: 12px; margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--line);
  color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }

/* tables scroll horizontally instead of squashing on narrow screens */
.tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.path { font-family: var(--mono); font-size: 12px; max-width: 60vw; overflow: hidden;
  text-overflow: ellipsis; }
.bar-cell { position: relative; }
.bar-cell .fill { position: absolute; inset: 0; background: rgba(91,140,255,.14); z-index: 0; }
.bar-cell span { position: relative; z-index: 1; }
.empty { padding: 18px 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel-2);
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }

/* ---- labels ---- */
.lbadge { font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .04em; margin-right: 6px; vertical-align: middle; }
.lbadge.me { background: rgba(54,211,153,.16); color: var(--accent-2); border: 1px solid rgba(54,211,153,.4); }
.lbadge.known { background: rgba(91,140,255,.16); color: var(--accent); border: 1px solid rgba(91,140,255,.4); }
.lbadge.unknown { background: rgba(240,169,59,.14); color: var(--warn); border: 1px solid rgba(240,169,59,.4); }

.lfilter { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  overflow-x: auto; -webkit-overflow-scrolling: touch; }
.lfilter button { flex: 0 0 auto; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; font-size: 12px; }
.lfilter button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.vcard.is-me { box-shadow: inset 3px 0 0 var(--accent-2); }
.vcard.is-known { box-shadow: inset 3px 0 0 var(--accent); }
.vcard.is-unknown { box-shadow: inset 3px 0 0 var(--warn); }

/* ---- dossier label controls ---- */
.label-ctl { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.lc-row { display: flex; gap: 8px; flex-wrap: wrap; }
.lc { flex: 1 1 auto; min-width: 72px; background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-size: 13px; font-weight: 600; }
.lc.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.lc[data-kind="me"].on { background: var(--accent-2); border-color: var(--accent-2); color: #06281c; }
.lc[data-kind="unknown"].on { background: var(--warn); border-color: var(--warn); color: #2a1c04; }
.lc.clear { flex: 0 0 auto; min-width: 0; color: var(--muted); font-weight: 500; }
.lc.clear.off { opacity: .4; }
.lc:disabled { opacity: .5; }
.lc-name { width: 100%; }
.lc-hint { color: var(--muted); font-size: 12px; }

/* ---- signature: visitor feed ---- */
.feed > h2 { position: sticky; top: 0; }
.vlist { display: flex; flex-direction: column; }
.vcard {
  display: flex; flex-direction: column; gap: 7px;
  width: 100%; text-align: left; background: transparent; color: inherit;
  border: 0; border-bottom: 1px solid var(--line); padding: 13px 14px;
}
.vcard:active { background: var(--panel-2); }
@media (hover: hover) { .vcard:hover { background: var(--panel-2); } }
.vc-top { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.vc-path { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex: 1; }
.vc-when { color: var(--accent-2); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vc-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--panel-2);
  border: 1px solid var(--line); white-space: nowrap; }
.vc-meta { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.vc-counts { font-variant-numeric: tabular-nums; }

/* ---- drawer (desktop right panel) / bottom sheet (mobile) ---- */
.drawer {
  position: fixed; z-index: 40; background: var(--panel);
  display: flex; flex-direction: column;
  transition: transform .28s cubic-bezier(.2,.7,.2,1);
}
.drawer .dh { display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.drawer .dh h3 { margin: 0; font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer .db { overflow: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.x { background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  width: 30px; height: 30px; border-radius: 7px; flex: 0 0 auto; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; opacity: 0;
  pointer-events: none; transition: opacity .25s; }
.scrim.open { opacity: 1; pointer-events: auto; }

/* mobile: bottom sheet */
.drawer { left: 0; right: 0; bottom: 0; max-height: 92vh; height: auto;
  border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  transform: translateY(100%); padding-bottom: var(--safe-b); }
.drawer.open { transform: translateY(0); box-shadow: 0 -20px 60px rgba(0,0,0,.6); }
.drawer .dh::before { content: ""; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 36px; height: 4px; border-radius: 99px; background: var(--line); }
.drawer .dh { position: relative; padding-top: 18px; }

/* ---- dossier ---- */
.dossier { padding: 0 0 16px; }
.d-hero { padding: 16px; text-align: center; border-bottom: 1px solid var(--line); }
.d-hero-big { font-size: 20px; font-weight: 700; text-transform: capitalize; }
.d-hero-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.d-counts { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.d-counts > div { padding: 12px; text-align: center; border-right: 1px solid var(--line); }
.d-counts > div:last-child { border-right: 0; }
.d-counts b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.d-counts span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.spec-grid { margin: 0; padding: 4px 0; }
.spec { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 8px 16px; border-bottom: 1px solid rgba(35,43,58,.5); }
.spec dt { color: var(--muted); font-size: 12px; }
.spec dd { margin: 0; font-size: 13px; word-break: break-word; }
.spec dd .pill { margin-right: 4px; }
.trunc { word-break: break-all; font-size: 11px; color: var(--muted); }
.d-h4 { margin: 0; padding: 14px 16px 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tl .row { padding: 9px 16px; border-bottom: 1px solid rgba(35,43,58,.5); display: flex; gap: 10px; flex-wrap: wrap; }
.tl .t { color: var(--muted); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.tl .p { font-family: var(--mono); font-size: 12px; word-break: break-word; }
.evt { color: var(--accent-2); }

/* ---- page-visitor list inside drawer ---- */
.pv-list { display: flex; flex-direction: column; }
.pv-row { display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left;
  background: transparent; color: inherit; border: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; }
.pv-row:active { background: var(--panel-2); }
@media (hover: hover) { .pv-row:hover { background: var(--panel-2); } }
.pv-row .muted { font-size: 12px; }

.err { color: var(--warn); font-size: 13px; }

/* ---- tablet / desktop ---- */
@media (min-width: 640px) {
  main { padding: 20px; gap: 18px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .bar h1 { font-size: 16px; }
  .bar .spacer { flex: 1; height: auto; }
  .bar select { flex: 0 0 auto; }
  td.path { max-width: 320px; }
}
@media (min-width: 900px) {
  .grid2 { grid-template-columns: 1.5fr 1fr; }

  /* right-side drawer instead of bottom sheet */
  .drawer { top: 0; bottom: auto; left: auto; right: 0; height: 100%; max-height: none;
    width: min(560px, 95vw); border-radius: 0; border-top: 0; border-left: 1px solid var(--line);
    transform: translateX(100%); }
  .drawer.open { transform: translateX(0); box-shadow: -20px 0 60px rgba(0,0,0,.5); }
  .drawer .dh { padding-top: 14px; }
  .drawer .dh::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer, .scrim { transition: none; }
  .dot { animation: none; }
}
