/* Admin statistics page; shares tokens and controls with styles.css. */
.stats-page { background: var(--bg); }
.stats-head {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
}
.stats-head .home { margin: 0; text-decoration: none; }
.stats-head h1 { margin: 0; font-size: 18px; flex: 1; }
.stats { max-width: 1280px; margin: 0 auto; padding: 20px; }
.sub { font-weight: 400; font-size: 12px; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi__label { font-size: 12px; color: var(--muted); }
.kpi__value { font-size: 26px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi__note { font-size: 12px; color: var(--muted); margin-top: 2px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; min-width: 0; }
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 0 16px; }
.empty-note { color: var(--muted); font-size: 13px; margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.when { white-space: nowrap; color: var(--muted); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.details { color: var(--muted); }
.details b { color: var(--text); font-weight: 500; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text); margin: 1px 4px 1px 0; }
.tag--nda { background: var(--error-bg); color: var(--error-text); }

/* Activity chart: one series (searches/day), hover shows the day's details. */
.chart svg { display: block; width: 100%; height: 200px; overflow: visible; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.is-hover { fill: color-mix(in srgb, var(--accent) 75%, var(--text)); }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; padding: 8px 10px; border-radius: 8px; font-size: 12px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.tooltip b { display: block; margin-bottom: 2px; }

.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.img-card { font-size: 12px; min-width: 0; }
.img-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; background: var(--surface-2); display: block; }
.img-card a { color: inherit; text-decoration: none; }
.img-card__title { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.img-card__nums { color: var(--muted); }

/* Users chart: one stacked bar per user (searches / views / exports), most active first. */
.user-chart { --u1: #2a78d6; --u2: #eb6834; --u3: #1baf7a; margin: 4px 0 16px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .user-chart { --u1: #3987e5; --u2: #d95926; --u3: #199e70; }
}
:root[data-theme="dark"] .user-chart { --u1: #3987e5; --u2: #d95926; --u3: #199e70; }
.user-chart__legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.user-chart__legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.user-chart__rows { display: grid; gap: 4px; }
.user-chart__row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; align-items: center; gap: 12px;
  font-size: 13px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.user-chart__row:hover { background: var(--surface-2); }
.user-chart__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chart__track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-chart__bar { display: flex; gap: 2px; height: 14px; min-width: 2px; }
.user-chart__bar span { height: 100%; min-width: 2px; }
.user-chart__bar span:first-child { border-radius: 4px 0 0 4px; }
.user-chart__bar span:last-child { border-radius: 0 4px 4px 0; }
.user-chart__bar span:only-child { border-radius: 4px; }
.user-chart__total { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.user-chart__more { font-size: 12px; color: var(--muted); margin: 6px 4px 0; }
@media (max-width: 600px) { .user-chart__row { grid-template-columns: 100px 1fr; gap: 8px; } }

.bars { display: grid; gap: 6px; max-width: 640px; }
.bars__row { display: grid; grid-template-columns: 220px 1fr 40px; align-items: center; gap: 10px; font-size: 13px; }
.bars__track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bars__fill { height: 100%; background: var(--accent); border-radius: 4px; }

.preview-form { display: flex; gap: 8px; margin-bottom: 10px; }
.preview-form .input { width: 200px; }
#preview-result .ok { color: var(--text); }
.preview-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.refresh { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.refresh__facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: 13px; }
.refresh__facts dt { color: var(--muted); }
.refresh__facts dd { margin: 0; }
.ok { color: var(--text); }
.fail { color: var(--error-text); }

.role-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: -4px 0 10px; }

.feed-filters { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
#feed-user { cursor: pointer; }
.more { text-align: center; margin-top: 10px; }

@media (max-width: 760px) {
  .stats { padding: 12px; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .bars__row { grid-template-columns: 120px 1fr 32px; }
}
