﻿/* Hidden admin portal (/admin), rendered by js/admin/shell.js and its section modules. Standalone styles (no
   theme dependency) so the page reads cleanly on its own; palette mirrors the app's cards. Replaces the old
   admin-dash.css + admin-merges.css — the portal merged both pages into one left-nav shell. */
.admin-page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  font-family: "Nunito", system-ui, sans-serif;
  color: #1f2937;
}
.admin-page-wide { max-width: none; }

.admin-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.admin-head h1 { font-size: 22px; margin: 0; flex: 1; }
.admin-back { color: #2563eb; text-decoration: none; font-weight: 600; font-size: 14px; }
.admin-back:hover { text-decoration: underline; }

.admin-status { color: #6b7280; font-size: 14px; margin: 8px 0 16px; }

/* --- portal shell: a left sidebar of grouped sections + one panel --- */

.admin-body {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  margin-top: 14px;
}

.admin-nav-toggle {
  display: none;   /* shown only under the mobile breakpoint below */
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
}

.admin-nav {
  flex: 0 0 200px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
.admin-nav-group { margin: 0 0 18px; }
.admin-nav-title {
  margin: 0 0 4px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #9ca3af;
}
.admin-nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #4b5563;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.admin-nav-item:hover { background: #f3f4f6; color: #1f2937; }
.admin-nav-item[aria-current="true"] { background: #eef2ff; color: #2563eb; }

.admin-panel { flex: 1; min-width: 0; }

@media (max-width: 860px) {
  .admin-nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .admin-body { flex-direction: column; }
  .admin-nav {
    position: fixed;
    inset: 0 25% 0 0;
    z-index: 20;
    background: #fff;
    padding: 16px;
    box-shadow: 2px 0 12px rgba(0, 0, 0, .15);
    transform: translateX(-100%);
    transition: transform .18s ease;
  }
  .admin-nav.open { transform: translateX(0); }
  .admin-panel { width: 100%; }
}

/* --- shared controls (filter/select/status bar) used by every table-shaped section --- */

.ad-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
.ad-controls .admin-status { margin: 0; }

.ad-input, .ad-select {
  font: inherit;
  font-size: 14px;
  color: #1f2937;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 6px 10px;
}
.ad-input { min-width: 280px; }
.ad-input:focus, .ad-select:focus { outline: 2px solid #bfdbfe; border-color: #2563eb; }

.ad-btn {
  font: inherit;
  font-size: 14px;
  color: #1f2937;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.ad-btn:hover { background: #f3f4f6; }
.ad-btn:focus { outline: 2px solid #bfdbfe; border-color: #2563eb; }

/* The table is wider than any screen and can be thousands of rows long: it scrolls inside its own box, so the
   page never scrolls sideways and the header row can stay stuck to the top of that box while scanning. */
.ad-tablewrap {
  overflow: auto;
  max-height: calc(100vh - 220px);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
}

.ad-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  white-space: nowrap;
}
.ad-table th, .ad-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f2f4;
}
/* Count columns hold one or two digits; keep their cells tight so the sideways label above sets the width. */
.ad-table td.ad-r { padding-left: 6px; padding-right: 6px; }

.ad-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 128px;
  padding: 6px 4px;
  vertical-align: bottom;
  background: #f9fafb;
  color: #4b5563;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid #e5e7eb;
}
.ad-table th:hover { color: #1f2937; }
.ad-table th.ad-sorted { color: #2563eb; }
/* A non-sortable header (no data-key) never claimed the pointer cursor / hover color in the first place. */
.ad-table th:not([data-key]) { cursor: default; }
.ad-table th:not([data-key]):hover { color: #4b5563; }

.ad-thwrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  height: 116px;
}
.ad-table th.ad-l .ad-thwrap { align-items: flex-start; }
/* vertical-rl reads top-to-bottom; the 180° turn flips it to bottom-to-top, which is the readable direction. */
.ad-thlabel {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}
.ad-thsort { font-size: 10px; line-height: 1; min-height: 10px; }
.ad-table tbody tr:hover td { background: #fafbfc; }

.ad-l { text-align: left; }
.ad-r { text-align: right; font-variant-numeric: tabular-nums; }
.ad-strong { font-weight: 700; color: #047857; }
.ad-dim { color: #9ca3af; }
.ad-warn { color: #b45309; font-weight: 700; }
.ad-bad { color: #dc2626; font-weight: 700; }

/* A run expands into the groups/searches it swept: indented, tinted, and aligned under the parent's numbers. */
.ad-table tbody tr[data-run] { cursor: pointer; }
.ad-expand { user-select: none; }
.ad-table tbody tr.ad-open .ad-expand { font-weight: 700; }
.ad-table tbody tr.ad-open .ad-expand::first-letter { color: #2563eb; }

.ad-table tr.ad-child td { background: #f8fafc; color: #4b5563; }
.ad-table tr.ad-child:hover td { background: #f1f5f9; }
.ad-childname {
  display: inline-block;
  padding-left: 22px;
  max-width: 480px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.ad-table tr.ad-group td {
  background: #eef2ff;
  font-weight: 700;
  color: #1f2937;
  border-bottom: 1px solid #dbe2fb;
}
.ad-table tr.ad-group:hover td { background: #eef2ff; }

.ad-search {
  color: #2563eb;
  text-decoration: none;
  max-width: 320px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}
.ad-search:hover { text-decoration: underline; }

/* A button styled as a link, for in-page hash navigation (users.js): a real <a href="#..."> resolves against
   <base href="/"> and navigates clean away from /admin instead of just changing the fragment, so these targets
   are buttons that set location.hash in JS instead. */
.ad-linkbtn, .au-detail-back {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: #2563eb;
  text-decoration: none;
  cursor: pointer;
}
.ad-linkbtn:hover, .au-detail-back:hover { text-decoration: underline; }
.au-detail-back { display: inline-block; margin-bottom: 10px; font-weight: 600; font-size: 13px; }

/* --- Logs section --- */

/* Same "scrolls inside its own box" rule as the tables: a log line is long and there are thousands of them, so
   the page itself must never scroll sideways. pre-wrap (not nowrap) keeps stack traces readable. */
.ad-log {
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  max-height: calc(100vh - 220px);
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.ad-log span { display: block; }
.ad-log .ad-log-err { color: #fca5a5; }
.ad-log .ad-log-warn { color: #fcd34d; }
.ad-log .ad-dim { color: #94a3b8; }

/* --- Config section (read-only) --- */

.ad-cfg-group { margin: 0 0 22px; }

.ad-cfg-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #6b7280;
}

.ad-cfg-list { margin: 0; }

/* Key and value on one line, the explanation on its own line beneath in small type — so the page scans as a
   list of settings first, and only gives you the prose when you stop on one. */
.ad-cfg-row {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f3f5;
  display: grid;
  grid-template-columns: minmax(180px, 320px) 1fr;
  column-gap: 14px;
}
.ad-cfg-row:hover { background: #f9fafb; }

.ad-cfg-key { margin: 0; font-size: 13px; font-weight: 600; color: #1f2937; }

.ad-cfg-val {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: #111827;
  word-break: break-all;
}
.ad-cfg-val.ad-cfg-on { color: #047857; font-weight: 600; }
.ad-cfg-val.ad-cfg-off { color: #b45309; font-weight: 600; }

.ad-cfg-hint {
  grid-column: 1 / -1;
  margin: 3px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: #9ca3af;
}

@media (max-width: 720px) {
  .ad-cfg-row { grid-template-columns: 1fr; row-gap: 2px; }
}

/* --- Merges section (card list, not a table) --- */

.am-row {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.am-row.am-reverted { opacity: .6; }

.am-rowhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.am-when { color: #6b7280; font-size: 13px; }

.am-unmerge {
  border: 1px solid #dc2626;
  color: #dc2626;
  background: #fff;
  border-radius: 8px;
  padding: 6px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.am-unmerge:hover:not(:disabled) { background: #dc2626; color: #fff; }
.am-unmerge:disabled { opacity: .6; cursor: default; }

.am-badge {
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  background: #f3f4f6;
  border-radius: 999px;
  padding: 4px 10px;
}

.am-sides {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 12px;
}
.am-arrow {
  align-self: center;
  color: #9ca3af;
  font-size: 22px;
  font-weight: 700;
}

.am-side {
  border: 1px solid #eef0f3;
  border-radius: 10px;
  padding: 10px;
  background: #fafbfc;
}
.am-side.am-merged { background: #fff7ed; border-color: #fed7aa; }

.am-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.am-tag { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #6b7280; }
.am-side.am-merged .am-tag { color: #c2410c; }
.am-side-id { font-size: 12px; color: #2563eb; text-decoration: none; font-weight: 600; }
.am-side-id:hover { text-decoration: underline; }

.am-title { font-weight: 700; font-size: 15px; line-height: 1.25; margin-bottom: 2px; }
.am-meta { font-size: 13px; color: #4b5563; margin-bottom: 8px; }
.am-price { font-weight: 700; color: #111827; }

.am-photos { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.am-photo { display: block; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; background: #eef0f3; }
.am-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.am-more { font-size: 12px; color: #6b7280; font-weight: 600; }
.am-noimg { font-size: 12px; color: #9ca3af; padding: 8px 0; }

@media (max-width: 720px) {
  .am-sides { grid-template-columns: 1fr; }
  .am-arrow { transform: rotate(90deg); justify-self: center; }
}

/* --- Users section: list → detail --- */
/* .au-detail-back itself is styled next to .ad-linkbtn above (same "button as link" reason). */

.au-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.au-avatar { width: 48px; height: 48px; border-radius: 50%; background: #eef0f3; object-fit: cover; }
.au-identity h2 { margin: 0; font-size: 18px; }
.au-identity .ad-dim { font-size: 13px; }

.au-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #2563eb;
  background: #eef2ff;
  border-radius: 999px;
  padding: 3px 9px;
  margin-left: 6px;
}

.au-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.au-stat {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}
.au-stat-n { font-size: 20px; font-weight: 700; color: #1f2937; }
.au-stat-l { font-size: 12px; color: #6b7280; }

.au-section { margin: 0 0 22px; }
.au-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #6b7280;
}
.au-section .ad-dim { font-size: 12px; margin-top: 6px; }

/* A saved search's criteria JSON / an evidence storage key: raw machine text, so it gets mono type and is
   allowed to wrap rather than stretching the card. */
.au-criteria {
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.45;
  color: #6b7280;
  word-break: break-all;
  /* A freehand-zone filter serialises a few hundred polygon points — ~10 KB of coordinates that would
     otherwise bury every block below it. Scrolls inside its own box instead. */
  max-height: 5.8em;
  overflow-y: auto;
  background: #f9fafb;
  border-radius: 6px;
  padding: 6px 8px;
}

/* --- SEO section --- */

.aseo-title { font-weight: 600; }
.aseo-og { color: #6b7280; }

/* --- Shared modal shell (js/admin/ui.js openModal) — today: the Live/Sessions device popup. Its own
   light palette, deliberately NOT the map's .modal-overlay/.modal-card (map.css), which is painted with the
   map's dark theme variables and would render dark-on-dark here. --- */
.ad-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}
.ad-modal-card {
  background: #fff;
  border-radius: 12px;
  max-width: 520px;
  width: 100%;
  max-height: calc(100vh - 80px);
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.ad-modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  background: #fff;
}
.ad-modal-head b { flex: 1; font-size: 15px; }
.ad-modal-close {
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #6b7280;
  padding: 2px 6px;
}
.ad-modal-close:hover { color: #1f2937; }
.ad-modal-body { padding: 14px 16px; }

/* Device popup content: a compact fact grid, section-scoped so it can't clash with .au-grid's stat-tile look. */
.avd-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 13px;
}
.avd-grid dt { color: #6b7280; }
.avd-grid dd { margin: 0; word-break: break-word; }
.avd-ua {
  margin-top: 10px;
  padding: 8px 10px;
  background: #f9fafb;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  word-break: break-all;
}

/* --- Shared analytics: the IP cell and the "not counted" marks, used by Live and Sessions alike --- */
.aip { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.aip-country { display: inline-flex; align-items: center; gap: 4px; }
/* A hairline border so flags that are mostly white (JP, PL) don't dissolve into the row. */
.aip-flag { width: 18px; height: 13px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .12); }
.aip-addr { font-variant-numeric: tabular-nums; }
/* Struck through, not hidden: an ignored address is still shown, it just stops being counted. */
.aip-ignored { text-decoration: line-through; color: #9ca3af; }
.aip-host { color: #6b7280; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.al-excluded { font-size: 11px; padding: 1px 5px; border-radius: 4px; background: #fef3c7; color: #92400e; }

/* --- Live section --- */
.al-auto { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: #4b5563; }
.al-kind { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.al-kind-arrive { background: #dbeafe; color: #1d4ed8; }
.al-kind-open { background: #dcfce7; color: #15803d; }
.al-kind-click { background: #fae8ff; color: #a21caf; }
.al-summary { color: #374151; }

/* --- Sessions section --- */
.as-totals { display: flex; flex-wrap: wrap; gap: 24px; padding: 4px 0 12px; }
.as-total-group { display: flex; align-items: baseline; gap: 14px; }
.as-total-group h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; }
.as-total { display: flex; align-items: baseline; gap: 4px; }
.as-total-n { font-size: 20px; font-weight: 700; color: #1f2937; font-variant-numeric: tabular-nums; }
.as-total-l { font-size: 12px; color: #6b7280; }

/* Long URLs must not widen the table; the full value is on the title attribute. */
.as-landing, .as-referrer { display: inline-block; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.as-landing { color: #6b7280; font-size: 12px; }

.as-detail-back { border: none; background: none; color: #2563eb; font-weight: 600; cursor: pointer; padding: 0 0 12px; font-size: 14px; }
.as-timeline { list-style: none; margin: 0; padding: 0; }
.as-event {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
}
.as-event-when { color: #6b7280; }
.as-event-kind { font-weight: 700; margin-right: 8px; }
.as-event-summary { color: #374151; }
.as-event-thumb { display: block; margin-top: 6px; max-width: 160px; border-radius: 6px; }

/* --- Device popup: the "that's me, don't count it" switch --- */
.avd-actions { display: flex; align-items: center; gap: 10px; padding: 10px 0 4px; font-size: 13px; }
.avd-actions label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* Requests queue. The excerpt column is the one that must not push the actionable columns off screen, so it
   is clamped to a single line; the full post is in the expanded row underneath. */
.ad-req-area { display: inline-block; max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.ad-req-excerpt { display: block; max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .8; }
.ad-req-full { white-space: pre-wrap; max-width: 90ch; margin-bottom: .5rem; }
.ad-req-url { margin: .4rem 0; word-break: break-all; }
.ad-req-reply { white-space: pre-wrap; max-width: 90ch; margin: .4rem 0 0; padding: .5rem .6rem;
  border-left: 3px solid var(--ad-accent, #7E948A); background: rgba(127, 148, 138, .10); font: inherit; }

/* --- Analytics: Live kind picker + Exclusions page ------------------------------------------------ */
/* A <details> popover rather than a tall column of checkboxes: 20 kinds would otherwise push the table
   off the screen, and the summary keeps saying what is on while it is shut. */
.al-kinds { position: relative; display: inline-block; }
.al-kinds-summary { cursor: pointer; list-style: none; user-select: none; display: inline-block; }
.al-kinds-summary::-webkit-details-marker { display: none; }
.al-kinds-summary::after { content: " ▾"; color: #6b7280; }
.al-kinds-menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 260px;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px 12px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .12); max-height: 60vh; overflow-y: auto;
}
.al-kinds-actions { display: flex; gap: 10px; padding-bottom: 6px; border-bottom: 1px solid #f3f4f6; margin-bottom: 6px; }
.al-kinds-group { margin-bottom: 8px; }
.al-kinds-group h4 { margin: 6px 0 3px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #9ca3af; }
.al-kind-opt { display: flex; align-items: center; gap: 6px; padding: 2px 0; white-space: nowrap; cursor: pointer; }

.ax-section { margin-bottom: 22px; }
.ax-h { margin: 0 0 2px; font-size: 14px; }
.ax-hint { margin: 0 0 8px; max-width: 70ch; }
.ax-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ax-add .ad-input { width: auto; min-width: 180px; }
/* Triage tags read as secondary to the one action that matters (Copy + open), so they sit quieter. */
.ad-req-tag { opacity: .55; }
.ad-req-tag:hover { opacity: 1; }
