/* The owner-only admin panel (public/admin.js, docs/admin-panel/DESIGN.md).
   Dark is the default (no data-theme attribute); [data-theme="light"] is the
   override. Colours come from style.css's tokens. Every section shows in
   full: no inner scroll areas on a big screen. The charts are the Brands
   board's (pbPlot), so their rules are the board's, scoped to this tab. */

#tab-admin {
  --adm-person: #3987e5;
  --adm-browser: #8fb8ec;
  --adm-bot: #8a6d3b;
  --adm-scanner: #ff5a52;
  --adm-real: #e8a832;
  --adm-other: #6f6a60;
  --adm-ok: #00e676;
  --adm-error: #ff5a52;
  --pb-ig: #3987e5; --pb-yt: #d95926; --pb-tt: #23b5a8; --pb-x: #ecebe4;
  --pb-line: rgba(232, 168, 50, 0.12);
}
[data-theme="light"] #tab-admin {
  --adm-person: #2a78d6;
  --adm-browser: #9cc0ea;
  --adm-bot: #996600;
  --adm-scanner: #cc1133;
  --adm-real: #20201e;
  --adm-other: #b5b2aa;
  --adm-ok: #1a8a4a;
  --adm-error: #cc1133;
  --pb-ig: #2a78d6; --pb-yt: #eb6834; --pb-tt: #0f9488; --pb-x: #20201e;
  --pb-line: rgba(0, 0, 0, 0.08);
}

#tab-admin .adm-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 16px; margin-bottom: 16px; }
#tab-admin .adm-title { margin: 0; font-size: 20px; font-weight: 800; color: var(--text); }
#tab-admin .adm-title:focus { outline: none; }
#tab-admin .adm-sub { margin: 4px 0 0; font-size: 13px; line-height: 1.5; color: var(--text-secondary); }
#tab-admin .adm-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
#tab-admin .adm-seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-full); overflow: hidden; }
#tab-admin .adm-seg button { border: 0; background: none; padding: 5px 12px; font: inherit; font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer; }
#tab-admin .adm-seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
#tab-admin .adm-seg button:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; }
#tab-admin .adm-updated { font-size: 12.5px; color: var(--text-muted); }

#tab-admin #adm-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
/* The app's body zoom (1.25) makes these minimums a quarter wider on screen:
   four charts and all nine tiles fit in a row on a 1680 px window. */
#tab-admin .adm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 16px; }
#tab-admin .adm-box { min-width: 0; padding: 14px 16px; border: 1px solid var(--tile-border); border-radius: var(--radius-md); background: var(--tile-bg); }
#tab-admin .adm-box-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; margin-bottom: 10px; }
#tab-admin .adm-box-head h3 { margin: 0; font-size: 15px; font-weight: 700; color: var(--text); }
#tab-admin .adm-box h4 { margin: 10px 0 4px; font-size: 12.5px; font-weight: 700; color: var(--text-secondary); }
#tab-admin .adm-box h4:first-child { margin-top: 0; }
#tab-admin .adm-muted { color: var(--text-muted); font-size: 12.5px; }
#tab-admin .adm-good { color: var(--success); }
#tab-admin .adm-warn { color: var(--warm); }
#tab-admin .adm-bad { color: var(--danger); }
#tab-admin .adm-missing { margin: 0; color: var(--text-secondary); font-size: 13px; }
#tab-admin .adm-missing span { font-weight: 700; margin-right: 4px; }
#tab-admin .adm-error p { margin: 0 0 8px; color: var(--danger); }
#tab-admin .adm-counts { margin: -6px 0 0; }

/* KPI tiles: label, big value (or a dash), subline, note. */
#tab-admin .adm-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 132px), 1fr)); gap: 12px; }
#tab-admin .adm-kpis.is-small { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin-bottom: 8px; }
#tab-admin .adm-tile { min-width: 0; padding: 12px 14px; border: 1px solid var(--tile-border); border-radius: var(--radius-md); background: var(--tile-bg); }
#tab-admin .adm-kpis.is-small .adm-tile { padding: 8px 10px; }
#tab-admin .adm-tile-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
#tab-admin .adm-tile-value { margin-top: 2px; font-size: 28px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.15; }
#tab-admin .adm-kpis.is-small .adm-tile-value { font-size: 20px; }
#tab-admin .adm-tile.is-missing .adm-tile-value { color: var(--text-muted); }
#tab-admin .adm-tile-sub { margin-top: 4px; font-size: 12px; line-height: 1.4; color: var(--text-secondary); }
#tab-admin .adm-tile-note { margin-top: 4px; font-size: 12px; line-height: 1.4; color: var(--warm); }

/* Needs attention. */
#tab-admin .adm-attn { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#tab-admin .adm-attn li { display: flex; align-items: baseline; gap: 8px; font-size: 13.5px; line-height: 1.45; }
#tab-admin .adm-attn-text { min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; }
#tab-admin .adm-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); transform: translateY(-1px); }
#tab-admin .adm-attn li.is-bad .adm-dot { background: var(--danger); }
#tab-admin .adm-attn li.is-warn .adm-dot { background: var(--warm); }
#tab-admin .adm-attn li.is-info .adm-dot { background: var(--adm-person); }

/* Users: a full-height table on a big screen (no inner scroll), stacked
   cards on a narrow one. */
#tab-admin .adm-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 10px; font-size: 13px; color: var(--text-secondary); }
#tab-admin .adm-toolbar label { display: inline-flex; align-items: center; gap: 6px; }
#tab-admin .adm-toolbar select, #tab-admin .adm-search { font: inherit; font-size: 13px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 5px 8px; }
#tab-admin .adm-search { min-width: min(100%, 260px); }
#tab-admin .adm-users, #tab-admin .adm-table, #tab-admin .adm-mini { width: 100%; border-collapse: collapse; font-size: 12.5px; color: var(--text); }
#tab-admin .adm-users th, #tab-admin .adm-users td,
#tab-admin .adm-table th, #tab-admin .adm-table td,
#tab-admin .adm-mini th, #tab-admin .adm-mini td { padding: 6px 8px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); line-height: 1.4; }
#tab-admin .adm-users thead th, #tab-admin .adm-table thead th, #tab-admin .adm-mini thead th { font-size: 11.5px; font-weight: 600; color: var(--text-muted); vertical-align: bottom; }
/* break-word, not anywhere: an email keeps its column wide enough to show it
   whole on a big screen, and still wraps where nothing else fits. */
#tab-admin .adm-users td, #tab-admin .adm-table td, #tab-admin .adm-mini td { overflow-wrap: break-word; }
#tab-admin .adm-users td:first-child { min-width: 190px; }
#tab-admin .adm-table tbody th { font-weight: 600; }
#tab-admin .adm-table tr.is-bad th { color: var(--danger); }
#tab-admin .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#tab-admin .adm-user-btn { border: 0; background: none; padding: 0; font: inherit; color: var(--text); cursor: pointer; text-align: left; text-decoration: underline; text-decoration-color: var(--border-hover); text-underline-offset: 2px; overflow-wrap: anywhere; }
#tab-admin .adm-user-btn:hover { text-decoration-color: currentColor; }
#tab-admin .adm-user-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
#tab-admin .adm-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }
#tab-admin .adm-user-row.is-open td { background: var(--glass-hover); }
#tab-admin .adm-pill { display: inline-block; padding: 1px 8px; border-radius: var(--radius-full); background: var(--accent-dim); color: var(--text-secondary); font-size: 11.5px; font-weight: 700; white-space: nowrap; }
#tab-admin .adm-pill.is-real { background: var(--success-dim); color: var(--success); }
#tab-admin .adm-pill.is-owner { background: var(--warm-dim); color: var(--warm); }
#tab-admin .adm-drawer { padding: 6px 2px 10px; }
#tab-admin .adm-loose-drawer { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px 0; margin-bottom: 10px; background: var(--glass-hover); }
#tab-admin .adm-loose-drawer > p { margin: 0 0 4px; font-size: 13px; overflow-wrap: anywhere; }
#tab-admin .adm-drawer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px 24px; }
#tab-admin .adm-drawer-grid .is-wide { grid-column: 1 / -1; }
#tab-admin .adm-drawer p { margin: 0 0 6px; font-size: 13px; }
#tab-admin .adm-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }

@media (max-width: 1100px) {
  #tab-admin .adm-users thead { display: none; }
  #tab-admin .adm-users, #tab-admin .adm-users tbody { display: block; }
  #tab-admin .adm-users tr.adm-user-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  #tab-admin .adm-users tr.adm-user-row td { display: block; padding: 0; border: 0; }
  #tab-admin .adm-users tr.adm-user-row td:first-child { grid-column: 1 / -1; }
  #tab-admin .adm-users tr.adm-user-row td::before { content: attr(data-label); display: block; font-size: 11.5px; font-weight: 600; color: var(--text-muted); }
  #tab-admin .adm-users tr.adm-drawer-row, #tab-admin .adm-users tr.adm-drawer-row td { display: block; padding: 0; border: 0; }
  #tab-admin .adm-users td { overflow-wrap: anywhere; }
}
/* The funnel on a phone: the step and its two numbers on a line, what it
   counts under them. */
@media (max-width: 640px) {
  #tab-admin .adm-table thead { display: none; }
  #tab-admin .adm-table, #tab-admin .adm-table tbody { display: block; }
  #tab-admin .adm-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 2px 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
  #tab-admin .adm-table th, #tab-admin .adm-table td { padding: 0; border: 0; }
  #tab-admin .adm-table td:last-child { grid-column: 1 / -1; overflow-wrap: anywhere; }
  #tab-admin .adm-mini { font-size: 11.5px; }
  #tab-admin .adm-mini th, #tab-admin .adm-mini td { padding: 4px; overflow-wrap: anywhere; }
}

/* Top lists: entry pages, referrers, countries. */
#tab-admin .adm-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 10px 18px; margin-bottom: 8px; }
#tab-admin .adm-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; font-size: 12.5px; }
#tab-admin .adm-bars li { display: grid; grid-template-columns: minmax(0, 1fr) 60px auto; align-items: center; gap: 8px; }
#tab-admin .adm-bar-key { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
#tab-admin .adm-meter { display: block; height: 4px; border-radius: 2px; background: var(--pb-line); overflow: hidden; }
#tab-admin .adm-meter span { display: block; height: 100%; background: var(--adm-person); }

/* The board's one-bar-a-day plot (pbPlot), scoped to this tab. */
#tab-admin .pb-c-person { background: var(--adm-person); }
#tab-admin .pb-c-browser { background: var(--adm-browser); }
#tab-admin .pb-c-bot { background: var(--adm-bot); }
#tab-admin .pb-c-scanner { background: var(--adm-scanner); }
#tab-admin .pb-c-real { background: var(--adm-real); }
#tab-admin .pb-c-other { background: var(--adm-other); }
#tab-admin .pb-c-ok { background: var(--adm-ok); }
#tab-admin .pb-c-error { background: var(--adm-error); }
#tab-admin .pb-c-branded { background: var(--adm-real); }
#tab-admin .pb-c-instagram { background: var(--pb-ig); }
#tab-admin .pb-c-youtube { background: var(--pb-yt); }
#tab-admin .pb-c-tiktok { background: var(--pb-tt); }
#tab-admin .pb-c-x { background: var(--pb-x); }
#tab-admin .pb-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--text-secondary); }
#tab-admin .pb-legend li { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
#tab-admin .pb-swatch { display: inline-block; width: 10px; height: 10px; flex: none; }
#tab-admin .pb-swatch-fresh { display: inline-flex; flex-direction: column-reverse; opacity: 0.45; }
#tab-admin .pb-swatch-fresh span { flex: 1 1 0; }
#tab-admin .pb-swatch-none { display: inline-block; width: 4px; height: 4px; margin: 0 3px; border-radius: 50% !important; background: var(--text-muted); flex: none; }
#tab-admin .pb-slot.is-none::after { content: ""; position: absolute; left: 50%; bottom: -2px; width: 3px; height: 3px; margin-left: -1.5px; border-radius: 50% !important; background: var(--text-muted); opacity: 0.75; }
#tab-admin .pb-bars { position: relative; margin-top: 22px; padding-left: 50px; }
#tab-admin .pb-plot { position: relative; height: 132px; }
#tab-admin .pb-grid-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--pb-line); }
#tab-admin .pb-grid-line span { position: absolute; right: calc(100% + 6px); top: -9px; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
#tab-admin .pb-slots { position: absolute; inset: 0; display: flex; }
#tab-admin .pb-slot { flex: 1 1 0; min-width: 0; position: relative; border: 0; background: none; padding: 0; cursor: pointer; border-radius: 6px 6px 0 0; }
#tab-admin .pb-slot:hover, #tab-admin .pb-slot[aria-pressed="true"] { background: var(--glass-strong); }
#tab-admin .pb-slot:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; }
#tab-admin .pb-col { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: min(24px, 72%); display: flex; flex-direction: column-reverse; }
#tab-admin .pb-part { display: block; flex: none; }
#tab-admin .pb-part + .pb-part { border-bottom: 1px solid var(--bg); }
#tab-admin .pb-col.is-fresh { opacity: 0.45; }
#tab-admin .pb-bars.is-dense .pb-col { width: max(2px, 62%); }
#tab-admin .pb-bars.is-dense .pb-slot { border-radius: 0; }
#tab-admin .pb-col-v { position: absolute; z-index: 2; left: 50%; transform: translateX(-50%); display: none; font-size: 12.5px; font-weight: 700; white-space: nowrap; color: var(--text); font-variant-numeric: tabular-nums; pointer-events: none; text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg), 0 0 2px var(--bg); }
#tab-admin .pb-slot.is-marked .pb-col-v, #tab-admin .pb-slot[aria-pressed="true"] .pb-col-v { display: block; }
#tab-admin .pb-slots:has(.pb-slot[aria-pressed="true"]:not(.is-marked) > .pb-col-v) .pb-slot.is-marked:not([aria-pressed="true"]) .pb-col-v { display: none; }
#tab-admin .pb-dates { position: relative; height: 18px; margin-top: 6px; font-size: 12px; color: var(--text-muted); }
#tab-admin .pb-dates span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; line-height: 1.25; }
#tab-admin .pb-dates span.is-fresh { color: var(--text-secondary); font-weight: 600; }
@media (max-width: 560px) { #tab-admin .pb-dates span.is-extra { display: none; } }
#tab-admin .adm-chart-detail { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--pb-line); font-size: 13.5px; min-height: 1.5em; color: var(--text); }
#tab-admin .pb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
