@layer programming {
  .programming-app [hidden] { display: none !important; }

  .programming-app {
    min-width: 320px;
    min-height: 100vh;
    background: var(--cf-color-page);
    color: var(--cf-color-ink);
  }

  .programming-topbar {
    position: sticky;
    z-index: var(--cf-z-navigation);
    top: 0;
    display: grid;
    grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr);
    min-height: 72px;
    border-bottom: 1px solid var(--cf-color-line);
    align-items: center;
    gap: var(--cf-space-6);
    background: rgba(255, 255, 255, 0.97);
    padding: var(--cf-space-4) var(--cf-space-7);
  }

  .programming-brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: var(--cf-space-5);
    color: var(--cf-color-ink);
    text-decoration: none;
  }

  .programming-brand img {
    width: 40px;
    height: 48px;
    object-fit: contain;
  }

  .programming-brand span { display: grid; gap: 1px; }
  .programming-brand small { color: var(--cf-color-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
  .programming-brand strong { color: var(--cf-color-brand-600); font-family: var(--cf-font-title); font-size: 22px; text-transform: uppercase; }

  .programming-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(110px, 1fr));
    border: 1px solid var(--cf-color-line);
    border-radius: var(--cf-radius-sm);
    background: var(--cf-color-surface);
    box-shadow: var(--cf-shadow-control);
    padding: 2px;
  }

  .programming-nav button {
    min-height: 40px;
    border: 0;
    border-radius: 2px;
    background: transparent;
    color: var(--cf-color-muted);
    cursor: pointer;
    font: 600 13px var(--cf-font-title);
  }

  .programming-nav button[aria-selected="true"] { background: var(--cf-color-brand-600); color: #fff; }

  .programming-account {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: flex-end;
    gap: var(--cf-space-4);
    color: var(--cf-color-muted);
    font-size: 11px;
  }

  .auth-gate {
    display: grid;
    min-height: calc(100vh - 72px);
    place-items: center;
    padding: var(--cf-space-8);
  }

  .auth-panel {
    display: grid;
    width: min(420px, 100%);
    gap: var(--cf-space-6);
    border: 1px solid var(--cf-color-line);
    border-radius: var(--cf-radius-md);
    background: var(--cf-color-surface);
    box-shadow: var(--cf-shadow-panel);
    padding: var(--cf-space-8);
  }

  .auth-panel > img { width: 44px; }
  .auth-panel h1, .auth-panel p { margin: 0; }
  .auth-form { display: grid; gap: var(--cf-space-5); }
  .auth-message { border-left: 4px solid var(--cf-color-info); background: var(--cf-color-info-soft); padding: var(--cf-space-5); }
  .auth-message[data-state="error"], .auth-message[data-state="expired"] { border-color: var(--cf-color-danger); background: var(--cf-color-danger-soft); }
  .auth-detail { color: var(--cf-color-muted); font-size: 12px; }
  .auth-secondary-actions { display: flex; gap: var(--cf-space-4); }

  .programming-shell { min-height: calc(100vh - 72px); }

  .programme-commandbar {
    display: grid;
    grid-template-columns: minmax(180px, 0.7fr) minmax(220px, 1fr) auto auto auto minmax(150px, auto);
    align-items: end;
    gap: var(--cf-space-5);
    border-bottom: 1px solid var(--cf-color-line);
    background: var(--cf-color-paper);
    padding: var(--cf-space-5) var(--cf-space-7);
  }

  .save-state { align-self: center; color: var(--cf-color-muted); font-size: 11px; font-weight: 600; text-align: right; }
  .save-state[data-state="dirty"] { color: var(--cf-color-warning); }
  .save-state[data-state="error"] { color: var(--cf-color-danger); }
  .save-state[data-state="saved"] { color: var(--cf-color-positive); }

  .workspace-empty {
    display: grid;
    min-height: 420px;
    place-content: center;
    gap: var(--cf-space-3);
    color: var(--cf-color-muted);
    text-align: center;
  }

  .workspace-empty strong { color: var(--cf-color-ink); font: 700 18px var(--cf-font-title); }
  .workspace-empty p { margin: 0; }
  .programming-workspace { width: min(1500px, 100%); margin: 0 auto; }
  .view-panel { padding: var(--cf-space-7); }

  .view-heading {
    display: flex;
    min-height: 68px;
    align-items: center;
    justify-content: space-between;
    gap: var(--cf-space-6);
    border-bottom: 1px solid var(--cf-color-line);
    margin-bottom: var(--cf-space-6);
  }

  .view-heading h1, .view-heading p { margin: 0; }
  .view-heading h1 { font-size: 24px; }
  .programme-context { color: var(--cf-color-muted); font-size: 12px; }

  .programme-settings {
    display: grid;
    grid-template-columns: minmax(280px, 2fr) repeat(3, minmax(110px, 0.5fr));
    gap: var(--cf-space-5);
    border-bottom: 1px solid var(--cf-color-line);
    padding-bottom: var(--cf-space-6);
  }

  .session-tabs, .week-tabs {
    display: flex;
    overflow-x: auto;
    gap: 2px;
    align-items: center;
    padding: var(--cf-space-5) 0;
  }

  .session-tabs button, .week-tabs button {
    min-width: 100px;
    min-height: 36px;
    border: 1px solid var(--cf-color-line);
    border-radius: var(--cf-radius-xs);
    background: var(--cf-color-surface);
    color: var(--cf-color-muted);
    cursor: pointer;
    padding: var(--cf-space-3) var(--cf-space-5);
    font-weight: 600;
  }

  .session-tabs button[aria-selected="true"], .week-tabs button[aria-selected="true"] {
    border-color: var(--cf-color-brand-600);
    background: var(--cf-color-brand-600);
    color: #fff;
  }

  .session-overview-field { display: grid; gap: var(--cf-space-3); margin-bottom: var(--cf-space-5); color: var(--cf-color-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
  .session-overview-field textarea { min-height: 72px; border: 1px solid var(--cf-color-line); border-radius: var(--cf-radius-sm); padding: var(--cf-space-5); resize: vertical; }
  .build-rows, .progress-rows { display: grid; gap: var(--cf-space-4); }

  .programme-row {
    display: grid;
    grid-template-columns: 66px minmax(180px, 1.3fr) minmax(140px, 0.9fr) minmax(150px, 1fr) minmax(90px, 0.55fr) minmax(100px, 0.6fr) minmax(190px, 1.3fr);
    gap: var(--cf-space-4);
    align-items: end;
    border: 1px solid var(--cf-color-line);
    border-radius: var(--cf-radius-sm);
    background: var(--cf-color-surface);
    padding: var(--cf-space-5);
  }

  .programme-row--text { grid-template-columns: 66px minmax(0, 1fr); align-items: start; }
  .programme-row-label { align-self: start; color: var(--cf-color-brand-600); font: 700 16px var(--cf-font-title); }
  .programme-row .cf-label { min-height: 28px; }
  .programme-row textarea { min-height: 72px; }

  .progress-controls { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--cf-space-7); align-items: center; border-bottom: 1px solid var(--cf-color-line); margin-bottom: var(--cf-space-5); }
  .progress-row { grid-template-columns: 66px minmax(170px, 1.1fr) minmax(130px, 0.8fr) minmax(150px, 0.9fr) minmax(90px, 0.5fr) minmax(100px, 0.55fr) minmax(190px, 1.2fr) auto; }
  .base-value { min-height: 36px; color: var(--cf-color-muted); font-size: 12px; line-height: 1.4; }
  .use-base { align-self: end; white-space: nowrap; }

  .review-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    border-top: 1px solid var(--cf-color-line);
    border-bottom: 1px solid var(--cf-color-line);
    margin-bottom: var(--cf-space-7);
  }

  .review-stat { display: grid; gap: var(--cf-space-2); padding: var(--cf-space-6); }
  .review-stat + .review-stat { border-left: 1px solid var(--cf-color-line); }
  .review-stat span { color: var(--cf-color-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
  .review-stat strong { font: 700 24px var(--cf-font-title); }
  .review-programme { display: grid; gap: var(--cf-space-7); }
  .review-session { border-bottom: 1px solid var(--cf-color-line); padding-bottom: var(--cf-space-6); }
  .review-session h2 { margin: 0 0 var(--cf-space-5); font-size: 17px; }
  .review-table { width: 100%; border-collapse: collapse; background: var(--cf-color-surface); }
  .review-table th, .review-table td { border-bottom: 1px solid var(--cf-color-line-subtle); padding: var(--cf-space-4); text-align: left; vertical-align: top; }
  .review-table th { color: var(--cf-color-muted); font-size: 10px; text-transform: uppercase; }
  .review-table td { font-size: 12px; }
  .version-history { margin-top: var(--cf-space-8); border-top: 1px solid var(--cf-color-line); padding-top: var(--cf-space-6); }
  .version-history header { display: flex; align-items: center; justify-content: space-between; }
  .version-history h2 { font-size: 17px; }
  .version-history header span { color: var(--cf-color-muted); font-size: 11px; }
  .version-item { display: flex; justify-content: space-between; border-bottom: 1px solid var(--cf-color-line-subtle); padding: var(--cf-space-4) 0; font-size: 12px; }

  dialog { width: min(520px, calc(100vw - 32px)); border: 0; border-radius: var(--cf-radius-md); box-shadow: var(--cf-shadow-overlay); padding: 0; }
  dialog::backdrop { background: rgba(20, 24, 28, 0.55); }
  .programme-dialog { display: grid; gap: var(--cf-space-6); padding: var(--cf-space-6); }
  .programme-dialog header, .programme-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: var(--cf-space-4); }
  .programme-dialog h2 { margin: 0; font-size: 18px; }
  .programme-dialog footer { justify-content: flex-end; border-top: 1px solid var(--cf-color-line); padding-top: var(--cf-space-5); }
  .dialog-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--cf-space-4); }

  .client-finder-dialog { width: min(760px, calc(100vw - 32px)); max-height: min(820px, calc(100vh - 32px)); }
  .client-finder-shell { max-height: inherit; grid-template-rows: auto minmax(0, 1fr) auto; gap: 0; padding: 0; }
  .client-finder-shell > header, .client-finder-shell > footer { padding: var(--cf-space-5) var(--cf-space-6); }
  .client-finder-shell > footer { padding-top: var(--cf-space-5); }
  .client-finder-body { overflow: auto; padding: var(--cf-space-6); }
  .client-finder-status { min-height: 20px; margin: var(--cf-space-4) 0; color: var(--cf-color-muted); font-size: 12px; }
  .client-finder-status[data-status="error"] { color: var(--cf-color-danger); font-weight: 600; }
  .client-finder-results { display: grid; border-top: 1px solid var(--cf-color-line); }
  .client-finder-empty { margin: 0; border-bottom: 1px solid var(--cf-color-line); color: var(--cf-color-muted); padding: var(--cf-space-6); text-align: center; }
  .client-finder-result { display: grid; width: 100%; min-height: 68px; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--cf-space-4); border: 0; border-bottom: 1px solid var(--cf-color-line); background: transparent; color: var(--cf-color-ink); padding: var(--cf-space-4); text-align: left; cursor: pointer; }
  .client-finder-result:hover, .client-finder-result:focus-visible { background: var(--cf-color-brand-100); }
  .client-finder-result[aria-selected="true"] { box-shadow: inset 4px 0 0 var(--cf-color-brand-600); background: var(--cf-color-brand-100); }
  .client-finder-result span { display: grid; min-width: 0; gap: var(--cf-space-1); }
  .client-finder-result strong { overflow-wrap: anywhere; }
  .client-finder-result small, .client-finder-result code { overflow-wrap: anywhere; color: var(--cf-color-muted); font-size: 11px; }
  .client-finder-result em { color: var(--cf-color-positive); font-size: 10px; font-style: normal; font-weight: 700; text-transform: uppercase; }
  .client-release-dialog { width: min(520px, calc(100vw - 32px)); margin: auto; border: 1px solid var(--cf-color-line); border-radius: var(--cf-radius-md); background: var(--cf-color-surface); box-shadow: 0 28px 90px rgba(21, 24, 30, .28); color: var(--cf-color-ink); padding: 0; }
  .client-release-dialog::backdrop { background: rgba(21, 24, 30, .62); backdrop-filter: blur(2px); }
  .client-release-shell { gap: 0; padding: 0; }
  .client-release-shell > header, .client-release-shell > footer { padding: var(--cf-space-5) var(--cf-space-6); }
  .client-release-shell > header { border-bottom: 1px solid var(--cf-color-line-subtle); }
  .client-release-body { display: grid; gap: var(--cf-space-3); padding: var(--cf-space-6); }
  .client-release-body p { margin: 0; color: var(--cf-color-muted); }

  @media (max-width: 1050px) {
    .programming-topbar { grid-template-columns: 1fr auto; }
    .programming-nav { grid-row: 2; grid-column: 1 / -1; width: 100%; }
    .programme-commandbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .programme-commandbar .cf-button { align-self: stretch; }
    .save-state { text-align: left; }
    .programme-settings { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .programme-settings .cf-field:first-child { grid-column: 1 / -1; }
    .programme-row, .progress-row { grid-template-columns: 54px repeat(2, minmax(0, 1fr)); }
    .programme-row-label { grid-row: 1 / span 3; }
    .progress-controls { grid-template-columns: 1fr; gap: 0; }
  }

  @media (max-width: 680px) {
    .programming-topbar { position: static; grid-template-columns: 1fr; padding: var(--cf-space-4); }
    .programming-account { justify-content: space-between; }
    .programming-nav { grid-row: auto; grid-column: auto; grid-template-columns: repeat(3, 1fr); }
    .programme-commandbar { grid-template-columns: 1fr; padding: var(--cf-space-4); }
    .view-panel { padding: var(--cf-space-4); }
    .view-heading { align-items: flex-start; flex-direction: column; justify-content: center; }
    .programme-settings { grid-template-columns: 1fr 1fr; }
    .programme-settings .cf-field:first-child { grid-column: 1 / -1; }
    .programme-row, .progress-row { grid-template-columns: 42px minmax(0, 1fr); }
    .programme-row-label { grid-row: 1 / span 6; }
    .review-summary { grid-template-columns: 1fr 1fr; }
    .review-stat:nth-child(3) { border-left: 0; border-top: 1px solid var(--cf-color-line); }
    .review-stat:nth-child(4) { border-top: 1px solid var(--cf-color-line); }
    .review-table { display: block; overflow-x: auto; }
    .dialog-grid { grid-template-columns: 1fr; }
    .client-finder-shell > footer { display: grid; grid-template-columns: 1fr; }
  }
}

/* Unlayered to override the legacy builder's unlayered button defaults. */
.client-finder-results .client-finder-result {
  display: grid;
  width: 100%;
  min-height: 68px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 0;
  border-bottom: 1px solid var(--cf-color-line);
  border-radius: 0;
  background: #fff;
  color: var(--cf-color-ink);
  text-align: left;
}
.client-finder-results .client-finder-result:hover,
.client-finder-results .client-finder-result:focus-visible,
.client-finder-results .client-finder-result[aria-selected="true"] {
  background: #fbeef0;
  color: var(--cf-color-ink);
}
.client-finder-results .client-finder-result[aria-selected="true"] {
  box-shadow: inset 3px 0 0 var(--cf-color-brand-600);
}
