/* Aforeworn — Analytics module styles. Scoped under .aw-an- prefixes.
 * Inherits theme tokens (--bg, --panel, --border, …) from styles.css. */

.aw-an {
  --aw-an-gap: 16px;
  color: var(--text);
  font-family: var(--font);
}
.aw-an *, .aw-an *::before, .aw-an *::after { box-sizing: border-box; }

/* ---------- toolbar ---------- */
.aw-an-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.aw-an-title { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.aw-an-grow { flex: 1 1 auto; }

.aw-an-seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--panel); border: 1px solid var(--border-soft);
  border-radius: 999px;
}
.aw-an-segbtn {
  appearance: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 6px 13px; border-radius: 999px;
  background: transparent; color: var(--muted);
  transition: color .15s ease, background .15s ease;
}
.aw-an-segbtn:hover { color: var(--text); }
.aw-an-segbtn.is-on {
  background: linear-gradient(145deg, var(--primary), #c48f31);
  color: var(--primary-ink); box-shadow: 0 3px 10px rgba(217,164,65,.28);
}
.aw-an-seg[data-role="interval"] .aw-an-segbtn.is-on {
  background: rgba(91,157,255,.16); color: var(--secondary);
  box-shadow: none; border: 0;
}

/* ---------- KPI tiles ---------- */
.aw-an-kpis {
  display: grid; gap: var(--aw-an-gap);
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  margin-bottom: var(--aw-an-gap);
}
.aw-an-kpi {
  position: relative; overflow: hidden;
  padding: 14px 16px 12px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border-soft);
  animation: aw-an-rise .45s ease both; animation-delay: var(--aw-delay, 0ms);
}
.aw-an-kpi-top { display: flex; align-items: center; gap: 8px; }
.aw-an-kpi-label {
  flex: 1 1 auto; min-width: 0;
  color: var(--muted); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aw-an-kpi-val {
  font-size: 27px; font-weight: 750; letter-spacing: -.02em;
  margin-top: 6px; font-variant-numeric: tabular-nums;
}
.aw-an-kpi-spark { height: 34px; margin-top: 8px; }
.aw-an-nospark { height: 34px; }

.aw-an-chip {
  flex: none; display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  border: 1px solid transparent;
}
.aw-an-chip-up { color: var(--green); background: rgba(62,207,142,.12); border-color: rgba(62,207,142,.35); }
.aw-an-chip-down { color: var(--red); background: rgba(255,92,92,.12); border-color: rgba(255,92,92,.35); }
.aw-an-chip-flat, .aw-an-chip-flat.aw-an-chip { color: var(--muted); background: rgba(139,151,173,.1); border-color: var(--border); }

.aw-an-spark { width: 100%; height: 100%; display: block; }

/* ---------- panels ---------- */
.aw-an-panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: var(--aw-an-gap);
  animation: aw-an-rise .5s ease both;
}
.aw-an-panelhead {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.aw-an-h { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.aw-an-sub { color: var(--muted-2); font-size: 12px; }
.aw-an-live {
  display: inline-flex; align-items: center; gap: 6px; margin-left: auto;
  color: var(--green); font-size: 11.5px; font-weight: 600;
}
.aw-an-livedot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 8px var(--green); animation: aw-an-pulse 1.8s ease-in-out infinite;
}

/* ---------- primary chart ---------- */
.aw-an-primary .aw-an-panelhead { justify-content: space-between; }
.aw-an-tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.aw-an-tab {
  appearance: none; cursor: pointer; font-family: inherit;
  font-size: 12.5px; font-weight: 600; padding: 6px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-soft);
  background: var(--bg-2); color: var(--muted);
  transition: color .15s, border-color .15s, background .15s;
}
.aw-an-tab:hover { color: var(--text); border-color: #33456a; }
.aw-an-tab.is-on {
  color: var(--primary); border-color: rgba(217,164,65,.45);
  background: rgba(217,164,65,.1);
}
.aw-an-chartwrap { position: relative; width: 100%; }
.aw-an-areasvg { width: 100%; height: auto; display: block; overflow: visible; }
.aw-an-grid { stroke: var(--border-soft); stroke-width: 1; vector-effect: non-scaling-stroke; }
.aw-an-axis { fill: var(--muted-2); font-size: 11px; font-family: var(--font); }
.aw-an-axis-y { text-anchor: end; }
.aw-an-cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }

.aw-an-tt {
  position: absolute; z-index: 5; pointer-events: none;
  transform: translate(-50%, -100%);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 10px;
  box-shadow: var(--shadow); white-space: nowrap;
}
.aw-an-tt-b { color: var(--muted); font-size: 11px; }
.aw-an-tt-v { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* ---------- row2: funnel + feed ---------- */
.aw-an-row2 {
  display: grid; gap: var(--aw-an-gap);
  grid-template-columns: 1.15fr 1fr;
}
.aw-an-row2 .aw-an-panel { margin-bottom: 0; }

/* ---------- funnel ---------- */
.aw-an-funnel { display: flex; flex-direction: column; gap: 12px; }
.aw-an-fstep { animation: aw-an-rise .4s ease both; animation-delay: var(--aw-delay, 0ms); }
.aw-an-fhead { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 5px; }
.aw-an-flabel { font-size: 13px; font-weight: 600; }
.aw-an-fcount { font-size: 14px; font-weight: 750; font-variant-numeric: tabular-nums; }
.aw-an-ftrack { height: 12px; border-radius: 999px; background: var(--border); overflow: hidden; }
.aw-an-fbar {
  height: 100%; border-radius: 999px; min-width: 4px;
  transform-origin: left center; animation: aw-an-grow .55s cubic-bezier(.2,.7,.2,1) both;
  animation-delay: var(--aw-delay, 0ms);
}
.aw-an-fmeta {
  display: flex; justify-content: space-between; gap: 10px; margin-top: 4px;
  font-size: 11.5px; color: var(--muted-2); font-variant-numeric: tabular-nums;
}
.aw-an-good { color: var(--green); }
.aw-an-warn { color: var(--orange); }
.aw-an-bad { color: var(--red); }
.aw-an-dim { color: var(--muted-2); }

/* ---------- feed ---------- */
.aw-an-feed {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 420px; overflow-y: auto; overflow-x: hidden;
}
.aw-an-feedrow {
  display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: center;
  padding: 9px 6px; border-bottom: 1px solid var(--border-soft);
  animation: aw-an-fade .4s ease both;
}
.aw-an-feedrow:last-child { border-bottom: none; }
.aw-an-feedico {
  width: 30px; height: 30px; flex: none; border-radius: 9px;
  display: grid; place-items: center; font-size: 14px;
  background: var(--bg-2); border: 1px solid var(--border-soft);
}
.aw-an-type-conversion .aw-an-feedico, .aw-an-type-payment .aw-an-feedico { color: var(--green); border-color: rgba(62,207,142,.35); }
.aw-an-type-funnel .aw-an-feedico { color: var(--primary); border-color: rgba(217,164,65,.35); }
.aw-an-type-pageview .aw-an-feedico { color: var(--secondary); border-color: rgba(91,157,255,.3); }
.aw-an-feedmain { min-width: 0; }
.aw-an-feedtitle {
  font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aw-an-feedval { color: var(--green); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 12px; }
.aw-an-feedmeta {
  color: var(--muted-2); font-size: 11.5px; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aw-an-feedtime { color: var(--muted-2); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- breakdowns ---------- */
.aw-an-breakdowns {
  display: grid; gap: var(--aw-an-gap);
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.aw-an-bd { margin-bottom: 0; }
.aw-an-barsvg { width: 100%; height: auto; display: block; }
.aw-an-btrack { fill: var(--border); }
.aw-an-blabel { fill: var(--text); font-size: 12.5px; font-family: var(--font); }
.aw-an-bval { fill: var(--muted); font-size: 12px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.aw-an-brow rect[fill]:not(.aw-an-btrack) { transform-origin: left; animation: aw-an-grow .55s cubic-bezier(.2,.7,.2,1) both; }

.aw-an-donutwrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.aw-an-donutsvg { width: 150px; height: 150px; flex: none; }
.aw-an-arc { transition: opacity .15s; }
.aw-an-arc:hover { opacity: .82; }
.aw-an-donuttot { fill: var(--text); font-size: 24px; font-weight: 750; font-family: var(--font); font-variant-numeric: tabular-nums; }
.aw-an-donutlbl { fill: var(--muted-2); font-size: 10px; font-family: var(--font); text-transform: uppercase; letter-spacing: .05em; }
.aw-an-legend { list-style: none; margin: 0; padding: 0; flex: 1 1 130px; min-width: 130px; display: flex; flex-direction: column; gap: 7px; }
.aw-an-legrow { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.aw-an-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.aw-an-leglabel { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: capitalize; }
.aw-an-legval { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.aw-an-legpct { color: var(--muted-2); font-weight: 500; }

/* ---------- states ---------- */
.aw-an-empty {
  text-align: center; padding: 30px 16px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: rgba(255,255,255,.01);
}
.aw-an-empty-big { font-size: 14px; color: var(--text); font-weight: 600; margin-bottom: 5px; }
.aw-an-err {
  display: flex; align-items: center; gap: 9px; padding: 12px 14px;
  color: #ffd0a0; font-size: 13px;
  border: 1px solid rgba(255,157,70,.3); border-radius: var(--radius);
  background: rgba(255,157,70,.07);
}
.aw-an-err-ico { font-size: 15px; }
.aw-an-loading { color: var(--muted); padding: 22px; text-align: center; font-size: 13px; }
.aw-an-spinner {
  display: inline-block; width: 13px; height: 13px; vertical-align: -2px;
  border: 2px solid rgba(255,255,255,.22); border-top-color: var(--primary);
  border-radius: 50%; animation: aw-an-spin .7s linear infinite;
}

/* ---------- animations ---------- */
@keyframes aw-an-spin { to { transform: rotate(360deg); } }
@keyframes aw-an-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes aw-an-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes aw-an-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes aw-an-pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

@media (prefers-reduced-motion: reduce) {
  .aw-an * { animation: none !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .aw-an-row2 { grid-template-columns: 1fr; }
  .aw-an-row2 .aw-an-panel:first-child { margin-bottom: var(--aw-an-gap); }
}
@media (max-width: 560px) {
  .aw-an-toolbar { gap: 8px; }
  .aw-an-title { width: 100%; }
  .aw-an-seg { flex-wrap: wrap; }
  .aw-an-kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .aw-an-kpi-val { font-size: 23px; }
}
