/* ==========================================================================
   nebty investigations — public dataset browser
   Tokens are lifted verbatim from the nebty design system (colors_and_type.css).
   House rules being followed here, from the system README:
     - Montserrat for headings, Lato for text, both from Google Fonts
     - gray-50 canvas, white cards, 1px borders (borders AND shadow, so it reads
       as a dashboard rather than as marketing)
     - radius 8px, shadow-sm/md only, no glow and no coloured shadows
     - no glassmorphism, no backdrop blur, no left-accent-border cards
     - motion 150-300ms ease-out; hover shifts the brand hex one step darker,
       never a scale; no continuous animation except a loading spinner
   ========================================================================== */

:root {
  --nebty-primary: #4c7fff;
  --nebty-primary-hover: #3b6fee;
  --nebty-accent: #e2856e;
  --nebty-dark: #2b2d42;
  --nebty-off-white: #edf2f4;

  --border: hsl(214.3 31.8% 91.4%);
  --ring: hsl(214 100% 65%);
  --muted: hsl(210 40% 96%);

  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-900: #111827;

  --success: #16a34a;
  --destructive: hsl(0 84.2% 60.2%);
  --warning-bg: #fdebe4;
  --warning-fg: #9c3d23;
  --blue-50: #eff6ff;
  --blue-200: #bfdbfe;

  --font-display: 'Montserrat', ui-sans-serif, system-ui, sans-serif;
  --font-text: 'Lato', ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --radius: 0.5rem;
  --radius-md: 6px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px -1px rgb(0 0 0 / 0.06);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 200ms;
  --container: 84rem;
}

* { box-sizing: border-box; }

html {
  font-family: var(--font-text);
  color: var(--gray-900);
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--gray-50);
  font-size: 1rem;
  line-height: 1.5;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--nebty-dark);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0;
}

a { color: #315fdb; text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: var(--container); margin: 0 auto; padding: 0 1rem; }
@media (min-width: 640px) { .wrap { padding: 0 1.5rem; } }
@media (min-width: 1024px) { .wrap { padding: 0 2rem; } }

/* ----- Header ------------------------------------------------------------ */

.site-header {
  background: var(--nebty-off-white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.site-header .inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 4rem;
}
.brand { display: flex; align-items: center; gap: 0.625rem; transition: opacity var(--dur) var(--ease); }
.brand:hover { opacity: 0.8; text-decoration: none; }
.brand img { height: 26px; width: auto; display: block; }
.brand .sep { color: var(--gray-300); font-size: 1.125rem; }
.brand .section {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--nebty-dark);
}
.header-spacer { flex: 1; }
.header-link {
  font-size: 0.875rem;
  color: var(--gray-600);
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}
.header-link:hover { color: var(--nebty-dark); text-decoration: none; }

/* ----- Hero -------------------------------------------------------------- */

.hero { padding: 2.5rem 0 1.5rem; }
.eyebrow {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--nebty-primary);
  margin-bottom: 0.625rem;
}
.hero h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.75rem; }
@media (min-width: 640px) { .hero h1 { font-size: 2.125rem; } }
.hero .lede {
  font-size: 1.0625rem;
  color: var(--gray-600);
  max-width: 62ch;
  margin: 0 0 1.5rem;
}

/* ----- Stat cards -------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
@media (min-width: 768px) { .stats { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1rem; } }
.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.125rem;
}
.stat .n {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--nebty-dark);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat .k { font-size: 0.8125rem; color: var(--gray-500); margin-top: 0.25rem; }

/* ----- Notice ------------------------------------------------------------ */

.notice {
  background: var(--blue-50);
  border: 1px solid var(--blue-200);
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  margin-bottom: 1.5rem;
  font-size: 0.9375rem;
  color: #1e40af;
}
.notice strong { color: #1e3a8a; }

/* ----- Controls ---------------------------------------------------------- */

.controls {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.125rem;
  margin-bottom: 1rem;
  position: sticky;
  top: 4rem;
  z-index: 20;
}
.search-row { display: flex; gap: 0.625rem; align-items: center; }
.search-wrap { position: relative; flex: 1; }
.search-wrap svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  pointer-events: none;
}
input[type='search'], select {
  font-family: var(--font-text);
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--gray-900);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input[type='search'] {
  width: 100%;
  height: 2.75rem;
  padding: 0 0.875rem 0 2.375rem;
}
input[type='search']:focus, select:focus {
  outline: none;
  border-color: var(--nebty-primary);
  box-shadow: 0 0 0 3px rgb(76 127 255 / 0.15);
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: center;
}
select { height: 2.25rem; padding: 0 2rem 0 0.625rem; font-size: 0.875rem; cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
}
.chk {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  color: var(--gray-600);
  cursor: pointer;
  user-select: none;
  height: 2.25rem;
  padding: 0 0.5rem;
}
.chk input { accent-color: var(--nebty-primary); width: 15px; height: 15px; cursor: pointer; }

/* ----- Buttons ----------------------------------------------------------- */

.btn {
  font-family: var(--font-text);
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: var(--radius);
  padding: 0.5rem 0.875rem;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  line-height: 1;
  min-height: 2.25rem;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--nebty-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--nebty-primary-hover); }
.btn-outline { background: #fff; color: var(--nebty-dark); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--gray-50); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--nebty-dark); }
.btn-sm { font-size: 0.8125rem; padding: 0.375rem 0.625rem; min-height: 2rem; }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Table ------------------------------------------------------------- */

.table-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.result-count { font-size: 0.875rem; color: var(--gray-600); font-variant-numeric: tabular-nums; }
.result-count b { color: var(--nebty-dark); font-weight: 700; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  text-align: left;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-500);
  background: var(--gray-50);
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--nebty-dark); }
thead th .arrow { opacity: 0.35; margin-left: 0.25rem; }
thead th.active .arrow { opacity: 1; color: var(--nebty-primary); }
tbody td { padding: 0.75rem 0.875rem; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.row:hover { background: var(--gray-50); }
tbody tr.row { cursor: pointer; }
.cell-domain { font-family: var(--font-mono); font-size: 0.8125rem; color: var(--nebty-dark); word-break: break-all; }
.cell-brand { font-weight: 700; color: var(--nebty-dark); }
.cell-brand.unnamed { font-weight: 400; color: var(--gray-400); font-style: italic; }
.cell-muted { color: var(--gray-500); font-size: 0.8125rem; }
.actions-cell { text-align: right; white-space: nowrap; }

/* ----- Badges ------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.1875rem 0.5rem;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-confirmed { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badge-likely { background: var(--warning-bg); color: var(--warning-fg); border-color: #f8cfc0; }
.badge-dormant { background: var(--gray-100); color: var(--gray-600); border-color: var(--gray-200); }
.badge-unrelated { background: var(--gray-100); color: var(--gray-500); border-color: var(--gray-200); }
.badge-neutral { background: var(--muted); color: var(--gray-600); border-color: var(--gray-200); }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot-live { background: var(--success); }
.dot-probable { background: var(--nebty-accent); }
.dot-unknown { background: var(--gray-300); }
.live-label { font-size: 0.8125rem; color: var(--gray-600); display: inline-flex; align-items: center; gap: 0.375rem; }

/* ----- Detail panel ------------------------------------------------------ */

tr.detail-row td { background: var(--gray-50); padding: 0; border-bottom: 1px solid var(--border); }
.detail {
  padding: 1.125rem 1.25rem;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) { .detail { grid-template-columns: 1.4fr 1fr; } }
.detail h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.375rem 1rem; font-size: 0.8125rem; }
.kv dt { color: var(--gray-500); }
.kv dd { margin: 0; color: var(--gray-900); word-break: break-word; }
.kv dd.mono { font-family: var(--font-mono); font-size: 0.75rem; }
.sibling-list { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.sibling {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.5rem;
  color: var(--gray-700);
}
.sibling:hover { border-color: var(--nebty-primary); color: var(--nebty-primary); text-decoration: none; }

.scan-result {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 0.75rem 0.875rem;
  font-size: 0.8125rem;
}
.scan-result.err { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.scan-result img {
  margin-top: 0.5rem;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: block;
}

/* ----- Pagination -------------------------------------------------------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.875rem 1.125rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.pager .page-info { font-size: 0.875rem; color: var(--gray-600); font-variant-numeric: tabular-nums; }
.pager .group { display: flex; gap: 0.375rem; align-items: center; }

.empty { padding: 3rem 1.5rem; text-align: center; color: var(--gray-500); }
.empty svg { color: var(--gray-300); margin-bottom: 0.75rem; }
.empty h3 { font-size: 1rem; margin-bottom: 0.375rem; color: var(--gray-700); }
.skeleton {
  height: 0.75rem;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 37%, var(--gray-100) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ----- Footer ------------------------------------------------------------ */

.site-footer {
  margin-top: 3rem;
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 2rem 0;
  font-size: 0.875rem;
  color: var(--gray-500);
}
.site-footer .cols { display: grid; gap: 1.5rem; grid-template-columns: 1fr; }
@media (min-width: 768px) { .site-footer .cols { grid-template-columns: 2fr 1fr 1fr 1fr; } }
.site-footer h4 { font-size: 0.8125rem; color: var(--nebty-dark); margin-bottom: 0.5rem; }
.site-footer a { color: var(--gray-600); }
.site-footer p { margin: 0 0 0.5rem; max-width: 52ch; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.filter-note {
  margin: 0.625rem 0 0;
  font-size: 0.8125rem;
  color: var(--gray-500);
  max-width: 80ch;
}

/* A brand read only from the shop's own page title is the operator's claim, not ours.
   Marked in the row, because the reader decides from the row -- not from an expanded panel
   they may never open. */
.attr-weak {
  display: inline-block;
  max-width: 100%;
  margin-left: 0.4rem;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--warning-fg);
  background: var(--warning-bg);
  border: 1px solid #f8cfc0;
  border-radius: var(--radius-full);
  padding: 0.0625rem 0.375rem;
  vertical-align: middle;
  cursor: help;
}

/* ==========================================================================
   Phone layout
   A forwarded link is most often opened on a phone, and the desktop table does not
   survive the trip: measured at 390px it needed 921px inside a 324px scroller, so five
   of seven columns — including the Re-scan button the page tells you to press — sat
   off-screen with no scrollbar, no fade and no hint they existed.
   Below 768px each row becomes a card instead. Nothing is dropped; the columns are
   relabelled inline from data-label so the row still carries its own verdict and status,
   which is what a reader needs to judge it.
   ========================================================================== */
@media (max-width: 767px) {
  /* The sticky pair ate 539px of an 844px viewport (64%), and all of it once the keyboard
     opened. Only the search stays pinned; the filters scroll away with the page. */
  .controls { position: static; }
  .site-header { position: static; }

  .table-scroll { overflow-x: visible; }
  table, thead, tbody, tr, td { display: block; width: auto; }
  thead { display: none; }

  tbody tr.row {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 0.75rem 0.75rem 0;
    padding: 0.75rem 0.875rem;
    background: #fff;
    box-shadow: var(--shadow-sm);
  }
  tbody tr.row:hover { background: #fff; }
  tbody td { border: none; padding: 0.1875rem 0; }

  /* Domain and brand lead the card; the rest are labelled key/value lines. */
  tbody td.cell-domain {
    font-size: 0.875rem;
    font-weight: 700;
    padding-bottom: 0.25rem;
    overflow-wrap: anywhere;
  }
  /* Grid with exactly two tracks: the label, and ONE element holding the whole value.
     A flex row here put every child of the cell on the same line, so a cell containing a
     long brand plus its "unconfirmed" chip pushed the chip past the right edge and clipped
     it. The value now lives in a single .v box that wraps inside its own column. */
  tbody td[data-label]:not(.cell-domain):not(.actions-cell) {
    display: grid;
    grid-template-columns: 5.75rem minmax(0, 1fr);
    gap: 0.125rem 0.5rem;
    align-items: baseline;
  }
  tbody td[data-label]:not(.cell-domain):not(.actions-cell)::before {
    content: attr(data-label);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-500);
    font-weight: 700;
    line-height: 1.7;
  }
  tbody td .v { min-width: 0; overflow-wrap: anywhere; }
  /* The chip follows the brand text inline and wraps with it rather than being pushed out. */
  tbody td .attr-weak { margin-left: 0; margin-top: 0.25rem; }
  /* A labelled dash is pure noise on a phone. Declared AFTER the flex rules above, which
     would otherwise win on source order and reinstate every empty field. */
  tbody td[data-label][data-empty='1'] { display: none !important; }
  tbody td.actions-cell { text-align: left; padding-top: 0.625rem; }
  tbody td.actions-cell .btn { width: 100%; min-height: 2.75rem; }

  tr.detail-row td { padding: 0; }
  .detail { grid-template-columns: 1fr; padding: 0.875rem 1rem; }
  .kv { grid-template-columns: 1fr; gap: 0.125rem; }
  .kv dt { margin-top: 0.5rem; font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.04em; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters select, .filters .chk, .filters .btn { width: 100%; }
  .search-row { flex-wrap: wrap; }
  .hero h1 { font-size: 1.5rem; }
  .table-head { gap: 0.5rem; }
}

/* Column headers stay put while a long page scrolls; without this the reader loses the
   verdict/status labels the moment they scroll, which are the basis for judging a row. */
@media (min-width: 768px) {
  thead th { position: sticky; top: 4rem; z-index: 10; }
}

.linkish {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: #315fdb;
  cursor: pointer;
  text-decoration: underline;
}
.linkish:hover { color: var(--link-hover, #244bb5); }

/* Outcome messages for actions taken while no row is expanded. */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(92vw, 34rem);
}
.toast {
  background: var(--nebty-dark);
  color: #fff;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
}
.toast.err { background: #7f1d1d; }
.toast a { color: #fff; text-decoration: underline; margin-left: 0.375rem; }

.as-of { font-size: 0.8125rem; color: var(--gray-500); margin: -0.5rem 0 1rem; }

/* Shown only when a single brand is in view: the point at which a brand owner stops
   browsing and needs to leave with something. */
.brand-actions {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0.875rem 1.125rem;
  margin-bottom: 1rem;
}
.brand-actions-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.9375rem;
  color: var(--gray-600);
}
.brand-actions .group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
@media (max-width: 767px) {
  .brand-actions-inner { align-items: stretch; }
  .brand-actions .group { width: 100%; }
  .brand-actions .btn { flex: 1; min-height: 2.75rem; }
}
