/* EstiWright demo gallery — animated app-screen mocks.
 *
 * Motion model: every screen runs one shared --cycle loop. Children stagger via
 * an --i index and a per-archetype delay, so a screen "plays" (rows stream in,
 * statuses flip, gates unlock) and then resets, forever. Hovering or focusing a
 * card pauses it so a visitor can actually read the thing.
 *
 * These are hand-built mocks in the site theme, modelled on the real app's
 * structure and populated with real demo-tenant data. They are not screenshots.
 */

.demos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 26px;
}

.demo-tile {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.demo-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-raised);
}
.demo-tile__body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.demo-tile__body h3 {
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 600;
  margin: 0;
}
.demo-tile__body h3 a { color: inherit; }
.demo-tile__body h3 a:hover { color: var(--bronze); }
.demo-tile__body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.55;
}
.demo-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 10px;
}
.demo-tag {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--bronze-deep);
  border: 1px solid color-mix(in srgb, var(--bronze) 18%, transparent);
}

/* ── App-window chrome ──────────────────────────────────────────── */
.dm {
  --cycle: 7s;
  --stagger: 0.3s;
  position: relative;
  background: var(--ivory);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.45;
  overflow: hidden;
}
.dm__bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  background: var(--ivory-sunk);
  border-bottom: 1px solid var(--line);
}
.dm__bar i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}
.dm__bar span {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--soft);
  margin-left: 4px;
}
.dm__stage {
  padding: 12px 14px 14px;
  min-height: 176px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dm__note {
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--bronze);
  padding: 0 14px 12px;
}

/* Pause when the visitor engages with the card. */
.demo-tile:hover .dm *,
.demo-tile:focus-within .dm * { animation-play-state: paused; }

/* ── Shared entrance ────────────────────────────────────────────── */
.dm [data-i] {
  animation: dmIn var(--cycle) linear infinite;
  animation-delay: calc(var(--i) * var(--stagger) + var(--phase, 0s));
}
@keyframes dmIn {
  0%, 3% { opacity: 0; transform: translateY(7px); }
  10%, 91% { opacity: 1; transform: none; }
  98%, 100% { opacity: 0; transform: translateY(-4px); }
}

/* ── Tables ─────────────────────────────────────────────────────── */
.dm-table { width: 100%; border-collapse: collapse; }
.dm-table th {
  text-align: left;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--soft);
  padding: 0 8px 6px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.dm-table td {
  padding: 6px 8px 6px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  color: var(--ink);
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dm-table tr:last-child td { border-bottom: 0; }

/* ── Step rail / journey ────────────────────────────────────────── */
.dm-steps { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding-top: 6px; }
.dm-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--soft);
}
.dm-step b {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 19px;
  padding: 0 5px;
  border-radius: var(--radius-xs, 5px);
  background: var(--ivory-sunk);
  border: 1px solid var(--line-strong);
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  color: var(--soft);
  animation: dmStep var(--cycle) linear infinite;
  animation-delay: calc(var(--i) * 0.5s + var(--phase, 0s));
}
.dm-step--on b { background: var(--gradient); border-color: transparent; color: #fff; }
.dm-step i { width: 10px; height: 1px; background: var(--line-strong); }
@keyframes dmStep {
  0%, 6% { transform: scale(0.86); opacity: 0.35; }
  14%, 86% { transform: none; opacity: 1; }
  100% { transform: scale(0.86); opacity: 0.35; }
}
.dm-journey { display: flex; flex-wrap: wrap; gap: 5px; }
.dm-journey span {
  font-family: var(--mono);
  font-size: 0.63rem;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--ivory-sunk);
  border: 1px solid var(--line);
  color: var(--soft);
}
.dm-journey span.on { background: var(--gold-soft); color: var(--bronze-deep); border-color: color-mix(in srgb, var(--bronze) 22%, transparent); }

/* ── Status badges that flip ────────────────────────────────────── */
.dm-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}
.dm-badge-row:last-child { border-bottom: 0; }
.dm-badge-row > span:first-child {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dm-flip { position: relative; display: inline-grid; min-width: 74px; justify-items: end; }
.dm-flip > b {
  grid-area: 1 / 1;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  animation: dmFlipA var(--cycle) steps(1) infinite;
  animation-delay: calc(var(--i) * 0.22s + var(--phase, 0s));
  background: var(--ivory-sunk);
  border: 1px solid var(--line-strong);
  color: var(--soft);
}
.dm-flip > b + b { animation-name: dmFlipB; }
@keyframes dmFlipA { 0%, 44% { opacity: 1; } 46%, 100% { opacity: 0; } }
@keyframes dmFlipB { 0%, 44% { opacity: 0; } 46%, 100% { opacity: 1; } }
.dm-t-ok   { background: var(--ok-bg) !important; color: var(--ok) !important; border-color: color-mix(in srgb, var(--ok) 30%, transparent) !important; }
.dm-t-warn { background: color-mix(in srgb, #b45309 13%, transparent) !important; color: #92400e !important; border-color: color-mix(in srgb, #b45309 30%, transparent) !important; }
.dm-t-crit { background: color-mix(in srgb, #b91c1c 12%, transparent) !important; color: #991b1b !important; border-color: color-mix(in srgb, #b91c1c 28%, transparent) !important; }
.dm-t-mute { background: var(--ivory-sunk) !important; color: var(--soft) !important; }

/* ── KPI counters ───────────────────────────────────────────────── */
.dm-kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.dm-kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm, 9px);
  padding: 8px 10px;
}
.dm-kpi b {
  display: block;
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.dm-kpi span {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: var(--soft);
  text-transform: uppercase;
}
.dm-kpi.is-ok b { color: var(--ok); }
.dm-kpi.is-warn b { color: #92400e; }

/* ── Bars ───────────────────────────────────────────────────────── */
.dm-bar { display: grid; grid-template-columns: 62px 1fr auto; align-items: center; gap: 8px; }
.dm-bar span { font-size: 0.72rem; color: var(--soft); }
.dm-bar i {
  height: 8px;
  border-radius: 999px;
  background: var(--gradient);
  transform-origin: left center;
  animation: dmGrow var(--cycle) cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
  animation-delay: calc(var(--i) * 0.24s + var(--phase, 0s));
}
.dm-bar b { font-family: var(--mono); font-size: 0.66rem; color: var(--bronze); font-variant-numeric: tabular-nums; }
@keyframes dmGrow {
  0%, 5% { transform: scaleX(0.02); }
  32%, 84% { transform: scaleX(1); }
  96%, 100% { transform: scaleX(0.02); }
}

/* ── Chips ──────────────────────────────────────────────────────── */
.dm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dm-chips b {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--bronze-deep);
  border: 1px solid color-mix(in srgb, var(--bronze) 18%, transparent);
}

/* ── Chat / companion lines ─────────────────────────────────────── */
.dm-line {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 9px;
  border-radius: var(--radius-sm, 9px);
  background: var(--ivory-sunk);
  border-left: 2px solid var(--line-strong);
}
.dm-line em {
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--soft);
}
.dm-line span { color: var(--ink); }
.dm-line.is-ok { border-left-color: var(--ok); }
.dm-line.is-warn { border-left-color: #b45309; }

/* ── Deliverable ladder ─────────────────────────────────────────── */
.dm-rung {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  border-radius: var(--radius-sm, 9px);
  border: 1px solid var(--line);
  background: var(--card);
}
.dm-rung > span { display: flex; align-items: center; gap: 7px; color: var(--ink); }
.dm-rung u {
  text-decoration: none;
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}
.dm-rung.is-locked { opacity: 0.55; }
.dm-rung.is-approved { border-color: color-mix(in srgb, var(--ok) 34%, transparent); background: var(--ok-bg); }
.dm-rung.is-ready { border-color: color-mix(in srgb, var(--bronze) 34%, transparent); background: var(--gold-soft); }

/* ── Upload / files / code / translate / toggle / palette ───────── */
.dm-drop {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-sm, 9px);
  padding: 14px;
  text-align: center;
  color: var(--soft);
  background: color-mix(in srgb, var(--gold-soft) 45%, transparent);
}
.dm-drop b { display: block; font-family: var(--mono); font-size: 0.74rem; color: var(--bronze-deep); }
.dm-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm, 9px);
  background: var(--card);
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--bronze-deep);
}
.dm-file::before {
  content: "";
  width: 13px;
  height: 16px;
  flex: none;
  border-radius: 2px;
  background: var(--gradient);
}
.dm-code {
  font-family: var(--mono);
  font-size: 0.68rem;
  background: var(--ink);
  color: #f2ede1;
  border-radius: var(--radius-sm, 9px);
  padding: 10px 11px;
  overflow-x: auto;
}
.dm-code b { display: block; color: #dcbc5e; font-weight: 500; }
.dm-tr { display: flex; flex-direction: column; gap: 7px; }
.dm-tr div {
  padding: 8px 10px;
  border-radius: var(--radius-sm, 9px);
  background: var(--ivory-sunk);
  border: 1px solid var(--line);
  color: var(--ink);
}
.dm-tr div:last-child { background: var(--gold-soft); direction: rtl; text-align: right; }
.dm-toggle { display: flex; flex-direction: column; gap: 9px; align-items: center; justify-content: center; flex: 1; }
.dm-toggle > div { position: relative; display: inline-grid; }
.dm-toggle b {
  grid-area: 1 / 1;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--ivory-sunk);
  color: var(--soft);
  white-space: nowrap;
  animation: dmFlipA var(--cycle) steps(1) infinite;
  animation-delay: var(--phase, 0s);
}
.dm-toggle b + b { animation-name: dmFlipB; }
.dm-switch {
  width: 46px;
  height: 24px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  animation: dmTrack var(--cycle) steps(1) infinite;
  animation-delay: var(--phase, 0s);
}
.dm-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  animation: dmKnob var(--cycle) cubic-bezier(0.5, 0, 0.2, 1) infinite;
  animation-delay: var(--phase, 0s);
}
@keyframes dmTrack { 0%, 44% { background: var(--line-strong); } 46%, 100% { background: var(--ok); } }
@keyframes dmKnob { 0%, 40% { transform: none; } 50%, 100% { transform: translateX(22px); } }
.dm-palette { display: flex; flex-direction: column; gap: 7px; }
.dm-palette__in {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm, 9px);
  background: var(--card);
  color: var(--soft);
  font-size: 0.75rem;
}
.dm-palette__in b {
  color: var(--ink);
  font-weight: 500;
  border-right: 1.5px solid var(--bronze);
  padding-right: 1px;
  animation: dmType var(--cycle) steps(6) infinite, dmCaret 0.9s steps(1) infinite;
  animation-delay: var(--phase, 0s), 0s;
  white-space: nowrap;
  overflow: hidden;
}
@keyframes dmType { 0%, 3% { max-width: 0; } 26%, 88% { max-width: 7ch; } 100% { max-width: 0; } }
@keyframes dmCaret { 50% { border-color: transparent; } }
.dm-res { display: flex; align-items: baseline; gap: 8px; padding: 4px 2px; }
.dm-res em {
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--soft);
  min-width: 58px;
}
.dm-res span { color: var(--ink); }

/* ── Gallery filter ─────────────────────────────────────────────── */
.demos-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 30px; }
.demos-filter button {
  font: inherit;
  font-size: 0.88rem;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.demos-filter button:hover { border-color: var(--bronze); color: var(--bronze); }
.demos-filter button[aria-pressed="true"] {
  background: var(--gradient);
  border-color: transparent;
  color: #fff;
}
.demos-count { color: var(--soft); font-size: 0.9rem; margin-bottom: 18px; }

/* Respect reduced motion: hold the finished state, never loop. */
@media (prefers-reduced-motion: reduce) {
  .dm *,
  .dm *::after {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
    max-width: none !important;
  }
  .dm-flip > b:first-child,
  .dm-toggle b:first-child { display: none; }
  .dm-switch { background: var(--ok); }
  .dm-switch::after { transform: translateX(22px) !important; }
  .demo-tile:hover { transform: none; }
}

/* Only cards in view animate — 57 looping screens otherwise stall scrolling.
   `content-visibility` also skips layout/paint for tiles far off-screen. */
/* NOTE: content-visibility:auto was tried here and removed. It let some engines
   skip painting the tiles entirely, rendering a blank gallery — a far worse
   failure than the compositing cost it saves. The observer below is enough. */
.demo-tile.is-off .dm * { animation-play-state: paused !important; }
