/* ==========================================================================
   Sitelyup stylesheet. One file (single hashed route), organised in sections:
   1. Tokens          5. Tables            9. Prepare
   2. Base            6. Dialogs           10. Editor
   3. Chrome (header) 7. Auth + errors     11. Admin
   4. Buttons, forms  8. Projects/project
   ========================================================================== */

/* ---- 1. Tokens ---------------------------------------------------------- */
:root {
  --color-primary: #1f6f5c;
  --color-primary-hover: #185a4a;
  --color-primary-text: #ffffff;
  --color-danger: #b42318;
  --color-danger-bg: #fbe9e9;
  --color-danger-border: #e3b3b0;
  --color-danger-text: #8f1d1d;
  --color-warn-bg: #fbf1de;
  --color-warn-text: #7a5208;
  --color-warn-dot: #d08a12;
  --color-ok-bg: #e3f1e6;
  --color-ok-text: #1d5c2d;
  --color-surface: #ffffff;
  --color-surface-2: #fafaf9;
  --color-bg: #f4f5f3;
  --color-text: #1b1f1e;
  --color-muted: #5f6b67;
  --color-border: #d5dbd8;
  --color-row-border: #eceeeb;
  --color-tint: #f4f8f6;
  --color-tint-strong: #e3efea;
  --color-pill-bg: #eceeeb;
  --color-canvas: #8f9391;
  --color-backdrop: rgb(28 31 30 / 0.35);
  --radius: 0.5rem;
  --radius-sm: 0.375rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 2rem;
  --header-h: 2.75rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #3aa58b;
    --color-primary-hover: #52bfa4;
    --color-primary-text: #0b1512;
    --color-danger: #f97066;
    --color-danger-bg: #3a1c1a;
    --color-danger-border: #7a3a35;
    --color-danger-text: #fda29b;
    --color-warn-bg: #3a2c10;
    --color-warn-text: #f5c875;
    --color-warn-dot: #e0a23a;
    --color-ok-bg: #1b3524;
    --color-ok-text: #8fd6a2;
    --color-surface: #1c2220;
    --color-surface-2: #212826;
    --color-bg: #121615;
    --color-text: #e8ecea;
    --color-muted: #9aa7a2;
    --color-border: #333c39;
    --color-row-border: #2a312f;
    --color-tint: #1f2a26;
    --color-tint-strong: #26372f;
    --color-pill-bg: #2a312f;
    --color-canvas: #4a504e;
    --color-backdrop: rgb(0 0 0 / 0.55);
  }
}

/* ---- 2. Base ------------------------------------------------------------ */
[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, sans-serif;
  font-size: 0.875rem;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a {
  color: var(--color-primary);
}

a:hover {
  color: var(--color-primary-hover);
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

main {
  flex: 1;
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  padding: var(--spacing-lg) var(--spacing-md) 3.5rem;
}

main.page-md {
  max-width: 60rem;
}
main.page-lg {
  max-width: 65rem;
}
main.page-xl,
main.wide {
  max-width: 70rem;
}

h1 {
  margin: 0;
  font-size: 1.625rem;
  line-height: 1.25;
}

h2 {
  font-size: 1.125rem;
  margin: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.row.wrap {
  flex-wrap: wrap;
}

.spacer {
  flex: 1;
}

form.inline {
  display: inline;
}

.error {
  color: var(--color-danger);
  font-weight: 600;
}

.alert {
  padding: 0.5rem 0.75rem;
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  color: var(--color-danger-text);
  border-radius: var(--radius-sm);
}

.muted {
  color: var(--color-muted);
}

.small {
  font-size: 0.875rem;
}

.notes {
  white-space: pre-wrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

kbd {
  font: inherit;
  font-size: 0.85em;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  background: var(--color-bg);
}

/* ---- 3. Chrome (header) ------------------------------------------------- */
.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--spacing-md);
  min-height: var(--header-h);
  padding: 0 var(--spacing-md);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  justify-self: start;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
}

.crumbs a {
  color: var(--color-muted);
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--color-text);
}

.crumbs .sep {
  color: var(--color-muted);
  opacity: 0.6;
}

.crumbs .current {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-user {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.875rem;
  min-width: 0;
}

.header-user .who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- 4. Buttons and forms ------------------------------------------------ */
button,
.btn {
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 2.25rem;
  padding: 0.375rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-primary-text);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
a.btn:hover {
  background: var(--color-primary-hover);
  color: var(--color-primary-text);
}

button.secondary,
.btn.secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
  font-weight: 400;
}

button.secondary:hover,
a.btn.secondary:hover {
  background: var(--color-tint);
  color: var(--color-text);
}

button.secondary[aria-pressed='true'] {
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
  background: var(--color-tint-strong);
}

button.danger,
.btn.danger {
  background: var(--color-danger);
  color: var(--color-surface);
}

button.danger:hover {
  background: var(--color-danger);
  filter: brightness(0.9);
  color: var(--color-surface);
}

button.danger-outline,
.btn.danger-outline {
  background: var(--color-surface);
  color: var(--color-danger);
  border-color: var(--color-danger-border);
  font-weight: 400;
}

button.danger-outline:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

button.link {
  background: none;
  color: var(--color-primary);
  padding: 0;
  min-height: 0;
  border: 0;
  font-weight: 400;
}

button.link:hover {
  background: none;
  color: var(--color-primary-hover);
  text-decoration: underline;
}

button.icon {
  padding: 0.25rem;
  min-height: 2rem;
  min-width: 2rem;
}

button.tiny {
  padding: 0.15rem 0.4rem;
  min-height: 0;
  font-size: 0.75rem;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-weight: 600;
}

label.radio,
.inline-label {
  flex-direction: row;
  align-items: center;
  font-weight: 400;
}

.optional {
  font-weight: 400;
  color: var(--color-muted);
}

.hint {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--color-muted);
}

input,
textarea,
select {
  font: inherit;
  padding: 0.5rem 0.625rem;
  min-height: 2.375rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: inherit;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
  background: var(--color-surface);
}

textarea {
  resize: vertical;
}

.password-field {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  overflow: hidden;
}

.password-field:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
  background: var(--color-surface);
}

.password-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  outline: none;
}

.password-field button {
  border: 0;
  border-left: 1px solid var(--color-border);
  border-radius: 0;
  background: var(--color-surface);
  color: var(--color-muted);
  font-weight: 400;
  font-size: 0.8125rem;
}

.file-btn {
  display: inline-flex;
  flex-direction: row;
  position: relative;
  padding: 0.375rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-weight: 400;
  cursor: pointer;
}

.file-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-btn:focus-within {
  outline: 2px solid var(--color-primary);
}

/* ---- 5. Cards, pills and tables ------------------------------------------ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--spacing-md) var(--spacing-lg);
  margin: var(--spacing-lg) 0;
}

.card.narrow {
  max-width: 26rem;
  margin-inline: auto;
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel > h2.panel-title {
  padding: 0.875rem var(--spacing-md);
  font-size: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.panel-danger {
  border-color: var(--color-danger-border);
}

.panel-danger h2 {
  color: var(--color-danger-text);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3125rem;
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--color-pill-bg);
  color: var(--color-muted);
}

.pill.warn,
.pill.editing {
  background: var(--color-warn-bg);
  color: var(--color-warn-text);
}

.pill.warn::before,
.pill.editing::before {
  content: '';
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--color-warn-dot);
}

dl.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem var(--spacing-md);
  margin: 0;
}

dl.facts dt {
  color: var(--color-muted);
}

dl.facts dd {
  margin: 0;
}

table.data {
  width: 100%;
  border-collapse: collapse;
}

table.data th,
table.data td {
  text-align: left;
  padding: 0.5rem var(--spacing-md);
  border-bottom: 1px solid var(--color-row-border);
  vertical-align: middle;
}

table.data thead th {
  background: var(--color-surface-2);
  border-bottom-color: var(--color-border);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-muted);
}

table.data tbody tr:last-child > * {
  border-bottom: 0;
}

table.data th a {
  color: inherit;
  text-decoration: none;
}

table.data tbody tr:hover {
  background: var(--color-tint);
}

table.data .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.thumb {
  max-width: 100%;
  max-height: 14rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.list-thumb {
  display: block;
  width: 4.5rem;
  height: 3.5rem;
  flex: none;
  object-fit: cover;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  background: #fff;
}

.list-thumb.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  border-style: dashed;
  background: var(--color-surface-2);
  color: var(--color-muted);
  font-size: 0.6875rem;
}

/* ---- 6. Dialogs ----------------------------------------------------------- */
dialog.modal {
  width: min(27.5rem, calc(100vw - 2rem));
  padding: 1.375rem;
  border: 0;
  border-radius: 0.625rem;
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.25);
}

dialog.modal::backdrop {
  background: var(--color-backdrop);
}

dialog.modal h2 {
  margin: 0 0 0.625rem;
  font-size: 1.1875rem;
}

dialog.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-md);
}

/* ---- 7. Auth and error pages ---------------------------------------------- */
main.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 4rem;
}

.tagline {
  max-width: 24rem;
  margin: 0 0 1.25rem;
  text-align: center;
  font-size: 1.0625rem;
  color: var(--color-muted);
  text-wrap: pretty;
}

.auth-card {
  width: 100%;
  max-width: 24rem;
  margin: 0;
  padding: 1.75rem 1.75rem 1.5rem;
}

.auth-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.auth-card .switch {
  margin: 0;
  text-align: center;
}

.error-card {
  max-width: 26rem;
  margin: 3rem auto 0;
  padding: 1.75rem;
}

.error-card .code {
  font-size: 0.8125rem;
  color: var(--color-muted);
  margin-bottom: 0.25rem;
}

.error-card h1 {
  font-size: 1.375rem;
  margin-bottom: 0.625rem;
}

/* ---- 8. Projects list and project overview ---------------------------------- */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--spacing-md);
  margin-bottom: 0.375rem;
}

.new-project {
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.new-project .head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

#projects-table td.name a {
  font-weight: 700;
  text-decoration: none;
}

#projects-table .name-cell {
  min-width: 0;
}

#projects-table .notes-line {
  display: block;
  max-width: 28rem;
  color: var(--color-muted);
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--spacing-md);
  margin-bottom: 1.5rem;
}

.project-head h1 {
  margin-bottom: 0.375rem;
}

.project-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18.75rem;
  gap: 1.25rem;
  align-items: start;
}

.project-cols > aside {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel-pad {
  padding: var(--spacing-md);
}

.panel .panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md) 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.empty-state {
  padding: 2rem 1.25rem;
  text-align: center;
  color: var(--color-muted);
}

.scenario-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.scenario-list li {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--color-row-border);
}

.scenario-row {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.scenario-row .text {
  flex: 1;
  min-width: 0;
}

.scenario-row .title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.scenario-link {
  font-weight: 700;
  font-size: 1rem;
}

.scenario-row .btn,
.scenario-row button {
  min-height: 2rem;
  padding: 0.25rem 0.625rem;
}

.scenario-edit {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
}

.scenario-edit input {
  flex: 1;
}

.scenario-confirm {
  display: flex;
  gap: 0.625rem;
  align-items: center;
  padding: 0.5rem 0.625rem;
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-sm);
  color: var(--color-danger-text);
}

.scenario-confirm span {
  flex: 1;
}

.scenario-new {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--color-tint);
  border-bottom: 1px solid var(--color-border);
}

.scenario-new input {
  flex: 1;
}

.panel-foot {
  padding: 0.625rem 1.25rem;
  font-size: 0.8125rem;
  color: var(--color-muted);
}

.block-plan-img {
  display: block;
  width: 100%;
  max-height: none;
  aspect-ratio: 1;
  object-fit: contain;
  margin-bottom: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  background: #fff;
}

.block-plan-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  margin-bottom: 0.75rem;
  border: 1px dashed var(--color-border);
  border-radius: 0.25rem;
  background: var(--color-surface-2);
  color: var(--color-muted);
}

.project-edit {
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  padding: var(--spacing-md);
  margin-bottom: 1.5rem;
}

/* ---- 9. Prepare plan -------------------------------------------------------- */
.prep-frame {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-width: 62.5rem;
}

.prep-bar {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 0.5rem 0.75rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.prep-bar .bar-sep {
  width: 1px;
  height: 1.375rem;
  background: var(--color-border);
}

.prep-bar .plan-name {
  font-weight: 600;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.steps {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.steps .step {
  border: 0;
  border-radius: 0;
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 400;
}

.steps .step + .step {
  border-left: 1px solid var(--color-border);
}

.steps .step:hover:not(:disabled):not([aria-pressed='true']) {
  background: var(--color-tint);
}

.steps .step[aria-pressed='true'] {
  background: var(--color-primary);
  color: var(--color-primary-text);
  font-weight: 600;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 50%;
  background: var(--color-pill-bg);
  color: var(--color-muted);
  font-size: 0.6875rem;
  font-weight: 700;
}

.step[aria-pressed='true'] .step-num {
  background: var(--color-surface);
  color: var(--color-primary);
}

.step .tick {
  color: var(--color-ok-text);
  font-weight: 700;
}

.step[aria-pressed='true'] .tick {
  color: var(--color-primary-text);
}

.prep-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  min-height: 0;
}

.prep-stage {
  position: relative;
  min-height: 0;
  background: var(--color-canvas);
}

.prep-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

.prep-stage canvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--color-primary);
}

.prep-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  pointer-events: none;
}

.prep-empty p {
  margin: 0.25rem 0;
}

.prep-panel {
  overflow: auto;
  padding: var(--spacing-md);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
}

.prep-panel h2 {
  margin-top: 0;
  font-size: 1rem;
}

.prep-panel fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin: 0 0 var(--spacing-sm);
}

.prep-panel dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.375rem 0.875rem;
}

.prep-panel dt {
  color: var(--color-muted);
}

.prep-panel dd {
  margin: 0;
}

.prep-foot {
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  font-size: 0.75rem;
  white-space: nowrap;
}

.prep-foot .status-text {
  flex: 1;
  margin: 0;
  padding: 0.3125rem 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prep-foot .hint-text {
  padding: 0.3125rem 0.75rem;
  border-left: 1px solid var(--color-row-border);
  color: var(--color-muted);
}

.assist {
  margin-bottom: 1rem;
}

.assist .row {
  flex-wrap: wrap;
}

.assist-chip[aria-pressed='true'] {
  outline: 2px solid var(--color-warn-dot);
}

/* ---- 10. Editor -------------------------------------------------------------- */
body.editor-page {
  height: 100vh;
  overflow-x: auto;
  overflow-y: hidden;
  font-size: 0.8125rem;
}

.ed-toolbar button,
.prep-bar button,
.prep-bar .file-btn {
  min-height: 1.875rem;
  padding: 0.1875rem 0.75rem;
}

main.editor-main {
  flex: 1;
  min-height: 0;
  max-width: none;
  margin: 0;
  padding: 0;
}

.ed-frame {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100%;
  min-width: 68.75rem;
}

.ed-body {
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr) 17.5rem;
  min-height: 0;
}

.ed-left,
.ed-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--color-surface);
}

.ed-left {
  border-right: 1px solid var(--color-border);
}

.ed-right {
  overflow: auto;
  border-left: 1px solid var(--color-border);
}

.ed-section {
  padding: 0.75rem 0.875rem 0.625rem;
  border-bottom: 1px solid var(--color-border);
}

.ed-section.grow {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-bottom: 0;
  padding: 0.75rem 0.5rem 0.5rem;
}

.ed-label {
  margin: 0 0 0.5rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-muted);
}

h2.ed-label {
  font-size: 0.6875rem;
}

.ed-label h2 {
  font-size: inherit;
  letter-spacing: inherit;
}

.ed-label .muted {
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.75rem;
}

.split {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--spacing-sm);
}

.pad {
  padding: 0 0.375rem;
}

.ed-center {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.ed-toolbar {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.ed-toolbar .bar-sep {
  width: 1px;
  height: 1.375rem;
  margin: 0 0.375rem;
  background: var(--color-border);
}

.ed-canvas {
  position: relative;
  flex: 1;
  min-height: 0;
}

.editor-stage {
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  background: var(--color-canvas);
  outline: none;
}

.editor-stage:focus-visible {
  box-shadow: inset 0 0 0 2px var(--color-primary);
}

.float-card {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  width: 19rem;
  padding: 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);
}

.float-card p {
  margin: 0.25rem 0 0.5rem;
}

.float-card .measure-out {
  font-size: 1rem;
  color: var(--color-danger);
}

.float-card .row {
  flex-wrap: wrap;
  gap: 0.375rem;
}

.view-controls {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.08);
}

.view-controls .ghost {
  min-height: 1.75rem;
  padding: 0 0.5rem;
  background: none;
  border: 0;
  color: var(--color-text);
  font-weight: 400;
}

.view-controls .ghost:hover {
  background: var(--color-tint-strong);
  color: var(--color-text);
}

.view-controls .sep {
  width: 1px;
  height: 1.125rem;
  background: var(--color-border);
}

.zoom-level {
  min-width: 2.75rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
}

/* Footer status bar */
.ed-foot {
  display: flex;
  align-items: stretch;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
}

.ed-foot .cell {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin: 0;
  padding: 0.3125rem 0.75rem;
  border-right: 1px solid var(--color-row-border);
}

.ed-foot .cell:last-child {
  border-right: 0;
}

.ed-foot .cell:empty {
  display: none;
}

.ed-foot .selected-cell {
  min-width: 13.75rem;
}

.ed-foot .status-cell {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.ed-foot .cursor-cell {
  min-width: 11rem;
  font-variant-numeric: tabular-nums;
  white-space: pre;
}

.presence-line.editing::before,
.presence-line::before {
  content: '';
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.375rem;
  border-radius: 50%;
  background: var(--color-muted);
}

.presence-line.editing::before {
  background: var(--color-warn-dot);
}

/* Conflict banner: lives in #presence but floats over the canvas. */
.presence-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem 0.5rem 0.875rem;
  border-radius: var(--radius);
  background: var(--color-pill-bg);
  font-size: 0.875rem;
  white-space: normal;
}

.presence-banner.newer {
  position: fixed;
  top: 6.5rem;
  left: 50%;
  z-index: 20;
  transform: translateX(-50%);
  background: var(--color-warn-bg);
  color: var(--color-warn-text);
  border: 1px solid var(--color-warn-dot);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);
}

.presence-banner.newer button {
  min-height: 1.75rem;
}

.save-chip {
  display: inline-block;
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  background: var(--color-ok-bg);
  color: var(--color-ok-text);
}

.save-chip[data-state='saving'],
.save-chip[data-state='unsaved'] {
  background: var(--color-pill-bg);
  color: var(--color-muted);
}

.save-chip[data-state='offline'] {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}

/* Left column: library tabs, plan rows, shapes, layers */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 0.625rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.tabs .tab {
  border: 0;
  border-radius: 0;
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 400;
}

.tabs .tab + .tab {
  border-left: 1px solid var(--color-border);
}

.tabs .tab[aria-selected='true'] {
  background: var(--color-primary);
  color: var(--color-primary-text);
  font-weight: 600;
}

.plan-list,
.item-list {
  list-style: none;
  margin: 0 0 var(--spacing-sm);
  padding: 0;
}

.plan-row {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  gap: 0.625rem;
  align-items: start;
  padding: 0.375rem 0.25rem;
  border-radius: var(--radius-sm);
}

.plan-row:hover {
  background: var(--color-tint);
}

.plan-row.unscaled .plan-thumb {
  filter: grayscale(1);
  opacity: 0.6;
}

.plan-thumb {
  width: 2.5rem;
  height: 3.125rem;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
}

.plan-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.plan-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  margin-top: 0.25rem;
}

.plan-actions button {
  min-height: 1.875rem;
  padding: 0.25rem 0.625rem;
}

.plan-actions button.icon {
  padding: 0.25rem;
  min-width: 1.875rem;
}

.plan-actions .icon-link,
.plan-actions .plan-place {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.875rem;
  min-height: 1.875rem;
  padding: 0.25rem;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--color-primary) 6%, var(--color-surface));
  color: var(--color-primary);
}

.plan-actions .icon-link:hover,
.plan-actions .plan-place:hover:not(:disabled) {
  background: color-mix(
    in srgb,
    var(--color-primary) 36%,
    var(--color-surface)
  );
}

.plan-actions button.danger-outline {
  background: color-mix(in srgb, var(--color-danger) 6%, var(--color-surface));
}

.plan-actions button.danger-outline:hover {
  background: color-mix(in srgb, var(--color-danger) 36%, var(--color-surface));
}

.shape-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.375rem;
}

.shape-btn {
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.4375rem 0.5rem;
  text-align: left;
}

.shape-btn:hover {
  border-color: var(--color-primary);
}

.swatch {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.25rem;
  border: 1px solid rgb(0 0 0 / 0.2);
}

.shape-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.shape-name {
  font-weight: 600;
}

.shape-size {
  font-size: 0.6875rem;
}

.item-row {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  margin-bottom: 0.125rem;
  border-radius: var(--radius-sm);
}

.item-row:hover {
  background: var(--color-tint);
}

.item-row.selected {
  background: var(--color-tint-strong);
}

.item-row.is-hidden .item-name {
  opacity: 0.5;
  text-decoration: line-through;
}

.item-pick {
  flex: 1;
  min-width: 0;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.375rem 0.25rem;
  text-align: left;
  background: none;
  color: inherit;
  border: 0;
  font-weight: 400;
}

.item-pick:hover {
  background: none;
  color: inherit;
}

.item-pick.plain {
  cursor: default;
  padding-inline: 0.5rem;
}

.item-row.selected .item-pick {
  font-weight: 600;
}

.item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  flex: none;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  border: 1px solid rgb(0 0 0 / 0.25);
}

/* Right column: selection properties */
.props-head {
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-sm);
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--color-row-border);
}

.props-title {
  flex: 1;
  min-width: 0;
}

.props-title .ed-label {
  margin: 0;
}

.props-name {
  display: block;
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.close-x {
  font-size: 1.25rem;
  line-height: 1;
  padding: 0 0.25rem;
  color: var(--color-muted);
}

.props-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
}

.props-body label {
  font-weight: 600;
}

.props-body input[type='text'],
.props-body input[type='number'] {
  width: 100%;
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
}

.props-body input[type='range'] {
  width: 100%;
  min-height: 0;
  padding: 0;
  accent-color: var(--color-primary);
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.prefixed {
  flex-direction: row;
  align-items: center;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  padding-left: 0.5rem;
  font-weight: 400;
}

.prefixed:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
  background: var(--color-surface);
}

.prefixed .prefix {
  width: 1rem;
  color: var(--color-muted);
}

.props-body .prefixed input {
  border: 0;
  background: none;
  outline: none;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.rot-row {
  display: flex;
  gap: 0.375rem;
}

.rot-row .prefixed {
  flex: 1;
  min-width: 0;
}

.rot-row button {
  flex: none;
  min-height: 2rem;
  padding: 0 0.625rem;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.swatch-btn {
  width: 1.5rem;
  height: 1.5rem;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgb(0 0 0 / 0.25);
}

.swatch-btn:hover {
  filter: brightness(1.1);
}

.swatch-btn[aria-pressed='true'] {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.tint-row {
  margin-top: 0.5rem;
}

.props-body input[type='color'] {
  min-height: 1.75rem;
  width: 2.5rem;
  padding: 0.125rem;
}

.readout-box {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.875rem;
  margin: 0;
  padding: 0.625rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-row-border);
  border-radius: var(--radius-sm);
}

.readout-box dt {
  color: var(--color-muted);
}

.readout-box dd {
  margin: 0;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.375rem;
}

.btn-grid button {
  min-height: 2rem;
  padding-inline: 0.25rem;
}

.locked-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
  padding: 0.5rem 0.625rem;
  background: var(--color-pill-bg);
  border-radius: var(--radius-sm);
}

.measure-out {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Keyboard shortcuts dialog */
.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-backdrop);
}

.help-card {
  width: min(40rem, calc(100vw - 2rem));
  max-height: 85vh;
  overflow: auto;
  padding: 1.25rem 1.375rem;
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 0.625rem;
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.25);
}

.help-head {
  align-items: center;
  margin-bottom: 0.875rem;
}

.help-head h2 {
  font-size: 1.0625rem;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.125rem 1.75rem;
}

.help-grid h3 {
  margin: 0 0 0.375rem;
  font-size: 0.875rem;
}

.help-grid dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3125rem 0.75rem;
  margin: 0;
}

.help-grid dd {
  margin: 0;
}

/* ---- 11. Admin ---------------------------------------------------------------- */
.totals-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin: 0;
}

.totals-strip > div {
  padding: 0.875rem var(--spacing-md);
  border-right: 1px solid var(--color-row-border);
}

.totals-strip > div:last-child {
  border-right: 0;
}

.totals-strip dt {
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-bottom: 0.25rem;
}

.totals-strip dd {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.totals-strip .sub {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-muted);
}

.admin-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.admin-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 62rem) {
  .totals-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .admin-pair,
  .project-cols {
    grid-template-columns: minmax(0, 1fr);
  }
}

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

.panel-pad h2.tight {
  margin-bottom: 0.625rem;
}

dialog.modal ul {
  margin: 0;
  padding-left: 1.25rem;
  line-height: 1.6;
}

a.btn.tiny {
  min-height: 0;
  padding: 0.1875rem 0.5rem;
  font-size: 0.75rem;
}
