:root {
  --bg: #0e0f11;
  --panel: #17191d;
  --panel-2: #1d2025;
  --line: #2b2f36;
  --ink: #e9ecef;
  --ink-dim: #9aa3ad;
  --ink-faint: #6b737d;
  --accent: #5aa9ff;
  --warn: #ffb454;
  --ok: #59c98a;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

/* Must beat the display:flex on .detail / .light below, or `hidden` does
   nothing and the overlays cover the page. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #15171b, #101215);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .2px;
  margin: 0;
}

.rainbow { display: flex; flex-direction: column; width: 13px; border-radius: 2px; overflow: hidden; }
.rainbow i { height: 4px; }
.rainbow i:nth-child(1) { background: #61bb46; }
.rainbow i:nth-child(2) { background: #fdb827; }
.rainbow i:nth-child(3) { background: #f5821f; }
.rainbow i:nth-child(4) { background: #e03a3e; }
.rainbow i:nth-child(5) { background: #963d97; }
.rainbow i:nth-child(6) { background: #009ddc; }

.stats { display: flex; gap: 22px; color: var(--ink-dim); font-size: 12.5px; }
.stats b { display: block; color: var(--ink); font-size: 18px; font-weight: 600; line-height: 1.2; }

/* ----------------------------------------------------------- controls */

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: #121418;
  position: sticky;
  top: 61px;
  z-index: 19;
}

.searchwrap { position: relative; flex: 1 1 320px; max-width: 460px; }

#search {
  width: 100%;
  padding: 9px 40px 9px 13px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(90,169,255,.15); }
#search::placeholder { color: var(--ink-faint); }

.searchwrap kbd {
  position: absolute;
  right: 9px; top: 50%;
  transform: translateY(-50%);
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink-faint);
  font: 11px/1.6 ui-monospace, Menlo, monospace;
  pointer-events: none;
}

.filters { display: flex; gap: 7px; flex-wrap: wrap; }

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-dim);
  font-size: 12.5px;
  cursor: pointer;
  transition: .12s;
  white-space: nowrap;
}
.chip:hover { color: var(--ink); border-color: #3a4049; }
.chip[aria-pressed="true"] {
  background: rgba(90,169,255,.14);
  border-color: var(--accent);
  color: #cfe4ff;
}

.count { margin-left: auto; color: var(--ink-faint); font-size: 12.5px; white-space: nowrap; }

/* --------------------------------------------------------------- grid */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  padding: 22px 24px 60px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .13s, border-color .13s;
  display: flex;
  flex-direction: column;
}
.card:hover { transform: translateY(-3px); border-color: #3f4650; }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card figure {
  margin: 0;
  aspect-ratio: 4 / 3;
  background: #0a0b0d;
  position: relative;
  overflow: hidden;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }

.card .n {
  position: absolute;
  right: 7px; bottom: 7px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(4px);
  font-size: 11px;
  color: #dfe4ea;
}

.card .meta { padding: 11px 12px 13px; display: flex; flex-direction: column; gap: 3px; }
.card .id { font: 11px/1 ui-monospace, Menlo, monospace; color: var(--ink-faint); letter-spacing: .4px; }
.card .name { font-weight: 550; font-size: 13.5px; line-height: 1.35; }
.card .sub { font-size: 11.5px; color: var(--ink-dim); }

.flags { display: flex; align-items: center; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.flag {
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 4px;
  border: 1px solid transparent;
}
.flag.issue { background: rgba(255,180,84,.13); color: var(--warn); border-color: rgba(255,180,84,.3); }
.flag.diag  { background: rgba(89,201,138,.13); color: var(--ok);  border-color: rgba(89,201,138,.3); }

.empty { text-align: center; color: var(--ink-faint); padding: 60px 20px; }

/* ------------------------------------------------------------- detail */

.detail { position: fixed; inset: 0; z-index: 40; display: flex; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.72); backdrop-filter: blur(3px); }

.detail-panel {
  position: relative;
  margin: auto;
  width: min(1080px, 94vw);
  max-height: 92vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

/* Grid/flex children default to min-height:auto and refuse to shrink below
   their content, which stops the overflow-y:auto on .detail-body from ever
   engaging — long repair logs then get clipped with no way to scroll. */
.detail-media, .detail-body { min-height: 0; }

.detail-media { background: #08090b; display: flex; flex-direction: column; min-width: 0; }
#d-hero {
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  cursor: zoom-in;
  background: #08090b;
}

.strip { display: flex; gap: 7px; padding: 10px; overflow-x: auto; border-top: 1px solid var(--line); }
.strip img {
  width: 62px; height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  opacity: .55;
  flex: none;
}
.strip img:hover { opacity: .85; }
.strip img[aria-current="true"] { opacity: 1; border-color: var(--accent); }

.detail-body { padding: 26px 26px 30px; overflow-y: auto; min-width: 0; }

.tag {
  display: inline-block;
  font: 11px/1 ui-monospace, Menlo, monospace;
  color: var(--accent);
  background: rgba(90,169,255,.1);
  border: 1px solid rgba(90,169,255,.25);
  padding: 4px 8px;
  border-radius: 5px;
  letter-spacing: .5px;
}

.detail-body h2 { margin: 12px 0 18px; font-size: 21px; line-height: 1.25; font-weight: 600; }

#d-fields { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 9px 16px; align-items: start; }
#d-fields dt { color: var(--ink-faint); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; padding-top: 2px; }
#d-fields dd { margin: 0; font-size: 13.5px; overflow-wrap: anywhere; }
#d-fields dd.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }

/* Named `repair-log`, not `diag` — the card badge already uses `.flag.diag`,
   and a shared class name let this block's padding/border hit the badge. */
.repair-log {
  margin-top: 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.repair-log h3 { margin: 0 0 4px; font-size: 13px; letter-spacing: .4px; text-transform: uppercase; color: var(--ok); }
.repair-log .when { color: var(--ink-faint); font-size: 12px; margin-bottom: 12px; }
.repair-log h4 { margin: 14px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-faint); }
.repair-log p { margin: 0; font-size: 13px; white-space: pre-wrap; line-height: 1.55; }

.close {
  position: absolute;
  top: 12px; right: 14px;
  z-index: 3;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(20,22,26,.85);
  color: var(--ink);
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
}
.close:hover { background: #262a30; }

/* ---------------------------------------------------------- lightbox */

.light { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.95); display: flex; align-items: center; justify-content: center; }
.light img { max-width: 94vw; max-height: 88vh; object-fit: contain; }
.light-cap { position: absolute; bottom: 18px; color: var(--ink-dim); font: 12px ui-monospace, Menlo, monospace; }

.light .nav {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  width: 46px; height: 66px;
  background: rgba(255,255,255,.06);
  border: none;
  color: #fff;
  font-size: 30px;
  cursor: pointer;
  border-radius: 8px;
}
.light .nav:hover { background: rgba(255,255,255,.14); }
.light .prev { left: 16px; }
.light .next { right: 16px; }

@media (max-width: 860px) {
  /* Stacked: photo pane sizes to content, text pane takes the rest and scrolls. */
  .detail-panel { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); max-height: 94vh; }
  .detail-media { max-height: 44vh; }
  .stats { display: none; }
  .controls { top: 57px; }
}
