/* ==========================================================================
   Explain8 Operate layer: client portal, staff console, order flow, account.
   Loaded after site.css (and pages.css) by every workflow layout and by the
   order pages. Tokens only; the one literal colour is the keyword `black`
   behind video.

   Surfaces are separated by tone, never by outline:
     canvas   --fog    main background on .app-surface
     panel    --paper  .card
     well     --fog    bands and nested panels on a panel
     lead     --suite  .lead, the one dark panel that says what to do now
   Tables and form fields keep their lines (site.css).

   Contents
     1  Surface and type scale
     2  Page head, back link
     3  Portal shell: sidebar, phone strip
     4  Panels: card, lead, key-value, empty state, callouts
     5  Status: badge, timeline
     6  Controls: disclosure, file rows, inline forms
     7  Monitor: the video stage
     8  Tables
     9  Helpers
   ========================================================================== */

/* 1 Surface and type scale ------------------------------------------------ */

.app-surface {
  --app-h1: clamp(1.625rem, 1.3rem + 0.95vw, 2rem);
  --app-h2: clamp(1.25rem, 1.1rem + 0.45vw, 1.5rem);
  --panel-pad: clamp(1.15rem, 2.4vw, 1.6rem);
}

.app-surface main {
  background: var(--fog);
}

.app-surface h1 {
  max-width: none;
  margin: 0;
  font-size: var(--app-h1);
  line-height: 1;
  letter-spacing: -0.03em;
}

.app-surface h2 {
  margin: 0 0 0.75rem;
  font-size: var(--app-h2);
  font-stretch: 86%;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.app-surface h3 {
  margin: 0 0 0.4rem;
  font-family: var(--font-text);
  font-size: var(--step-body);
  font-stretch: 100%;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
}

.app-surface :is(time, .num, .tabular, dd, td, th, .badge, output) {
  font-variant-numeric: tabular-nums;
}

/* Running text is full ink; only small meta lines stay grey. */
.app-surface p.muted:not(.small) {
  color: var(--ink-soft);
}

.app-surface .suite p.muted:not(.small),
.app-surface p.muted:not(.small).suite {
  color: var(--on-suite-soft);
}

.app-surface :is(.card, .lead) > :last-child {
  margin-bottom: 0;
}

/* 2 Page head, back link -------------------------------------------------- */

.app-head {
  display: grid;
  gap: 0.35rem;
  padding: 0 0 clamp(1.25rem, 2.6vw, 1.85rem);
}

.app-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 2rem;
}

.app-head-row > :first-child {
  min-width: 0;
}

.app-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.app-head .lede,
.app-sub {
  max-width: 46rem;
  margin: 0.55rem 0 0;
  font-size: var(--step-body);
  font-weight: 450;
  line-height: 1.5;
  letter-spacing: 0;
  color: var(--ink-soft);
}

.app-head-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.85rem;
  margin: 0.65rem 0 0;
  font-size: var(--step-small);
  font-weight: 600;
  color: var(--slate);
}

.suite .app-head-meta {
  color: var(--on-suite-soft);
}

.app-back {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  align-self: start;
  min-height: 2.75rem;
  font-size: var(--step-small);
  font-weight: 650;
  text-decoration: none;
}

.app-back::before {
  content: "";
  width: 1rem;
  height: 1rem;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5M11 6l-6 6 6 6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5M11 6l-6 6 6 6'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform var(--t-ui) var(--ease-out);
}

.app-back:hover {
  text-decoration: underline;
}

@media (hover: hover) {
  .app-back:hover::before {
    transform: translateX(-3px);
  }
}

/* 3 Portal shell: sidebar, phone strip ------------------------------------- */

.portal-layout {
  padding-bottom: clamp(2.5rem, 5vw, 4.5rem);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar :focus-visible {
  outline-color: var(--signal-light);
  outline-offset: 2px;
}

.sidebar h2 {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.side-user {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0 0.75rem;
  margin: 0 0 0.35rem;
  padding: 0.65rem 0.75rem 0.85rem;
}

.side-user-mark {
  display: grid;
  grid-row: span 2;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  background: var(--suite-3);
  color: var(--signal-light);
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 800;
  line-height: 1;
}

.side-user-name,
.side-user-meta {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-user-name {
  font-weight: 700;
  line-height: 1.25;
  color: var(--on-suite);
}

.side-user-meta {
  font-size: var(--step-small);
  line-height: 1.3;
  color: var(--on-suite-soft);
}

.sidebar a {
  justify-content: flex-start;
  gap: 0.7rem;
}

.sidebar a > span:not(.badge) {
  flex: 1 1 auto;
}

.sidebar a .icon {
  width: 1.15rem;
  height: 1.15rem;
  opacity: 0.85;
}

.sidebar a[aria-current="page"] .icon,
.sidebar a:hover .icon {
  opacity: 1;
}

.sidebar .badge {
  margin-left: auto;
  padding-block: 0.05rem;
}

.sidebar a[aria-current="page"] .badge-solid {
  background: var(--paper);
  color: var(--signal-deep);
}

.sidebar a:active {
  transform: scale(0.98);
}

.portal-side-actions {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.75rem;
  padding: 0.25rem 0 0.15rem;
}

.portal-side-actions form {
  margin: 0;
}

.portal-side-actions .button {
  width: 100%;
  justify-content: center;
}

/* ".sidebar a" in site.css would otherwise turn the link-styled button label ink-coloured and repaint its hover. */
.portal-side-actions a.button {
  background: var(--signal);
  color: var(--paper);
}

.portal-side-actions a.button:hover {
  background: var(--signal-deep);
  color: var(--paper);
}

.sidebar .button-ghost {
  color: var(--on-suite-soft);
}

.sidebar .button-ghost:hover {
  background: var(--suite-3);
  color: var(--paper);
}

@media (max-width: 61.99rem) {
  .portal-layout {
    gap: 1.5rem;
    padding-top: 0;
  }

  /* On a phone the sidebar is a second row of the app bar: one scrolling strip, flush under the header. */
  .sidebar {
    display: block;
    margin-inline: calc(var(--gutter) * -1);
    padding: 0.35rem var(--gutter);
    border-radius: 0;
  }

  .side-user,
  .portal-side-actions,
  .sidebar a .icon {
    display: none;
  }

  .sidebar ul {
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .sidebar ul::-webkit-scrollbar {
    display: none;
  }

  .sidebar li {
    flex: none;
  }

  .sidebar a {
    min-height: 2.75rem;
    padding: 0.4rem 0.9rem;
    white-space: nowrap;
  }
}

.portal-main {
  min-width: 0;
}

/* 4 Panels: card, lead, key-value, empty state, callouts ------------------- */

.app-surface .card {
  padding: var(--panel-pad);
  background: var(--paper);
}

.app-surface .card .card,
.app-surface .card .notice-quiet {
  background: var(--fog);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.card-head h2,
.card-head h3 {
  margin: 0;
}

/* The one dark panel on a screen: what to do now. Add .suite beside it. */
.lead {
  padding: clamp(1.25rem, 3vw, 2rem);
  border-radius: var(--radius);
}

.lead h2 {
  margin-bottom: 0.5rem;
}

.lead .actions {
  margin-top: 1.25rem;
}

.suite .kv dt,
.kv.suite dt {
  color: var(--on-suite-soft);
}

.kv {
  display: grid;
  gap: 0;
  margin: 0;
}

.kv > div {
  display: grid;
  gap: 0.1rem 1.5rem;
  padding: 0.55rem 0;
}

.kv > div:first-child {
  padding-top: 0;
}

.kv > div:last-child {
  padding-bottom: 0;
}

@media (min-width: 40rem) {
  .kv > div {
    grid-template-columns: minmax(8.5rem, 12rem) minmax(0, 1fr);
  }
}

.kv dt {
  margin: 0;
  font-size: var(--step-small);
  font-weight: 650;
  line-height: 1.5;
  color: var(--muted);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Long lists read better as separate bands, one tone step off the panel. */
.kv-bands {
  gap: 0.25rem;
}

.kv-bands > div,
.kv-bands > div:first-child,
.kv-bands > div:last-child {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  background: var(--fog);
}

.suite .kv-bands > div,
.kv-bands.suite > div {
  background: var(--suite-2);
}

.app-empty {
  display: grid;
  gap: 0.75rem 2rem;
  align-content: center;
  justify-items: start;
  padding: var(--panel-pad);
  border-radius: var(--radius);
  background: var(--paper);
}

.app-empty > * {
  margin: 0;
}

.app-empty h1,
.app-empty h2 {
  max-width: 26ch;
}

.app-empty p {
  max-width: 44rem;
}

.app-empty .actions {
  margin-top: 0.5rem;
}

.app-empty-art {
  margin: 0;
}

.app-empty-art img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.app-empty-art figcaption {
  margin-top: 0.5rem;
  font-size: var(--step-small);
  color: var(--muted);
}

@media (min-width: 52rem) {
  .app-empty:has(.app-empty-art) {
    grid-template-columns: minmax(0, 6fr) minmax(0, 5fr);
  }
}

/* A filled strip that names a fact or a consequence (a note on a panel, not a warning). */
.callout {
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  background: var(--wash);
  color: var(--ink);
}

.callout > :last-child {
  margin-bottom: 0;
}

/* 5 Status: badge, timeline ------------------------------------------------- */

.app-surface .badge {
  gap: 0.4rem;
  padding: 0.15rem 0.6rem 0.15rem 0.5rem;
  font-size: var(--step-small);
}

/* A square tally light before the word, the same ink as the word. Counts get none. */
.app-surface .badge:not(.badge-solid, .tab-badge)::before {
  content: "";
  flex: none;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 1px;
  background: currentColor;
}

.sidebar .badge::before {
  content: none;
}

.app-surface .badge-muted {
  color: var(--slate);
}

.tab-badge {
  margin-left: 0.4rem;
}

/* The project timeline is a track: one clip per step, the playhead on the step we are at. */
.timeline {
  display: grid;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline-step {
  position: relative;
  display: grid;
  grid-template-columns: 0.75rem minmax(0, 1fr) auto;
  grid-template-areas: "marker label meta";
  align-items: center;
  gap: 0 0.85rem;
  min-height: 2.75rem;
  margin: 0;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  background: var(--fog);
}

.timeline-marker {
  grid-area: marker;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 1px;
  background: color-mix(in srgb, var(--ink) 16%, var(--paper));
}

.timeline-label {
  grid-area: label;
  font-weight: 650;
  line-height: 1.3;
  color: var(--slate);
}

.timeline-meta {
  grid-area: meta;
  font-size: var(--step-small);
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--slate);
}

.timeline-step.is-done .timeline-marker {
  background: var(--signal);
}

.timeline-step.is-done .timeline-label {
  color: var(--ink);
}

.timeline-step.is-current {
  background: var(--wash);
}

.timeline-step.is-current .timeline-marker {
  background: var(--ink);
}

.timeline-step.is-current .timeline-label {
  color: var(--ink);
  font-weight: 750;
}

@media (min-width: 56rem) {
  .timeline {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .timeline-step {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "marker"
      "label"
      "meta";
    align-items: start;
    row-gap: 0.55rem;
    padding: 0 0 0.9rem;
    border-radius: 0;
    background: none;
  }

  .timeline-step.is-current {
    background: none;
  }

  /* The clip: a bar the width of its column. */
  .timeline-marker {
    width: 100%;
    height: 0.5rem;
    border-radius: var(--radius);
  }

  .timeline-step.is-current .timeline-marker {
    background: var(--signal);
  }

  /* The playhead: an amber notch on the current clip, the one place amber appears on a light panel. */
  .timeline-step.is-current::before {
    content: "";
    position: absolute;
    top: -0.55rem;
    left: 0;
    width: 0.8rem;
    height: 0.55rem;
    background: var(--amber);
    clip-path: polygon(0 0, 100% 0, 50% 100%);
  }

  .timeline-step.is-current::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0.35rem;
    width: 0.125rem;
    height: 0.5rem;
    background: var(--amber);
  }

  .timeline-label,
  .timeline-meta {
    text-align: left;
  }
}

/* A step track (order steps, brief progress): one clip per step, drawn as a bar on top of the step's own content.
   Mark a step with .is-done, or aria-current="step" on the li (or on a control inside it). */
.track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.track > li {
  position: relative;
  min-width: 0;
  margin: 0;
  padding-top: 0.85rem;
}

.track > li::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 0.5rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--ink) 16%, var(--paper));
  transition: background-color var(--t-ui) ease;
}

.track > li.is-done::before {
  background: var(--signal);
}

.track > li[aria-current="step"]::before,
.track > li:has(> [aria-current="step"])::before {
  background: var(--ink);
}

.suite .track > li::before {
  background: var(--suite-3);
}

.suite .track > li.is-done::before {
  background: var(--signal-bright);
}

.suite .track > li[aria-current="step"]::before {
  background: var(--amber);
}

/* 6 Controls: disclosure, file rows, inline forms ---------------------------- */

/* A calm second step before a consequential action: the summary is a tone-step button. */
.disclosure > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  background: var(--fog-2);
  color: var(--ink);
  font-weight: 700;
  list-style: none;
  cursor: pointer;
  transition: background-color var(--t-hover) ease, transform var(--t-press) var(--ease-out);
}

.disclosure > summary::-webkit-details-marker {
  display: none;
}

.disclosure > summary::after {
  content: "";
  flex: none;
  width: 1rem;
  height: 1rem;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform var(--t-ui) var(--ease-out);
}

.disclosure[open] > summary::after {
  transform: rotate(180deg);
}

.disclosure > summary:hover {
  background: var(--wash);
}

.disclosure > summary:active {
  transform: scale(0.98);
}

.disclosure[open] > summary {
  margin-bottom: 1rem;
}

.disclosure-danger > summary {
  color: var(--bad);
}

.disclosure-danger > summary:hover {
  background: var(--bad-bg);
}

.file-list {
  display: grid;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.file-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin: 0;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  background: var(--fog);
}

.file-row-main {
  display: grid;
  min-width: 0;
}

.file-row-name {
  overflow-wrap: anywhere;
}

.file-row-actions {
  --cluster-gap: 0.5rem;
}

.inline-form {
  display: inline;
  margin: 0;
}

.prewrap {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 7 Monitor: the video stage ------------------------------------------------- */

/* Video always sits on the suite ground, like a program monitor. */
.monitor {
  display: grid;
  place-items: center;
  padding: clamp(0.75rem, 2vw, 1.25rem);
  border-radius: var(--radius);
  background: var(--suite);
  color: var(--on-suite);
  color-scheme: dark;
}

.monitor-frame {
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius);
  background: black;
}

.monitor-frame[data-layout="horizontal"] {
  aspect-ratio: 16 / 9;
}

.monitor-frame[data-layout="vertical"] {
  width: min(100%, 22rem);
  aspect-ratio: 9 / 16;
}

.monitor-frame video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: black;
}

/* A timecode is the one amber thing on a dark chip, readable on any panel. */
.timecode {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.55rem;
  border-radius: var(--radius);
  background: var(--suite);
  color: var(--amber);
  font-size: var(--step-small);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  white-space: nowrap;
}

/* 8 Tables ---------------------------------------------------------------------- */

.app-surface .table-wrap {
  background: var(--paper);
}

.app-surface thead th {
  background: var(--fog-2);
  color: var(--slate);
  font-size: var(--step-small);
  font-weight: 700;
}

.app-surface th.num,
.app-surface td.num {
  text-align: right;
}

/* Button rows sit closer to the copy above them than on a marketing page. */
.app-surface .actions {
  margin-top: 1.25rem;
}

/* Project and section tabs: a raised strip on the canvas, the current tab a filled block. */
.app-surface .tabs {
  margin-bottom: 1.5rem;
  background: var(--paper);
}

.app-surface .tabs a,
.app-surface .tabs button {
  min-height: 2.75rem;
}

.app-surface .tabs a:hover,
.app-surface .tabs button:hover {
  background: var(--fog-2);
}

.app-surface .tabs [aria-current="page"]:hover,
.app-surface .tabs [aria-selected="true"]:hover {
  background: var(--ink);
}

/* 9 Helpers ----------------------------------------------------------------------- */

.pre-line {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.plain-list {
  margin: 0 0 0.75rem;
  padding-left: 1.1rem;
}

@media print {
  .sidebar,
  .app-back {
    display: none !important;
  }
}
