/* =========================================================================
   TERRITORY SPLIT DEMO (#territorySplitDemo).
   See src/components/TerritorySplitDemo.astro for the storyboard.
   Timeline: public/js/territory-split-demo.js toggles `is-*` classes and
   positions `.tsd__cursor` at runtime.

   Two full-width scenes crossfade (accounts grouping into territories → the
   assigned quota splitting down through them) — the same
   single-scene-at-a-time pattern BudgetVarianceDemo uses, since it's the
   only one that scales to any width without a per-breakpoint rework.

   The --tsd-* palette mirrors the PRODUCT (webapp_v3 src/styles/_theme.scss),
   same likeness rules and exact values as every other demo on the site.
   ========================================================================= */

.tsd {
  --tsd-canvas: #FAF9F5;
  --tsd-card: #FFFFFF;
  --tsd-border: #DBDBDE;
  --tsd-line: #EAEAEA;
  --tsd-head: #F6F6F7;
  --tsd-ink: #2B2B2B;
  --tsd-ink2: #777777;
  --tsd-accent: #6A5BC6;
  --tsd-accent-soft: #ECECFF;
  --tsd-blue: #5B77C6;
  --tsd-red: #D63B29;
}

/* standard product-demo dimensions (matches every other demo's stage —
   width:100% keeps aspect-ratio from computing width off the min-height
   floor in a narrow container, the bug this pattern has hit before). */
.tsd__stage {
  position: relative; overflow: hidden; width: 100%;
  aspect-ratio: 3 / 2; min-height: 380px; max-width: 640px; margin: 0 auto;
  background: var(--tsd-canvas);
  display: flex; flex-direction: column;
  transition: opacity .5s ease;
}
.tsd.is-out .tsd__stage { opacity: 0; }

.tsd__topBar {
  flex: none; font-size: 11px; font-weight: 600; color: var(--tsd-ink);
  padding: 12px 14px 9px; border-bottom: 1px solid var(--tsd-line);
  white-space: nowrap;
}

.tsd__scene { position: relative; flex: 1; min-height: 0; }
.tsd__sceneStack { position: absolute; inset: 0; }

/* each scene fills the whole stage and crossfades in/out — only one is
   opaque at a time, driven by is-scene-2 on the root (scene 1 is the
   default, unmarked state). */
.tsd__scenePanel {
  position: absolute; inset: 0; overflow: hidden; min-width: 0;
  display: flex; flex-direction: column;
  opacity: 0; transition: opacity .5s ease;
}
.tsd__scenePanel--s1 { opacity: 1; }
.tsd.is-scene-2 .tsd__scenePanel--s1 { opacity: 0; }
.tsd.is-scene-2 .tsd__scenePanel--s2 { opacity: 1; }

.tsd__pane { flex: 1; min-height: 0; min-width: 0; padding: 12px 14px; display: flex; flex-direction: column; }

/* ---------- panel header ---------- */
.tsdHead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.tsdHead__title { font-size: 12px; font-weight: 600; color: var(--tsd-ink); }
.tsdHead__sync {
  font-size: 8.5px; font-weight: 600; color: var(--tsd-blue);
  background: #EDF1FB; border: 1px solid #D3DDF5; border-radius: 999px; padding: 3px 8px;
  white-space: nowrap;
}
.tsdHead__owner {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 8.5px; font-weight: 600; color: var(--tsd-ink); white-space: nowrap;
}
.tsdHead__owner i {
  width: 15px; height: 15px; border-radius: 50%; font-style: normal;
  font-size: 6px; font-weight: 700; color: #fff; background: var(--c);
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- scene 1: the grouping control ---------- */
.tsdGroupBy {
  align-self: flex-start; margin-bottom: 8px;
  font-size: 9px; color: var(--tsd-ink2);
  background: var(--tsd-card); border: 1px solid var(--tsd-border); border-radius: 999px;
  padding: 5px 10px;
  transition: transform .15s ease, border-color .3s ease, background .3s ease;
}
.tsdGroupBy b { color: var(--tsd-ink); font-weight: 600; }
.tsd.is-press-group .tsdGroupBy { transform: scale(.95); }
.tsd.is-grouped .tsdGroupBy { border-color: #CFC7EF; background: var(--tsd-accent-soft); }
.tsd.is-grouped .tsdGroupBy b { color: var(--tsd-accent); }

/* the two states of the same block — account rows, then the territories
   they group into — stacked so neither can shift the other's layout. */
.tsdSwap { position: relative; flex: 1; min-height: 0; }
.tsdSwap__layer { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 5px; transition: opacity .45s ease; }
.tsdSwap__layer--territories { opacity: 0; }
.tsd.is-grouped .tsdSwap__layer--accounts { opacity: 0; }
.tsd.is-grouped .tsdSwap__layer--territories { opacity: 1; }

/* an account, carrying the field values a territory gets built from. */
.tsdAcct {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--tsd-card); border: 1px solid var(--tsd-border); border-radius: 6px;
  padding: 6px 9px; font-size: 9.5px;
}
.tsdAcct__name { color: var(--tsd-ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tsdAcct__fields { display: inline-flex; gap: 4px; flex: none; }
.tsdAcct__fields i {
  font-style: normal; font-size: 7.5px; font-weight: 600; color: var(--tsd-ink2);
  background: var(--tsd-head); border: 1px solid var(--tsd-line); border-radius: 3px;
  padding: 2px 5px; white-space: nowrap;
}

/* a territory, once the accounts have been grouped. */
.tsdTerr {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--tsd-card); border: 1px solid #CFC7EF; border-radius: 6px;
  padding: 8px 9px; font-size: 9.5px;
  transform: translateY(6px);
  transition: transform .4s ease;
  transition-delay: calc(var(--i) * .07s);
}
.tsd.is-grouped .tsdTerr { transform: none; }
.tsdTerr__name { color: var(--tsd-ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tsdTerr__count { flex: none; color: var(--tsd-ink2); font-variant-numeric: tabular-nums; }

/* ---------- scene 2: the split down through the structure ---------- */
.tsdTotal {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--tsd-accent-soft); border: 1px solid #CFC7EF; border-radius: 7px;
  padding: 7px 10px; margin-bottom: 7px;
  font-size: 9.5px; color: var(--tsd-ink2);
}
.tsdTotal b { font-size: 12px; font-weight: 700; color: var(--tsd-accent); font-variant-numeric: tabular-nums; }

.tsdTree { display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.tsdRow {
  display: flex; align-items: center; gap: 6px;
  background: var(--tsd-card); border: 1px solid var(--tsd-border); border-radius: 6px;
  padding: 5px 9px; font-size: 9.5px;
  opacity: 0; transform: translateY(4px);
  transition: opacity .35s ease, transform .35s ease, border-color .3s ease, background .3s ease;
  transition-delay: calc(var(--i, 0) * .12s);
}
.tsd.is-split .tsdRow--terr { opacity: 1; transform: none; }
.tsdRow__chev { flex: none; color: var(--tsd-ink2); font-size: 10px; transition: transform .3s ease; }
.tsd.is-expanded .tsdRow__chev { transform: rotate(90deg); }
.tsdRow__name { color: var(--tsd-ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tsdRow__val { margin-left: auto; flex: none; color: var(--tsd-ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.tsdRow__val.is-flash {
  outline: 1.5px solid var(--tsd-accent); outline-offset: 2px; border-radius: 3px;
  color: var(--tsd-accent);
}
.tsdRow__val.is-editing {
  outline: 1.5px solid var(--tsd-accent); outline-offset: 2px; border-radius: 3px;
  color: var(--tsd-accent); min-width: 42px; text-align: right;
}

/* the reps inside the open territory. */
.tsdReps {
  display: flex; flex-direction: column; gap: 4px;
  margin: 4px 0 4px 14px; padding-left: 8px; border-left: 1px solid var(--tsd-line);
  max-height: 0; overflow: hidden;
  transition: max-height .45s ease;
}
.tsd.is-expanded .tsdReps { max-height: 140px; }
.tsdRow--rep { background: #FCFCFB; padding: 4px 8px; }
.tsd.is-expanded .tsdRow--rep { opacity: 1; transform: none; }
.tsdRow--rep .tsdRow__name { font-weight: 500; color: var(--tsd-ink2); }
.tsdRow__tag {
  flex: none; font-size: 7.5px; font-weight: 600; color: var(--tsd-accent);
  background: var(--tsd-accent-soft); border: 1px solid #CFC7EF; border-radius: 3px;
  padding: 1px 5px;
}

/* the gap the adjustment opens, handed on to the reconciliation step. */
.tsdFlag {
  margin-top: auto; display: flex; align-items: center; gap: 5px;
  padding: 6px 9px; background: #FDF0EE; border: 1px solid #F3CFC9; border-radius: 6px;
  font-size: 9px; color: var(--tsd-ink2);
  opacity: 0; transform: translateY(4px);
  transition: opacity .35s ease, transform .35s ease;
}
.tsdFlag b { color: var(--tsd-red); font-weight: 700; font-variant-numeric: tabular-nums; }
.tsd.is-flagged .tsdFlag { opacity: 1; transform: none; }

/* ---------- cursor — positioned at runtime (JS sets left/top in px via
   getBoundingClientRect against .tsd__sceneStack). ---------- */
.tsd__cursor {
  position: absolute; opacity: 0; pointer-events: none; z-index: 9;
  transition: left .6s cubic-bezier(.5, .05, .3, 1), top .6s cubic-bezier(.5, .05, .3, 1), opacity .3s ease;
}
.tsd.is-cursor-visible .tsd__cursor { opacity: 1; }

/* ---------- responsive — the rows keep their shape, the stage just grows
   taller so nothing has to be cut. ---------- */
@media (max-width: 460px) {
  .tsd__stage { aspect-ratio: auto; min-height: 440px; }
  .tsdAcct__fields i:nth-child(2) { display: none; }
}
