.page, .page * { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding:
    max(1.75rem, env(safe-area-inset-top, 0px))
    max(1rem, env(safe-area-inset-right, 0px))
    max(2.25rem, env(safe-area-inset-bottom, 0px))
    max(1rem, env(safe-area-inset-left, 0px));
}

.page {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  line-height: 1.5;
}

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

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.header h1 a {
  color: inherit;
  text-decoration: none;
}

.header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1.25rem;
}

.hidden { display: none !important; }

.card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.25rem;
  margin-bottom: 0.5rem;
}

.section-head h2 {
  margin: 0;
}

.view-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
}

.view-toggle__btn {
  opacity: 0.45;
}

.view-toggle__btn.is-active {
  opacity: 1;
  text-decoration: underline;
}

.status {
  margin: 0;
  font-size: 0.875rem;
}

.status--error {
  color: #b91c1c;
}

a, .btn {
  color: link;
}

a:visited, .btn:visited {
  color: visited;
}

a {
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.btn {
  min-height: 2.75rem;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  font: inherit;
  line-height: 1.2;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn:hover:not(:disabled) {
  text-decoration: underline;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.dish-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

.dish-form input,
.ingredient-form input,
.dish-name-input,
.dish-servings-input,
.qty-input {
  min-height: 2.75rem;
  padding: 0.25rem 0;
  font: inherit;
  font-size: 1rem;
  border: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
  background: transparent;
  color: inherit;
  border-radius: 0;
}

.dish-form input,
.ingredient-form input {
  width: 100%;
}

.dish-form .btn,
.ingredient-form .btn {
  align-self: flex-start;
}

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

.dish-store-bought {
  font-size: 0.85rem;
  opacity: 0.55;
  align-self: center;
}

.ingredient-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  margin-top: 1rem;
}

.estimate-queue {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.estimate-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 1rem;
  padding: 0.375rem 0;
  opacity: 0.4;
  pointer-events: none;
  line-height: 1.2;
}

.estimate-name {
  font-weight: 500;
}

.estimate-meta {
  font-size: 0.875rem;
  opacity: 0.85;
}

.dish-list,
.ingredient-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dish-row,
.ingredient-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem 1rem;
  padding: 0.375rem 0;
  line-height: 1.2;
}

.dish-name-input {
  flex: 1 1 12rem;
  min-width: 0;
  font-weight: 500;
}

.dish-servings-input {
  width: 4.5rem;
  text-align: right;
  font-weight: 500;
}

.dish-servings-label {
  opacity: 0.55;
  font-size: 0.875rem;
  white-space: nowrap;
  align-self: center;
}

.dish-actions,
.ingredient-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  width: 100%;
}

.qty-input {
  width: 4.5rem;
  text-align: right;
}

.unit-input {
  width: 5rem;
  opacity: 0.75;
  font-size: 0.875rem;
}

.ingredient-name {
  flex: 1 1 8rem;
  min-width: 0;
  font-weight: 500;
  align-self: center;
}

.have-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  font-size: 0.875rem;
  opacity: 0.75;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.have-label input {
  margin: 0;
  width: 1.125rem;
  height: 1.125rem;
}

.ingredient-row--have {
  opacity: 0.45;
}

.ingredient-row--have .ingredient-name {
  text-decoration: line-through;
}

.polished-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.polished-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 1rem;
  padding: 0.375rem 0;
  line-height: 1.2;
}

.polished-line {
  font-weight: 500;
}

.polished-from {
  opacity: 0.45;
  font-size: 0.875rem;
}

.polished-cost {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  font-size: 0.875rem;
}

.polished-total {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.empty {
  margin: 0;
  opacity: 0.45;
  font-size: 0.875rem;
}

@media (min-width: 641px) {
  body {
    padding:
      max(clamp(2rem, 5vw, 3rem), env(safe-area-inset-top, 0px))
      max(clamp(1.5rem, 4vw, 2.5rem), env(safe-area-inset-right, 0px))
      max(clamp(2.5rem, 6vw, 3.5rem), env(safe-area-inset-bottom, 0px))
      max(clamp(1.5rem, 4vw, 2.5rem), env(safe-area-inset-left, 0px));
  }

  .page {
    gap: 2.5rem;
  }

  .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }

  .header h1 {
    font-size: 1.75rem;
  }

  .btn {
    min-height: 0;
  }

  .dish-form,
  .ingredient-form {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
  }

  .dish-form input#dish-name {
    width: 16rem;
  }

  .dish-form input#dish-servings {
    width: 6rem;
  }

  .ingredient-form input#ing-name {
    width: 12rem;
  }

  .ingredient-form input#ing-qty {
    width: 4.5rem;
  }

  .ingredient-form input#ing-unit {
    width: 5rem;
  }

  .dish-form input,
  .ingredient-form input,
  .dish-name-input,
  .dish-servings-input,
  .qty-input,
  .unit-input {
    min-height: 0;
  }

  .dish-list,
  .ingredient-list,
  .polished-list {
    gap: 0.875rem;
  }

  .dish-row,
  .ingredient-row,
  .polished-row {
    align-items: center;
    padding: 0;
    gap: 0.75rem 1rem;
  }

  .dish-name-input {
    flex: none;
    width: min(16rem, 100%);
  }

  .dish-actions,
  .ingredient-actions {
    width: auto;
    margin-left: auto;
  }

  .have-label {
    min-height: 0;
  }
}

@media print {
  body {
    padding: 0;
  }

  .page {
    gap: 1.5rem;
  }

  .header__actions,
  .dish-form,
  .ingredient-form,
  .status,
  .dish-actions,
  .ingredient-remove,
  .have-label,
  .view-toggle,
  #add-section {
    display: none !important;
  }

  .ingredient-row--have,
  .polished-from {
    display: none !important;
  }

  .qty-input,
  .unit-input {
    border: none;
    width: auto;
    text-align: left;
    opacity: 1;
  }

  .dish-name-input {
    border: none;
  }
}
