.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; border-bottom: 1px solid var(--br);
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); z-index: 100; gap: 12px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-right { flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; color: var(--c1); }
.brand-name { font-family: "Fraunces", serif; font-size: 20px; font-weight: 700; }

.page { max-width: 1180px; margin: 0 auto; padding: 32px 28px 100px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-title { font-family: "Fraunces", serif; font-size: 34px; font-weight: 700; margin: 0; }

.toolbar { display: flex; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar #search-input { flex: 1; min-width: 220px; }
.toolbar select { width: auto; min-width: 190px; }

.dish-filter { display: block; margin-bottom: 28px; }
.dish-filter-toggle, .dish-type-toggle {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 42px; padding: 8px 14px; border: 1px solid var(--br); border-radius: 999px;
  background: var(--bg2); color: var(--t1); font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: border-color 0.18s ease, background 0.18s ease;
}
@media (hover: hover) and (pointer: fine) {
.dish-filter-toggle:hover, .dish-type-toggle:hover { border-color: var(--c1); }
}
.dish-filter-toggle svg, .dish-type-toggle svg {
  width: 16px; height: 16px; flex: none; color: var(--t2); transition: transform 0.2s ease;
}
.dish-filter-toggle[aria-expanded="true"] svg, .dish-type-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}
.dish-filter-count {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: color-mix(in srgb, var(--c1) 18%, var(--bg3));
  color: var(--c1); font-size: 12px;
}
.dish-filter-content, .dish-type-content {
  display: grid; grid-template-rows: 0fr; opacity: 0;
}
.dish-filter-content.open, .dish-type-content.open { grid-template-rows: 1fr; opacity: 1; }
.dish-filter-options, .dish-type-content > .chip-select {
  min-height: 0; overflow: hidden; display: flex; flex-wrap: wrap; gap: 8px;
}
.dish-filter-content.open { margin-top: 12px; }
.dish-type-toggle { width: 100%; border-radius: var(--radius-sm); text-align: left; }
.dish-type-toggle > span { flex: 1; }
.dish-type-content.open { padding-top: 10px; }
.dish-type-content > .chip-select { gap: 7px; }
.dish-type-content .chip { font-size: 12px; padding: 6px 10px; }

.recipes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 20px;
}

.recipe-card {
  background: var(--bg2); border: 1px solid var(--br); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: transform 0.18s ease, border-color 0.18s ease;
  display: flex; flex-direction: column;
}
@media (hover: hover) and (pointer: fine) {
.recipe-card:hover { transform: translateY(-3px); border-color: var(--c1); }
}
.recipe-card-photo {
  aspect-ratio: 16/7; background: var(--bg3); position: relative; overflow: hidden;
}
.recipe-card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.recipe-card-photo .no-photo {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--t3);
  background: repeating-linear-gradient(135deg, var(--bg3), var(--bg3) 10px, var(--bg) 10px, var(--bg) 20px);
}
.recipe-card-fav {
  position: absolute; top: 10px; right: 10px; font-size: 16px;
  background: color-mix(in srgb, var(--bg) 70%, transparent); border-radius: 50%;
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
}
.recipe-card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.recipe-card-title { font-family: "Fraunces", serif; font-size: 18px; font-weight: 700; margin: 0; }
.recipe-card-desc { font-size: 13px; color: var(--t2); flex: 1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; margin: 0; }
.recipe-card-meta { display: flex; gap: 12px; font-size: 12px; color: var(--t3); }
.recipe-card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.recipe-card-tag { font-size: 11px; padding: 3px 8px; border-radius: 100px; background: var(--bg3); color: var(--t2); }
.recipe-card-actions {
  display: flex; gap: 6px; padding: 0 16px 14px; opacity: 0; transition: opacity 0.15s ease;
}
@media (hover: hover) and (pointer: fine) {
.recipe-card:hover .recipe-card-actions { opacity: 1; }
}
@media (hover: none) {
  .recipe-card-actions { opacity: 1; }
}
.recipe-card-actions button { flex: 1; font-size: 12px; padding: 7px; }

.recipe-view-photo-wrap {
  aspect-ratio: 16 / 7; max-height: 300px; margin: 0 0 16px;
  border-radius: var(--radius-sm); overflow: hidden; background: var(--bg3);
}
.recipe-view-photo-wrap[hidden] { display: none; }
.recipe-view-photo-wrap img { width: 100%; height: 100%; display: block; object-fit: cover; }
.recipe-view-description { margin: 0 0 16px; color: var(--t2); white-space: pre-wrap; overflow-wrap: anywhere; }
.recipe-view-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.recipe-view-tag { padding: 5px 10px; border-radius: 999px; background: var(--bg3); color: var(--t2); font-size: 12px; }
.recipe-view-section { margin: 20px 0; }
.recipe-view-section h3 { margin: 0 0 10px; font-family: "Fraunces", serif; font-size: 18px; }
.recipe-view-list { margin: 0; padding: 0; list-style: none; }
.recipe-view-ingredient {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--br); overflow-wrap: anywhere;
}
.recipe-view-ingredient:first-child { border-top: 1px solid var(--br); }
.recipe-view-amount { color: var(--t2); text-align: right; }
.recipe-view-steps { counter-reset: recipe-step; }
.recipe-view-steps li {
  position: relative; padding: 10px 0 10px 30px; border-bottom: 1px solid var(--br);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.recipe-view-steps li::before {
  counter-increment: recipe-step; content: counter(recipe-step);
  position: absolute; left: 0; top: 10px; color: var(--c1); font-weight: 700;
}
.recipe-view-section[hidden] { display: none; }

.chip-select { display: flex; flex-wrap: wrap; gap: 8px; }

.photo-upload-row { display: flex; align-items: center; gap: 10px; }
.photo-drop {
  flex: 1; min-width: 0; aspect-ratio: 16/7; max-height: 280px;
  border: 1px solid var(--br); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--t2); overflow: hidden; position: relative; background: var(--bg3);
}
.photo-drop.is-empty {
  flex: 0 0 auto; width: auto; height: 44px; aspect-ratio: auto; padding: 0 14px;
  border-style: solid; font-size: 14px; font-weight: 600;
}
.photo-drop.is-empty #photo-drop-label { display: inline-flex; align-items: center; gap: 8px; }
.photo-drop.is-empty #photo-drop-label svg { flex: none; }
.photo-drop:focus-visible { outline: 2px solid var(--c1); outline-offset: 3px; }
.photo-drop img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.photo-drop:not(.is-empty) { cursor: grab; touch-action: none; user-select: none; }
.photo-drop.is-positioning { cursor: grabbing; }
.photo-position-hint {
  position: absolute; z-index: 1; left: 8px; right: 8px; bottom: 8px; width: fit-content;
  max-width: calc(100% - 16px); margin: auto; padding: 6px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 78%, transparent); color: var(--t1);
  font-size: 12px; line-height: 1.3; text-align: center; pointer-events: none;
}
.photo-position-hint[hidden] { display: none; }
.photo-remove-btn {
  flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--br); background: var(--bg3); color: var(--t1); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
@media (hover: hover) and (pointer: fine) {
.photo-remove-btn:hover { background: #ff6b6b; }
}
.photo-remove-btn[hidden] { display: none; }
.modal textarea { max-height: min(40vh, 320px); max-height: min(40dvh, 320px); overflow-y: hidden; }
.modal textarea::-webkit-scrollbar { width: 6px; }

.field-inline { display: flex; flex-direction: column; gap: 10px; }
.switch-label { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--t1); font-weight: 400; cursor: pointer; }
.switch-label input { width: 20px; height: 20px; }

.dynamic-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.dynamic-row input, .dynamic-row textarea { flex: 1; min-width: 0; }
.dynamic-row .remove-row {
  background: none; border: none; color: var(--t3); cursor: pointer; font-size: 18px; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
}
@media (hover: hover) and (pointer: fine) {
.dynamic-row .remove-row:hover { color: #ff6b6b; background: #ff6b6b11; }
}
.dynamic-row .remove-row svg { width: 17px; height: 17px; display: block; margin: auto; }
.step-num, .ingredient-num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--bg3); color: var(--t2); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .page { padding: 22px 16px 80px; }
  .page-title { font-size: 26px; }
  .modal { padding: 18px; }
  .modal-close { top: 14px; right: 16px; }
  .user-badge span { max-width: 80px; }
  .dynamic-row input[data-role="ing-amount"] { max-width: 110px !important; }
  .dish-filter-toggle { min-height: 44px; }
  .dish-filter-options { gap: 7px; }
}

@media (max-width: 400px) {
  .page { padding-right: 12px; padding-left: 12px; }
  .page-head { align-items: flex-start; }
  .page-head > div { min-width: 0; }
  .page-head .btn { flex: 0 1 auto; max-width: 100%; }
  .toolbar { gap: 8px; }
  .toolbar #search-input { min-width: 0; flex-basis: 100%; }
  .toolbar .custom-select, .toolbar select { width: 100%; min-width: 0; }
  .recipes-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .recipe-card-body { min-width: 0; padding: 12px; }
  .recipe-card-actions { padding: 0 12px 12px; }
  .recipe-card-actions button { min-width: 0; }
  .recipe-card-tag { overflow-wrap: anywhere; }
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal {
    width: 100%; max-width: none; height: 100%; max-height: 100dvh;
    border: 0; border-radius: 0; padding: max(18px, env(safe-area-inset-top)) 14px
      max(18px, env(safe-area-inset-bottom));
  }
  .modal-close { top: max(14px, env(safe-area-inset-top)); right: 12px; }
  .modal h2 { max-width: calc(100% - 48px); overflow-wrap: anywhere; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions > button { flex: 1 1 120px; min-width: 0; }
  #ingredients-list .dynamic-row {
    display: grid; grid-template-columns: 26px minmax(0, 1fr) 40px; gap: 6px;
  }
  #ingredients-list .ingredient-num { grid-column: 1; grid-row: 1 / 3; }
  #ingredients-list input[data-role="ing-name"] { grid-column: 2; grid-row: 1; }
  #ingredients-list input[data-role="ing-amount"] {
    grid-column: 2; grid-row: 2; max-width: none !important;
  }
  #ingredients-list .remove-row { grid-column: 3; grid-row: 1 / 3; }
  #steps-list .dynamic-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) 40px; gap: 6px; }
  #steps-list textarea { min-width: 0; }
  .recipe-view-ingredient { gap: 8px; }
}

@media (max-width: 400px) {
  .confirm-overlay { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); align-items: center; }
  .confirm-overlay .confirm-modal {
    width: 100%; max-width: 380px; height: auto; max-height: calc(100dvh - 32px);
    border: 1px solid var(--br); border-radius: var(--radius); padding: 22px 18px; text-align: center;
  }
  .confirm-overlay .confirm-modal h2 {
    max-width: none; margin-right: 0; margin-left: 0; text-align: center;
  }
  .confirm-overlay .confirm-modal p { text-align: center; }
}

.custom-select {
  position: relative;
  width: auto;
  min-width: 190px;
}
.custom-select-native {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}
.custom-select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  background: var(--bg3);
  border: 1px solid var(--br);
  color: var(--t1);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
@media (hover: hover) and (pointer: fine) {
.custom-select-trigger:hover {
  border-color: var(--c1);
}
}
.custom-select-trigger svg {
  flex-shrink: 0;
  color: var(--t3);
  transition: transform 0.15s ease;
}
.custom-select.open .custom-select-trigger svg {
  transform: rotate(180deg);
}
.custom-select-panel {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--bg3);
  border: 1px solid var(--br);
  border-radius: var(--radius-sm);
  padding: 4px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.custom-select.open .custom-select-panel {
  display: block;
}
.custom-select-option {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--t1);
  font-size: 14px;
  font-family: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
.custom-select-option:hover {
  background: var(--bg2);
}
}
.custom-select-option.active {
  color: var(--c1);
  font-weight: 600;
}

/* Скелетон списку рецептів: та сама висота, що й у картки, лише пульсує прозорість */
.recipe-skel { min-height: 260px; border-radius: 18px; background: var(--bg3); animation: recipe-pulse 1.2s ease-in-out infinite alternate; }
@keyframes recipe-pulse { from { opacity: 0.45; } to { opacity: 1; } }
