/* ================= Аналитика — «Центр эффективности» =================
   Its own .an-* namespace rather than more .dm-* : this page is a dashboard, not a
   step-by-step configurator, so it shares only the atoms that genuinely repeat
   (.dm-segmented/.dm-segment-btn, .dm-select, .dm-view-tabs, .dm-history-table,
   .dm-empty-state) and defines the rest here. Every colour is a project token. */
.an-page { display: block; }

.an-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1.15rem;
}
.an-head h2 { font-family: var(--font-display); font-size: 1.22rem; font-weight: 600; letter-spacing: -0.015em; }
.an-head p { margin-top: 0.3rem; max-width: 46rem; color: var(--color-text-muted); font-size: 0.82rem; line-height: 1.5; }
.an-filters { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
/* Периоды — всегда в одну строку (иначе «Сегодня/7 дней» + «30 дней» ломались на два ряда). */
.an-filters .dm-segmented { margin: 0; flex-wrap: nowrap; width: max-content; }
.an-filters .dm-segment-btn { text-decoration: none; display: inline-flex; align-items: center; white-space: nowrap; }

.an-metric-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.75rem; margin-bottom: 0.9rem;
}
.an-metric {
  border: 1px solid var(--color-border); border-radius: 16px; padding: 0.95rem 1rem;
  background: var(--color-surface);
}
.an-metric-top { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.an-metric-label { color: var(--color-text-muted); font-size: 0.74rem; font-weight: 700; }
.an-metric-icon {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 10px;
  background: var(--color-surface-muted); color: var(--color-text-muted); flex: none;
}
.an-metric-icon svg { width: 1.05rem; height: 1.05rem; }
.an-metric-icon.is-purple { background: color-mix(in srgb, var(--color-primary) 14%, transparent); color: var(--color-primary); }
.an-metric-icon.is-green { background: var(--color-success-bg); color: var(--color-success-text); }
.an-metric-icon.is-blue { background: color-mix(in srgb, var(--color-primary) 12%, transparent); color: var(--color-primary); }
.an-metric-icon.is-red { background: var(--color-danger-bg); color: var(--color-danger-text); }
.an-metric-value { margin-top: 0.5rem; font-family: var(--font-display); font-size: 1.75rem; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.an-metric-foot { margin-top: 0.3rem; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; color: var(--color-text-faint); font-size: 0.72rem; }
.an-delta { font-weight: 800; }
.an-delta.is-up { color: var(--color-success-text); }
.an-delta.is-down { color: var(--color-danger-text); }

.an-card {
  border: 1px solid var(--color-border); border-radius: 18px; padding: 1rem 1.05rem;
  background: var(--color-surface); min-width: 0;
}
.an-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.an-card-title { font-size: 0.92rem; font-weight: 750; }
.an-card-sub { margin-top: 0.2rem; color: var(--color-text-muted); font-size: 0.74rem; }
.an-tiny-link { color: var(--color-primary); font-size: 0.74rem; font-weight: 700; text-decoration: none; white-space: nowrap; }
.an-tiny-link:hover { text-decoration: underline; }

.an-badge {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.22rem 0.5rem;
  border-radius: 999px; font-size: 0.68rem; font-weight: 750;
  background: var(--color-surface-muted); color: var(--color-text-muted);
}
.an-badge.is-ok { background: var(--color-success-bg); color: var(--color-success-text); }
.an-badge.is-warn { background: var(--color-warning-bg); color: var(--color-warning-text); }
.an-badge.is-error { background: var(--color-danger-bg); color: var(--color-danger-text); }

/* align-items:start — карточки по своему контенту, а не растянуты до высоты графика
   (из-за растяжки в «Состоянии системы» снизу зияла пустота). */
.an-grid-main { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 0.85rem; margin-bottom: 1.1rem; align-items: start; }
.an-bottom-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 0.85rem; }

.an-trend-wrap { position: relative; }
.an-trend-chart { width: 100%; height: 16rem; overflow: visible; }
.an-chart-grid { stroke: var(--color-border); stroke-width: 1; opacity: 0.6; }
.an-chart-label { fill: var(--color-text-faint); font-size: 10px; font-variant-numeric: tabular-nums; }
.an-chart-line { fill: none; stroke: var(--color-primary); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.an-chart-line-2 { fill: none; stroke: var(--color-success-text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.an-chart-area { fill: url(#anAreaFill); stroke: none; }
/* selective marks: emphasized endpoints + hover crosshair (no dot-per-point) */
.an-end-dot { stroke: var(--color-surface); stroke-width: 2.5; }
.an-end-dot.is-actions { fill: var(--color-primary); }
.an-end-dot.is-replies { fill: var(--color-success-text); }
.an-crosshair { stroke: var(--color-text-faint); stroke-width: 1.25; stroke-dasharray: 3 3; opacity: 0.7; }
.an-hover-dot { stroke: var(--color-surface); stroke-width: 2.5; pointer-events: none; }
.an-hover-dot.is-actions { fill: var(--color-primary); }
.an-hover-dot.is-replies { fill: var(--color-success-text); }
.an-hit { cursor: crosshair; pointer-events: all; }
.an-chart-tooltip {
  position: absolute; transform: translate(-50%, -132%); pointer-events: none; opacity: 0;
  display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  padding: 0.45rem 0.6rem; border-radius: 10px; white-space: nowrap; z-index: 2;
  background: var(--color-surface); border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md); font-size: 0.72rem;
  transition: opacity var(--transition-fast) var(--ease);
}
.an-chart-tooltip b { font-size: 0.7rem; color: var(--color-text-muted); font-weight: 700; }
.an-tt-row { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.an-tt-dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; flex: none; }
.an-tt-dot.a { background: var(--color-primary); }
.an-tt-dot.r { background: var(--color-success-text); }
.an-chart-legend { display: flex; gap: 1rem; margin-top: 0.65rem; color: var(--color-text-muted); font-size: 0.73rem; }
.an-legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.an-legend-dot { width: 0.55rem; height: 0.55rem; border-radius: 999px; background: var(--color-primary); }
.an-legend-dot.is-green { background: var(--color-success-text); }

.an-health { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.an-score-ring {
  position: relative; width: 6.5rem; height: 6.5rem; border-radius: 50%; flex: none;
  background: conic-gradient(var(--color-primary) calc(var(--an-score) * 1%), var(--color-surface-muted) 0);
}
.an-score-ring::after {
  content: ""; position: absolute; inset: 0.55rem; border-radius: 50%; background: var(--color-surface);
}
/* Flex column, not a two-row grid: with place-items:center the implicit rows each took
   half the ring's height and pushed "77" and "из 100" to opposite ends of it. */
.an-score-label {
  position: absolute; inset: 0; z-index: 1; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.an-score-label b { display: block; font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; line-height: 1; }
.an-score-label span { display: block; margin-top: 0.1rem; color: var(--color-text-faint); font-size: 0.62rem; line-height: 1; }
.an-health-list { display: flex; flex-direction: column; gap: 0.7rem; flex: 1; min-width: 11rem; }
.an-health-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; }
.an-health-row > div { flex: 1; min-width: 0; }
.an-health-row span { display: block; color: var(--color-text-muted); font-size: 0.73rem; }
.an-health-row b { font-size: 0.78rem; font-weight: 750; white-space: nowrap; font-variant-numeric: tabular-nums; }
.an-progress { margin-top: 0.3rem; height: 0.35rem; border-radius: 999px; background: var(--color-surface-muted); overflow: hidden; }
.an-progress i { display: block; height: 100%; border-radius: 999px; background: var(--color-primary); }
.an-progress.green i { background: var(--color-success-text); }
.an-progress.yellow i { background: var(--color-warning-text); }
.an-progress.red i { background: var(--color-danger-text); }

.an-insight {
  display: flex; align-items: flex-start; gap: 0.6rem; margin-top: 0.9rem;
  padding: 0.7rem 0.8rem; border-radius: 13px;
  background: var(--color-surface-muted); border: 1px solid var(--color-border);
}
.an-insight svg { width: 1.05rem; height: 1.05rem; flex: none; margin-top: 0.1rem; color: var(--color-primary); }
.an-insight strong { display: block; font-size: 0.78rem; }
.an-insight p { margin-top: 0.2rem; color: var(--color-text-muted); font-size: 0.73rem; line-height: 1.5; }

.an-role-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 0.75rem; margin-bottom: 0.9rem; }
.an-role-card {
  border: 1px solid var(--color-border); border-radius: 16px; padding: 0.9rem;
  background: var(--color-surface); text-decoration: none; color: inherit; display: block;
  transition: border-color var(--transition-fast) var(--ease), transform var(--transition-fast) var(--ease);
}
.an-role-card:hover { border-color: color-mix(in srgb, var(--color-primary) 45%, var(--color-border)); transform: translateY(-1px); }
.an-role-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.an-role-name { display: flex; align-items: center; gap: 0.5rem; font-size: 0.83rem; font-weight: 750; min-width: 0; }
.an-role-name .an-metric-icon { width: 1.85rem; height: 1.85rem; }
.an-role-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; margin-top: 0.8rem; }
.an-role-stat span { display: block; color: var(--color-text-faint); font-size: 0.66rem; }
.an-role-stat b { display: block; margin-top: 0.12rem; font-size: 0.92rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.an-role-spark { margin-top: 0.7rem; height: 2.2rem; }
.an-role-spark svg { width: 100%; height: 100%; overflow: visible; }

.an-table-wrap { overflow-x: auto; }
.an-account-cell { display: inline-flex; align-items: center; gap: 0.5rem; min-width: 0; }
.an-avatar-sm {
  display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 9px; flex: none;
  background: var(--color-surface-muted); color: var(--color-text-muted); font-size: 0.72rem; font-weight: 800;
}
.an-account-copy { min-width: 0; }
.an-account-copy b { display: block; font-size: 0.76rem; }
.an-account-copy span { display: block; color: var(--color-text-faint); font-size: 0.68rem; }

.an-status, .an-risk {
  display: inline-flex; align-items: center; padding: 0.2rem 0.45rem; border-radius: 999px;
  font-size: 0.66rem; font-weight: 800; white-space: nowrap;
  background: var(--color-surface-muted); color: var(--color-text-muted);
}
.an-status.is-active { background: var(--color-success-bg); color: var(--color-success-text); }
.an-status.is-pending { background: var(--color-warning-bg); color: var(--color-warning-text); }
.an-status.is-error, .an-status.is-banned { background: var(--color-danger-bg); color: var(--color-danger-text); }
.an-risk.is-low { background: var(--color-success-bg); color: var(--color-success-text); }
.an-risk.is-mid { background: var(--color-warning-bg); color: var(--color-warning-text); }
.an-risk.is-high { background: var(--color-danger-bg); color: var(--color-danger-text); }

.an-funnel { display: flex; flex-direction: column; gap: 0.6rem; }
.an-funnel-row { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr) 3rem; align-items: center; gap: 0.6rem; }
.an-funnel-row > span { color: var(--color-text-muted); font-size: 0.73rem; }
.an-funnel-row > b { text-align: right; font-size: 0.76rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.an-funnel-bar { position: relative; height: 1.55rem; border-radius: 9px; background: var(--color-surface-muted); overflow: hidden; }
.an-funnel-bar i {
  display: block; height: 100%; border-radius: 9px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-grad-end));
}
.an-funnel-bar em {
  position: absolute; inset: 0; display: flex; align-items: center; padding-left: 0.55rem;
  font-style: normal; font-size: 0.7rem; font-weight: 750; color: var(--color-text);
}

.an-source-list { display: flex; flex-direction: column; }
.an-source-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 7rem 3rem; align-items: center; gap: 0.7rem;
  padding: 0.55rem 0; border-bottom: 1px solid var(--color-border);
}
.an-source-row:last-child { border-bottom: 0; }
.an-source-main { min-width: 0; }
.an-source-main b { display: block; font-size: 0.77rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.an-source-main span { display: block; color: var(--color-text-faint); font-size: 0.68rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.an-source-row > strong { text-align: right; font-size: 0.76rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.an-mini-progress { height: 0.35rem; border-radius: 999px; background: var(--color-surface-muted); overflow: hidden; }
.an-mini-progress i { display: block; height: 100%; border-radius: 999px; background: var(--color-primary); }

.an-activity-list { display: flex; flex-direction: column; }
.an-activity {
  display: flex; align-items: flex-start; gap: 0.65rem; padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-border);
}
.an-activity:last-child { border-bottom: 0; }
.an-activity-icon {
  display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 9px; flex: none;
  background: var(--color-surface-muted); color: var(--color-text-muted);
}
.an-activity-icon svg { width: 1rem; height: 1rem; }
.an-activity-icon.is-error { background: var(--color-danger-bg); color: var(--color-danger-text); }
.an-activity-icon.is-flood { background: var(--color-warning-bg); color: var(--color-warning-text); }
.an-activity-icon.is-info { background: color-mix(in srgb, var(--color-primary) 12%, transparent); color: var(--color-primary); }
.an-activity-copy { flex: 1; min-width: 0; }
.an-activity-copy b { display: block; font-size: 0.77rem; }
.an-activity-copy p { margin-top: 0.15rem; color: var(--color-text-muted); font-size: 0.71rem; line-height: 1.45; }
.an-activity-time { color: var(--color-text-faint); font-size: 0.67rem; white-space: nowrap; flex: none; }

.an-danger-box {
  padding: 0.7rem 0.8rem; border-radius: 13px; margin-bottom: 0.6rem;
  background: var(--color-danger-bg); color: var(--color-danger-text);
}
.an-danger-box.is-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.an-danger-box b { display: block; font-size: 0.78rem; }
.an-danger-box p { margin-top: 0.2rem; font-size: 0.72rem; line-height: 1.5; opacity: 0.92; }
.an-note { margin-top: 0.5rem; color: var(--color-text-faint); font-size: 0.7rem; line-height: 1.5; }

.an-module-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.55rem 0.6rem; border-radius: 10px; text-decoration: none; color: inherit;
  transition: background var(--transition-fast) var(--ease);
}
.an-module-row:hover { background: var(--color-surface-muted); }

.an-inventory { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: 0.5rem; margin-top: 0.7rem; }
.an-inventory > div { padding: 0.5rem 0.6rem; border-radius: 11px; background: var(--color-surface-muted); }
.an-inventory span { display: block; color: var(--color-text-faint); font-size: 0.65rem; }
.an-inventory b { display: block; margin-top: 0.1rem; font-size: 0.9rem; font-weight: 800; font-variant-numeric: tabular-nums; }

@media (max-width: 1100px) {
  .an-grid-main, .an-bottom-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .an-funnel-row { grid-template-columns: 6.5rem minmax(0, 1fr) 2.6rem; }
  .an-source-row { grid-template-columns: minmax(0, 1fr) 4.5rem 2.6rem; }
  .an-health { justify-content: center; }
}

