/* =========================================================================
   QUOTA RECONCILE DEMO (#quotaReconcileDemo).
   See src/components/QuotaReconcileDemo.astro for the storyboard.
   Timeline: public/js/quota-reconcile-demo.js toggles `is-*` classes and
   positions `.qrd__cursor` at runtime.

   A single steady scene (no crossfade — same pattern as BudgetOwnerDemo):
   assigned quota against the approved number at every level of the
   hierarchy, with the difference resolved in the model.

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

.qrd {
  --qrd-canvas: #FAF9F5;
  --qrd-card: #FFFFFF;
  --qrd-border: #DBDBDE;
  --qrd-line: #EAEAEA;
  --qrd-head: #F6F6F7;
  --qrd-ink: #2B2B2B;
  --qrd-ink2: #777777;
  --qrd-accent: #6A5BC6;
  --qrd-accent-soft: #ECECFF;
  --qrd-green: #2C8E45;
  --qrd-green-soft: #C4EECF;
  --qrd-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). */
.qrd__stage {
  position: relative; overflow: hidden; width: 100%;
  aspect-ratio: 3 / 2; min-height: 380px; max-width: 640px; margin: 0 auto;
  background: var(--qrd-canvas);
  display: flex; flex-direction: column;
  transition: opacity .5s ease;
}
.qrd.is-out .qrd__stage { opacity: 0; }

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

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

/* ---------- panel header ---------- */
.qrdHead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.qrdHead__title { font-size: 12px; font-weight: 600; color: var(--qrd-ink); }
.qrdHead__round {
  font-size: 8.5px; font-weight: 600; color: var(--qrd-ink2);
  background: var(--qrd-head); border: 1px solid var(--qrd-border); border-radius: 999px;
  padding: 3px 8px; white-space: nowrap;
  transition: color .3s ease, background .3s ease, border-color .3s ease;
}
.qrd.is-saved .qrdHead__round { color: var(--qrd-green); background: #E3F5E9; border-color: var(--qrd-green-soft); }

/* ---------- the reconciliation table — flex rows rather than a CSS grid,
   so the team rows under a segment can collapse and expand. ---------- */
.qrdTable {
  background: var(--qrd-card); border: 1px solid var(--qrd-border); border-radius: 8px;
  overflow: hidden;
}
.qrdRow {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 9px; font-size: 9.5px; color: var(--qrd-ink2);
  border-bottom: 1px solid var(--qrd-line);
  transition: background .3s ease;
}
.qrdTable > .qrdRow:last-child { border-bottom: none; }
.qrdRow--head { background: var(--qrd-head); font-weight: 500; border-bottom: 1px solid var(--qrd-border); }
.qrdRow--co { background: #FCFCFB; font-weight: 700; color: var(--qrd-ink); }
.qrdRow--team { background: #FCFCFB; padding-left: 22px; }
.qrdRow__label {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px;
  font-weight: 600; color: var(--qrd-ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.qrdRow--head .qrdRow__label, .qrdRow--team .qrdRow__label { font-weight: 500; color: var(--qrd-ink2); }
.qrdRow--head .qrdRow__label { color: var(--qrd-ink2); }
.qrdRow__val { flex: none; width: 58px; text-align: right; font-variant-numeric: tabular-nums; color: var(--qrd-ink); }
.qrdRow--head .qrdRow__val, .qrdRow--head .qrdRow__diff { color: var(--qrd-ink2); font-weight: 500; }
.qrdRow__diff { flex: none; width: 56px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--qrd-ink2); }
.qrdRow__diff.is-short { color: var(--qrd-red); }
.qrdRow__diff.is-clear { color: var(--qrd-green); }

/* the segment the cursor drills into. */
.qrdRow__chev { font-style: normal; flex: none; color: var(--qrd-ink2); font-size: 10px; transition: transform .3s ease; }
.qrd.is-expanded .qrdRow__chev { transform: rotate(90deg); }
.qrd.is-press-ent .qrdRow--seg[data-el="entRow"] { background: var(--qrd-accent-soft); }

/* the team rows, collapsed until the segment is opened. */
.qrdSub { max-height: 0; overflow: hidden; transition: max-height .45s ease; }
.qrd.is-expanded .qrdSub { max-height: 150px; }

/* a value or difference the moment it recalculates. */
.qrdRow__val.is-flash, .qrdRow__diff.is-flash {
  outline: 1.5px solid var(--qrd-accent); outline-offset: 2px; border-radius: 3px;
  color: var(--qrd-accent);
}

/* ---------- the fix — cursor-clickable, same visual weight as the action
   pills on the other demos. ---------- */
.qrdAction {
  align-self: flex-start; margin-top: 9px;
  font-size: 9.5px; font-weight: 600; color: var(--qrd-accent);
  background: var(--qrd-accent-soft); border: 1px solid #CFC7EF; border-radius: 999px;
  padding: 6px 11px;
  transition: transform .15s ease, opacity .3s ease;
}
.qrd.is-press-realloc .qrdAction { transform: scale(.94); }
.qrd.is-saved .qrdAction { opacity: 0; }

/* ---------- reconciled banner ---------- */
.qrdBanner {
  margin-top: 9px; display: flex; align-items: center; gap: 7px;
  padding: 7px 10px; background: #F4FBF6;
  border: 1px solid var(--qrd-green-soft); border-radius: 7px;
  font-size: 9px; color: var(--qrd-ink2);
  opacity: 0; transform: translateY(4px);
  transition: opacity .35s ease, transform .35s ease;
}
.qrdBanner b { font-size: 9.5px; font-weight: 700; color: var(--qrd-green); }
.qrd.is-saved .qrdBanner { opacity: 1; transform: none; }

/* ---------- what sits behind a territory's number — opened in place, so
   the levels above it stay readable rather than being covered. ---------- */
.qrdDetail {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 0; overflow: hidden;
  padding: 0 9px 0 22px; background: var(--qrd-accent-soft);
  transition: max-height .4s ease, padding .4s ease;
}
.qrd.is-drilled .qrdDetail { max-height: 60px; padding: 7px 9px 8px 22px; }
.qrdDetail__head { font-size: 9px; font-weight: 700; color: var(--qrd-accent); }
.qrdDetail__body { font-size: 8.5px; line-height: 1.4; color: var(--qrd-ink2); }

/* the team row reads as the open one while its detail is showing. */
.qrd.is-drilled .qrdRow--team[data-el="westRow"] { background: var(--qrd-accent-soft); }
.qrdRow__chev--team { font-size: 9px; }
.qrd.is-drilled .qrdRow__chev--team { transform: rotate(90deg); }
/* only the segment chevron follows the segment's own expanded state. */
.qrd.is-expanded .qrdRow__chev--team { transform: none; }
.qrd.is-expanded.is-drilled .qrdRow__chev--team { transform: rotate(90deg); }

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

/* ---------- responsive — the table keeps its shape, the stage just grows
   taller so nothing has to be cut. ---------- */
@media (max-width: 460px) {
  .qrd__stage { aspect-ratio: auto; min-height: 450px; }
  .qrdRow { padding: 5px 7px; font-size: 9px; }
  .qrdRow__val { width: 50px; }
  .qrdRow__diff { width: 50px; }
  .qrdRow--team { padding-left: 16px; }
}
