.page-shell:has([data-routine-builder]) {
  /* Clip horizontal decoration without creating a scrolling ancestor for the toolbar. */
  overflow: clip;
}
.routine-intro {
  max-width: 850px;
  margin: 24px 0;
}
.routine-intro h1 {
  font-size: clamp(2rem, 3.6vw, 3rem);
  max-width: none;
  line-height: 1.08;
  letter-spacing: -0.045em;
  margin: 12px 0;
}
.routine-intro p {
  max-width: 65ch;
}
.routine-builder {
  margin: 24px 0 44px;
  padding: clamp(18px, 3vw, 36px);
  background: #eef3ec;
  border-top: 3px solid #236354;
  scroll-margin-top: 95px;
}
.routine-builder h2 {
  margin: 0 0 12px;
  font-size: clamp(1.45rem, 2.6vw, 2rem);
}
.routine-builder p {
  max-width: 76ch;
}
.routine-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 20px 0;
}
.routine-builder label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  min-width: 0;
}
.routine-builder input,
.routine-builder select,
.routine-builder textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px;
  border: 1px solid #9eafa5;
  border-radius: 4px;
  font: inherit;
  font-size: 1rem;
  color: #18382f;
  background: #fff;
  box-sizing: border-box;
}
.routine-builder textarea {
  resize: vertical;
  font-weight: 400;
}
.routine-builder :focus-visible {
  outline: 3px solid #236354;
  outline-offset: 3px;
}
.routine-builder [aria-invalid="true"] {
  border-color: #9a3434;
  outline: 2px solid #9a3434;
  outline-offset: 2px;
}
.routine-builder .puppy-preview strong {
  white-space: pre-wrap;
}
.routine-assignment-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0 20px;
}
.routine-assignment-tools [hidden] {
  display: none;
}
.routine-entry-edit {
  display: block;
  min-height: 44px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: #1d6357;
  text-decoration: underline;
  text-underline-offset: 3px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.routine-builder .routine-row {
  display: grid;
  grid-template-columns: 9em 8em minmax(150px, 1fr) 120px 70px;
  gap: 10px;
  padding: 16px 0;
  border-bottom: 1px solid #ccd9ce;
  align-items: start;
}
.routine-row .routine-remove {
  align-self: end;
  border: 0;
  background: transparent;
  min-height: 44px;
  text-decoration: underline;
  cursor: pointer;
  color: #6f3131;
  font: inherit;
  font-size: 0.8rem;
}
.routine-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
}
.routine-actions button {
  min-height: 44px;
  cursor: pointer;
}
.routine-toolbar {
  position: sticky;
  top: calc(var(--routine-header-height, 80px) + 6px);
  z-index: 5;
  padding: 12px 0;
  margin: 0;
  background: #eef3ec;
  border-bottom: 1px solid #b5c5bc;
}
.routine-more {
  flex: 1 0 100%;
}
.routine-more summary {
  cursor: pointer;
  font-weight: 700;
  padding: 10px 0;
  min-height: 44px;
  box-sizing: border-box;
}
.routine-more > div {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 12px;
}
.routine-status {
  min-height: 2em;
  font-weight: 600;
  font-size: 0.9rem;
}
.routine-table-wrap {
  overflow-x: auto;
}
.routine-sample {
  margin-top: 24px;
}
.routine-sample table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}
.routine-sample th,
.routine-sample td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid #ccd9ce;
  vertical-align: top;
}
.routine-sample th:first-child {
  width: 100px;
}
.routine-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  margin: 22px 0;
}
.routine-links a {
  color: #1d6357;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.routine-notes {
  max-width: 850px;
  margin: 32px 0 60px;
}
.routine-notes h2 {
  margin-top: 32px;
}
#routine-print {
  display: none;
}
.routine-dialog {
  --routine-dialog-padding: clamp(20px, 4vw, 36px);
  box-sizing: border-box;
  width: min(700px, calc(100% - 32px));
  max-height: calc(100dvh - 40px);
  overflow: auto;
  padding: var(--routine-dialog-padding);
  border: 1px solid #b5c5bc;
  border-radius: 8px;
  background: #f8faf6;
  color: #18382f;
  box-shadow: 0 18px 70px #173e3738;
}
.routine-dialog::backdrop {
  background: #142e29a6;
}
.routine-dialog-controls {
  position: sticky;
  top: calc(-1 * var(--routine-dialog-padding));
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  margin: calc(-1 * var(--routine-dialog-padding))
    calc(-1 * var(--routine-dialog-padding)) 20px;
  padding: 8px var(--routine-dialog-padding);
  background: #f8faf6;
  border-bottom: 1px solid #ccd9ce;
}
.routine-dialog .routine-dialog-controls .button {
  width: auto;
  min-height: 44px;
  margin: 0;
  padding: 8px 16px;
}
.routine-dialog h2 {
  margin: 0 0 16px;
  font-size: 1.55rem;
  line-height: 1.2;
}
.routine-dialog p {
  line-height: 1.6;
}
.routine-dialog label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  margin: 16px 0;
}
.routine-dialog input:not([type="checkbox"]),
.routine-dialog select,
.routine-dialog textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  min-width: 0;
  padding: 10px;
  font: inherit;
  font-size: 1rem;
  border: 1px solid #9eafa5;
  border-radius: 4px;
  background: #fff;
  color: #18382f;
}
.routine-dialog textarea {
  resize: vertical;
}
.routine-entry-fields {
  display: grid;
  /* Native time fields need room for their text and picker as text grows. */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9em), 1fr));
  gap: 16px;
}
.routine-assignment-list .routine-check span {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.routine-selection-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.routine-dialog .routine-selection-tools .button {
  margin: 0;
}
.routine-dialog .button {
  margin: 8px 8px 8px 0;
  cursor: pointer;
}
.routine-dialog .routine-check {
  display: flex;
  gap: 12px;
  align-items: start;
  font-weight: 400;
  padding: 12px 0;
  margin: 0;
}
.routine-check input {
  order: -1;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  accent-color: #236354;
}
.routine-calendar-fields {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.routine-calendar-list {
  padding: 12px 0;
  border: 0;
  margin: 16px 0;
  max-height: 280px;
  overflow: auto;
  border-block: 1px solid #ccd9ce;
}
.routine-calendar-list legend {
  font-weight: 700;
  padding: 0 0 8px;
}
.routine-calendar-list .routine-check + .routine-check {
  border-top: 1px solid #dde5dc;
}
.routine-dialog :focus-visible,
#routine-shared :focus-visible {
  outline: 3px solid #236354;
  outline-offset: 3px;
}
body.viewing-routine
  > *:not(#routine-shared):not(#routine-print):not(#routine-feedback):not(
    dialog
  ) {
  display: none !important;
}
#routine-feedback {
  position: fixed;
  z-index: 60;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(520px, calc(100vw - 32px));
  box-sizing: border-box;
  padding: 12px 16px;
  border-radius: 8px;
  background: #123f35;
  color: #fff;
  font-size: 0.9rem;
  line-height: 1.5;
  pointer-events: none;
}
#routine-shared {
  max-width: 860px;
  margin: auto;
  padding: 28px clamp(16px, 4vw, 40px) 64px;
}
#routine-shared header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid #b5c5bc;
  padding-bottom: 20px;
  margin-bottom: 32px;
}
#routine-shared header a {
  font-weight: 800;
  color: #1d6357;
}
#routine-shared header span {
  font-size: 0.85rem;
}
#routine-shared h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  max-width: none;
  overflow-wrap: anywhere;
}
#routine-shared p {
  line-height: 1.6;
}
.routine-shared-list {
  list-style: none;
  margin: 24px 0;
  padding: 0;
  border-top: 2px solid #236354;
}
.routine-shared-list li {
  display: grid;
  grid-template-columns: minmax(110px, min-content) minmax(0, 1fr);
  gap: 20px;
  padding: 18px 0;
  border-bottom: 1px solid #ccd9ce;
  overflow-wrap: anywhere;
}
.routine-shared-list li p {
  margin: 0;
  white-space: pre-wrap;
}
.routine-shared-list small {
  display: block;
  margin-top: 6px;
  color: #4c6258;
}
@media (max-width: 550px) {
  .routine-calendar-fields {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .routine-dialog .button {
    width: 100%;
  }
  .routine-shared-list li {
    grid-template-columns: minmax(76px, min-content) minmax(0, 1fr);
    gap: 14px;
  }
}
@media (max-width: 850px) {
  .routine-builder .routine-row {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, max(9em, calc(50% - 5px))), 1fr));
  }
  .routine-row label:nth-child(3) {
    grid-column: 1 / -1;
  }
  .routine-row label:nth-child(4) {
    grid-column: auto;
  }
  .routine-row .routine-remove {
    grid-column: auto;
    text-align: right;
  }
}
@media (max-width: 550px) {
  .routine-form-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, max(9em, calc(50% - 8px))), 1fr));
  }
  .routine-form-grid label:first-child {
    grid-column: 1 / -1;
  }
  .routine-actions .button {
    flex: 1 1 calc(50% - 10px);
    padding-inline: 8px;
    font-size: 0.8rem;
  }
}
@media print {
  body.printing-routine {
    background: #fff !important;
  }
  body.printing-routine > *:not(#routine-print) {
    display: none !important;
  }
  body.printing-routine #routine-print {
    display: block;
    background: #fff;
    color: #000;
    font:
      10pt/1.45 Arial,
      sans-serif;
  }
  #routine-print h2 {
    font-size: 20pt;
    overflow-wrap: anywhere;
  }
  #routine-print table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    margin: 18px 0;
  }
  #routine-print th,
  #routine-print td {
    border: 1px solid #888;
    padding: 7px;
    text-align: left;
    vertical-align: top;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
  }
  #routine-print th:first-child {
    width: 16%;
  }
  #routine-print th:last-child {
    width: 22%;
  }
  #routine-print thead {
    display: table-header-group;
  }
  #routine-print tr {
    break-inside: avoid;
  }
  #routine-print p {
    font-size: 9pt;
  }
  #routine-print a::after {
    content: none;
  }
}

/* Small screens and on-screen keyboards need unobstructed editing space. */
.routine-builder.routine-compact .routine-toolbar {
  position: static;
}
.routine-more[open] > div {
  max-height: min(
    280px,
    calc(100dvh - var(--routine-header-height, 80px) - 260px)
  );
  overflow-y: auto;
}
.routine-compact .routine-more[open] > div {
  max-height: none;
  overflow: visible;
}
.routine-builder form > .button + .button {
  margin: 8px 0 8px 8px;
}
.routine-builder form > .button[hidden] {
  display: none;
}
