:root {
  --bg:        #0d1117;
  --bg-1:      #131a23;
  --bg-2:      #182029;
  --bg-3:      #1f2934;
  --line:      #2a3441;
  --line-soft: #212a35;
  --fg:        #d7dee7;
  --fg-dim:    #9fabb9;
  --fg-faint:  #838e9c;
  --accent:    #4aa3ff;
  --ok:        #3fb950;
  --fail:      #f85149;
  --warn:      #d29922;
  --idle:      #6e7681;
  --station:   #d29922;
  --oui:       #8b949e;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --rail: 268px;
  --media-h: 132px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 var(--sans);
  overflow: hidden;
}

/* ── top bar ──────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  height: 52px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.bolt { font-size: 20px; }
.brand h1 { font-size: 14px; margin: 0; font-weight: 600; letter-spacing: .2px; }
.sub { margin: 0; font-size: 11px; color: var(--fg-dim); font-family: var(--mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }

.toggle { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--fg-dim); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); margin: 0; }
.toggle:hover { color: var(--fg); }

input[type="search"] {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--fg);
  padding: 5px 9px;
  font: 12px var(--sans);
  min-width: 210px;
}
input[type="search"]:focus { outline: none; border-color: var(--accent); }

/* ── layout ───────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas: "rail panes" "media media";
  height: calc(100% - 52px);
}

.rail   { grid-area: rail;   border-right: 1px solid var(--line); background: var(--bg-1); display: flex; flex-direction: column; min-height: 0; }
.panes  { grid-area: panes;  display: grid; grid-template-columns: 1fr 1fr; min-height: 0; min-width: 0; }
.media { grid-area: media; border-top: 1px solid var(--line); background: var(--bg-1); }

/* ── attempt rail ─────────────────────────────────────────────── */
.rail-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 12px; font-size: 11px; color: var(--fg-dim);
  border-bottom: 1px solid var(--line-soft); text-transform: uppercase; letter-spacing: .5px;
}
.hint { color: var(--fg-faint); text-transform: none; letter-spacing: 0; }

.rail-head .spacer { flex: 1; }
.minibtn {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--fg-dim);
  border-radius: 4px; cursor: pointer; padding: 1px 6px; font-size: 11px; line-height: 1.4;
}
.minibtn:hover { background: #26313d; color: var(--fg); }

.rail-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.rail-foot { padding: 5px 12px; border-top: 1px solid var(--line-soft); }
.rail-foot .hint { font-size: 10px; }

/* ── charger group header ─────────────────────────────────────── */
.grp {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  gap: 2px 6px;
  align-items: baseline;
  padding: 7px 10px 7px 8px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 1;
}
.grp:hover { background: var(--bg-3); }
.grp.open { background: var(--bg-3); }
.grp-caret { grid-column: 1; grid-row: 1; color: var(--fg-faint); font-size: 9px; }
.grp-name {
  grid-column: 2; grid-row: 1; text-align: left;
  font-size: 12px; font-weight: 600; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.grp-name.unnamed { font-family: var(--mono); font-weight: 500; font-size: 11.5px; }
.grp-meta { grid-column: 2 / -1; grid-row: 2; font-size: 10px; font-family: var(--mono); color: var(--fg-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp-count { grid-column: 3; grid-row: 1; font-size: 10px; font-family: var(--mono); color: var(--fg-dim); white-space: nowrap; }
.grp-dots { grid-column: 2 / -1; grid-row: 3; display: flex; gap: 3px; align-items: center; margin-top: 2px; }
.grp-dots .more { font: 9px var(--mono); color: var(--fg-faint); }
.grp-dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.grp-edit {
  grid-column: 4; grid-row: 1; background: none; border: none; color: var(--fg-faint);
  cursor: pointer; font-size: 11px; padding: 0 2px; opacity: 0; justify-self: end;
}
.grp:hover .grp-edit { opacity: 1; }
.grp-edit:hover { color: var(--accent); }
.grp-input {
  grid-column: 2 / -1; grid-row: 1; background: var(--bg); border: 1px solid var(--accent);
  color: var(--fg); border-radius: 4px; padding: 3px 6px; font: 12px var(--sans); width: 100%;
}
.grp-tier { font-size: 9px; padding: 0 5px; border-radius: 8px; border: 1px solid currentColor; }

.rail-item { padding-left: 22px; }

.rail-item {
  padding: 7px 12px;
  border-bottom: 1px solid var(--line-soft);
  border-left: 3px solid transparent;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 8px;
  align-items: baseline;
}
.rail-item:hover { background: var(--bg-2); }
.rail-item.sel { background: #1d2a38; border-left-color: var(--accent); }
.rail-item.idle { opacity: .55; }

.ri-no   { font-family: var(--mono); font-size: 11px; color: var(--fg-faint); }
.ri-mac  { font-family: var(--mono); font-size: 11px; color: var(--fg); overflow: hidden; text-overflow: ellipsis; }
.ri-kw   { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); }
.ri-out  { grid-column: 2 / -1; font-size: 11px; color: var(--fg-dim); }
.ri-dot  { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 5px; vertical-align: 1px; }
.dot-ok { background: var(--ok); } .dot-fail { background: var(--fail); }
.dot-none { background: var(--warn); } .dot-idle { background: var(--idle); }

.ri-link { grid-column: 2 / -1; font-size: 10px; font-family: var(--mono); }
.link-exact   { color: var(--ok); }
.link-station { color: var(--station); }
.link-oui     { color: var(--oui); }
.link-none    { color: var(--fg-faint); }

/* ── panes ────────────────────────────────────────────────────── */
.pane {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  border-right: 1px solid var(--line);
}
.pane-old { border-right: none; }

.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg-2); border-bottom: 1px solid var(--line);
  gap: 10px;
}
.pane-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12px; font-weight: 600; }
.pane-title > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 700; letter-spacing: .5px; }
.badge-new { background: #10304f; color: #79c0ff; }
.badge-old { background: #3a2c12; color: #e3b341; }

.stepper { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.stepper button, .btn, .collapse {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--fg);
  border-radius: 5px; cursor: pointer; padding: 3px 9px; font: 12px var(--sans);
}
.stepper button:hover:not(:disabled), .btn:hover, .collapse:hover { background: #26313d; border-color: #3a4653; }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper span { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); min-width: 46px; text-align: center; }

/* ── metadata grid ────────────────────────────────────────────── */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line-soft);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.mcell { background: var(--bg-1); padding: 5px 9px; min-width: 0; }
.mk { font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--fg-faint); }
.mv { font-family: var(--mono); font-size: 12px; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcell.wide { grid-column: span 2; }        /* the charger MAC must never be clipped */
.mcell.wide .mv { font-size: 12.5px; }
.mv.ok { color: var(--ok); } .mv.fail { color: var(--fail); } .mv.warn { color: var(--warn); }
.mv small { color: var(--fg-faint); font-size: 10px; }

.empty {
  padding: 26px 16px; text-align: center; color: var(--fg-faint); font-size: 12px;
}

/* ── match bar ────────────────────────────────────────────────── */
.matchbar { padding: 6px 12px; font-size: 11px; border-bottom: 1px solid var(--line); background: var(--bg-1); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tier {
  font-size: 10px; padding: 1px 7px; border-radius: 9px; font-weight: 600;
  border: 1px solid currentColor;
}
.tier-exact   { color: var(--ok); }
.tier-station { color: var(--station); }
.tier-oui     { color: var(--oui); }
.matchbar .why { color: var(--fg-dim); }
.mac-chip { font-family: var(--mono); background: var(--bg-3); padding: 1px 6px; border-radius: 4px; }

/* ── chart ────────────────────────────────────────────────────── */
.chartwrap { flex-shrink: 0; border-bottom: 1px solid var(--line); background: var(--bg-1); }
.chartwrap svg { display: block; width: 100%; height: 104px; }
.chartwrap .nochart { padding: 12px; font-size: 11px; color: var(--fg-faint); text-align: center; }
.ch-grid { stroke: var(--line-soft); stroke-width: 1; }
.ch-kw   { fill: rgba(74,163,255,.14); stroke: var(--accent); stroke-width: 1.3; }
.ch-soc  { stroke: var(--ok); stroke-width: 1.2; fill: none; stroke-dasharray: 3 2; }
.ch-lbl  { fill: var(--fg-faint); font: 9px var(--mono); }

/* ── log tools + log ──────────────────────────────────────────── */
.logtools {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px;
  border-bottom: 1px solid var(--line); background: var(--bg-2); flex-shrink: 0;
}
.logtools input[type="search"] { min-width: 0; flex: 1; font-size: 11px; padding: 3px 7px; }
.tagfilter { display: flex; gap: 3px; flex-wrap: wrap; }
.tagbtn {
  font: 10px var(--mono); padding: 2px 6px; border-radius: 4px; cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--fg-dim);
}
.tagbtn.on { color: var(--fg); border-color: var(--accent); background: #17293d; }

.log {
  flex: 1; overflow: auto; font-family: var(--mono); font-size: 11.5px;
  padding: 4px 0; min-height: 0;
}
.lrow {
  display: grid; grid-template-columns: 74px 42px 1fr; gap: 8px;
  padding: 0 10px; white-space: pre-wrap; word-break: break-word;
  content-visibility: auto; contain-intrinsic-size: auto 17px;
}
.lrow:hover { background: var(--bg-2); }
.lt { color: var(--fg-faint); white-space: nowrap; }
.ltag { font-weight: 600; }
.ltxt { color: var(--fg); }
.lrow.sev-E .ltxt { color: var(--fail); }
.lrow.sev-W .ltxt { color: var(--warn); }
.lrow.hit { background: #2d2a12; }
.lcont { color: var(--fg-dim); display: block; }

.tag-EXI  { color: #79c0ff; } .tag-GBT { color: #d2a8ff; }
.tag-CONV { color: #7ee787; } .tag-SLAC{ color: #ffa657; }
.tag-SDP  { color: #56d4dd; } .tag-PLC { color: #a5a5a5; }
.tag-FAIL { color: var(--fail); } .tag-CP { color: #e3b341; }
.tag-LOG  { color: var(--fg-faint); }

.hl-row { color: var(--fg); }

/* ── media ────────────────────────────────────────────────────── */
.media-head { display: flex; align-items: center; gap: 10px; padding: 5px 12px; font-size: 12px; border-bottom: 1px solid var(--line-soft); }
.media-head .spacer { flex: 1; }
.collapse { padding: 1px 7px; }
.btn-file { cursor: pointer; background: var(--bg-3); border: 1px solid var(--line); border-radius: 5px; padding: 3px 9px; font-size: 12px; }
.btn-file:hover { background: #26313d; }

.media-strip {
  height: var(--media-h); overflow-x: auto; overflow-y: hidden;
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
}
.media.collapsed .media-strip { display: none; }
.media.dragover { outline: 2px dashed var(--accent); outline-offset: -4px; }
.dropnote { color: var(--fg-faint); font-size: 11px; margin: 0; }
.dropnote em { color: var(--fg-dim); font-style: normal; }

.media-strip[data-busy]::after {
  content: attr(data-busy); color: var(--accent); font-size: 11px; flex-shrink: 0; padding-left: 8px;
}

.thumb { position: relative; height: 100%; flex-shrink: 0; }
.thumb img,
.thumb video { height: 100%; border-radius: 5px; border: 1px solid var(--line); cursor: zoom-in; display: block; }
/* clips get a play badge so a poster frame is not mistaken for a still */
.thumb .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; text-shadow: 0 0 6px rgba(0,0,0,.8); pointer-events: none;
}
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; font-size: 9px; padding: 2px 4px; background: rgba(0,0,0,.72); color: var(--fg-dim); border-radius: 0 0 5px 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb .del { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.7); border: none; color: #fff; border-radius: 3px; cursor: pointer; font-size: 10px; padding: 1px 5px; opacity: 0; }
.thumb:hover .del { opacity: 1; }
.thumb.pinned .del { display: none; }
.thumb.pinned::after { content: "◆"; position: absolute; top: 3px; right: 4px; color: var(--accent); font-size: 9px; }

/* ── lightbox ─────────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 50;
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px;
}
/* an author-origin display: wins over the UA sheet's [hidden] rule, so say it explicitly */
.lightbox[hidden] { display: none; }
.lightbox img,
.lightbox video { max-width: 92vw; max-height: 84vh; border-radius: 6px; }
.lightbox img[hidden],
.lightbox video[hidden] { display: none; }
.lightbox p { color: var(--fg-dim); font-size: 12px; margin: 0; font-family: var(--mono); }
.lb-close { position: absolute; top: 14px; right: 18px; background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }

/* ── scrollbars ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #2c3742; border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3a4653; }

@media (max-width: 1100px) {
  .panes { grid-template-columns: 1fr; }
  .pane-old { border-top: 1px solid var(--line); }
}

/* ── stars, notes, sync state ─────────────────────────────────── */
.star {
  background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1;
  color: var(--fg-faint); padding: 0 4px; flex-shrink: 0;
}
.star:hover { color: var(--warn); }
.star.on { color: var(--warn); }

.notebar {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 5px 10px; border-bottom: 1px solid var(--line);
  background: var(--bg-1); flex-shrink: 0;
}
.notebar textarea {
  flex: 1; min-height: 22px; max-height: 108px; resize: vertical;
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: 5px;
  color: var(--fg); font: 11.5px/1.45 var(--sans); padding: 4px 7px;
}
.notebar textarea:focus { outline: none; border-color: var(--accent); background: var(--bg-3); }
.notebar textarea:disabled { opacity: .4; cursor: not-allowed; }
.notebar textarea.has { border-color: #35506e; background: var(--bg-3); }
.notestate { font-size: 10px; color: var(--fg-faint); min-width: 42px; padding-top: 5px; }
.notestate.saved { color: var(--ok); }

.syncbadge {
  font-size: 10px; padding: 2px 7px; border-radius: 9px; font-weight: 600;
  border: 1px solid currentColor; color: var(--fg-faint); cursor: help; white-space: nowrap;
}
.syncbadge.shared { color: var(--ok); }
.syncbadge.local  { color: var(--warn); }

.ri-star, .grp-star { color: var(--warn); font-size: 10px; }
.ri-note, .grp-note { color: var(--accent); font-size: 10px; }
.grp-star, .grp-note { grid-row: 1; }
