.plan-grid {
  display: grid; gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  padding: 0; margin: 0; list-style: none;

  > li { min-width: 0; }
}

.plan-filter { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: -0.5rem 0 1.5rem; }
.plan-filter .chip[aria-current] { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.plan-filter .chip[aria-current] .muted { color: var(--rule); }

.plan-card {
  display: grid; grid-template-rows: auto 1fr;
  height: 100%;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink); text-decoration: none;
  overflow: hidden;

  &:hover { border-color: var(--ink); }
  h2 { margin: 0; font-size: 1.1rem; }
  .stamp { justify-self: start; white-space: normal; }
}

/* The assembled piece on a sheet of graph paper, like the plan it opens. */
.plan-card__view {
  position: relative;
  display: grid; place-items: center;
  aspect-ratio: 4 / 3;
  border-bottom: 1px solid var(--rule);
  background-color: var(--paper);
  background-image: repeating-linear-gradient(0deg, transparent 0 23px, #f0efe9 23px 24px), repeating-linear-gradient(90deg, transparent 0 23px, #f0efe9 23px 24px);

  img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 0.5rem; }
}
.plan-card__rev {
  position: absolute; top: 0.6rem; right: 0.6rem;
  padding: 0.1em 0.45em;
  border: 1px solid var(--ink); border-radius: var(--radius);
  background: #fff;
  font-size: 0.75rem; font-weight: 600;
}
.plan-card__body { display: grid; align-content: start; justify-items: start; gap: 0.5rem; padding: 1rem 1.2rem 1.1rem; }
.plan-card__body .stamp { white-space: normal; }

.empty {
  padding: 3rem 1.5rem;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  text-align: center;
}

.starts { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0 1.5rem; }

/* The design view: the chat on the left, the live plan on the right. */
.workspace {
  display: grid;
  grid-template-columns: minmax(22rem, 30rem) 1fr;
  height: calc(100dvh - 64px);
}

.workspace__panes { display: contents; }

.workspace__chat {
  display: grid; grid-template-rows: auto 1fr auto auto;
  min-height: 0;
  border-right: 1px solid var(--rule);
}

.workspace__head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--rule);

  h1 { font-size: 1.15rem; margin: 0; }
}

.workspace__viewer { position: relative; min-height: 0; background: #fff; }

.viewer { display: flex; flex-direction: column; height: 100%; }
.viewer__bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--rule);
  font-size: 0.9rem;
}
.viewer iframe { width: 100%; flex: 1; min-height: 0; border: 0; display: block; }
.viewer__empty {
  display: grid; place-content: center; gap: 0.5rem;
  flex: 1; padding: 2rem;
  text-align: center; color: var(--ink-soft);
  background: repeating-linear-gradient(0deg, transparent 0 23px, #f0efe9 23px 24px), repeating-linear-gradient(90deg, transparent 0 23px, #f0efe9 23px 24px);
}

/* The turn being designed now: stages, the designer's notes, parts as drafted, the Foreman's checks. */
.progress--idle { display: none; }
.progress {
  display: grid; gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  font-size: 0.9rem;
  overflow: auto;
}
.progress--over-model { max-height: 42%; }
.viewer:has(.progress:not(.progress--idle)) .viewer__empty { display: none; }
.viewer:has(.progress:not(.progress--idle)) .progress:not(.progress--over-model) { flex: 1; align-content: start; }

.progress__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.progress__stages { display: flex; flex-wrap: wrap; gap: 0.35rem 1.1rem; list-style: none; margin: 0; padding: 0; counter-reset: stage; }
.progress__stages li { counter-increment: stage; color: var(--ink-soft); font: 500 0.8rem/1.4 var(--mono); }
.progress__stages li::before {
  content: counter(stage);
  display: inline-grid; place-items: center; width: 1.25rem; height: 1.25rem; margin-right: 0.35rem;
  border: 1px solid var(--rule); border-radius: 50%; font-size: 0.7rem;
}
.progress__stages li.done { color: var(--material); }
.progress__stages li.done::before { content: "✓"; border-color: var(--material); }
.progress__stages li.active { color: var(--ink); font-weight: 600; }
.progress__stages li.active::before { border-color: var(--walnut); background: var(--walnut); color: #fff; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.progress__note { margin: 0; font: italic 1rem/1.45 var(--body); color: var(--ink); }
.progress__body { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: flex-start; }
.progress__body > section { flex: 1 1 20rem; min-width: 0; }
.progress__body h3 { margin: 0 0 0.4rem; }
.progress__parts table { width: 100%; border-collapse: collapse; }
.progress__parts td { padding: 0.2rem 0.4rem 0.2rem 0; border-bottom: 1px solid #eeede8; vertical-align: middle; }
.progress__parts td.mono { white-space: nowrap; }
/* The panel is redrawn as it streams, so only the newest line flashes. */
.progress__parts tr:last-child { animation: arrive 0.6s ease-out; }
@keyframes arrive { from { background: var(--endgrain); } }
.progress__review ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
.progress__review li:last-child { animation: arrive 0.6s ease-out; }
.progress__issues { margin-top: 0.5rem !important; }
.progress__issues li { padding-left: 0.6rem; border-left: 2px solid var(--mark); }
.result { display: inline-block; min-width: 3.2em; font: 600 0.7rem/1.6 var(--mono); text-transform: uppercase; text-align: center; border-radius: var(--radius); background: #eeede8; }
.result--pass, .result--fixed { background: #e3efe7; color: var(--material); }
.result--flag { background: #f6ecd9; color: var(--walnut); }
.result--fail { background: #f6dfdc; color: var(--mark); }
.progress__log { flex-basis: 100%; list-style: none; margin: 0; padding: 0; font-size: 0.75rem; color: var(--ink-soft); display: grid; gap: 0.1rem; }
.progress__log li::before { content: "— "; }

.revisions { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; }
.revisions li {
  display: grid; grid-template-columns: 3.5rem 1fr auto; gap: 1rem; align-items: center;
  padding: 0.9rem 1rem; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff;
}
.revisions .letter { font: 700 1.6rem/1 var(--display); font-stretch: 125%; }

/* A plan page on its own (a shared plan, an old revision): the bar, then the plan filling the window. */
main.viewer { display: flex; flex-direction: column; height: calc(100dvh - 64px); }
main.viewer .shared-frame { flex: 1; height: auto; min-height: 0; }
.viewer__note { margin: 0; padding: 0.45rem 1rem; border-bottom: 1px solid var(--rule); background: var(--sel-soft); font-size: 0.9rem; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 55dvh auto; height: auto; }
  .workspace__panes { display: contents; }

.workspace__chat { border-right: 0; border-bottom: 1px solid var(--rule); }
  .workspace__viewer { height: 80dvh; }
}

.workspace__actions { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; white-space: nowrap; }

.problem-form { margin-top: 1.75rem; }

.copy-size { border: 0; padding: 0; margin: 0 0 1.1em; }
.copy-size__fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
.copy-size__fields .field { margin: 0; }

.share-preview {
  display: flex; align-items: center; gap: 1rem;
  margin: 0 0 1.5rem; padding: 0.75rem;
  border: 1px solid var(--rule); border-radius: var(--radius); background: #fff;

  img { flex: none; width: 96px; height: 96px; background: var(--paper); border-radius: var(--radius); }
  .stamp { margin-top: 0.35rem; }
}
.share-link { display: flex; gap: 0.5rem; margin: 1rem 0 0.5rem; }
.share-link input { flex: 1; min-width: 0; font-size: 0.85rem; }
.share-actions { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 1.5rem; margin-top: 1.5rem; font-size: 0.95rem; }
.viewer__share { display: flex; align-items: center; gap: 1rem; }
.viewer__share .button { padding: 0.45em 0.9em; }

/* Printing: the sheet picker and the PDF it makes. */
.locked { padding: 1.25rem 1.4rem; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; }
.print-warning, .print .flash { margin: 1rem 0; }
.print-standards { font-size: 0.9rem; }
.print { display: grid; gap: 0.75rem; margin-top: 1rem; }
.print p { margin: 0; }
.print .button + .button { margin-left: 0.5rem; }
.preview { display: grid; gap: 0.5rem; margin-top: 0.5rem; }
.preview h2 { margin: 0; font-size: 1.1rem; }
.preview__pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: 0.75rem; }
.preview__page { display: grid; gap: 0.25rem; padding: 0; border: 0; background: none; cursor: zoom-in; font: inherit; color: var(--ink-soft); text-align: center; }
.preview__page canvas { width: 100%; aspect-ratio: 8.5 / 11; background: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.18); }
.preview__page--drawn canvas { aspect-ratio: auto; }
.preview__page:hover canvas, .preview__page:focus-visible canvas { outline: 2px solid var(--walnut); outline-offset: 2px; }
.preview__dialog { width: min(60rem, 94vw); max-height: 94vh; padding: 0.75rem; border: 0; border-radius: 6px; }
.preview__dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.preview__dialog header { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.preview__close { margin-left: auto; }
.preview__sheet { overflow: auto; }
.preview__sheet canvas { display: block; margin: 0 auto; box-shadow: 0 1px 6px rgb(0 0 0 / 0.25); }
.print__status::before { content: ""; display: inline-block; width: 0.7em; height: 0.7em; margin-right: 0.5em; border: 2px solid var(--walnut); border-right-color: transparent; border-radius: 50%; animation: spin 0.9s linear infinite; vertical-align: -0.05em; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Two revisions side by side, with what changed between them above */
main.comparing { height: calc(100dvh - 64px); }
.comparison { display: grid; grid-template-rows: auto auto 1fr; height: 100%; min-height: 0; }

.comparison__head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 0.75rem 1.5rem;
  padding: 0.9rem var(--gutter) 0.6rem;
  h1 { margin: 0.2em 0 0; font-size: 1.4rem; }
}
.comparison__pick { display: flex; align-items: center; gap: 0.5rem; select { width: auto; } }

.comparison__changes {
  max-height: 28dvh; overflow-y: auto;
  padding: 0.2rem var(--gutter) 0.8rem;
  border-bottom: 1px solid var(--rule);
  h2 { margin: 0 0 0.4em; font-size: 1rem; }
  p { margin: 0; }
}

.changes { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; font-size: 0.92rem; }
.change__part {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0.2em 0.6em;
  padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
  &:hover .mono { color: var(--hardware); text-decoration: underline; }
}
.change__details { color: var(--ink-soft); }
.change__kind {
  display: inline-block; min-width: 5.2em;
  padding: 0.05em 0.45em; border-radius: var(--radius);
  font: 500 0.68rem/1.5 var(--mono); letter-spacing: 0.05em; text-transform: uppercase; text-align: center;
}
.change__kind--changed { background: var(--sel-soft); color: var(--hardware); }
.change__kind--added { background: #E3EFE7; color: var(--material); }
.change__kind--removed { background: #F6E1DE; color: var(--mark); }

.comparison__panes { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; min-height: 0; }
.comparison__pane { display: grid; grid-row: span 2; grid-template-rows: subgrid; min-height: 0; background: #fff; }
.comparison__pane + .comparison__pane { border-left: 1px solid var(--rule); }
.comparison__pane iframe { width: 100%; height: 100%; border: 0; display: block; }

@media (max-width: 900px) {
  main.comparing { height: auto; }
  .comparison__panes { grid-template-columns: 1fr; grid-template-rows: none; }
  .comparison__pane { grid-row: auto; grid-template-rows: auto 1fr; height: 80dvh; }
  .comparison__pane + .comparison__pane { border-left: 0; border-top: 1px solid var(--rule); }
}
