/* Analytics view (SPA sidebar → Analytics).
 *
 * Everything here is scoped under `.an-` and lives in its own file so it cannot
 * leak into another view — the same modular-CSS rule the studio/company sheets
 * follow. Charts are pure CSS on purpose (no chart library anywhere in the app).
 *
 * The three outcome colours are declared ONCE as custom properties and used by
 * the donut, the stacked platform bars and the day columns, so "green means
 * published" cannot drift between panels.
 */

.an-wrap {
  --an-ok: #16a34a;
  --an-bad: #dc2626;
  --an-mut: #94a3b8;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---- header ------------------------------------------------------------ */
.an-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.an-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}

.an-sub {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 13.5px;
}

.an-open-activity {
  text-decoration: none;
  font-weight: 600;
  display: inline-block;
  white-space: nowrap;
}

/* ---- filter bar -------------------------------------------------------- */
.an-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-start;
  padding: 14px 16px;
  /* `.card` sets `overflow: hidden` (to clip its rounded corners), which cut the
     channel dropdown off at the card's bottom edge — the list looked like it was
     behind a wall. This card has no bleeding background to clip, so it may
     overflow; the menu is `position: absolute` + z-index and then floats OVER
     the tiles below it. */
  overflow: visible;
  position: relative;
  z-index: 5;
}

.an-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.an-field-grow {
  flex: 1 1 100%;
  order: 99;
}

.an-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
}

.an-select,
.an-input {
  height: 36px;
  min-width: 130px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 0 10px;
  box-sizing: border-box;
}

.an-select:focus,
.an-input:focus {
  outline: 2px solid var(--brand-300, #a5b4fc);
  outline-offset: 1px;
}

.an-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.an-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border, #e2e8f0);
  background: #fff;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}

.an-pill img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: none;
}

.an-pill:hover {
  border-color: var(--brand-400, #818cf8);
  color: var(--text);
}

.an-pill.on {
  background: var(--brand-600, #4f46e5);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .35);
}

/* The icon is NEVER recoloured. `brightness(0) invert(1)` used to flatten every
   logo into a white silhouette the moment its pill was selected — Aparat's
   became a blank white square. Colours are the platforms' identity, so they stay;
   the corner radius only keeps a JPEG's baked-in white background from reading as
   a raw square inside the rounded pill. */
.an-pill img {
  border-radius: 4px;
}

.an-globe {
  font-size: 14px;
  line-height: 1;
}

.an-clear {
  align-self: flex-end;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px dashed var(--border, #e2e8f0);
  background: transparent;
  color: var(--text-3);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.an-clear:hover {
  color: var(--an-bad);
  border-color: var(--an-bad);
}

/* ---- channel multi-select ---------------------------------------------- */
.an-multi {
  position: relative;
}

.an-multi-btn {
  cursor: pointer;
  text-align: start;
}

.an-menu {
  position: absolute;
  z-index: 70;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  width: 290px;
  max-height: 320px;
  overflow: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, .18);
}

.an-menu-search {
  width: 100%;
  margin-bottom: 4px;
}

.an-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.an-opt:hover {
  background: var(--surface-2, #f1f5f9);
}

.an-opt input {
  margin: 0;
  flex: none;
}

.an-opt-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-opt small {
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  flex: none;
}

.an-menu-empty {
  padding: 10px 8px;
  font-size: 12.5px;
  color: var(--text-3);
}

.an-menu-clear {
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  border: 0;
  border-top: 1px solid var(--border, #e2e8f0);
  background: transparent;
  color: var(--brand-600, #4f46e5);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

/* A result row in the ADMIN user picker: a <button>, so it keeps .an-opt's look
   (the label/small layout above) but resets the browser's button box. */
.an-opt-btn {
  width: 100%;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text);
  text-align: start;
  cursor: pointer;
}

/* Text that behaves like a link but is a button (or an <a> that must not look
   like the browser's default blue). Used by the admin user table. */
.an-linkbtn {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--brand-600, #4f46e5);
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.an-linkbtn:hover,
.an-linkbtn:focus-visible {
  text-decoration: underline;
}

.an-muted {
  color: var(--text-3);
  font-size: 11px;
  margin-inline-start: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- KPI tiles --------------------------------------------------------- */
.an-kpis {
  display: grid;
  /* 132px, not 150: the strip carries five or six tiles and a wider minimum
     pushed the last one onto a row of its own at the usual content width. */
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 12px;
}

.an-kpi {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.an-kpi-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
}

.an-kpi-num {
  font-size: 25px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.an-kpi.ok .an-kpi-num { color: var(--an-ok); }
.an-kpi.bad .an-kpi-num { color: var(--an-bad); }
.an-kpi.mut .an-kpi-num { color: var(--an-mut); }

/* ---- queue strip ------------------------------------------------------- */
.an-queue {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 32px;
  padding: 14px 18px;
}

.an-queue-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  color: var(--text-2);
}

.an-queue-item b {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.an-queue-item small {
  font-size: 11.5px;
  font-weight: 600;
}

.an-warn {
  color: #b45309;
}

/* ---- cards / panels ---------------------------------------------------- */
.an-card {
  padding: 0;
  overflow: hidden;
}

.an-card .card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.an-card .card-head h3 {
  margin: 0;
  font-size: 16px;
}

.an-hint {
  font-size: 12px;
  color: var(--text-3);
}

.an-card-body {
  padding: 16px 20px;
}

.an-grid2 {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 18px;
}

.an-empty {
  padding: 22px 8px;
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

/* ---- donut ------------------------------------------------------------- */
.an-donut-wrap {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  justify-content: center;
}

.an-donut {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.an-donut-hole {
  width: 94px;
  height: 94px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.an-donut-hole b {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}

.an-donut-hole span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
}

.an-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  min-width: 150px;
}

.an-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.an-legend-row i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.an-legend-row span {
  flex: 1;
  color: var(--text-2);
}

.an-legend-row b {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ---- bar rows (platforms + weekday) ------------------------------------ */
.an-bar-row {
  display: grid;
  grid-template-columns: minmax(96px, 128px) 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.an-bar-row:last-child {
  margin-bottom: 0;
}

.an-bar-row-sm {
  grid-template-columns: 44px 1fr auto;
  margin-bottom: 9px;
}

.an-bar-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-bar-name img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex: none;
}

.an-track {
  display: flex;
  height: 14px;
  border-radius: 999px;
  background: var(--surface-2, #f1f5f9);
  overflow: hidden;
}

.an-track i {
  display: block;
  height: 100%;
}

.an-bar-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.an-ok-t { color: var(--an-ok); }
.an-bad-t { color: var(--an-bad); }

/* ---- channel table ----------------------------------------------------- */
.an-table-wrap {
  overflow-x: auto;
}

.an-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.an-table th {
  text-align: start;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  white-space: nowrap;
}

.an-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  color: var(--text);
}

.an-table tr:last-child td {
  border-bottom: 0;
}

.an-num {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

/* ---- sortable headers --------------------------------------------------- */
.an-sortable button {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  cursor: pointer;
}

.an-sortable button:hover,
.an-sortable button:focus-visible {
  color: var(--brand-600, #4f46e5);
}

.an-sortable.on button {
  color: var(--text);
}

.an-table-more {
  padding: 10px 10px 0;
  font-size: 11.5px;
  color: var(--text-3);
}

.an-cell-name {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
}

.an-cell-name img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex: none;
}

.an-cell-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- daily volume ------------------------------------------------------ */
.an-days {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  /* 132 not 120: a horizontal scrollbar and an 13px label strip both eat into
     this box, and at 120 the tallest column pushed its label under the thumb. */
  height: 132px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.an-day {
  flex: 1 0 16px;
  min-width: 16px;
  height: 100%;
  position: relative;
  /* The label is taken OUT of the layout so it can never add to the column's
     percentage height — that is what clipped it before. */
  padding-bottom: 14px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

.an-day-col {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border-radius: 4px 4px 0 0;
  overflow: hidden;
  min-height: 2px;
}

.an-day-col span {
  display: block;
  width: 100%;
}

.an-day small {
  position: absolute;
  bottom: 0;
  inset-inline: 0;
  text-align: center;
  font-size: 9.5px;
  line-height: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

/* ---- top failures ------------------------------------------------------ */
.an-errors {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.an-error {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 12.5px;
  color: var(--text-2);
}

.an-error span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-error b {
  flex: none;
  color: var(--an-bad);
  font-variant-numeric: tabular-nums;
}

/* ---- responsive -------------------------------------------------------- */
@media (max-width: 900px) {
  .an-grid2 {
    grid-template-columns: 1fr;
  }
  .an-bar-row {
    grid-template-columns: minmax(80px, 100px) 1fr auto;
  }
}

@media (max-width: 620px) {
  .an-filters {
    padding: 12px;
  }
  .an-select,
  .an-input {
    min-width: 0;
    width: 100%;
  }
  .an-field {
    flex: 1 1 100%;
  }
  .an-menu {
    width: min(290px, 88vw);
  }
  .an-kpi-num {
    font-size: 22px;
  }
  .an-cell-name {
    max-width: 180px;
  }
}

/* ---- Studio & product output (see anProdCard in shell.js) -----------------
   One card per STUDIO/feature: icon + name, the headline number in that
   feature's own unit, and only the secondary metrics that actually moved.
   A feature with no output in the range stays on screen but dimmed — "none" is
   an answer, and hiding the card would read as "this tool does not exist". */
.an-prodcard .card-head h3 {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.an-prod-sum {
  font-size: 12px; font-weight: 600; color: var(--an-mut, #64748b);
}
.an-prodgrid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.an-prod {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  border: 1px solid var(--border, #e6eaf3); border-radius: 12px;
  padding: 11px 12px 10px;
  background: #fbfcff;
}
.an-prod.is-zero { opacity: .55; background: #fafbfd; }
.an-prod-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.an-prod-ico { font-size: 14px; line-height: 1; flex: none; }
.an-prod-name {
  font-size: 12px; font-weight: 700; color: #334155;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.an-prod-val {
  font-size: 22px; font-weight: 800; line-height: 1.15;
  color: #1e293b; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.an-prod-lbl { font-size: 11.5px; color: var(--an-mut, #64748b); }
.an-prod-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.an-prod-chip {
  font-size: 10.5px; font-weight: 600; color: #475569;
  background: #eef2f9; border-radius: 99px; padding: 2px 7px;
  white-space: nowrap;
}
.an-prod-chip b { color: #1e293b; }
.an-prod-all {
  font-size: 10.5px; color: #94a3b8; margin-top: auto; padding-top: 6px;
}
@media (max-width: 560px) {
  .an-prodgrid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .an-prod-val { font-size: 19px; }
}

/* ---- public pages: one row per profile + the total ---------------------- */
/* Same card, table and chips the rest of the view uses, so the block reads as
   part of Analytics rather than a bolt-on. */
.an-ppkpis {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px;
}
.an-ppchip {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: #eef2f9; border-radius: 12px; padding: 7px 12px;
  font-size: 11.5px; color: var(--an-mut, #64748b);
}
.an-ppchip b {
  font-size: 17px; font-weight: 800; color: #1e293b;
  font-variant-numeric: tabular-nums;
}
/* The per-page block is DRAWN, not tabulated (asked 2026-11-08 — "public pages
   should be graphical also, just like the ones below it"): each page owns two
   bars on one shared scale, and the handful of small numbers that are not worth
   a bar ride underneath as a single line. */
.an-pplist {
  display: flex; flex-direction: column;
}
.an-pp-page {
  padding: 13px 0 11px;
  border-top: 1px solid #eef1f6;
}
.an-pp-page:first-child {
  border-top: 0; padding-top: 2px;
}
.an-pp-who {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  margin-bottom: 9px;
}
.an-pp-link { color: #4338ca; font-weight: 800; text-decoration: none; }
.an-pp-link:hover { text-decoration: underline; }
.an-pp-slug {
  font-size: 10.5px; color: var(--an-mut, #94a3b8);
  font-weight: 600; direction: ltr;
}
.an-pp-flag {
  font-size: 10px; font-weight: 700; color: #92400e;
  background: #fef3c7; border-radius: 99px; padding: 1px 6px;
}
.an-pp-bars {
  display: flex; flex-direction: column; gap: 6px;
}
.an-pp-bar {
  display: grid;
  grid-template-columns: minmax(78px, 108px) 1fr minmax(2.6em, auto);
  align-items: center; gap: 10px;
  font-size: 12px;
}
.an-pp-bar > span:first-child {
  color: var(--an-mut, #64748b); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.an-pp-bar .an-track { height: 10px; }
.an-pp-bar b {
  justify-self: end;
  font-size: 12.5px; font-weight: 800; color: #1e293b;
  font-variant-numeric: tabular-nums;
}
.an-pp-meta {
  margin-top: 8px; font-size: 11.5px; line-height: 1.55;
  color: var(--an-mut, #94a3b8);
}
.an-pp-total {
  border-top: 2px solid #e2e8f0; padding-bottom: 2px;
}
.an-pp-tname {
  font-size: 13px; font-weight: 800; color: #1e293b;
}
.an-pp-total .an-pp-bar b { color: #0f172a; }
.an-pp-total .an-pp-meta { color: #64748b; font-weight: 600; }
.an-pp-top {
  font-size: 11.5px; color: var(--an-mut, #64748b); margin-top: 12px;
}
@media (max-width: 640px) {
  /* A phone has no room for a 108px label beside a bar: the label moves ABOVE
     its track, and the number stays on the right of the same line. */
  .an-pp-bar {
    grid-template-columns: 1fr minmax(2.6em, auto);
    gap: 6px 10px;
  }
  .an-pp-bar > span:first-child { grid-column: 1 / -1; }
}
