/* Spatial motion: shared by Alpaca Desktop (AMS Factory) and Alpaca Support (ams_portal). Single source.
   Glass = inset highlight + shadow, never a border. Surfaces and ink come from the host app's --sp-* tokens. */

:root {
  /* Categorical slots 1-10 (validated light palette, >=3:1 graphical contrast), then neutral for "+N more". */
  --sm-cat-1: #1d6fd1;
  --sm-cat-2: #d15220;
  --sm-cat-3: #138f63;
  --sm-cat-4: #b87900;
  --sm-cat-5: #c84478;
  --sm-cat-6: #6650d6;
  --sm-cat-7: #0e7c86;
  --sm-cat-8: #5c7c19;
  --sm-cat-9: #3b55a8;
  --sm-cat-10: #9c3691;
  --sm-cat-more: #8c857d;
  --rc-remove: rgba(192, 57, 43, .09);
  --rc-remove-flash: rgba(192, 57, 43, .26);
  --rc-add: rgba(35, 148, 106, .10);
  --rc-add-flash: rgba(35, 148, 106, .32);
}
:root[data-theme="dark"], :root[data-alpaca-theme="dark"], :root[data-desk-theme="dark"] {
  --sm-cat-1: #4f9cf9;
  --sm-cat-2: #f07c4e;
  --sm-cat-3: #2fc28e;
  --sm-cat-4: #ebb02a;
  --sm-cat-5: #ec74a4;
  --sm-cat-6: #9b8bf2;
  --sm-cat-7: #33bfcc;
  --sm-cat-8: #99c246;
  --sm-cat-9: #7a95e8;
  --sm-cat-10: #d674cc;
  --sm-cat-more: #7e7973;
  --rc-remove: rgba(239, 138, 122, .12);
  --rc-remove-flash: rgba(239, 138, 122, .30);
  --rc-add: rgba(95, 199, 154, .12);
  --rc-add-flash: rgba(95, 199, 154, .32);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-alpaca-theme="light"]):not([data-desk-theme="light"]) {
    --sm-cat-1: #4f9cf9;
    --sm-cat-2: #f07c4e;
    --sm-cat-3: #2fc28e;
    --sm-cat-4: #ebb02a;
    --sm-cat-5: #ec74a4;
    --sm-cat-6: #9b8bf2;
    --sm-cat-7: #33bfcc;
    --sm-cat-8: #99c246;
    --sm-cat-9: #7a95e8;
    --sm-cat-10: #d674cc;
    --sm-cat-more: #7e7973;
    --rc-remove: rgba(239, 138, 122, .12);
    --rc-remove-flash: rgba(239, 138, 122, .30);
    --rc-add: rgba(95, 199, 154, .12);
    --rc-add-flash: rgba(95, 199, 154, .32);
  }
}

.sm-dash { display: flex; flex-direction: column; gap: 14px; container-type: inline-size; container-name: sm-dash; }
.sm-dash .sp-stat,
.sm-dash .sp-card,
.sm-dash .sp-stage-tile,
.sm-dash .sp-area-btn { border: 0 !important; }

/* KPI tile layout: fixed 112px ring slot + flexible top-aligned text column; zero overlap. */
.sm-dash .sp-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.sm-dash .sp-stat {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: start;
  gap: 16px;
  padding: 16px 18px;
  min-width: 0;
}
/* Host pages (AMS Factory's .ifx svg {16px}) must not resize the dashboard's graphics. */
.sm-dash .sp-stat-vis {
  position: relative;
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  flex: none;
  overflow: visible;
}
.sm-dash .sp-stat-vis svg {
  display: block;
  width: 112px;
  height: 112px;
  overflow: visible;
}
.sm-dash .sp-ring-track,
.sm-dash .sp-ring-val,
.sm-dash .sp-ring-track-on,
.sm-dash .sp-ring-val-on {
  stroke-width: 10;
}
.sm-dash .sp-ring-inner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  clip-path: circle(42px at 50% 50%);
  pointer-events: none;
}
.sm-dash .sp-stat-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.sm-dash .sp-stat-label,
.sm-dash .sp-stat-value,
.sm-dash .sp-stat-sub {
  max-width: 100%;
  overflow-wrap: break-word;
}
.sm-dash .sp-stat[data-sm-state="pending"] .sp-stat-value,
.sm-dash .sp-stat[data-sm-state="unconfigured"] .sp-stat-value,
.sm-dash .sp-stat[data-sm-state="pending"] .sp-ring-inner,
.sm-dash .sp-stat[data-sm-state="unconfigured"] .sp-ring-inner {
  color: var(--sp-t2);
}

.sm-dash .sp-charts {
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr);
}
.sm-dash .sp-donut-wrap svg { width: 132px; height: 132px; }
.sm-dash .sp-area-right { flex: 1 1 auto; min-width: 0; }
.sm-dash .sp-area-legend { max-height: none; overflow: visible; padding-right: 0; }
.sm-dash .sp-area-name { overflow: visible; text-overflow: clip; white-space: nowrap; }
.sm-num { font-variant-numeric: tabular-nums; }
.sm-dash .sp-stat-value, .sm-dash .sp-stage-n, .sm-dash .sp-ring-inner, .sm-dash .sp-donut-center strong { font-variant-numeric: tabular-nums; }
.sm-dash .sp-stage-tile { justify-content: flex-start; }
.sm-dash .sp-stage-n { margin-top: auto; }
.sm-link { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.sm-link-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 0;
  background: var(--sp-chip);
  color: var(--sp-accent-ink);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .15s ease;
}
.sm-link-pill:hover {
  background: var(--sp-chip-hover);
  text-decoration: none;
}
.sm-link-pill:focus-visible {
  outline: 2px solid var(--sp-focus);
  outline-offset: 2px;
}
.sm-replay { display: flex; justify-content: flex-end; }

/* Container-responsive layout so sidebars (Admin Overview, embedded AMS Factory) never crush tiles or legend. */
@container sm-dash (max-width: 1080px) {
  .sm-dash .sp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container sm-dash (max-width: 998px) {
  .sm-dash .sp-charts { grid-template-columns: 1fr; }
  .sp-area-card { gap: 14px; }
  .sp-area-btn { gap: 7px; padding: 5px 6px; }
  .sm-link { white-space: nowrap; }
}
@container sm-dash (max-width: 920px) {
  .sm-dash .sp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container sm-dash (min-width: 581px) {
  .sp-stage-tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@container sm-dash (max-width: 580px) {
  .sp-stage-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sm-dash .sp-area-name { overflow: hidden; text-overflow: ellipsis; }
}
@container sm-dash (max-width: 560px) {
  .sm-dash .sp-stats { grid-template-columns: 1fr; }
}
@container sm-dash (max-width: 420px) {
  .sp-stage-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sp-area-card { flex-direction: column; align-items: stretch; }
  .sp-donut-wrap { margin: 0 auto; }
}

/* Segmented pipeline: 2px glass gaps between stage segments. */
.sm-pipeline { display: flex; gap: 2px; }
.sm-pipeline .sp-stage-seg { flex: 0 1 auto; min-width: 0; height: 100%; border-radius: 3px; }
.sm-pipeline .sp-stage-seg:not([data-sm-pct="0"]) { min-width: 6px; }

/* Per-stage mini bar. */
.sm-mini { display: block; height: 4px; margin-top: 8px; border-radius: 999px; background: var(--sp-track); overflow: hidden; }
.sm-mini-fill { display: block; height: 100%; border-radius: 999px; background: var(--sp-t2); }
.sm-mini-fill[data-stage="received"] { background: var(--sp-stg-received); }
.sm-mini-fill[data-stage="understood"] { background: var(--sp-stg-understood); }
.sm-mini-fill[data-stage="in_progress"] { background: var(--sp-stg-in_progress); }
.sm-mini-fill[data-stage="needs_you"] { background: var(--sp-stg-needs_you); }
.sm-mini-fill[data-stage="resolved"] { background: var(--sp-stg-resolved); }

/* Donut slices grow on hover; legend rows follow. */
.sm-slice { transition: stroke-width .18s ease; cursor: pointer; }
.sp-area-btn.sm-hot { background: var(--sp-chip); }

/* Ambient motion (motion-calm: centered breathing halo, single soft sheen pass, calm 24s pending ring). */
.sm-breathe::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, .36);
  animation: sm-breathe 3.6s ease-in-out infinite;
}
@keyframes sm-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .32); }
  55% { box-shadow: 0 0 0 10px rgba(255, 255, 255, 0); }
}

.sm-sheen { position: relative; overflow: hidden; }
.sm-sheen::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -60%;
  width: 60%;
  pointer-events: none;
  opacity: 0.12;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, .85) 50%, transparent 100%);
  animation: sm-sheen 2.4s ease-out 1 both;
}
@keyframes sm-sheen {
  0% { transform: translateX(0); }
  100% { transform: translateX(300%); }
}

.sm-dash .sp-ring-track.sm-pending,
.sm-pending {
  stroke-width: 4;
  stroke-dasharray: 2 6;
  stroke-linecap: butt;
  opacity: 0.35;
  transform-box: fill-box;
  transform-origin: center;
  animation: sm-pending 24s linear infinite;
}
@keyframes sm-pending {
  to { transform: rotate(360deg); }
}
@keyframes rc-flow-dash { to { stroke-dashoffset: -20; } }

.sm-paused .sm-breathe::after, .sm-paused .sm-sheen::after, .sm-paused .sm-pending { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .sm-breathe::after, .sm-sheen::after, .sm-pending, path.jas-link { animation: none !important; }
  .sm-sheen::after { display: none; }
  .sm-slice { transition: none; }
}
