/* Recipe designer — document scroll (same model as Planner; no nested board scroller). */

.td-shell {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  width: 100%;
  max-width: none;
  position: relative;
  left: auto;
  margin: 0;
  height: auto;
  min-height: 0;
  background: #f0f2f8;
}

.td-shell-header {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: flex-end;
}

.td-shell-header-actions {
  margin-left: auto;
}

.td-shell-header-main {
  flex: 1 1 16rem;
  min-width: 0;
}

.td-shell-header label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6c757d;
  margin-bottom: 0.25rem;
}

.td-shell-header .td-name-input {
  font-size: 1.15rem;
  font-weight: 700;
  border: 1px solid #ced4da;
  border-radius: 0.45rem;
  padding: 0.4rem 0.7rem;
  width: min(100%, 28rem);
  background: #fff;
  color: #212529;
}

.td-shell-header-meta {
  font-size: 0.78rem;
  color: #6c757d;
  padding-bottom: 0.45rem;
}

.td-shell-anon {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.82rem;
  color: #6c757d;
}

.td-float-panel--wide {
  /* Prefer % of the fixed backdrop — 100vw overruns the visual viewport on iOS. */
  width: min(36rem, 100%);
  max-width: 100%;
}

.td-overview,
.td-overview--panel {
  width: 100%;
  border: 1px solid #ced4da;
  border-radius: 0.45rem;
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 12rem;
  box-sizing: border-box;
}

.td-ingredients-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.td-ingredients-hint {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.85rem;
  color: #6c757d;
}

.td-ingredients-head-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  flex: 0 0 auto;
}

.td-ingredients-head-actions .icon-btn {
  width: 2.25rem;
  height: 2.25rem;
}

.td-ingredients-empty {
  margin: 0;
  font-size: 0.85rem;
  color: #6c757d;
}

.td-ingredients-grid {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.td-ingredients-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(5.5rem, 1fr) auto;
  gap: 0.4rem;
  align-items: center;
}

.td-ingredients-row--head {
  font-size: 0.72rem;
  font-weight: 600;
  color: #6c757d;
}

.td-shell-body {
  flex: 0 0 auto;
  display: block;
  min-height: 0;
  overflow: visible;
}

/* Planner-style floating pill rail (reuses .tree-rail / .icon-btn from app.css). */
.td-recipe-rail.tree-rail {
  float: right;
  margin: 0.85rem 0.55rem 1rem 0.35rem;
  z-index: 9;
  /* Same top/bottom gaps as Planner rail (via shared --rail-* vars). */
}

.td-recipe-rail .icon-btn[data-td-palette] {
  cursor: grab;
  touch-action: none;
  border-color: rgba(180, 83, 9, 0.45);
  background: #fff7ed;
  color: var(--accent-deep, #9a3412);
}

.td-recipe-rail .icon-btn[data-td-palette]:active {
  cursor: grabbing;
}

.td-shell-board-wrap {
  position: relative;
  overflow: visible;
  min-width: 0;
}

.td-shell-board {
  position: static;
  overflow: visible;
  min-height: 22rem;
  background-color: #e8ecf4;
  background-image: radial-gradient(circle, #b8c0d0 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;
}

.td-shell-board-inner {
  position: relative;
  min-width: 0;
  width: 100%;
  min-height: 0;
  box-sizing: border-box;
  /* Room for floated .td-recipe-rail (same idea as Planner .tree-body). */
  padding: 1.5rem 3.1rem 3rem 1rem;
}

.td-shell-stem {
  max-width: 48rem;
  margin: 0 auto;
  position: relative;
}

/* Stem trunk on dotted board */
.td-shell-stem.tree-spine::before {
  background: #1c1917;
}

.td-shell-status {
  flex-shrink: 0;
  padding: 0.35rem 1rem;
  font-size: 0.75rem;
  color: #6c757d;
  background: transparent;
  border-top: 1px solid #dee2e6;
}

.td-shell-status--error {
  color: #842029;
  background: transparent;
  border-top-color: #dee2e6;
  font-weight: 500;
}

.td-shell-status--ok {
  color: #6c757d;
  background: transparent;
  border-top-color: #dee2e6;
}

/* Drop zones on board */
.td-drop {
  height: 14px;
  margin: 0 auto 0.15rem;
  max-width: 12rem;
  border-radius: 999px;
  border: 1px dashed transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: height 0.12s ease, background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  position: relative;
  z-index: 2;
}

body.td-dragging .td-drop {
  height: 28px;
  margin-bottom: 0.35rem;
  border-color: rgba(0, 0, 0, 0.15);
  color: #6c757d;
  background: rgba(255, 255, 255, 0.55);
}

.td-drop.is-hot {
  height: 36px;
  border-color: #b45309;
  background: rgba(180, 83, 9, 0.14);
  color: #9a3412;
  font-weight: 700;
}

.td-node.is-selected .node-card {
  outline: 2px solid #b45309;
  outline-offset: 2px;
}

.td-card-meta {
  font-size: 0.78rem;
  color: #6c757d;
  margin-top: 0.25rem;
}

.td-card-substeps {
  list-style: none;
  margin: 0.45rem 0 0;
  padding: 0;
  display: grid;
  gap: 0;
}

.td-card-substeps li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 0.78rem;
}

.td-card-substeps li:first-child {
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  margin-top: 0.15rem;
  padding-top: 0.45rem;
}

.td-card-sub-instruction {
  color: #212529;
  opacity: 0.9;
  min-width: 0;
  word-break: break-word;
}

.td-card-sub-dur {
  flex: 0 0 auto;
  color: #6c757d;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.td-substeps-block {
  margin-top: 0.35rem;
}

.td-substeps-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.td-substeps-edit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.td-substep-edit-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 0.55rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 0.65rem;
  background: rgba(0, 0, 0, 0.02);
}

.td-substep-edit-row.is-draggable {
  cursor: grab;
}

.td-substep-edit-row.is-drag-over {
  border-color: rgba(45, 106, 79, 0.45);
  box-shadow: inset 0 0 0 1px rgba(45, 106, 79, 0.25);
}

.td-substep-drag {
  grid-row: 1 / span 3;
  align-self: center;
  color: rgba(0, 0, 0, 0.35);
  font-size: 0.95rem;
  letter-spacing: -0.08em;
  user-select: none;
  line-height: 1;
  padding: 0.2rem 0.1rem;
}

.td-substep-edit-row:not(.is-draggable) .td-substep-drag {
  visibility: hidden;
}

.td-substep-edit-row .td-float-field {
  margin: 0;
}

.td-substep-instruction,
.td-substep-duration,
.td-substep-remove {
  grid-column: 2;
}

.td-substep-remove {
  justify-self: start;
}

@media (min-width: 720px) {
  .td-substep-edit-row {
    grid-template-columns: auto 1fr auto auto;
    align-items: end;
  }

  .td-substep-drag {
    grid-row: auto;
    grid-column: 1;
    margin-bottom: 0.35rem;
  }

  .td-substep-instruction {
    grid-column: 2;
  }

  .td-substep-duration {
    grid-column: 3;
  }

  .td-substep-remove {
    grid-column: 4;
    margin-bottom: 0.15rem;
  }
}

.td-card-instruction {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  color: #212529;
  opacity: 0.85;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}

.td-card-instruction--empty {
  opacity: 0.55;
  font-style: italic;
  display: block;
  -webkit-line-clamp: unset;
  white-space: normal;
}

.td-board-empty {
  position: absolute;
  inset: 1.5rem;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
  background: rgba(240, 242, 248, 0.92);
  border: 1px dashed #adb5bd;
  border-radius: 12px;
  color: #495057;
  pointer-events: auto;
}

.td-board-empty p {
  margin: 0;
  max-width: 18rem;
}

.td-card-hint {
  margin: 0.45rem 0 0;
  font-size: 0.68rem;
  color: #878787;
}

.td-step-card {
  position: relative;
  padding-top: 2.35rem;
}

.td-card-actions {
  position: absolute;
  top: 6px;
  left: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.td-node:hover .td-card-actions,
.td-node.is-selected .td-card-actions {
  opacity: 1;
  pointer-events: auto;
}

.td-card-icon-btn {
  width: 26px;
  height: 26px;
  border: 1px solid #adb5bd;
  border-radius: 4px;
  background: #fff;
  color: #343a40;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  line-height: 1;
}

.td-card-icon-btn:hover:not(:disabled) {
  background: #e9ecef;
  border-color: #868e96;
}

.td-card-icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.td-card-icon-btn--danger:hover:not(:disabled) {
  background: #dc3545;
  border-color: #dc3545;
  color: #fff;
}

.td-card-icon-btn.node-icon-upload {
  position: relative;
}

.td-card-icon-btn.node-icon-upload .photo-count-badge {
  top: -6px;
  right: -6px;
  font-size: 0.62rem;
  min-width: 1rem;
  height: 1rem;
  line-height: 1rem;
}

.td-node.is-photo-drop-target.is-photo-drag-over .td-step-card {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
  background: color-mix(in srgb, #0d6efd 8%, #fff);
}

.td-photo-error {
  margin: 0.5rem 1.25rem 0;
}

.td-ghost {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0.92;
  background: #fff7ed;
  border: 2px solid #b45309;
  color: #9a3412;
}

/* Floating edit / open panels (pipeline-picker style) */
.td-float-backdrop {
  position: fixed !important;
  inset: 0 !important;
  z-index: 5000 !important;
  display: flex;
  justify-content: flex-end;
  align-items: stretch;
  background: rgba(15, 23, 42, 0.45);
  pointer-events: auto;
}

.td-float-panel {
  width: min(420px, 100%);
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: #fff;
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  max-height: 100%;
  overflow-x: hidden;
  animation: td-slide-in 0.18s ease-out;
}

@keyframes td-slide-in {
  from {
    transform: translateX(12px);
    opacity: 0.6;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.td-float-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #dee2e6;
}

.td-float-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.td-float-body {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overflow-x: hidden;
  padding: 1rem;
  -webkit-overflow-scrolling: touch;
}

.td-float-footer {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #dee2e6;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: #f8f9fa;
  box-sizing: border-box;
}

.td-float-field {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #6c757d;
  min-width: 0;
  max-width: 100%;
}

.td-float-field .form-control {
  font-weight: 500;
  color: #212529;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.td-float-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  color: #212529;
}

.td-float-check input {
  width: 1.1rem;
  height: 1.1rem;
}

.td-float-instruction {
  resize: vertical;
  min-height: 8rem;
  font-size: 0.9rem;
  line-height: 1.4;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.td-float-key {
  font-size: 0.78rem;
  margin: 0.25rem 0 0;
  color: #6c757d;
}

.td-share-existing-media {
  display: grid;
  gap: 0.5rem;
  justify-items: start;
  font-weight: 500;
}

.td-share-cover-preview {
  display: grid;
  gap: 0.5rem;
  justify-items: start;
}

.td-share-cover-preview img {
  display: block;
  max-width: 100%;
  max-height: 10rem;
  width: auto;
  height: auto;
  object-fit: cover;
  border-radius: 0.5rem;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #f8f9fa;
}

.td-picker-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.td-picker-item {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  border-radius: 0.65rem;
  padding: 0.7rem 0.85rem;
  display: grid;
  gap: 0.15rem;
}

.td-picker-item span {
  font-size: 0.8rem;
  color: #6c757d;
}

.td-picker-item:hover {
  border-color: #b45309;
  background: #fffaf5;
}

.td-shop-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.td-shop-check-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.td-shop-check-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 0.65rem;
  padding: 0.65rem 0.8rem;
  background: #fff;
  cursor: pointer;
}

.td-shop-check-item:hover {
  border-color: #b45309;
  background: #fffaf5;
}

.td-shop-check-item input {
  margin-top: 0.2rem;
}

.td-shop-check-meta {
  display: grid;
  gap: 0.1rem;
}

.td-shop-check-meta span {
  font-size: 0.8rem;
  color: #6c757d;
}

.td-shop-section {
  margin-bottom: 1.1rem;
}

.td-shop-section h3 {
  font-size: 0.95rem;
  font-weight: 650;
  margin: 0 0 0.45rem;
}

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

.td-shop-lines li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0.5rem;
  border-radius: 0.4rem;
  background: rgba(0, 0, 0, 0.03);
  font-size: 0.92rem;
}

.td-shop-lines .td-shop-qty {
  white-space: nowrap;
  color: #444;
  font-variant-numeric: tabular-nums;
}

.td-shop-recipe-block {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.td-shop-recipe-block:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.td-shop-recipe-block h4 {
  font-size: 0.88rem;
  margin: 0 0 0.3rem;
  font-weight: 650;
}

.td-shop-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
  width: 100%;
}

/* AI Chef styles live in css/ai-chef.css */

@media (max-width: 700px) {
  .td-shell {
    margin: 0;
  }

  .td-recipe-rail.tree-rail {
    margin: 0.55rem 0.35rem 1rem 0.25rem;
  }

  .td-shell-board-inner {
    /* Fit the phone viewport; keep right padding for the floating rail. */
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 1rem 2.85rem calc(5.5rem + env(safe-area-inset-bottom, 0px)) 0.65rem;
  }

  .td-shell-stem {
    max-width: 100%;
  }

  .td-shell-header {
    padding: 0.55rem 0.75rem;
  }

  .td-shell-header .td-name-input {
    width: 100%;
  }

  /*
    Step editor / recipe panels on phones: keep a margin so the title bar and
    bottom action menu are not flush against the screen edges (notch / home bar).
  */
  .td-float-backdrop {
    justify-content: stretch;
    align-items: stretch;
    padding:
      max(0.75rem, env(safe-area-inset-top, 0px))
      0.75rem
      max(0.75rem, env(safe-area-inset-bottom, 0px))
      0.75rem;
    box-sizing: border-box;
  }

  .td-float-panel,
  .td-float-panel--wide {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: auto;
    max-height: 100%;
    border-radius: 0.85rem;
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.28);
    overflow: hidden;
  }

  .td-float-header,
  .td-float-body,
  .td-float-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Backdrop already clears the home indicator — avoid double bottom inset. */
  .td-float-footer {
    padding-bottom: 0.75rem;
  }

  /*
    iOS Safari zooms focused inputs when font-size < 16px, which shoves the
    right-docked panel (and Done) off the visual viewport. Keep ≥16px on phones.
  */
  .td-float-field .form-control,
  .td-float-instruction,
  .td-float-field .duration-edit,
  .td-overview,
  .td-overview--panel {
    font-size: 16px;
  }
}
